Skip to content

Latest commit

 

History

History
165 lines (132 loc) · 37.7 KB

TODO.md

File metadata and controls

165 lines (132 loc) · 37.7 KB

TODO

Storymap renders Vintage Story saves as a top-down map and a Mapcrafter-style isometric render. Format knowledge lives in docs/save-format/README.md, renderer research in docs/rendering.md and how blocks are read and drawn in docs/blocks.md: record every finding there, with its source, as it's made.

Feature completion

What's left for everything the game draws in a world to show on the map, in the order to do it. Block counts are for 1.22.7 with Primitive Survival, and counts of placed blocks for the largest test save. Difficulty: small is under a day in a file or two, fitting what's there; medium is a few days, or several modules, or a new data path; large is a new subsystem. Each was checked against the assets and test saves, except where it says otherwise.

Block types

World surfaces

  • Leaves' gaps, once light is read: tried and left out, as neither way was worth its cost on large.vcdbs. Each sprite pixel averages four samples of the texture. With a hole wherever at least half of them are transparent, trunks show, but with no light under trees, the forest floor shows as bright as open ground through thin canopies, so forests turn to speckle, and isometric tiles grow 21% (before and after). With a hole only where all four are, canopies stay solid and show only a few specks, and tiles grow 6% (before and after). To try again, in cubeLayers leave the holes of an all-tinted face empty and clear the sprite's fills. Leaves that share a sprite also share their holes' colour today, the first block's.
  • Decor (medium, high end): blocks kept on a face of the block beside them, in each chunk's DecorsSerialized (save format §3), a flat run of 8-byte pairs (packed position, face and rotation, then block ID), checked against all test saves. 38 block type files, 18 of them with shapes rather than SurfaceLayer. About a million in the largest save, 67% of them spotty moss, 13% rust and 6% mold; paint, plaster, banners and wallpaper aren't in any. Only 37% are on faces the view shows, and about 17% in the open, so the gain is modest, and most of it is moss. Needs decoding, a sparse list of extra looks per chunk, and drawing over a face. Cave art, wrapping onto shapes and decor on chiseled blocks would make it large; leave them out at first.

Block entities

Blocks whose look comes from their block entity. All need the first item.

  • Per-instance looks (medium, once): a block entity's data has to reach the renderer, and sprites are drawn once while preparing, so a look only known at render time needs what it's drawn from. The likely way is to keep boxes and face images in the file, tens of MiB by estimate, and give each worker a fixed cache of sprites by hash.
  • Typed shapes (medium): about 72,000 blocks that are whole coloured cubes today: clutter 51,348, rock-typed 6,925, bookshelves 4,578, crates 3,932, chests 5,009, which also always face east. A block entity's type picks a shape and textures from the block type's attributes, at an angle in 22.5° steps, in about 3,400 combinations, which suits a cache.
  • Chiseled blocks (medium): 119,906 in the largest save, whole land-coloured cubes today, in 7,302 distinct combinations, so a cache would hit about 94% of the time. Cutting each box's faces from its material's cube sprite may avoid keeping textures in the file; untested. Their decor and snow can wait.
  1. Item stacks. Decoding what a stack refers to is small: the class and id resolve for all 26,428 stacks in the largest save. Getting from a stack to something drawable is medium, as it means reading itemtypes/ as blocks are, and some stacks depend on their attributes.
  • Ground storage (medium, high end): after item stacks. 3,041 in the largest save. Firewood piles and stacked blocks are 68% of it, and need no items, so they're small to medium. A place can hold up to 12 sprites, which is new.
  1. Other block entities. Containers' contents, displays, doors and fruiting bushes, each medium or less once the above exist. Which are worth it hasn't been decided: a display's contents, 868 blocks, need item stacks, and fruiting bushes, 14,310, may already look right. Check those first.

Left out: shapes in other formats than the game's JSON, 4 blocks of one test block type, which would need triangles in world.Shape. Item 14 will show whether any mod uses them.

Top-down map

  1. Closer season tint. Grassland in style game:coloured is 15–20% darker than the game's map, forest about 10%: the game's season colour is brighter than the season map's columns average, and how it picks it is closed (docs/blocks.md). Also not followed: frost, the southern hemisphere, and block classes with their own colour (forest floor, water lilies, leaves coloured by their shape).

