Commit Graph

14 Commits

Author SHA1 Message Date
tobspr c54ec9fd2a Restructure buildings 2020-09-24 12:53:40 +02:00
LeopoldTal ff2274f671
fix size overflow when building sounds (#676)
Building the standalone with V8 v8 (Node v14) fails at step `sounds.musicHQ`, either by running out of memory or with the error "Invalid string length". Building with V8 v7 (Node v12) succeeds.

This is because `gulp-cache` builds a 994-MB string when [stringifying file contents](https://github.com/jgable/gulp-cache/blob/master/src/task-proxy.js#L262) to cache them. V8 v8 [limits string length to around 537 MB](https://github.com/v8/v8/blob/master/src/objects/string.h#L384), and thus cannot represent this string. (V8 v7 allows around 1074 MB, which is why the build passes on Node v12.)

But [`theme-full.mp3`](https://github.com/tobspr/shapez.io/blob/master/res_raw/sounds/music/theme-full.mp3) is only 79 MB: how did we get 1250% overhead?

Unlike plaintext files, binary files are read as buffers, but [by default](https://github.com/jgable/gulp-cache/blob/master/src/index.js#L46) `gulp-cache` stringifies them naively, producing the extremely inefficient representation:

````
[
  {
    "cwd": "/Users/tobspr/shapez.io/gulp",
    "base": "/Users/tobspr/shapez.io/res_raw/sounds/music",
    "contents": {
      "type": "Buffer",
      "data": [
        73,
        68,
        51,
        4,
        0,
        0,
…etc.
````

Fortunately, `gulp-cache` [can read base64-encoded cache files](https://github.com/jgable/gulp-cache/blob/master/src/index.js#L26).

Instead of using the default file transform function, **pass a `value` option to base64-encode the file contents**. This results in only 33% overhead on cache file size (106 MB for the largest file).

This has multiple benefits:

- Fixes the build failure
- Requires less memory (from 6 GB down to < 1 GB on my machine)
- When cache files are found, the `sounds.musicHQ` is much faster (from ~30 s down to ~4 s on my machine)
- Smaller cache files on disk
2020-09-21 08:37:50 +02:00
tobspr a8b37792e4 Allow configuring autosave interval 2020-06-22 12:09:02 +02:00
tobspr 5e83c4642b Reduce sound volume 2020-06-21 22:56:38 +02:00
Ivan Demchuk fc571e2c3e Use gulp.parallel instead of gulp-multi-process 2020-06-13 21:44:00 +03:00
Ivan Demchuk 8186da9d4c Fix gulp on Windows copying files to wrong location 2020-06-13 21:21:32 +03:00
Ivan Demchuk b2e95de0af Fix build error when sounds dir does not exist 2020-06-13 19:46:25 +03:00
Ivan Demchuk 506193b8c8 Switch to gulp 4 2020-06-13 18:59:25 +03:00
tobspr dda80568e1 Minor additional build fixes 2020-05-19 11:13:15 +02:00
tobspr 3ad359ef0b Minor build process fixes 2020-05-19 11:11:08 +02:00
tobspr a7fff0dcd2 Compress sounds into atlas 2020-05-19 11:08:28 +02:00
tobspr 7870f011b8 Initial support for themes, sound improvements 2020-05-16 09:49:00 +02:00
tobspr af0f56b5e4 Add basic sounds 2020-05-14 19:12:58 +02:00
Tobias Springer 93c6ea683d Initial commit 2020-05-09 16:45:23 +02:00