librg events wip

isolation_bkp/dynres
Dominik Madarász 2021-05-06 00:03:43 +02:00
parent df6e844c98
commit 87018a963a
4 changed files with 59 additions and 27 deletions

View File

@ -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) { int32_t network_client_connect(const char *hostname, uint16_t port) {
ENetAddress address = {0}; address.port = port; ENetAddress address = {0}; address.port = port;
enet_address_set_host(&address, hostname); enet_address_set_host(&address, hostname);

View File

@ -17,5 +17,8 @@ int32_t pkt_send_librg_update_handler(pkt_header *header) {
if (uc.item.type != CWP_ITEM_BIN) if (uc.item.type != CWP_ITEM_BIN)
return -1; 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;
} }

View File

@ -23,7 +23,7 @@ uint64_t player_spawn(char *name) {
librg_entity_track(world_tracker(), e); librg_entity_track(world_tracker(), e);
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, 2); /* 2 chunk radius visibility */ 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; return (uint64_t)e;
} }

View File

@ -29,6 +29,50 @@ static world_data world = {0};
int32_t world_gen(); 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) { 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.chunk_size = chunk_size;
world.world_size = world_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_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_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; return 0;
} }
@ -106,7 +158,8 @@ int32_t world_destroy(void) {
static void world_tracker_update(void) { static void world_tracker_update(void) {
if (world.tracker_update > zpl_time_rel_ms()) return; 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_IMPORT(world.ecs, Net);
ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo"); ecs_query_t *query = ecs_query_new(world.ecs, "Net.ClientInfo");