do incremental entity cleanup

isolation_bkp/dynres
Dominik Madarász 2021-05-13 15:44:08 +02:00
parent 784037a8fa
commit 7cb2b480b3
5 changed files with 34 additions and 13 deletions

View File

@ -5,7 +5,9 @@ typedef enum {
PROF_MAIN_LOOP,
PROF_WORLD_WRITE,
PROF_RENDER,
PROF_UPDATE_SYSTEMS,
PROF_ENTITY_LERP,
PROF_ENTITY_REMOVAL,
MAX_PROF,
PROF_FORCE_UINT8 = UINT8_MAX

View File

@ -86,7 +86,9 @@ static debug_item items[] = {
{ .kind = DITEM_RAW, .val = PROF_MAIN_LOOP, .proc = DrawProfilerDelta },
{ .kind = DITEM_RAW, .val = PROF_WORLD_WRITE, .proc = DrawProfilerDelta },
{ .kind = DITEM_RAW, .val = PROF_RENDER, .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_REMOVAL, .proc = DrawProfilerDelta },
{ .kind = DITEM_END },
},
//.is_collapsed = 1

View File

@ -9,6 +9,7 @@
#include "world_view.h"
#include "entity_view.h"
#include "camera.h"
#include "profiler.h"
#include "flecs/flecs.h"
#include "flecs/flecs_dash.h"
@ -168,19 +169,31 @@ void game_action_send_keystate(float x, float y, uint8_t use, uint8_t sprint) {
pkt_send_keystate_send(active_viewer->view_id, x, y, use, sprint);
}
#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 0
#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
}

View File

@ -9,7 +9,9 @@ static profiler profilers[] = {
{ .id = PROF_MAIN_LOOP, .name = "measured time" },
{ .id = PROF_WORLD_WRITE, .name = "world write" },
{ .id = PROF_RENDER, .name = "render" },
{ .id = PROF_UPDATE_SYSTEMS, .name = "update systems" },
{ .id = PROF_ENTITY_LERP, .name = "entity lerp" },
{ .id = PROF_ENTITY_REMOVAL, .name = "entity removal" },
};
static_assert((sizeof(profilers)/sizeof(profilers[0])) == MAX_PROF, "mismatched profilers");

View File

@ -202,7 +202,9 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius)
int32_t world_update() {
profile (PROF_UPDATE_SYSTEMS) {
ecs_progress(world.ecs, 0.0f);
}
world_tracker_update(0, WORLD_TRACKER_UPDATE_FAST_MS, 2);
world_tracker_update(1, WORLD_TRACKER_UPDATE_NORMAL_MS, 4);