some world fixes

isolation_bkp/dynres
Dominik Madarász 2021-05-08 22:32:31 +02:00
parent de93637d9a
commit c5df24cefc
10 changed files with 51 additions and 40 deletions

View File

@ -4,7 +4,6 @@ populate_pkt_srcs()
add_library(client-common STATIC add_library(client-common STATIC
source/network.c source/network.c
source/game.c source/game.c
source/main.c
source/camera.c source/camera.c
source/world_view.c source/world_view.c
@ -16,10 +15,12 @@ add_library(client-common STATIC
add_executable(eco2d-client add_executable(eco2d-client
source/platform_raylib.c source/platform_raylib.c
source/main.c
) )
add_executable(eco2d-cli add_executable(eco2d-cli
source/platform_text.c source/platform_text.c
source/main.c
) )
target_compile_definitions(client-common PRIVATE CLIENT) target_compile_definitions(client-common PRIVATE CLIENT)

View File

@ -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++) { for (uint32_t i = 0; i < num_viewers; i++) {
pkt_00_init_send(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() { int8_t game_is_networked() {

View File

@ -4,6 +4,15 @@
#include "game.h" #include "game.h"
#include "utils/options.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_WORLD_SEED 302097
#define DEFAULT_BLOCK_SIZE 16 /* amount of units within a block (single axis) */ #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) */ #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(); sighandler_register();
game_init(is_viewer_only, num_viewers, seed, block_size, chunk_size, world_size, is_dash_enabled); 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()) { while (game_is_running()) {
game_input(); game_input();
game_update(); game_update();

View File

@ -145,6 +145,7 @@ void display_conn_status() {
} }
} else { } else {
DrawText("Connection: single-player", 5, 5, 12, BLUE); DrawText("Connection: single-player", 5, 5, 12, BLUE);
//DrawText("Connection: ", 5, 5, 52, BLUE);
} }
DrawFPS(0, 20); DrawFPS(0, 20);

View File

@ -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_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_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_CREATE, tracker_read_create);
librg_event_set(view->tracker, LIBRG_READ_REMOVE, tracker_read_remove); librg_event_set(view->tracker, LIBRG_READ_REMOVE, tracker_read_remove);

View File

@ -28,8 +28,8 @@ uint64_t player_spawn(char *name) {
ecs_add(world_ecs(), e, Player); ecs_add(world_ecs(), e, Player);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL); Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
uint16_t half_world_dim = world_dim() / 2; uint16_t half_world_dim = world_dim() / 2;
pos->x=rand() % world_dim() - half_world_dim; pos->x=rand() % world_dim();
pos->y=rand() % world_dim() - half_world_dim; pos->y=rand() % world_dim();
librg_entity_owner_set(world_tracker(), e, (int64_t)e); librg_entity_owner_set(world_tracker(), e, (int64_t)e);
librg_entity_radius_set(world_tracker(), e, 3); librg_entity_radius_set(world_tracker(), e, 3);

View File

@ -106,7 +106,7 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
/* config our world grid */ /* config our world grid */
librg_config_chunksize_set(world.tracker, block_size * chunk_size, block_size * chunk_size, 0); 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_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_CREATE, tracker_write_create);
librg_event_set(world.tracker, LIBRG_WRITE_REMOVE, tracker_write_remove); 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) { for (int i = 0; i < chunk_amount * chunk_amount; ++i) {
ecs_entity_t e = ecs_new(world.ecs, 0); ecs_entity_t e = ecs_new(world.ecs, 0);
Chunk *chunk = ecs_get_mut(world.ecs, e, Chunk, NULL); 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_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"); zpl_printf("[INFO] Created a new server world\n");

View File

@ -23,9 +23,9 @@ void HandleCollisions(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) { for (int i = 0; i < it->count; i++) {
// NOTE(zaklaus): world bounds // NOTE(zaklaus): world bounds
{ {
double w = (double)world_dim()/2.0; double w = (double)world_dim();
p[i].x = zpl_clamp(p[i].x, -w+1, w-1); p[i].x = zpl_clamp(p[i].x, 0, w-1);
p[i].y = zpl_clamp(p[i].y, -w+1, w-1); p[i].y = zpl_clamp(p[i].y, 0, w-1);
} }
} }
} }

14
code/vendors/librg.h vendored
View File

@ -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) { LIBRG_ALWAYS_INLINE int16_t librg_util_chunkoffset_line(int16_t v, int16_t off, int16_t size) {
int16_t o = 0; int16_t o = 0;
if (off == LIBRG_OFFSET_BEG) 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); if (off == LIBRG_OFFSET_END) o = (size-1);
return v + o; 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? // 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 r1 = (int16_t)(id % (wld->worldsize.z * wld->worldsize.y));
int16_t y = r1 / 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); if (chunk_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); if (chunk_y) *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_z) *chunk_z = z - librg_util_chunkoffset_line(0, wld->chunkoffset.z, wld->worldsize.z);
return LIBRG_OK; return LIBRG_OK;
} }

2
code/vendors/zpl.h vendored
View File

@ -3968,7 +3968,7 @@ License:
do { \ do { \
zpl_array_header *zpl__ah = ZPL_ARRAY_HEADER(x); \ zpl_array_header *zpl__ah = ZPL_ARRAY_HEADER(x); \
ZPL_ASSERT(index < zpl__ah->count); \ 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; \ --zpl__ah->count; \
} while (0) } while (0)