validate worldgen data

isolation_bkp/dynres
Dominik Madarász 2021-11-03 18:02:10 +01:00
parent 3ce8df35dc
commit 5cf92444e2
3 changed files with 16 additions and 4 deletions

View File

@ -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");
}

View File

@ -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),

View File

@ -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);