Top-down map

  1. Incremental rendering. Re-render only the tiles whose chunks changed since the last render, and the zoomed-out tiles above them, instead of the whole world every time. The save has no change times, so a render compares hashes:
    • Per tile: a hash of the raw rows its pixels come from (the map chunks of its columns and their ring, the chunks holding its surface, its map region), with the style, the theme's colours, the prepared blocks and the season. A tile whose hash matches isn't decoded, drawn or encoded.
    • Interrupted renders: each tile is written to a temporary file and renamed into place, and its hash is recorded at once, not at the end (perhaps in a text chunk of the PNG itself). The next render then resumes where the last one stopped.
    • Goal: an interrupted render's tiles are visible. Every tile written before the interruption shows in the viewer. Today it doesn't: the page and map.json list the tiles that exist and the viewer asks only for those, but both are written when the render finishes.
    • Zoomed-out tiles: a parent with skipped children reads them back from their PNGs, which needs a PNG decoder in the tile pipeline.
    • First: measure what reading and hashing an unchanged world costs against a full render.
  2. Measure on a large world. The largest test world has 29,192 chunks (2.79 km²), and a render's fixed cost of about 60 ms is still a quarter of its time there (docs/performance.md); confirm the threading scales on a save with many more chunks.

Memory

No allocation at runtime, TigerBeetle style (docs/rendering.md). Stage 1, no allocation per chunk, is done.

  1. Buffers sized at startup. Nothing is allocated per tile, but a render's buffers are sized and allocated when it starts; once a process renders more than once (incremental rendering), they should be set up once.
  2. Enforcement. An allocator that refuses to allocate after startup; SQLite on a fixed block (SQLITE_ENABLE_MEMSYS5).
  3. Profile a render. A render of both views of a 76 MiB save, preparing first, peaked at 571 MiB of private memory, and what takes it hasn't been measured, nor how a render's memory and time divide between its stages. Measure both on large.vcdbs first: it decides what items 4 and 5 should go after. Also try --webp and --lossy-from on it: drawing tall grass took its isometric PNG tiles from 3.57 to 4.69 GiB, and if that can't be brought down, a render needs an option to leave out kinds of blocks.

Preparing

Not a priority before feature completion and render speed. Figures are for 1.22.7 with Primitive Survival.

  1. Draw sprites on every core. Preparing draws 222,236 sprites, four rotations of 55,559, in about 9 s on one core of 14, cold or warm. Sprites don't depend on each other, but the order they go into the file and are shared must stay the same, so the file comes out byte for byte as before. Plan:
    • The main thread works out each shape's faces and key, and picks the sprites to draw: about 87,000, 73,358 shapes and 14,032 cubes.
    • Workers take the next sprite from a shared counter and draw it into a target of their own, through a window of about two sprites each, so only a few drawn sprites are held at once.
    • One writer thread takes them in order, hashes them for sharing and writes them, so nothing else touches the file or the table and they need no lock.
    • Threads get small stacks, as in item 17.
  2. Read assets on several threads. A cold prepare is mostly reading: 8,582 reads of about 6,400 distinct files, 41.5 MiB in all, took about 31 s from a fresh copy of the game, 15.7 s from an install partly out of the cache, and 0.7 s warm. Each first read costs about 4.7 ms however small the file is, waiting on the disk or the antivirus; parsing and decoding take 1.3 s, and reading a file again costs about 0.08 ms, as it's cached by then. Several reads in flight at once should cut most of the 31 s.
    • Small stacks: Zig commits a thread's whole stack on Windows, 16 MiB by default: 8 threads added 128 MiB of private memory, and 2.2 MiB with 256 KiB stacks. Io.Threaded, if reading goes through io.async, spawns its threads with the same default and keeps them for the rest of the run, drawing included, so its stack size must be set too.
    • Memory: the bytes in flight are a few files, under 1 MiB, freed before drawing starts. Each reader needs a buffer of its own, sized at startup, since the allocator isn't shared across threads; parsing on the reader threads adds a decoder's scratch to each, about 100 KiB for PNGs.

