From 3327a6d8b3bb92ca9f34ee611f679aca138a9e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 10 May 2021 11:35:04 +0200 Subject: [PATCH] world cleanup --- code/common/world/world.c | 10 +++++----- code/common/world/world_gen.c | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/code/common/world/world.c b/code/common/world/world.c index e12dd80..8db96ec 100644 --- a/code/common/world/world.c +++ b/code/common/world/world.c @@ -62,7 +62,6 @@ entity_view world_build_entity_view(int64_t e) { } int32_t tracker_write_create(librg_world *w, librg_event *e) { - int64_t owner_id = librg_event_owner_get(w, e); int64_t entity_id = librg_event_entity_get(w, e); #ifdef WORLD_LAYERING if (world.active_layer_id != WORLD_TRACKER_LAYERS-1) { @@ -73,10 +72,12 @@ int32_t tracker_write_create(librg_world *w, librg_event *e) { size_t actual_length = librg_event_size_get(w, e); char *buffer = librg_event_buffer_get(w, e); - return entity_view_pack_struct(buffer, actual_length, world_build_entity_view(entity_id)); + return (int32_t)entity_view_pack_struct(buffer, actual_length, world_build_entity_view(entity_id)); } int32_t tracker_write_remove(librg_world *w, librg_event *e) { + zpl_unused(e); + zpl_unused(w); #ifdef WORLD_LAYERING if (world.active_layer_id != WORLD_TRACKER_LAYERS-1) { // NOTE(zaklaus): reject updates from smaller layers @@ -100,7 +101,7 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) { } } - return entity_view_pack_struct(buffer, actual_length, view); + return (int32_t)entity_view_pack_struct(buffer, actual_length, view); } void world_setup_pkt_handlers(world_pkt_reader_proc *reader_proc, world_pkt_writer_proc *writer_proc) { @@ -192,7 +193,6 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius) while (ecs_query_next(&it)) { ClientInfo *p = ecs_column(&it, ClientInfo, 1); - Position *pos = ecs_column(&it, Position, 2); for (int i = 0; i < it.count; i++) { size_t datalen = WORLD_LIBRG_BUFSIZ; @@ -211,7 +211,7 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius) zpl_printf("[error] an error happened writing the world %d\n", result); } - pkt_world_write(MSG_ID_LIBRG_UPDATE, pkt_send_librg_update_encode(buffer, datalen, ticker), 1, p[i].view_id, p[i].peer); + pkt_world_write(MSG_ID_LIBRG_UPDATE, pkt_send_librg_update_encode(buffer, (int32_t)datalen, ticker), 1, p[i].view_id, (void*)p[i].peer); } } } diff --git a/code/common/world/world_gen.c b/code/common/world/world_gen.c index 30992b0..659c4e3 100644 --- a/code/common/world/world_gen.c +++ b/code/common/world/world_gen.c @@ -7,13 +7,13 @@ #include "world/blocks.h" #include "world/perlin.h" -#define WORLD_BLOCK_OBSERVER(name) uint32_t name(uint32_t id, uint32_t block_idx) +#define WORLD_BLOCK_OBSERVER(name) uint8_t name(uint8_t id, uint32_t block_idx) typedef WORLD_BLOCK_OBSERVER(world_block_observer_proc); #define WORLD_PERLIN_FREQ 1.0 #define WORLD_PERLIN_OCTAVES 1 -static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { +static void world_fill_rect(uint8_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { for (uint32_t cy=y; cy= world.dim) continue; @@ -21,7 +21,7 @@ static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uin uint32_t i = (cy*world.dim) + cx; if (proc) { - uint32_t new_id = (*proc)(id, i); + uint8_t new_id = (*proc)(id, i); if (new_id != BLOCK_INVALID) { id = new_id; } @@ -33,7 +33,7 @@ static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uin } } -static void world_fill_circle(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { +static void world_fill_circle(uint8_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) { for (uint32_t cy=y; cy= world.dim) continue; @@ -41,7 +41,7 @@ static void world_fill_circle(uint32_t id, uint32_t x, uint32_t y, uint32_t w, u uint32_t i = (cy*world.dim) + cx; if (proc) { - uint32_t new_id = (*proc)(id, i); + uint8_t new_id = (*proc)(id, i); if (new_id != BLOCK_INVALID) { id = new_id; } @@ -53,7 +53,7 @@ static void world_fill_circle(uint32_t id, uint32_t x, uint32_t y, uint32_t w, u } } -static void world_fill_rect_anchor(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, float ax, float ay, world_block_observer_proc *proc) { +static void world_fill_rect_anchor(uint8_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, float ax, float ay, world_block_observer_proc *proc) { uint32_t w2 = (uint32_t)floorf(w*ax); uint32_t h2 = (uint32_t)floorf(h*ay); world_fill_rect(id, x-w2, y-h2, w, h, proc); @@ -96,18 +96,20 @@ static WORLD_BLOCK_OBSERVER(shaper_noise33) { return world_perlin_cond(block_idx, 0.33) ? shaper(id, block_idx) : BLOCK_INVALID; } +#if 0 static void world_fill_mountain(uint32_t x, uint32_t y) { } +#endif #define RAND_RANGE(x,y) (x + (int)rand()%(y-(x))) int32_t world_gen() { // TODO: perform world gen // atm, we will fill the world with ground and surround it by walls - uint32_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL); - uint32_t grnd_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND); - uint32_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER); + uint8_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL); + uint8_t grnd_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND); + uint8_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER); srand(world.seed);