diff --git a/code/apps/client/CMakeLists.txt b/code/apps/client/CMakeLists.txt index 1d58b46..bddd5a0 100644 --- a/code/apps/client/CMakeLists.txt +++ b/code/apps/client/CMakeLists.txt @@ -4,7 +4,6 @@ populate_pkt_srcs() add_library(client-common STATIC source/network.c source/game.c - source/main.c source/camera.c source/world_view.c @@ -16,10 +15,12 @@ add_library(client-common STATIC add_executable(eco2d-client source/platform_raylib.c + source/main.c ) add_executable(eco2d-cli source/platform_text.c + source/main.c ) target_compile_definitions(client-common PRIVATE CLIENT) diff --git a/code/apps/client/source/game.c b/code/apps/client/source/game.c index f7477f5..016caec 100644 --- a/code/apps/client/source/game.c +++ b/code/apps/client/source/game.c @@ -120,25 +120,6 @@ void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t bl for (uint32_t i = 0; i < num_viewers; i++) { pkt_00_init_send(i); } - - // TODO(zaklaus): VERY TEMPORARY -- SPAWN SOME NPCS THAT RANDOMLY MOVE - { - ECS_IMPORT(world_ecs(), General); - ECS_IMPORT(world_ecs(), Controllers); - ECS_IMPORT(world_ecs(), Physics); - uint16_t half_world_dim = world_dim() / 2; - for (int i = 0; i < 100; i++) { - uint64_t e = entity_spawn(NULL); - ecs_add(world_ecs(), e, EcsDemoNPC); - Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL); - pos->x=rand() % world_dim() - half_world_dim; - pos->y=rand() % world_dim() - half_world_dim; - - Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL); - v->x = (rand()%3-1) * 100; - v->y = (rand()%3-1) * 100; - } - } } int8_t game_is_networked() { diff --git a/code/apps/client/source/main.c b/code/apps/client/source/main.c index 10369c2..250b2cd 100644 --- a/code/apps/client/source/main.c +++ b/code/apps/client/source/main.c @@ -4,6 +4,15 @@ #include "game.h" #include "utils/options.h" +#include "flecs/flecs.h" +#include "flecs/flecs_dash.h" +#include "flecs/flecs_systems_civetweb.h" +#include "flecs/flecs_os_api_stdcpp.h" + +#include "modules/general.h" +#include "modules/physics.h" +#include "modules/controllers.h" + #define DEFAULT_WORLD_SEED 302097 #define DEFAULT_BLOCK_SIZE 16 /* amount of units within a block (single axis) */ #define DEFAULT_CHUNK_SIZE 16 /* amount of blocks within a chunk (single axis) */ @@ -55,7 +64,27 @@ int main(int argc, char** argv) sighandler_register(); game_init(is_viewer_only, num_viewers, seed, block_size, chunk_size, world_size, is_dash_enabled); - + + + // TODO(zaklaus): VERY TEMPORARY -- SPAWN SOME NPCS THAT RANDOMLY MOVE + { + ECS_IMPORT(world_ecs(), General); + ECS_IMPORT(world_ecs(), Controllers); + ECS_IMPORT(world_ecs(), Physics); + uint16_t half_world_dim = world_dim() / 2; + for (int i = 0; i < 100; i++) { + uint64_t e = entity_spawn(NULL); + ecs_add(world_ecs(), e, EcsDemoNPC); + Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL); + pos->x=rand() % world_dim(); + pos->y=rand() % world_dim(); + + Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL); + v->x = (rand()%3-1) * 100; + v->y = (rand()%3-1) * 100; + } + } + while (game_is_running()) { game_input(); game_update(); diff --git a/code/apps/client/source/platform_raylib.c b/code/apps/client/source/platform_raylib.c index 3f2d115..7dbda1a 100644 --- a/code/apps/client/source/platform_raylib.c +++ b/code/apps/client/source/platform_raylib.c @@ -145,6 +145,7 @@ void display_conn_status() { } } else { DrawText("Connection: single-player", 5, 5, 12, BLUE); + //DrawText("Connection: ", 5, 5, 52, BLUE); } DrawFPS(0, 20); diff --git a/code/apps/client/source/world_view.c b/code/apps/client/source/world_view.c index 8863d14..611eb67 100644 --- a/code/apps/client/source/world_view.c +++ b/code/apps/client/source/world_view.c @@ -55,7 +55,7 @@ void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uin librg_config_chunksize_set(view->tracker, block_size * chunk_size, block_size * chunk_size, 1); librg_config_chunkamount_set(view->tracker, chunk_amount, chunk_amount, 1); - librg_config_chunkoffset_set(view->tracker, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, 0); + librg_config_chunkoffset_set(view->tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, 0); librg_event_set(view->tracker, LIBRG_READ_CREATE, tracker_read_create); librg_event_set(view->tracker, LIBRG_READ_REMOVE, tracker_read_remove); diff --git a/code/common/player.c b/code/common/player.c index 8912103..a567e60 100644 --- a/code/common/player.c +++ b/code/common/player.c @@ -28,8 +28,8 @@ uint64_t player_spawn(char *name) { ecs_add(world_ecs(), e, Player); Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL); uint16_t half_world_dim = world_dim() / 2; - pos->x=rand() % world_dim() - half_world_dim; - pos->y=rand() % world_dim() - half_world_dim; + pos->x=rand() % world_dim(); + pos->y=rand() % world_dim(); librg_entity_owner_set(world_tracker(), e, (int64_t)e); librg_entity_radius_set(world_tracker(), e, 3); diff --git a/code/common/world/world.c b/code/common/world/world.c index 121c54a..99b8f20 100644 --- a/code/common/world/world.c +++ b/code/common/world/world.c @@ -106,7 +106,7 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1 /* config our world grid */ librg_config_chunksize_set(world.tracker, block_size * chunk_size, block_size * chunk_size, 0); librg_config_chunkamount_set(world.tracker, chunk_amount, chunk_amount, 0); - librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, 0); + librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_BEG, LIBRG_OFFSET_BEG, 0); librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create); librg_event_set(world.tracker, LIBRG_WRITE_REMOVE, tracker_write_remove); @@ -126,12 +126,9 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1 for (int i = 0; i < chunk_amount * chunk_amount; ++i) { ecs_entity_t e = ecs_new(world.ecs, 0); Chunk *chunk = ecs_get_mut(world.ecs, e, Chunk, NULL); - chunk->x = i % chunk_amount - chunk_amount/2; - chunk->y = i / chunk_amount - chunk_amount/2; - - librg_chunk chid = librg_chunk_from_chunkpos(world.tracker, chunk->x, chunk->y, 0); librg_entity_track(world.tracker, e); - librg_entity_chunk_set(world.tracker, e, chid); + librg_entity_chunk_set(world.tracker, e, i); + librg_chunk_to_chunkpos(world.tracker, i, &chunk->x, &chunk->y, NULL); } zpl_printf("[INFO] Created a new server world\n"); diff --git a/code/modules/source/physics.c b/code/modules/source/physics.c index cf9ef27..fa745f1 100644 --- a/code/modules/source/physics.c +++ b/code/modules/source/physics.c @@ -23,9 +23,9 @@ void HandleCollisions(ecs_iter_t *it) { for (int i = 0; i < it->count; i++) { // NOTE(zaklaus): world bounds { - double w = (double)world_dim()/2.0; - p[i].x = zpl_clamp(p[i].x, -w+1, w-1); - p[i].y = zpl_clamp(p[i].y, -w+1, w-1); + double w = (double)world_dim(); + p[i].x = zpl_clamp(p[i].x, 0, w-1); + p[i].y = zpl_clamp(p[i].y, 0, w-1); } } } diff --git a/code/vendors/librg.h b/code/vendors/librg.h index fd31c87..649acda 100644 --- a/code/vendors/librg.h +++ b/code/vendors/librg.h @@ -19965,7 +19965,7 @@ void * librg_event_userdata_get(librg_world *world, librg_event *event) { LIBRG_ALWAYS_INLINE int16_t librg_util_chunkoffset_line(int16_t v, int16_t off, int16_t size) { int16_t o = 0; if (off == LIBRG_OFFSET_BEG) o = 0; - if (off == LIBRG_OFFSET_MID) o = (size/2); + if (off == LIBRG_OFFSET_MID) o = (size/2.0); if (off == LIBRG_OFFSET_END) o = (size-1); return v + o; } @@ -20001,14 +20001,16 @@ int8_t librg_chunk_to_chunkpos(librg_world *world, librg_chunk id, int16_t *chun } // TODO(zaklaus): fix ,calc here ok? - int16_t z = (int16_t)(id / (wld->worldsize.z * wld->worldsize.y)); + /*int16_t z = (int16_t)(id / (wld->worldsize.z * wld->worldsize.y)); int16_t r1 = (int16_t)(id % (wld->worldsize.z * wld->worldsize.y)); int16_t y = r1 / wld->worldsize.y; - int16_t x = r1 % wld->worldsize.y; + int16_t x = r1 % wld->worldsize.y;*/ + int16_t y = id / wld->worldsize.x; + int16_t x = id % wld->worldsize.x; - *chunk_x = x - librg_util_chunkoffset_line(0, wld->chunkoffset.x, wld->worldsize.x); - *chunk_y = y - librg_util_chunkoffset_line(0, wld->chunkoffset.y, wld->worldsize.y); - *chunk_z = z - librg_util_chunkoffset_line(0, wld->chunkoffset.z, wld->worldsize.z); + if (chunk_x) *chunk_x = x - librg_util_chunkoffset_line(0, wld->chunkoffset.x, wld->worldsize.x); + if (chunk_y) *chunk_y = y - librg_util_chunkoffset_line(0, wld->chunkoffset.y, wld->worldsize.y); + //if (chunk_z) *chunk_z = z - librg_util_chunkoffset_line(0, wld->chunkoffset.z, wld->worldsize.z); return LIBRG_OK; } diff --git a/code/vendors/zpl.h b/code/vendors/zpl.h index 8e16cae..f29f35e 100644 --- a/code/vendors/zpl.h +++ b/code/vendors/zpl.h @@ -3968,7 +3968,7 @@ License: do { \ zpl_array_header *zpl__ah = ZPL_ARRAY_HEADER(x); \ ZPL_ASSERT(index < zpl__ah->count); \ - zpl_memmove(x + index, x + index + 1, zpl_size_of(x[0]) * (zpl__ah->count - index)); \ + zpl_memmove(x + index, x + index + 1, zpl_size_of(x[0]) * (zpl__ah->count - index - 1)); \ --zpl__ah->count; \ } while (0)