Isometric render

  1. Coloured cubes. Every block drawn as a cube in its average colour, its top, left and right faces lit differently, from one direction. Builds the isometric view without block art: tiles defined in pixels, each a slanted strip through the world's height; drawing back to front; what the game's reader gives the renderer (blocks in 3D, where the top-down map has a surface); a second projection in the viewer; and how fast it is, as it reads every chunk under a tile. Left:
    • Speed: tiles follow lines of sight now, reading 20,013 chunks for the larger world where reading every chunk under each tile took 109,168, with the same tiles. Target: the whole render of that world under 1 s on 12 cores, with textured blocks, at 32 pixels a block (16 pixels look too jagged). Now, with storymap bench --isometric --folder on AC power, the isometric view takes 8.6 s for its 4,439 tiles; summed over 14 threads, 13 s drawing, 48 s filtering PNG rows, 44 s compressing them, 7 s writing the files and 2 s shrinking tiles for the levels above (34 s filtering and 30 s compressing when the tiles aren't written). Filtering tries all five PNG filters on every row, a byte at a time.
      • Cache size: 128 chunks with blocks per worker (10 MiB: 80 KiB each, 2 bytes a block for its look and room for 4,096 liquids) and 4,096 without; measure how many a worker's tiles need at once, and how many chunks are read more than once.
      • Experiments, once blocks are textured (item 8), as textures change how tiles compress; measured with scripts/benchmark.zig --current --isometric --write:
        • Faster filtering: done, all five filters worked out together with vector instructions, picking the same filter, so the tiles are byte for byte the same: filtering took 4.0 s of the workers' time where it took 61 s, and the textured isometric view 7.7 s instead of 12.7 s, measured one after the other. Compressing, at 71 s, is now most of the work.
        • Fewer files: packs (item 11) or one file per level. Writing 4,439 files takes 7 s and slows encoding by about 40% while it runs.
        • An encoder for these tiles: deflate tuned for long repeats, as fpng does. lib/png has one, PixelDeflate (Options.compressor = .pixels), not used yet: it looks for a match only where a pixel starts, where those 4 bytes were last seen, and writes one block with its own Huffman codes. On the larger world's textured tiles, not written, compressing took 19.7 s of the workers' time where std's flate took 51.5, and the isometric view 3.03 s instead of 5.31, but the tiles take 995 MiB where std's take 813, 22% more; they decode to the same pixels with zlib. Also trying the pixel before and the pixel above found nothing more.
          • Tuned: remembering more places for each hash (Options.pixels.ways) is what helps: 2 made the tiles 935 MiB in 21.8 s of compressing, 4 892 MiB in 24.4 s, 8 863 MiB in 27.7 s, 16 847 MiB in 36.3 s and 32 840 MiB in 46.8 s, against std's 813 MiB in 48.8 s. 8 is the default, 6% larger in about half the time: the isometric view in 3.55 s instead of 5.12. Checking whether the next pixel starts a longer match made tiles no smaller, and matches starting at any byte only helped with one place per hash, so neither was kept.
        • libdeflate: done, lib/libdeflate (libdeflate 1.26) compresses the tiles at its level 1. On isometric tiles' filtered rows, one thread, it made them as small as std's flate at level_4 (+0.06%) in under a third of the time (1.98 s against 6.45 s); its level 4 made them 8% smaller in 60% of the time, and every level up to 6 was faster than std's level_4 and smaller. PixelDeflate's 8 ways were both larger and slower than libdeflate's level 2. With the same pixels in every tile, renders on a 4-core, 8-thread Xeon, tiles not written: a world of 115,896 chunks, isometric, 39.3 s instead of 69.5 s, and top-down 0.73 s instead of 0.95 s; a world of 17,224 chunks, both views, 5.83 s instead of 9.48 s, its tiles within 0.1% of std's size. RowEncoder, for --mode image, compresses bands of about 1 MiB of rows with libdeflate, chained into one stream by a patch to libdeflate (lib/libdeflate/deflate_compress.patch); on 8192 × 8192 isometric images, one thread, it built the image's stream 3.8–4.8 times as fast as std's flate, and each band left out the history of the one before for 0.05–0.09% more than compressing the whole image at once. zlib-ng 2.3.3 was tried instead and not kept: on tiles compressed whole it was 25–60% slower than libdeflate at the same size, and its level 1 makes them half as large again; on images fed a row at a time, which needs no patch, its level 2 was within 17% of libdeflate's bands either way, at sizes within 2%, and its higher levels smaller for their time, while libdeflate's time grows more evenly with its level.
        • Larger tiles: 1024 × 1024 pixels instead of 512 × 512, a quarter as many files, with fewer blocks drawn twice across tile edges, and larger runs for the encoder to find repeats in; each worker's tile buffers take 4 times the memory, and the viewer loads fewer, larger files. Tried on the larger world: 1,186 isometric files instead of 4,438; PNG 4% larger (842 MiB against 813: a 1024-pixel row is 4 KiB, so deflate's 32 KiB reaches 8 rows back instead of 16) and WebP 6% smaller (470 MiB against 499). Writing took a third of the workers' time (about 3 s against 8), but compressing grew about as much: written, the isometric view took the same time, WebP 7.30 s against 7.58 and PNG 8.57 s against 8.61 (medians of 3, taken in turn); not written, 5–9% longer, likely as 14 workers share fewer, larger tiles. Not worth it.
        • JPEG XL instead of PNG: lossless, with transparency and a very fast lossless encoder; on by default in Chrome 155 and Firefox 158, partly supported in Safari since 17, and not in Edge or Samsung Internet (caniuse, October 2026). Rendering takes --jpegxl (lib/jxl), with both formats kept until one is chosen:
          • Encoder: only libjxl 0.12.0's fast lossless encoder, lib/jxl/enc_fast_lossless.cc, one C++ file with 4 small headers, which builds unchanged with Zig's C++ compiler and adds 721 KiB to the program. The full libjxl encoder is 3.94 MiB of DLLs.
          • Results on the larger world, flat-coloured cubes: encoding took 7.4 CPU-s over 14 threads where PNG took 66, and the isometric view 1.35–1.54 s instead of 5.7 s, not written; both views end to end, written, about 2.5 s instead of 8.5 s. Full-detail tiles were 4% larger (75.2 MiB against 72.2 MiB), but all levels 46% larger (223 MiB against 153 MiB): shrunk tiles are gradients, which the fast encoder compresses poorly, so the zoomed-out levels may stay PNG or take a higher effort.
          • Effort: from effort 2 up, the encoder keeps a palette for a tile with few colours, and more effort samples more rows for better codes: effort 10 was fastest and smallest of 1, 2, 10 and 50. Textured tiles have many colours, so they should behave like effort 1, which took about 9 CPU-s and made all levels 334 MiB; still about 7 times cheaper than PNG.
          • Results on the larger world, textured cubes, effort 2: compressing took 11.2 s of the workers' time where PNG took 50.5, and the isometric view 2.07 s instead of 5.23 s, not written, measured one after the other. But the isometric tiles take 1.8 GiB where PNG's take 823 MiB, 2.2 times as much.
          • Effort doesn't help textured tiles: from 1 to 127, they took 1,789–1,805 MiB, while compressing grew from 12.0 to 19.7 s; 2 stays. The size is at full detail: level 0 is 2.25 times PNG's, level 1 2.3, evening out at level 4 and smaller above, at 0.8. A full-detail tile repeats the same block sprites, which deflate's matches find and the fast encoder, predicting each pixel from its neighbours, doesn't. So JPEG XL for the zoomed-out levels only, or an encoder that finds the repeats.
          • To adopt it: a viewer that handles browsers without JPEG XL; libjxl's working memory, allocated for every tile, under the no-allocation goal.
        • WebP instead of PNG: rendering takes --webp (lib/webp, libwebp 1.6.0's encoder), lossless at its fastest, method 0. On the larger world's textured tiles, not written, compressing took 52.5 s of the workers' time where PNG's filtering and compressing took 56, and the isometric view 5.41 s instead of 5.64, but the isometric tiles take 499 MiB where PNG's take 813, 39% less, decoding to the same pixels (libwebp may change the colour under fully transparent ones). Measured on PNG tiles with Pillow's libwebp beforehand: method 0 is as small as method 4 at full detail in a ninth of the time, but grows from level 4 up, past PNG's size at levels 6 to 8, which are a few small tiles. On Linux, the same build's WebP encoding took the workers 38.7 s where it took 57.6 on Windows, while PNG's took the same (62–64 s): libwebp allocated its working memory for every tile, which malloc on Windows handles worse. Now each worker's encoder sets it up once (lib/webp), and on Windows compressing took 35.0 s instead of 54.8, and the isometric view 4.29 s instead of 5.77, not written (medians of 5, taken in turn), the tiles byte for byte the same; on Linux, no change. Converting the pixels into a buffer of the encoder's own, instead of libwebp's copy, alone saved nothing. Since PNG is compressed with libdeflate (lib/libdeflate), WebP is the slower of the two: on a 4-core, 8-thread Xeon, both views, tiles not written, a world of 115,896 chunks took 52.9 s with WebP against PNG's 41.1 s, and one of 17,224 chunks 7.63 s against 5.98 s, 28–29% longer; written, WebP's tiles were 25–28% smaller in all (3.67 GiB against 4.90 GiB, and 424 MiB against 587 MiB), and lossy from level 2 30–33% smaller. WebP is smaller at the levels with most of the bytes and larger from level 5 or 6 up, where tiles are few and small.
        • Skipping identical tiles: encoding and writing one copy of tiles that come out the same, such as open sea. Measured on the larger world's textured PNG render: none of its 4,438 isometric tiles or 34 top-down ones is a copy of another, as even the sea's water is tinted by climate and its texture's variants change by position. Not worth it, unless worlds with large flat areas turn out common.
        • Lossy formats for the zoomed-out levels: rendering takes --lossy-from <level> with --webp, lossy WebP at quality 90, method 0, from that level up, the alpha channel still lossless. On the larger world, levels 2 and up took 21 MiB where lossless WebP's took 52 (all levels 467 MiB instead of 499), and from level 1, level 1 took 56 MiB instead of 93 (430 MiB in all); large.vcdbs the same, 617 MiB from level 2 instead of 655. It saves no time: compressing took 64–67 s of the workers' time against 65.5 lossless. By eye, at levels 1 and 2 at twice their size, fine texture softens a little and colours lose some saturation along sharp edges, as lossy WebP keeps colour at half resolution. Earlier, measured with Pillow on the larger world's PNG tiles, lossy WebP at quality 90, method 0, took about PNG's time for a third of its size at level 2 and a quarter at level 3, and AVIF at quality 80, speed 10, about the same; WebP at quality 80, method 4, a quarter of PNG's size even at full detail, in 3 times its time. Blurred block edges matter little where blocks are 8 pixels wide or less.
        • Cheaper zoomed-out levels: 32 pixels a block only at full detail.
        • Line lists instead of images, drawn in the browser: a full-detail tile is about 1,100 copies of the block sprites, each at a known place, so a tile can be what its lines of sight show (each line's sprite, the block's height for its depth, and its tint), and the viewer draws the sprites back to front with WebGL from an atlas of all of them, downloaded once. Measured on the larger world: 3,252 full-detail tiles, about 1,105 lines each, 5.1 KiB as lists, 1.2 KiB with gzip -9 (3.7 MiB in all; columns compressed no smaller than records) against 188 KiB as PNG (596 MiB); and with nothing drawn into tiles or encoded, the isometric view took 1.25 s instead of 5.4 s, still drawing into tiles and gzipping each list. Zoomed out:
          • Level 1 reuses the lists, 4 per tile, about 4,400 sprites, still light for the viewer; the browser never draws more.
          • Level 2 and up (341 of the larger world's 4,438 tiles) stay images, drawn by Storymap from the lists at their own scale, with the sprites shrunk once per level, instead of shrinking drawn tiles: each tile costs about the same, whatever its level, so the cost follows the far smaller number of tiles. Not byte for byte what shrinking gives, at the edges of blocks 8 pixels wide or less.
          • Open questions: index.html opened from the disk can't give WebGL or fetch local files; the viewer has to match the tiles' lighting, tint and rounding; shapes (item 9) that aren't whole cubes don't fit "the nearest block on each line" as simply; how a phone copes. A prototype first: the lists and atlas for one area, drawn by a small WebGL page, compared with the PNG tiles.
        • The GPU for drawing: drawing isn't what's slow, and encoding and writing stay on the CPU, so it doesn't help as long as tiles are PNGs.
    • Review the command line: whether the block width (32 pixels) is an option.
    • Review the viewer's switch between views: where it sits in each theme, its wording, and keys for it.
  2. Textured cubes. In style game (isometric/style.txt, the Plain theme's), blocks the game draws as plain cubes (drawtype cube, and grassy soil, TopSoil), leaves, as the cube the game draws them as at a distance, and liquids, drawn in their textures; other blocks as cubes in their textures' average colour until shapes (item 9). Done: preparing reads each cube block's top, south and east textures, with their overlays, and hands them to the renderer (world.CubeFaces), which draws each block's 32-pixel sprite from them. The climate and season tint, which the game's reader works out for each block where it is (tint), is multiplied into a sprite's tinted layer (grass, leaves, water) and into the colours of tinted blocks that aren't cubes. Tinting adds 0.4–0.7 s to the larger world's isometric view: 2.6 s of drawing summed over the workers, working out a tint for every tinted block drawn, and 5.5 s of compressing, as tinted tiles have more colours.
    • Textured tiles are larger: 381 MiB of isometric tiles for the larger world where relief makes 140 MiB, and the whole render takes about 0.6 s longer, most of it encoding. scripts/benchmark.zig --isometric measures these textured tiles, with game:coloured top-down.
    • Texture variants by position: a texture named with * (granite*) has variants, one picked per block by its position. Done, by vsapi's GameMath.MurmurHash3Mod; the game picks in closed code, so that it hashes the same way isn't checked. Variants make the isometric tiles 21% larger (599 MiB against 496 MiB for the larger world) and its view about 0.5 s slower, all in compressing.
  3. Shapes. A rasterizer for the game's shapes (boxes with rotations and per-face texture coordinates) draws the images of every other block: stairs, slabs, fences, plants, leaves and liquids.
    • Reading: done, into prepared blocks as boxes the blocks placed the same share (world.Shape, docs/blocks.md): 11,734 blocks of 1.22.7 with Primitive Survival, 51,007 boxes, which only drawing the sprites reads.
    • Drawing: done (docs/blocks.md): each block's shape is rasterized into its sprite when the blocks are prepared, by a rasterizer that draws into its own target of samples, so what's drawn per instance can go through a sprite of its own. A line of sight goes on past a block whose sprite doesn't fill its square; plants and low blocks are drawn in their shapes. Parts of shapes outside their block are drawn up to a block beyond its square, a tile keeping each pixel's real depth. About 20% slower on the larger world, most of it encoding the added detail.
    • Sprites when preparing: done (docs/blocks.md): every block's sprites are drawn once into the prepared blocks file, which a render maps; the file leaves out the face images and shapes, which only drawing them needs.
    • Then: see Feature completion. Done: randomDrawOffset, randomizeAxes, randomizeRotations, shapes' alternates and * bases, the plain cube's turned ones too, and texture alternates, with a texture's variants in vsapi's order.

Output

  1. Packs for hosting. Tiles written into packs instead of one file each, served by any static host with HTTP range requests, and updated by incremental renders (item 2). Copying or uploading a few packs is much faster than tens of thousands of small files.
    • Packs: each level split into packs of a block of its tiles (4 × 4, say: about 3 MiB of top-down tiles), each the tiles' PNGs end to end. A pack's name holds a hash of its contents (topdown/0/250_249.3fa9c2e1.tiles), so it never changes once written and can be cached forever.
    • Index: each tile's pack, offset, length and input hash (item 2), in one index per level that the viewer fetches when it first shows that level. The viewer asks for a tile's bytes with a range request.
    • Incremental renders: a pack with a changed tile is written again under its new name, copying its unchanged tiles' bytes from the old one; then the index is replaced in one rename, and packs neither the new index nor the previous one names are deleted, so a viewer that loaded the previous index can finish. An update uploads only the changed packs and the indexes.
    • Interrupted renders: the index still names only finished packs, so the map stays whole, and a rerun reuses the packs already written. Writing the index after each pack shows an interrupted render's tiles too.
    • Folder output stays the default: browsers make no range requests from file:// pages, so packs are for hosting.
    • Open: the pack size, measured on real updates.
    • Tried, 2 × 2: packs of the four tiles under one at the level above (<view>/<level>/<x/2>/<y/2>.pack: SMPK, each quarter's offset and length, then the PNGs or WebPs end to end, byte for byte the single files), written by the worker that built the four, so only levels below the work split, 4,329 of the larger world's 4,438 isometric tiles; 1,253 files instead of 4,438. Written, the isometric view took 9.09 s instead of 11.32 with PNG and 8.60 s instead of 11.80 with WebP (medians of 3, taken in turn, each into a fresh folder), close to 1024-pixel tiles (8.74 and 7.59 s), as writing took the workers 6–8 s instead of 27–28: creating files was slow in that sitting, at 13–29 s where it had taken 8, and packs depend far less on it. Copying the output with robocopy took 1.3–1.6 s instead of 3.1–3.6, nearly 1024-pixel tiles' 1.2–1.3.
    • Linux against Windows: the same three again, built for both and run one system after the other (medians of 3, written). On Linux (WSL 2, in its own file system), single 512-pixel files were fastest: 6.17 s with PNG and 4.88 s with WebP, packs 6.64 and 5.10 s, 1024-pixel tiles 8.39 and 5.82 s, as writing 4,438 files took the workers only 4–6 s. On Windows, packs were fastest: 6.62 s with PNG and 5.98 s with WebP, single files 7.50 and 6.86 s, 1024-pixel tiles 7.33 and 6.56 s, as writing single files took 11–17 s and packs 3–7. So packs save time only where creating files is slow; for hosting, they're still about fewer files to copy and upload.

Other games

  1. Compare with mapcrafter, once Minecraft is read as fully. Record a comparison of the same Minecraft world rendered by Storymap and by mapcrafter. A first look, on different worlds (mapcrafter 3.1, miclav's 1.21.4 fork, on a 5.68 km² Minecraft world; Storymap on a 10.96 km² VS world; both isometric at 32 pixels a block, 512 × 512 PNGs, on Linux): mapcrafter took 183 CPU-s per km² and 4.4 GiB of memory, Storymap 24 worker-s per km² and 370 MiB. Most of mapcrafter's time was encoding PNGs (58%), then drawing (25%) and reading chunks (11%); it draws more than Storymap does yet, with block shapes, see-through blocks and smooth lighting.

Platforms

  1. Run on macOS and Linux. Preparing has only been run on Windows; it compiles for Linux and macOS. Test it in CI or on a real Mac. Assets.findFolder also has no macOS locations yet, so a Mac needs --game and --data.

Testing

  1. Prepare with many mods. Preparing has only been run with one mod. Fetch something like the 100 most downloaded mods from VS ModDB and prepare with all of them, and each alone: check that nothing fails, compare memory, time and file size against the game alone, and see how close the file's limits come (docs/storyblk/spec.md), sprite_layers' 4 GiB above all. A limit reached stops a render as well as storymap prepare, rather than drawing the map without block colours, and a block's variants and alternates are assumed to fit their 16 bits.

Done

  • Zig 0.17.0 upgrade, SQLite built from the amalgamation (35484a3).
  • Palette over-read fix (092de71).
  • Blocks decoded from bit planes; greyscale top-down heightmap (a314adf).
  • Save format docs and interactive explainer (e900272, then the restructure into docs/save-format/).
  • Save path and output path as command-line arguments.
  • Tree attribute parser: every block entity in the 1.19 sample parses (src/vs/TreeAttribute.zig).
  • Saves opened with SQLite's immutable=1, so Storymap never writes next to them; a warning if the game may still be running.
  • storymap extract-assets: copied blocktypes, itemtypes, shapes, textures (minus gui/icons), worldproperties, patches and config/colormaps.json (173 MiB for 1.22.7) plus every mod, in the game's own layout. Since replaced by preparing blocks.
  • Block ID → block code mapping from gamedata (src/vs/GameData.zig); every ID in both test saves has a name.
  • No allocation per chunk (memory stage 1): one Chunk.Decoder and one fixed-size Chunk per worker, reused for every chunk (docs/rendering.md).
  • Sepia relief map: pale at sea level, darker below, paler above, with hill shading. Sea level comes from the world height (save format §6), so colours don't depend on the rest of the map: tiles will match, and different worlds look alike.
  • Water from the liquid layer: shaded by depth, saltwater (seas) apart from other water, inked coastlines; water plants don't hide the water.
  • Heights from mapchunk: the rain height map, so plants and loose stones don't hide the ground, and the terrain height for water depth. Block columns without a stored height, or whose stored height is out of date, are scanned.
  • Only the chunks holding the surface are read, fetched by key: 1,244 of 6,224 in the 1.22.7 world (docs/rendering.md).
  • Tiles: the top-down map is written as 512 × 512 tiles by a pipeline every view shares (src/tiles/tiles.zig), seamless across tile edges, with zoomed-out levels up to a single tile.
  • Only fully generated chunk columns (world-generation stage 6, Done) are drawn, like the game's own map: the rings of partly generated columns around them are left out (save format §7).
  • A viewer: index.html and map.json written beside the tiles; one page without libraries, panning and zooming with the mouse, touch and keyboard (docs/rendering.md).
  • The viewer's positions match the game's, relative to the world's centre: checked against a position the game showed and the player's position in the save (save format §2).
  • Themes: the page around the map is drawn by a theme, chosen with --theme: printed, plain or a folder of your own (docs/themes.md).
  • Chunk decoding on every core, one SQLite connection per worker; timings in docs/rendering.md.
  • Format checked against 1.22.7: schema, positions, chunk fields, block and liquid decoding and block entities all hold; differences are noted in the docs.
  • Chiseled blocks and ground storage checked on 1.22.7, in the larger test world's ruins: every block entity parses, every cuboid decodes, and the new keys are documented (save format §5).
  • Assets read in place from --game/--data (found in the standard locations by default): files read by path or listed by folder, mod zips read without unpacking, mods replacing the game's files (docs/rendering.md).
  • Preparing blocks, as Mapcrafter's Blockcrafter does: every block type of the game and mods expanded into the block codes the game makes, exactly those in the test saves, kept in one file (docs/storyblk/spec.md, vintagestory.storyblk in the current folder by default); a render prepares on demand (--prepare to force, storymap prepare alone) and reports blocks the save has that the game and mods don't (docs/blocks.md).
  • Map colours from the theme's topdown/style.txt: a colour per map type, drawn as a relief (Printed) or as the game draws its own map (plain), the game's style matching the game's own map cache on 99.65% of a test world's pixels (docs/themes.md, docs/rendering.md).
  • style game:coloured, the game's colour-accurate map without its tint: each block's texture colours worked out when preparing, with grain picked by the game's position hash, and its hill shading (docs/blocks.md).
  • Climate and season tint for style game:coloured, as the game's shader does it: the climate from the map regions, the colour maps prepared with the blocks, the season from the save's date or --season. Water matches the game's map (docs/blocks.md).
  • Command lines parsed and routed by lib/args, a library of our own, with each command's usage and help generated from what it takes.
  • Each part of Storymap a module of its own, so build.zig enforces what each may import, and the renderer can't import the game's reader (CONVENTIONS.md).
  • The game's own map styles drawn by the game's reader (src/vs/MapPainter.zig), in the game's own colours: game for the game's default, or game:shaded and game:coloured. The renderer draws only Storymap's relief, in the theme's colours. --style picks another style than the theme's (docs/themes.md).
  • No allocation per tile (memory stage 2): PNGs written by an encoder of our own (lib/png) into buffers set up before any work starts, replacing stb_image_write; tiles 20% smaller and renders 14% faster (docs/rendering.md).
  • Chiseled blocks in the top-down map, one colour per block: the relief shows the material covering most of the block's top, and the game: styles show them as the game does, the coloured one in their first material's colour and their majority material's grain (src/vs/ChiseledBlock.zig, docs/rendering.md).
  • Performance recorded per version, one table per save, by scripts/benchmark.zig, which builds each tag with the Zig release it names (docs/performance.md).
  • A modded world: the larger 1.22.7 test world was created with Primitive Survival. Mods' block and item codes carry their domain, and their IDs follow the game's (save format §6).
  • Shapes keyed by what they're drawn from: a shape's rounded faces and its images' pixels are hashed before drawing, and a match isn't drawn again, 134,846 of 138,893 repeated shapes. Drawing sprites went from about 21 s to about 9 s, and peak private memory from 93 to 106 MiB (docs/blocks.md, docs/internal/prepare-perf.md).
  • Bounds while rasterizing: the drawing area keeps the box its triangles reached, and clearing and trimming cover only that, about 2.2 s off drawing sprites, with the file byte-identical (docs/internal/prepare-perf.md).