do incremental entity cleanup
parent
784037a8fa
commit
7cb2b480b3
|
@ -5,7 +5,9 @@ typedef enum {
|
||||||
PROF_MAIN_LOOP,
|
PROF_MAIN_LOOP,
|
||||||
PROF_WORLD_WRITE,
|
PROF_WORLD_WRITE,
|
||||||
PROF_RENDER,
|
PROF_RENDER,
|
||||||
|
PROF_UPDATE_SYSTEMS,
|
||||||
PROF_ENTITY_LERP,
|
PROF_ENTITY_LERP,
|
||||||
|
PROF_ENTITY_REMOVAL,
|
||||||
|
|
||||||
MAX_PROF,
|
MAX_PROF,
|
||||||
PROF_FORCE_UINT8 = UINT8_MAX
|
PROF_FORCE_UINT8 = UINT8_MAX
|
||||||
|
|
|
@ -86,7 +86,9 @@ static debug_item items[] = {
|
||||||
{ .kind = DITEM_RAW, .val = PROF_MAIN_LOOP, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_MAIN_LOOP, .proc = DrawProfilerDelta },
|
||||||
{ .kind = DITEM_RAW, .val = PROF_WORLD_WRITE, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_WORLD_WRITE, .proc = DrawProfilerDelta },
|
||||||
{ .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_ENTITY_LERP, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_ENTITY_LERP, .proc = DrawProfilerDelta },
|
||||||
|
{ .kind = DITEM_RAW, .val = PROF_ENTITY_REMOVAL, .proc = DrawProfilerDelta },
|
||||||
{ .kind = DITEM_END },
|
{ .kind = DITEM_END },
|
||||||
},
|
},
|
||||||
//.is_collapsed = 1
|
//.is_collapsed = 1
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "world_view.h"
|
#include "world_view.h"
|
||||||
#include "entity_view.h"
|
#include "entity_view.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include "profiler.h"
|
||||||
|
|
||||||
#include "flecs/flecs.h"
|
#include "flecs/flecs.h"
|
||||||
#include "flecs/flecs_dash.h"
|
#include "flecs/flecs_dash.h"
|
||||||
|
@ -156,7 +157,7 @@ void game_update() {
|
||||||
network_client_tick();
|
network_client_tick();
|
||||||
}
|
}
|
||||||
else world_update();
|
else world_update();
|
||||||
|
|
||||||
game_world_cleanup_entities();
|
game_world_cleanup_entities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
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) {
|
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.
|
// 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
|
||||||
for (int i = 0; i < zpl_buffer_count(world_viewers); i += 1){
|
profile(PROF_ENTITY_REMOVAL) {
|
||||||
entity_view_tbl *view = &world_viewers[i].entities;
|
static uint64_t last_removal_time = 0;
|
||||||
|
if (last_removal_time > zpl_time_rel_ms()) return;
|
||||||
for (int j = 0; j < zpl_array_count(view->entries); j += 1){
|
last_removal_time = zpl_time_rel_ms() + GAME_ENT_REMOVAL_TIME;
|
||||||
entity_view *e = &view->entries[j].value;
|
|
||||||
if (e->tran_effect == ETRAN_REMOVE) {
|
for (int i = 0; i < zpl_buffer_count(world_viewers); i += 1){
|
||||||
entity_view_tbl_remove(view, e->ent_id);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ static profiler profilers[] = {
|
||||||
{ .id = PROF_MAIN_LOOP, .name = "measured time" },
|
{ .id = PROF_MAIN_LOOP, .name = "measured time" },
|
||||||
{ .id = PROF_WORLD_WRITE, .name = "world write" },
|
{ .id = PROF_WORLD_WRITE, .name = "world write" },
|
||||||
{ .id = PROF_RENDER, .name = "render" },
|
{ .id = PROF_RENDER, .name = "render" },
|
||||||
|
{ .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" },
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert((sizeof(profilers)/sizeof(profilers[0])) == MAX_PROF, "mismatched profilers");
|
static_assert((sizeof(profilers)/sizeof(profilers[0])) == MAX_PROF, "mismatched profilers");
|
||||||
|
|
|
@ -202,7 +202,9 @@ static void world_tracker_update(uint8_t ticker, uint32_t freq, uint8_t radius)
|
||||||
|
|
||||||
|
|
||||||
int32_t world_update() {
|
int32_t world_update() {
|
||||||
ecs_progress(world.ecs, 0.0f);
|
profile (PROF_UPDATE_SYSTEMS) {
|
||||||
|
ecs_progress(world.ecs, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
world_tracker_update(0, WORLD_TRACKER_UPDATE_FAST_MS, 2);
|
world_tracker_update(0, WORLD_TRACKER_UPDATE_FAST_MS, 2);
|
||||||
world_tracker_update(1, WORLD_TRACKER_UPDATE_NORMAL_MS, 4);
|
world_tracker_update(1, WORLD_TRACKER_UPDATE_NORMAL_MS, 4);
|
||||||
|
|
Loading…
Reference in New Issue