From 87018a963afac32e098a4c4c0aa1e3eff5649cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 6 May 2021 00:03:43 +0200 Subject: [PATCH] librg events wip --- code/apps/client/source/network.c | 24 --------- code/common/packets/pkt_send_librg_update.c | 5 +- code/common/player.c | 2 +- code/common/world/world.c | 55 ++++++++++++++++++++- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/code/apps/client/source/network.c b/code/apps/client/source/network.c index 52f1266..6bfd535 100644 --- a/code/apps/client/source/network.c +++ b/code/apps/client/source/network.c @@ -26,30 +26,6 @@ int32_t network_destroy() { } -#if 0 -int32_t client_read_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); - zpl_printf("[INFO] An entity %d was created for owner: %d\n", (int)entity_id, (int)owner_id); - return 0; -} - -int32_t client_read_remove(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); - zpl_printf("[INFO] An entity %d was removed for owner: %d\n", (int)entity_id, (int)owner_id); - return 0; -} - -int32_t client_read_update(librg_world *w, librg_event *e) { - // int64_t entity_id = librg_event_entity_get(w, e); - size_t actual_length = librg_event_size_get(w, e); - char *buffer = librg_event_buffer_get(w, e); - - return 0; -} -#endif - int32_t network_client_connect(const char *hostname, uint16_t port) { ENetAddress address = {0}; address.port = port; enet_address_set_host(&address, hostname); diff --git a/code/common/packets/pkt_send_librg_update.c b/code/common/packets/pkt_send_librg_update.c index 10c4ee2..8d477d3 100644 --- a/code/common/packets/pkt_send_librg_update.c +++ b/code/common/packets/pkt_send_librg_update.c @@ -17,5 +17,8 @@ int32_t pkt_send_librg_update_handler(pkt_header *header) { if (uc.item.type != CWP_ITEM_BIN) return -1; - return librg_world_read(world_tracker(), 1, uc.item.as.bin.start, uc.item.as.bin.length, NULL); + int32_t state = librg_world_read(world_tracker(), 1, uc.item.as.bin.start, uc.item.as.bin.length, NULL); + if (state < 0) zpl_printf("[ERROR] world read error: %d\n", state); + + return state; } diff --git a/code/common/player.c b/code/common/player.c index 2e05cd3..9c2325b 100644 --- a/code/common/player.c +++ b/code/common/player.c @@ -23,7 +23,7 @@ uint64_t player_spawn(char *name) { librg_entity_track(world_tracker(), e); librg_entity_owner_set(world_tracker(), e, (int64_t)e); librg_entity_radius_set(world_tracker(), e, 2); /* 2 chunk radius visibility */ - // librg_entity_chunk_set(world_tracker(), e, 1); + librg_entity_chunk_set(world_tracker(), e, 1); return (uint64_t)e; } diff --git a/code/common/world/world.c b/code/common/world/world.c index 36161c5..43df35d 100644 --- a/code/common/world/world.c +++ b/code/common/world/world.c @@ -29,6 +29,50 @@ static world_data world = {0}; int32_t world_gen(); +int32_t tracker_read_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); + zpl_printf("[INFO] An entity %d was created for owner: %d\n", (int)entity_id, (int)owner_id); + return 0; +} + +int32_t tracker_read_remove(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); + zpl_printf("[INFO] An entity %d was removed for owner: %d\n", (int)entity_id, (int)owner_id); + return 0; +} + +int32_t tracker_read_update(librg_world *w, librg_event *e) { + // int64_t entity_id = librg_event_entity_get(w, e); + size_t actual_length = librg_event_size_get(w, e); + char *buffer = librg_event_buffer_get(w, e); + + return 0; +} + +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); + return 0; +} + +int32_t tracker_write_remove(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); + return 0; +} + +int32_t tracker_write_update(librg_world *w, librg_event *e) { + // int64_t entity_id = librg_event_entity_get(w, e); +#if 0 + size_t actual_length = librg_event_size_get(w, e); + char *buffer = librg_event_buffer_get(w, e); +#endif + + return 0; +} + int32_t world_init_minimal(uint16_t block_size, uint16_t chunk_size, uint16_t world_size, world_pkt_reader_proc *reader_proc, world_pkt_writer_proc *writer_proc) { world.chunk_size = chunk_size; world.world_size = world_size; @@ -57,6 +101,14 @@ int32_t world_init_minimal(uint16_t block_size, uint16_t chunk_size, uint16_t wo librg_config_chunkamount_set(world.tracker, world_size, world_size, 1); librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID); + librg_event_set(world.tracker, LIBRG_READ_CREATE, tracker_read_create); + librg_event_set(world.tracker, LIBRG_READ_REMOVE, tracker_read_remove); + librg_event_set(world.tracker, LIBRG_READ_UPDATE, tracker_read_update); + + 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_UPDATE, tracker_write_update); + return 0; } @@ -106,7 +158,8 @@ int32_t world_destroy(void) { static void world_tracker_update(void) { if (world.tracker_update > zpl_time_rel_ms()) return; - world.tracker_update = zpl_time_rel_ms() + WORLD_TRACKER_UPDATE_MS; + world.tracker_update = zpl_time_rel_ms() + WORLD_TRACKER_UPDATE_MS; + ECS_IMPORT(world.ecs, Net); ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo");