How Storymap reads a block from the game's assets and draws it: its codes, its colour on the game's map, its texture colours, its climate and season tint, its cube faces and its shapes, what preparing keeps of it, and the sprites the isometric view draws it with. The assets themselves, and how the map is drawn and tiled, are in rendering.md; sourcing conventions are the same as in save-format/README.md. vs/block-pipeline.html follows one block through these steps in a browser.
A save names its blocks by code (rock-granite), and nothing in a code says which file defines it, so every block type is expanded into its codes as the game does it, by src/vs/BlockTypes.zig (Source: vsessentialsmod's RegistryObjectTypeLoader.cs and RegistryObjectType.cs):
- A block type is a file in any domain's
blocktypes/, with acodein the file's domain unless it names another. One withenabled: false(or0) makes no blocks.inheritFromlays the file over another one first. - Variant groups each give a list of states: their own
states, or a world property's variants (loadFromProperties: "block/rock"isworldproperties/block/rock.json, in thegamedomain unless it names another;loadFromPropertiesCombinejoins several). Groups that multiply (the default) give every combination of their states; groups that add give one block per state. A block's code is the type's code and its states, joined with-; an empty state adds nothing.selectiveMultiplysplits one state of another group; nothing in 1.22.7 or Primitive Survival uses it. skipVariantsandallowedVariantsthen filter the codes, by exact code or by wildcard, as…ByTypekeys are matched (below); none in 1.22.7 or Primitive Survival is a regular expression.…ByTypeproperties take a value per variant: inblockmaterialByType: { "*-snowy": "Snow", "*": "Soil" }, the first key matching the block's code givesblockmaterial(an object merges into one already there), and…ByTypeproperties inside are resolved the same way. Keys are wildcards,*matching any run of characters with letters in either case, or regular expressions after@, matching the whole code with case: the game's and Primitive Survival's use only groups of alternatives,.and*("@.*-(aged|veryaged)-.*"), which is all Storymap supports.{rock}in a string is the variant's state of therockgroup ({wood|rock}, either). (Source: vsessentialsmodRegistryObjectType.solveByType, vsapiWildcardUtil.csandRegistryObject.FillPlaceHolder.)- Patches aren't applied. Mods can patch block types, but no patch in 1.22.7 or Primitive Survival changes which codes there are.
The result is exactly the block codes in the saves: the 14,089 of the 1.22.7 world, and the 14,781 of the larger one created with Primitive Survival, beside air and mantle, which the game registers itself. (Verified (1.22.7): both worlds' BlockIDs, code by code.)
The game's map, in its default mode, colours each block from a palette of a dozen colours, picked by a colour code (step 4 of How the game draws its own world map). A block's colour code is its mapColorCode attribute, or else its block material's default:
| Material | Colour code |
|---|---|
| Soil, Ore, Stone | land |
| Sand, Gravel | desert |
| Leaves, Wood | forest |
| Plant | plant |
| Snow, Ice | glacier |
| Water | lake |
| Lava | lava |
| anything else | land |
A block type that names no material is Stone. The palette, as the game has it: land #AC8858, desert #C4A468, forest #98844C, plant #808650, lake, ocean and lava #CCC890, glacier #E0E0C0, settlement #856844, road #805030, devastation #755C3C, and ink and wateredge #483018 for outlines. (Source: vsessentialsmod ChunkMapLayer.cs, defaultMapColorCodes and hexColorsByCode; vsapi Block.BlockMaterial.)
Both depend on the variant, through blockmaterialByType, attributesByType or a mapColorCodeByType inside attributes (Block codes). In 1.22.7 with Primitive Survival, of 14,781 blocks: land 5,400, settlement 4,010 (most building blocks set it), forest 3,634, plant 795, desert 444, lake 217, glacier 83, ocean 70 and lava 70 (the liquids), devastation 45 and road 13. Water and lake ice are lake, saltwater is ocean, glacier ice and snow are glacier. (Verified (1.22.7): every block's material and colour code, against a separate implementation of the same rules.)
For accurate mode, each block's two textures are found as the game picks them (step 5 of How the game draws its own world map), from its textures and particlesTextureCode after …ByType and placeholders: a texture's base, in the block type's domain unless it names another, is textures/<base>.png. A block type's texture, singular, is its all, over one in its textures (Source: vsessentialsmod CollectibleType.OnDeserialized); flotsam, stone paths, seagrass and kelp name theirs so. A base ending in * is the first file it starts, by name (Source: vsapi CompositeTexture.Bake); in which order the game lists them isn't checked. Overlays and alternates aren't used.
The game's atlas works out each texture's colours in closed code, so Storymap's are its own: the average weighs each pixel by how opaque it is, and the 30 grain colours are pixels picked at random, among those that aren't transparent, the same ones every time. In 1.22.7 with Primitive Survival, 1,730 textures colour 13,375 of the 14,781 blocks. The other 1,406, such as mushrooms, doors and multiblocks, have no texture Storymap could read; it colours them by their colour code instead of white.
Grass, leaves and water have grey textures, which the game colours by where they are: a block type names a climate colour map and a season colour map (climateColorMap and seasonColorMap, by variant through …ByType; soil without grass has none), by their codes in the game's config/colormaps.json, which gives each an image in textures/environment/ and its padding. In 1.22.7 there are 5 climate maps (264 × 264, a 256 × 256 map inside 4 pixels of padding, e.g. climatePlantTint, climateWaterTint) and 21 season maps (128 × 16, e.g. seasonalGrass, seasonalOak). The game's map tints in closed code (ApplyColorMapOnRgba); the game's shader for the world, shaderincludes/colormap.vsh and colormap.fsh in the install, does the same, and is what Storymap follows:
- The climate at a column is its map region's climate map (§8 of the save format), interpolated between its values 32 blocks apart, each channel rounded down: temperature and rainfall, each 0 to 255 (Source: vsapi
IntDataMap2D.GetUnpaddedColorLerped). - Height changes it: the temperature falls by 1 for every 1.5 blocks above sea level, and rises below it; the rainfall changes by half the height above sea level, and gains 5 for each block closer than 8 above sea level, so 40 at sea level and below, each kept within 0 to 255 (Source: vsapi
Climate.cs,GetAdjustedTemperatureandGetRainFall). - The climate colour is the climate map's pixel at the temperature across and the rainfall down, inside the padding.
- The season colour is the season map's at how far through the year it is, across. The shader picks the row, and shifts the column a little, by noise at each place; Storymap takes the column's average over its rows. It's mixed into the climate colour by a weight that's higher where it's colder: with x the temperature at ground level, 0.5 − cos(x / 42) / 2.3 + max(0, 128 − x) / 512 − max(0, x − 130) / 200, within 0 to 1. A tropical season map (
extraFlags: 1) is weighted by rainfall instead. - The tint multiplies the block's average colour and its grain colour each, channel by channel, rounded down (
ColorUtil.ColorMultiplyEach).
How far through the year the save is comes from gamedata's clock (§6): TotalGameSeconds over 3,600 and HoursPerDay gives the day, and a year is 12 months of the world config's daysPerMonth. 0 is the start of January. --season draws a season instead, at its middle: winter mid-January, spring mid-April, summer mid-July, fall mid-October, taking spring to be March to May. The southern hemisphere, which has its seasons half a year apart, isn't handled.
Measured against a 1.22.7 world's map cache in accurate mode, water, which has no season map, matches the climate colour within 0.01 per channel: its tint is the climate map's pixel. Over grassland, the game's tint fits a climate colour and a single season colour mixed by the shader's weight, the same season colour everywhere to within 0.04, but brighter than any column of seasonalGrass averages, so Storymap's grass is darker than the game's. Which row and column the game picks, and how it gets that colour, is an open question. Not followed either: frost, which lightens tinted blocks where it's cold; and block classes with their own colour, such as forest floor, which mixes soil and grass by its grass level, and water lilies. A block type that names no colour maps takes those of its shape's first element naming them, as branchy leaves' and ferns' do (Cube faces, Shapes). (Measured (1.22.7): the cache divided by Storymap's untinted render, per 32-block cell, against the climate there.)
The isometric view's game style draws a block's top, south and east faces in its textures, for blocks the game draws as a plain cube:
- Cubes: drawtype
CubeorTopSoil, orJSON(the default) with the shapeblock/basic/cube(the default) orblock/basic/cube-nozfight(glacier ice's, its faces inset by 0.006 of a pixel), neither turned, moved, scaled nor overlaid, and with no alternates other than such a cube (Source: vsapiBlock,DrawTypeandDefaultCubeShape). Other shapes, such as stairs' and plants', and the plain cube turned, as in sand's alternates, are drawn in them (Shapes); other drawtypes, such as surface layers, aren't drawn yet. - Liquids: drawtype
liquid, water, salt water, lava and the rest, on the plain cube, each face in itsalltexture; the game mixes in a second, moving one (specialSecondTexture), which isn't drawn. A liquid fills the whole block, even where it flows lower. A place can hold a block and a liquid at once, as underwater plants' do: where the block doesn't fill its place, the liquid is drawn too. - See-through blocks: water and ice of the render pass (
renderpass)liquidortransparent, so not lava, which shares water's pass, nor packed glacier ice, which is opaque; and all blocks of the materialGlass, as panes name no pass. Lines of sight go on past them to the first opaque block, and once a tile's other blocks are drawn, its see-through blocks are painted over them from far to near: going from one block to the next along a line of sight crosses one face, so x + y + z sorts them on every pixel. Glass is drawn in its shapes, whose sprites keep how opaque their textures are, about 20% to 35% for its panes of glass and all of its frames and lead, each pixel mixed over what's behind it by that alone. A block's own faces are layered in its sprite, so the far side of a glass block shows through the near one, and two glass blocks side by side keep the frames between them, as theMergeMaterialof theirfaceCullModeisn't followed. Water and ice are cubes. Each pixel is mixed over what's behind it, 40% opaque with something right behind it, and the rest of the way to opaque over 4 blocks along the line of sight (1 - 0.6 · e^(-blocks / 4)), as there's no light to darken deep water. A face that touches its own material isn't painted, so a stack of water is one surface whose depth is the distance to what's behind it, while water shows under ice, and ice through the water beside it, with no limit on the layers. - Low blocks: a block whose selection box (
selectionBox, elsecollisionSelectionBox) reaches less than half a block high, such as loose stones, boulders, flints, ores and sticks, coral, crops and closed trapdoors, isn't drawn as a cube, as a whole cube would make it look far larger than it is, nor are plants: in the relief style they aren't drawn, and in thegamestyle only in their shapes. Thin layers of sand and gravel are drawn as whole blocks; snow layers are drawn at their height (Shapes). 1,974 of 1.22.7's blocks are low. - Leaves: up close, leaves are crossed planes of large leaves, but the shape the game draws them in at a distance (
lod0Shape, e.g.block/plant/leaves/normal-lod0) holds a plain cube, an element from 0 to 16 on every axis, in their small leaves. A block whose shape at a distance holds such a cube, unturned, is drawn as it, each face in the texture the element names for it. Branchy leaves name their colour maps on the element rather than the block type, and are tinted by those, in the coloured map too. The texture's holes take the block's average colour, tinted. 237 of 1.22.7's 245 leaves are cubes this way; narrow leaves, such as cypress's, have none. - A face's texture is the one named for it (
up,south,east), else its group's (verticalsfor top and bottom,horizontalsfor the sides), elseall, found as for Texture colours. Its overlays are drawn over it, each stretched or shrunk to its size. Itsrotation, 90, 180 or 270, turns it and its overlays anticlockwise, as planks and logs lying different ways name; a variant from a base ending in*keeps the rotation, and an alternate has its own. A shape's textures are turned the same way. - Variants: a texture can have several, so a field of one block doesn't repeat one sprite, in the order vsapi
CompositeTexture.Bakelists them (andBlock.FastTextureVariantsfor cubes): its base, or for a base ending in*, the first file it starts, by name, under the texture's overlays; then each of itsalternates, the first file of the alternate's base under the alternate's own overlays, as ores show one of three overlays; then the other files its base starts, without the texture's overlays, as reef ledges' coral shows its overlay only on the first of 32. A block shows the variant its position picks, by vsapi's position hash,GameMath.MurmurHash3Mod(x, y, z, count), the same for every face, with y as 0 for a block type whoserandomizeAxesisxz, so a tall plant shows the same variant all the way up; a layer with fewer variants than the block's others counts round again. The game picks in closed code, so whether it hashes the same way isn't checked. A variant that can't be read is left out. - Tint: a block with a climate or season colour map has every face tinted, except grassy soil (drawtype
TopSoil: soil, forest floor, peat, clay), which is its soil's texture with grass over it. The grass is itsspecialSecondTexture, twice as wide as high: the right half is the top, the left half the sides' fringe. Only the grass is tinted.
In 1.22.7 with Primitive Survival, 2,307 of the 14,781 blocks are cubes, 352 of them liquids, with 2,961 distinct face images; 1,248 cubes have variants, up to 10.
The renderer draws each cube once, when the blocks are prepared (Sprites), into a 32-pixel square (src/renderer/isometric.zig, cubeLayers): each pixel of a face averages its texture at 2 × 2 points across it, a 32-texel texture giving about 4 texels a pixel, and is lit as the relief style lights that face. The plain and tinted layers stay apart: where a block is drawn, its tinted layer is multiplied by the block's tint there (Climate and season tint, steps 1 to 4, at the block's own height) and drawn over the plain one by how much of each pixel it covers. Blocks that aren't cubes take their average colour times the tint.
Every other block of drawtype JSON, also JSONAndSnowLayer and JSONAndWater, the latter without its water, is read in its shape (src/vs/BlockTypes.zig, Shapes), as boxes placed in the block (world.Shape), and the isometric view's game style draws it in that shape.
-
The block type's
shape(vsapiCompositeShape) names a shape file,shapes/<base>.jsonin the block type's domain unless it names another, or with a base ending in*, several (see Alternates below). ItsrotateX,rotateYandrotateZturn the whole shape about the block's middle, as vsapiMeshData.Rotatedoes, thenscalescales it about the middle andoffsetX,offsetYandoffsetZmove it; in which order the game does those three isn't checked.quantityElementskeeps that many of the first elements,selectiveElementsonly the elements it names andignoreElementsleaves them out, an element by its name or its path from the top (Stem/Leaf), and with/*everything under it too. Itsoverlaysadd their shapes' elements. -
An element is a box from
fromtoto, in sixteenths of a block, turned about itsrotationOriginbyrotationX, thenrotationY, thenrotationZ, in degrees, and scaled byscaleX,scaleYandscaleZ; itschildrenare placed within it, from itsfrom(vsapiShapeElement.GetLocalTransformMatrix, animation version 0, andMat4f.RotateByXYZ). Elements are turned by any angle: 6,349 different angles in the game's block shapes.shade: falseleaves its faces unlit, and an element naming aclimateColorMaporseasonColorMapis tinted by it; a block type naming none takes the first element's (226 blocks, such as berry bushes and ferns). -
A face is keyed by the first letter of its name (
n,e,s,w,u,d), and left out ifenabledis false. Itsuvis a rectangle in the shape'stextureWidth×textureHeight(16 × 16 by default), or the texture's own size intextureSizes; without one, the face takes as much of the texture as it's big, from the corner. Which corner of the rectangle goes to which corner of the face, and howrotationshifts them a quarter turn at a time, follow the Model Creator, which draws shapes as the game does (Face.java,CubeVerticesandcubeUVCoords); the game's own tesselator is closed. -
A face's texture is named with a
#: the block type's texture of that name, or for a face named after a side, as stairs' are, its group's (horizontals,verticals); else the block type'sall; else the shape file's own of that name; else the block type'ssides, as cobblestone stairs name theirs. The game picks them for blocks in closed code; what it puts on display takes them in this order (vssurvivalmodBEBehaviorDisplay), and blocks show the same: snow on plank stairs, which name onlyall, is drawn in planks (VintageStory-Issues #9794), as it was on brick stairs and slabs until they named their shapes'snowcoveragain beside theirall(#4258), while cobblestone stairs and plank slabs, which namesides, keep their snow. Items are drawn the other way round, their shape's own texture before theirall. A face whose texture is none of these isn't drawn. -
Layers: a drawtype
BlockLayer_1toBlockLayer_7is a layer that many eighths of a block high, as snow layers, charcoal piles and embers are, drawn as the shapeblock/basic/layers/2voxelto14voxel, whatever shape the block type names: embers name the plain cube. Its top shows its whole texture, and its sides the bottom of theirs (Source: vsapiEnumDrawType). -
Crosses: a drawtype
Crossis two planes corner to corner, each 1.41 blocks high and showing all of its texture, one in the block type'snorthand the other in itssouth, drawn as the shapeblock/basic/cross, whatever shape the block type names. All 28 blocks drawn so are tall grass, 21 of them under snow (see below) (Source: vsapiEnumDrawType). -
Under snow: a drawtype
JSONAndSnowLayerorCrossAndSnowlayerdraws its shape or cross with a box of snow around its foot, 1/8 of a block high, andCrossAndSnowlayer_2to_42/8 to 4/8. The box fills the block's place, doesn't move or turn with the block, and is the first sprite ofsnowlayer-1tosnowlayer-4, so it's a sprite of its own: the block state'scover_sprite(the spec). The game draws it where the block below has a solid top (vsapiBlock.AllowSnowCoverage). Storymap draws it where a solid block below fills its place, which it knows from the sprites: on a cube, but not on a slab, a fence, another plant or a liquid. 1,075 blocks of 1.22.7 with Primitive Survival have one, such as flowers, saplings, fences and loose stones. -
A part named by a behaviour: a block type's
MPArchimedesScrewbehaviour names astaticShapePart, the part of it that doesn't turn, and it's read as one of the shape's overlays. The Archimedes screw'sshapeis only its shaft, and this is its hull (Source: vssurvivalmodBEBehaviorArchimedesScrew). -
Blocks placed the same share their boxes: a shape file placed by the same composite shape gives the same boxes, and each block only names its textures for them.
-
Alternates: a shape with
alternates, or whose base ends in*, gives a block several shapes, of which each block of it is drawn in one, picked by where it is. They're listed as vsapiCompositeShape.LoadAlternateslists them:- the shape itself, its base's first file if that ends in
*, or the plain cube if it stands for none; - its base's other files, turned, scaled and picking elements as the shape does, but neither moved nor overlaid;
- each of its
alternates, or for one whose base ends in*, each file it stands for, as above. An alternate without a base takes the shape's,*and all, and withoutquantityElements,selectiveElementsorignoreElements, the shape's; its turn, offset, scale and overlays are its own, not added to the shape's.
A shape listed twice is picked twice as often, as herbs' and lupins' are. A base ending in
*stands for every shape file in its domain whose path starts with it, in folders below too, whatever its format, each then read as the game's JSON; the game lists them in no set order, and Storymap takes them by name. A block picks its shape by the hash that picks its textures' variants (Cube faces),MurmurHash3Mod(x, y, z, count), with y as 0 for anxzblock, so with as many shapes as variants, a block's shape and variant go together. The game picks in closed code; the open-source berry bush, which draws its own shape in place of the game's once pruned, so has to pick the same, picks this way (BlockBerryBush). 1,718 blocks of 1.22.7 with Primitive Survival pick from several shapes, up to 40 (development plates), such as ferns, loose stones, flowers, coral and berry bushes; 86 of them, such as sand, gravel and old polished rock, pick from four plain cubes turned a quarter at a time, which turns their textures. Not drawn: the alternates of leaves, which are drawn as their cube at a distance (Cube faces). - the shape itself, its base's first file if that ends in
-
Moved off the middle: a block type's
randomDrawOffset,truefor 1 or a number, moves each block of it east by (GameMath.oaatHash(x, 0, z)% 12) / (24 + 12 ·randomDrawOffset) of a block and south by the same with 1 for 0, the remainder keeping the hash's sign, so by up to 11/36 of a block either way, as vsapiBlock.GetSelectionBoxesmoves its selection box; that the game moves the shape by the same isn't checked. A block that has an offset and whoseclassisBlockPlant,BlockCrop,BlockBambooor one built on them takes it from itsoverrideRandomDrawOffsetattribute instead, if it names one: 2 for tall grass, 5 for bamboo and 14 for berry bushes and amaranth (vssurvivalmodBlockPlant). Only those classes' code reads the attribute, so it does nothing on other blocks:devastationgrowth, which names no class, keeps its offset of 1, and fruiting bushes, which have no offset, stay in the middle. Storymap lists the game's classes by name, so a mod's own class built onBlockPlantkeeps its block type's offset. The renderer moves the block's sprite by it, to the nearest pixel. 476 blocks of 1.22.7 with Primitive Survival are moved so, such as flowers, tall grass, saplings and coral. -
Turned: a block type's
randomizeRotationsturns each block of it about the vertical line through the middle of its place, by one of 8 angles, −22.5° + 45° · i from east towards north, as vsapiTesselationMetaData.randomRotationslists them, with i picked by where it is:MurmurHash3Mod(x, y, z, 8), with y as 0 for anxzblock, the hash that picks its variant (Cube faces), so with 8 of each, a block's turn and variant go together. The game turns blocks in closed code. The renderer draws such a shape in each of the 8 turns. 727 blocks of 1.22.7 with Primitive Survival are turned so, such as coral, crops, flowers and mushrooms.
In 1.22.7 with Primitive Survival, 11,820 of the 14,781 blocks have shapes this way, 21,749 with their alternates, the same file placed the same way 3,620 times over, in 67,198 boxes, up to 722 for one shape; 57 of the textures their faces name are none of the above. 173 more blocks have shapes with nothing to draw (block/basic/nothing, block/basic/invisible), and are drawn as nothing: the game draws most of them from their block entities, such as ground storage, piles, pies and pit kilns, and the rest are the unseen parts of multiblock structures. About 38% of the boxes the blocks are drawn in reach outside their block, such as plants' turned planes. Not followed yet: shapes in other formats than the game's JSON (4), and elements' disableRandomDrawOffset, which leaves an element neither moved nor turned (vsapi ShapeElement), in 2 shape files, papyrus in ice, that no block uses. The drawtype read without a shape: SurfaceLayer (336 blocks).
The renderer draws a block's shape into its own sprite (src/renderer/isometric.zig, shapeSprite), once, when the blocks are prepared (Sprites).
- Faces are drawn as two triangles each, at 2 × 2 points for each pixel, nearer covering farther within the block (
src/renderer/rasterizer.zig). A point shows the texel there, if it's at least half opaque, so a plant's leaves leave the gaps between them. A pixel shows if at least half its points do, in their average colour, plain and tinted layers apart, as a cube's are. - Light is a cube's, top, south and east, mixed by how much the face faces up, south and east; a face turned away from the viewer, as a leaf seen from behind, is lit as though turned towards it. An element with
shade: falseis lit as a top. - Parts outside the block are drawn too, such as the tips of plants wider than their block, up to a block beyond the cube's square each way, the sprite trimmed to what it shows. In the game's block shapes the larger test world has, most sprites stay in their square or reach a pixel or two beyond it; ferns and tall grasses reach up to 30. A tile draws the blocks on lines of sight up to a block beyond its edges too, so a sprite reaching into it isn't cut there; that costs no time measurably, as encoding takes most of it.
- Depth: each pixel of a sprite keeps how far into its block its point is, x + y + z, as a cube's pixels do by the face they're on, and a tile keeps each pixel's depth in 256ths of a block, so a part reaching into a neighbour's square shows in front of or behind it as it is. A cube's faces are never less than a 64th of a block apart at the middle of a pixel, so cubes alone come out the same as when a whole block's x + y + z ordered them. Only a part reaching out from behind a block that hides the rest of it on the same line isn't drawn, as the line stops there.
- What's behind shows: a line of sight goes on past a block whose sprite doesn't cover the whole square, and draws the blocks behind it where it shows nothing, down to one that covers it.
Drawing shapes made the larger test world's isometric view about 11% slower, measured against the same render without them, and drawing their parts outside the block about 8% more, most of it in encoding the added detail.
Everything a map needs from the assets is prepared once, by src/vs/Prepared.zig, into one file, specified in storyblk/spec.md: vintagestory.storyblk in the current folder, or the one given (--blocks when rendering, the argument of storymap prepare). For each block, that's its code, its material, its colour code (Block colours), its texture colours (Texture colours), its colour maps (Climate and season tint), how high it reaches and how it's placed (Cube faces, Shapes), and its sprites (Sprites). Colour maps are kept as their pixels, so a render reads them in place. A block's face images and shapes aren't kept, as only drawing its sprites needs them.
- One file for the game and mods: the file's hash changes with how Storymap reads the assets and draws sprites, the game version and the mods (their names, sizes and times), so updating any of them prepares the file again.
- On demand: a render prepares the file if it isn't there or its hash differs.
--prepareprepares it again anyway, andstorymap preparedoes only that, and needs the game. - Without the game, a render reads the file as it is, without its hash, so a file copied from another machine works. One made differently, by another version of how Storymap reads the assets or draws sprites, or for another block width, isn't used: a warning names the difference, and the map is drawn without block colours.
- Never left half written: the file is written beside its path, as
<file name>.<process id>.partial, and renamed over it once complete, and a partial file is removed if writing fails. A file that doesn't start withSTORYBLKis never replaced. A partial file left by a killed writer is removed by a later prepare, once it's an hour old. A file a render has mapped can be replaced: the render goes on reading what it mapped. - A save's unknown blocks are reported: those of mods that aren't installed, and any others the file doesn't have.
Preparing 1.22.7 with Primitive Survival takes about 2 s, for 14,781 blocks, and drawing their sprites about 9 s more, at a peak of 106 MiB of memory beside the file: block type files are read one at a time, each freed before the next, with only how each shape file is placed kept between them, and sprites are written out as they're drawn.
The isometric view's sprites of every prepared block are drawn while preparing, once for each of the view's 4 rotations, into the file's sprites and sprite_layers sections (src/renderer/Sprites.zig): the game's reader prepares the blocks, and the renderer, which is all a sprite depends on besides them, draws each block's cube or shape (Cube faces, Shapes) in every variant of its textures, a block with several shapes in each of them, and a turned shape in each of its turns, blocks with the same faces, or the same shapes and textures turned alike, sharing sprites. A render maps the file and reads the sprites where they are, so a sprite costs it neither drawing nor memory of its own, and the operating system reads in only the pages of the sprites its world has.
- Written as they're drawn: how many sprites there are is worked out first (
isometric.planSprites), which givessprite_layersits place in the file. Sprites are then drawn in place in a 1 MiB buffer, written to the file whenever it's full (src/renderer/FileBuffer.zig). The sections before it are written last. - Every rotation: a file always has all 4, so one copied to a machine without the game can draw any of them.
- Pixels shared: sprites that come out the same keep one copy of their pixels, found by hashing each sprite as it's drawn. A rotation is mostly other sprites seen again: a turned plant at 90° is the same plant two turns along, and stairs facing north at 90° are the stairs facing west at 0°.
- Shapes not drawn twice: before a shape is drawn, what it's drawn from is hashed: its faces, with their corners rounded so faces placed by different arithmetic in the same place match, and their images by their pixels, so copies of a texture match too. A shape that matches one drawn before is that sprite again, which catches 96% of the repeats without drawing them. It also makes a shape reached by two routes, such as a plant's turn 2 at 0° and its turn 0 at 90°, look the same in both: drawn separately, float noise could break ties between its crossing faces differently, changing a few pixels.
- Its own version:
spritesandsprite_layerscarry the version of how sprites are drawn (Sprites.generatorVersion), which goes into the file's hash, so a change prepares the file again. - Laid out to be read in place: everything in the two sections lies at a multiple of its own size, in little-endian order (spec §3).
- Size: for 1.22.7 with Primitive Survival, 55,559 sprites in each rotation, 82,273 of the 222,236 different, 310 MiB of pixels, drawn in about 9 s; without sharing, it would be 748 MiB. A single rotation is 187 MiB; without the shapes' alternates, it was 108 MiB, and without their turns too, 88 MiB.