code: optimize streamer and entity packer

isolation_bkp/dynres
Dominik Madarász 2022-09-13 11:25:08 +00:00 committed by GitHub
parent 05144764bd
commit 5f908771df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -50,10 +50,10 @@ pkt_desc pkt_entity_view_desc[] = {
{ PKT_END }, { PKT_END },
}; };
size_t entity_view_pack_struct(void *data, size_t len, entity_view view) { size_t entity_view_pack_struct(void *data, size_t len, entity_view *view) {
cw_pack_context pc = {0}; cw_pack_context pc = {0};
cw_pack_context_init(&pc, data, (unsigned long)len, 0); cw_pack_context_init(&pc, data, (unsigned long)len, 0);
pkt_pack_struct(&pc, pkt_entity_view_desc, PKT_STRUCT_PTR(&view)); pkt_pack_struct(&pc, pkt_entity_view_desc, PKT_STRUCT_PTR(view));
return pc.current - pc.start; return pc.current - pc.start;
} }

View File

@ -96,7 +96,7 @@ void entity_view_destroy(entity_view_tbl *map, uint64_t ent_id);
entity_view *entity_view_get(entity_view_tbl *map, uint64_t ent_id); entity_view *entity_view_get(entity_view_tbl *map, uint64_t ent_id);
void entity_view_map(entity_view_tbl *map, void (*map_proc)(uint64_t key, entity_view *value)); void entity_view_map(entity_view_tbl *map, void (*map_proc)(uint64_t key, entity_view *value));
size_t entity_view_pack_struct(void *data, size_t len, entity_view view); size_t entity_view_pack_struct(void *data, size_t len, entity_view *view);
entity_view entity_view_unpack_struct(void *data, size_t len); entity_view entity_view_unpack_struct(void *data, size_t len);
void entity_view_mark_for_removal(entity_view_tbl *map, uint64_t ent_id); void entity_view_mark_for_removal(entity_view_tbl *map, uint64_t ent_id);

View File

@ -19,9 +19,9 @@ ZPL_TABLE(static, world_snapshot, world_snapshot_, entity_view);
static world_data world = {0}; static world_data world = {0};
static world_snapshot streamer_snapshot; static world_snapshot streamer_snapshot;
entity_view world_build_entity_view(int64_t e) { entity_view *world_build_entity_view(int64_t e) {
entity_view *cached_ev = world_snapshot_get(&streamer_snapshot, e); entity_view *cached_ev = world_snapshot_get(&streamer_snapshot, e);
if (cached_ev) return *cached_ev; if (cached_ev) return cached_ev;
entity_view view = {0}; entity_view view = {0};
@ -114,7 +114,7 @@ entity_view world_build_entity_view(int64_t e) {
} }
world_snapshot_set(&streamer_snapshot, e, view); world_snapshot_set(&streamer_snapshot, e, view);
return view; return world_snapshot_get(&streamer_snapshot, e);
} }
int32_t tracker_write_create(librg_world *w, librg_event *e) { int32_t tracker_write_create(librg_world *w, librg_event *e) {
@ -147,11 +147,11 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) {
int64_t entity_id = librg_event_entity_get(w, e); int64_t entity_id = librg_event_entity_get(w, e);
size_t actual_length = librg_event_size_get(w, e); size_t actual_length = librg_event_size_get(w, e);
char *buffer = librg_event_buffer_get(w, e); char *buffer = librg_event_buffer_get(w, e);
entity_view view = world_build_entity_view(entity_id); entity_view *view = world_build_entity_view(entity_id);
// NOTE(zaklaus): exclude chunks from updates as they never move // NOTE(zaklaus): exclude chunks from updates as they never move
{ {
if (view.kind == EKIND_CHUNK && !view.is_dirty) { if (view->kind == EKIND_CHUNK && !view->is_dirty) {
return LIBRG_WRITE_REJECT; return LIBRG_WRITE_REJECT;
} }
} }
@ -159,7 +159,7 @@ int32_t tracker_write_update(librg_world *w, librg_event *e) {
// NOTE(zaklaus): action-based updates // NOTE(zaklaus): action-based updates
#if ECO2D_STREAM_ACTIONFILTER #if ECO2D_STREAM_ACTIONFILTER
{ {
if (view.kind != EKIND_CHUNK && !entity_can_stream(entity_id)) { if (view->kind != EKIND_CHUNK && !entity_can_stream(entity_id)) {
return LIBRG_WRITE_REJECT; return LIBRG_WRITE_REJECT;
} }
} }