Store chunk tile data as a dense minified grid instead of per-tile objects
Cuts the six overworld chunk JSON files from 146KB to 10KB by replacing
{"pos":[x,y,z],"type":t,"tile":u} entries with a fixed 256-slot array
(index x + y*16, value null or [type, z]) and dropping pretty-printing.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -54,9 +54,11 @@ static bool_t assetChunkTilesHaveTerrain(const tile_t *tiles) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reads the "tiles" array - one quad's worth of column data per entry,
|
||||
// last one in the array wins per (x, y) column - matching
|
||||
// tools/asset/chunk/__main__.py:390-403.
|
||||
// Reads the "tiles" array - a dense, fixed-size CHUNK_TILE_COUNT grid,
|
||||
// one slot per (x, y) column at index x + y * CHUNK_WIDTH (position is
|
||||
// implicit in the index, not stored). Each slot is either `null` (empty
|
||||
// column, already zeroed = TILE_SHAPE_NULL) or a 2-element [type, z]
|
||||
// array.
|
||||
static void assetChunkParseTiles(yyjson_val *root, tile_t *tiles) {
|
||||
memoryZero(tiles, CHUNK_TILE_COUNT * sizeof(tile_t));
|
||||
|
||||
@@ -66,18 +68,12 @@ static void assetChunkParseTiles(yyjson_val *root, tile_t *tiles) {
|
||||
size_t idx, len;
|
||||
yyjson_val *tileVal;
|
||||
yyjson_arr_foreach(tilesArr, idx, len, tileVal) {
|
||||
yyjson_val *posArr = yyjson_obj_get(tileVal, "pos");
|
||||
if(!yyjson_is_arr(posArr) || yyjson_arr_size(posArr) < 3) continue;
|
||||
if(idx >= CHUNK_TILE_COUNT) break;
|
||||
if(!yyjson_is_arr(tileVal) || yyjson_arr_size(tileVal) < 2) continue;
|
||||
|
||||
int32_t x = (int32_t)yyjson_get_int(yyjson_arr_get(posArr, 0));
|
||||
int32_t y = (int32_t)yyjson_get_int(yyjson_arr_get(posArr, 1));
|
||||
int32_t z = (int32_t)yyjson_get_int(yyjson_arr_get(posArr, 2));
|
||||
if(x < 0 || x >= CHUNK_WIDTH || y < 0 || y >= CHUNK_HEIGHT) continue;
|
||||
|
||||
int32_t type = (int32_t)yyjson_get_int(yyjson_obj_get(tileVal, "type"));
|
||||
tiles[x + y * CHUNK_WIDTH] = (tile_t){
|
||||
.shape = (tileshape_t)type, .z = (uint8_t)z
|
||||
};
|
||||
int32_t type = (int32_t)yyjson_get_int(yyjson_arr_get(tileVal, 0));
|
||||
int32_t z = (int32_t)yyjson_get_int(yyjson_arr_get(tileVal, 1));
|
||||
tiles[idx] = (tile_t){ .shape = (tileshape_t)type, .z = (uint8_t)z };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user