From 5cf92444e238e0d097cec8bcff412580a5300ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Wed, 3 Nov 2021 18:02:10 +0100 Subject: [PATCH] validate worldgen data --- code/game/src/gen/texgen.c | 9 +++++++-- code/game/src/world/blocks_list.c | 2 +- code/game/src/world/world.c | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/code/game/src/gen/texgen.c b/code/game/src/gen/texgen.c index b4683d1..841d29a 100644 --- a/code/game/src/gen/texgen.c +++ b/code/game/src/gen/texgen.c @@ -14,6 +14,13 @@ Texture2D LoadImageEco(const char *name) { Texture2D texgen_build_sprite(asset_id id) { switch (id) { + case ASSET_EMPTY: { + Image img = GenImageColor(1, 1, PINK); + Texture2D tex = LoadTextureFromImage(img); + UnloadImage(img); + return tex; + }break; + case ASSET_DEMO_ICEMAKER: return LoadImageEco("demo_icemaker"); // NOTE(zaklaus): blocks @@ -41,6 +48,4 @@ Texture2D texgen_build_sprite(asset_id id) { return tex; }break; } - - ZPL_PANIC("unreachable code"); } diff --git a/code/game/src/world/blocks_list.c b/code/game/src/world/blocks_list.c index 716a1ee..369f082 100644 --- a/code/game/src/world/blocks_list.c +++ b/code/game/src/world/blocks_list.c @@ -6,7 +6,7 @@ } static block blocks[] = { - BLOCK(ASSET_EMPTY, 0, ' ', .drag = 1.0f, .friction = 1.0f), + BLOCK(ASSET_EMPTY, 0, 'E'), BLOCK(ASSET_GROUND, 0, '.', .drag = 1.0f, .friction = 1.0f), BLOCK(ASSET_DIRT, 0, ',', .drag = 2.1f , .friction = 1.0f), BLOCK(ASSET_WALL, BLOCK_FLAG_COLLISION, '#', .drag = 1.0f , .friction = 1.0f, .bounce = 1.0f), diff --git a/code/game/src/world/world.c b/code/game/src/world/world.c index 0c99f37..6f63be0 100644 --- a/code/game/src/world/world.c +++ b/code/game/src/world/world.c @@ -193,7 +193,14 @@ int32_t world_init(int32_t seed, uint16_t chunk_size, uint16_t chunk_amount) { int32_t world_build_status = worldgen_test(&world); ZPL_ASSERT(world_build_status >= 0); - for (int i = 0; i < world.chunk_amount * world.chunk_amount; ++i) { + for (int i = 0; i < zpl_square(world.dim); ++i) { + if (world.data[i] == 0) { + ZPL_PANIC("Worldgen failure! Block %d is unset!\n", i); + return -1; + } + } + + for (int i = 0; i < zpl_square(world.chunk_amount); ++i) { ecs_entity_t e = ecs_new(world.ecs, 0); ecs_set(world.ecs, e, Classify, {.id = EKIND_CHUNK }); Chunk *chunk = ecs_get_mut(world.ecs, e, Chunk, NULL);