Remove GC for OOB entities + perf improvements

isolation_bkp/dynres
Dominik Madarász 2021-10-27 10:55:07 +02:00
parent ff9f483da1
commit e7f55985db
7 changed files with 238 additions and 281 deletions

View File

@ -3,7 +3,7 @@
static debug_draw_queue draw_queue = {0}; static debug_draw_queue draw_queue = {0};
#ifdef ECO2D_PROD #ifndef _DEBUG
static bool draw_is_enabled = false; static bool draw_is_enabled = false;
#else #else
static bool draw_is_enabled = true; static bool draw_is_enabled = true;

View File

@ -193,7 +193,6 @@ static debug_item items[] = {
{ .kind = DITEM_RAW, .val = PROF_RENDER, .proc = DrawProfilerDelta }, { .kind = DITEM_RAW, .val = PROF_RENDER, .proc = DrawProfilerDelta },
{ .kind = DITEM_RAW, .val = PROF_UPDATE_SYSTEMS, .proc = DrawProfilerDelta }, { .kind = DITEM_RAW, .val = PROF_UPDATE_SYSTEMS, .proc = DrawProfilerDelta },
{ .kind = DITEM_RAW, .val = PROF_ENTITY_LERP, .proc = DrawProfilerDelta }, { .kind = DITEM_RAW, .val = PROF_ENTITY_LERP, .proc = DrawProfilerDelta },
{ .kind = DITEM_RAW, .val = PROF_ENTITY_REMOVAL, .proc = DrawProfilerDelta },
{ .kind = DITEM_RAW, .val = PROF_INTEGRATE_POS, .proc = DrawProfilerDelta }, { .kind = DITEM_RAW, .val = PROF_INTEGRATE_POS, .proc = DrawProfilerDelta },
{ .kind = DITEM_END }, { .kind = DITEM_END },
}, },

View File

@ -217,10 +217,6 @@ void game_update() {
network_server_tick(); network_server_tick();
} }
} }
if (game_mode != GAMEKIND_HEADLESS) {
game_world_cleanup_entities();
}
} }
void game_render() { void game_render() {
@ -244,35 +240,6 @@ void game_action_send_keystate(float x,
pkt_send_keystate_send(active_viewer->view_id, x, y, mx, my, use, sprint, ctrl, drop, selected_item, swap, swap_from, swap_to); pkt_send_keystate_send(active_viewer->view_id, x, y, mx, my, use, sprint, ctrl, drop, selected_item, swap, swap_from, swap_to);
} }
#define GAME_ENT_REMOVAL_TIME 10000
#define GAME_ENT_REMOVAL_TRESHOLD 500
void game_world_cleanup_entities(void) {
// TODO(zaklaus): not the best approach to do a cleanup, let memory stay for a while as it might be reused later on anyway.
#if 1
profile(PROF_ENTITY_REMOVAL) {
static uint64_t last_removal_time = 0;
if (last_removal_time > zpl_time_rel_ms()) return;
last_removal_time = zpl_time_rel_ms() + GAME_ENT_REMOVAL_TIME;
for (int i = 0; i < zpl_buffer_count(world_viewers); i += 1){
entity_view_tbl *view = &world_viewers[i].entities;
uint32_t deletions = 0;
for (int j = 0; j < zpl_array_count(view->entries); j += 1) {
if (deletions > GAME_ENT_REMOVAL_TRESHOLD) return;
entity_view *e = &view->entries[j].value;
if (e->tran_effect == ETRAN_REMOVE) {
entity_view_tbl_remove(view, e->ent_id);
deletions++;
}
}
}
}
#endif
}
void game_request_close() { void game_request_close() {
platform_request_close(); platform_request_close();
} }

View File

@ -30,7 +30,6 @@ void game_world_view_set_active(world_view *view);
void game_world_view_cycle_active(int8_t dir); void game_world_view_cycle_active(int8_t dir);
void game_world_view_active_entity_map(void (*map_proc)(uint64_t key, entity_view * value)); void game_world_view_active_entity_map(void (*map_proc)(uint64_t key, entity_view * value));
entity_view *game_world_view_active_get_entity(uint64_t ent_id); entity_view *game_world_view_active_get_entity(uint64_t ent_id);
void game_world_cleanup_entities(void);
//~ NOTE(zaklaus): viewer -> host actions //~ NOTE(zaklaus): viewer -> host actions
void game_action_send_keystate(float x, void game_action_send_keystate(float x,

View File

@ -12,7 +12,6 @@ static profiler profilers[] = {
{ .id = PROF_RENDER, .name = "render" }, { .id = PROF_RENDER, .name = "render" },
{ .id = PROF_UPDATE_SYSTEMS, .name = "update systems" }, { .id = PROF_UPDATE_SYSTEMS, .name = "update systems" },
{ .id = PROF_ENTITY_LERP, .name = "entity lerp" }, { .id = PROF_ENTITY_LERP, .name = "entity lerp" },
{ .id = PROF_ENTITY_REMOVAL, .name = "entity removal" },
{ .id = PROF_INTEGRATE_POS, .name = "entity movement" }, { .id = PROF_INTEGRATE_POS, .name = "entity movement" },
}; };

View File

@ -9,7 +9,6 @@ typedef enum {
PROF_RENDER, PROF_RENDER,
PROF_UPDATE_SYSTEMS, PROF_UPDATE_SYSTEMS,
PROF_ENTITY_LERP, PROF_ENTITY_LERP,
PROF_ENTITY_REMOVAL,
PROF_INTEGRATE_POS, PROF_INTEGRATE_POS,
MAX_PROF, MAX_PROF,

View File

@ -9,14 +9,8 @@
int32_t tracker_read_remove(librg_world *w, librg_event *e) { int32_t tracker_read_remove(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);
world_view *view = (world_view*)librg_world_userdata_get(w); world_view *view = (world_view*)librg_world_userdata_get(w);
if (view != game_world_view_get_active()) {
entity_view_destroy(&view->entities, entity_id);
} else {
entity_view_mark_for_removal(&view->entities, entity_id);
}
entity_view_remove_chunk_texture(&view->entities, entity_id); entity_view_remove_chunk_texture(&view->entities, entity_id);
entity_view_destroy(&view->entities, entity_id);
return 0; return 0;
} }