#define ZPL_NANO #include "zpl.h" #include "world/world.h" #include "world/blocks.h" #include "raylib.h" #include "gen/texgen.h" #include "world_view.h" #define BLOCKS_COUNT (sizeof(blocks)/sizeof(block)) ZPL_TABLE(static, blocks__chunk_tbl, blocks__chunk_tbl_, RenderTexture2D); static blocks__chunk_tbl baked_chunks; static void chunks_unload_textures(uint64_t key, RenderTexture2D *value) { (void)key; UnloadRenderTexture(*value); } typedef struct { char *name; uint32_t flags; uint32_t kind; uint32_t biome; char symbol; float drag; // NOTE(zaklaus): viewer data Texture2D img; } block; #include "blocks_list.c" int32_t blocks_setup(void) { for (uint32_t i=0; iimg = texgen_build_block(b->biome, b->kind); } blocks__chunk_tbl_init(&baked_chunks, zpl_heap()); return 0; } void blocks_destroy(void) { for (uint32_t i=0; ichunk_size; RenderTexture2D canvas = LoadRenderTexture(dims, dims); BeginTextureMode(canvas); ClearBackground(WHITE); for (int y = 0; y < view->chunk_size; y += 1) { for (int x = 0; x < view->chunk_size; x += 1) { #if 1 Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img; Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE}; Rectangle dst = {x*WORLD_BLOCK_SIZE, y*WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE}; DrawTexturePro(blk, src, dst, (Vector2){0.0f,0.0f}, 0.0f, WHITE); #endif } } EndTextureMode(); blocks__chunk_tbl_set(&baked_chunks, id, canvas); } void *blocks_get_chunk_tex(uint64_t id) { return blocks__chunk_tbl_get(&baked_chunks, id); } void blocks_remove_chunk_tex(uint64_t id) { RenderTexture2D *tex = blocks__chunk_tbl_get(&baked_chunks, id); if (!tex) return; UnloadRenderTexture(*tex); blocks__chunk_tbl_remove(&baked_chunks, id); }