From bc91aae1110a375a90c27df5fd48509eb578fb47 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 19 Jan 2020 07:33:46 +1000 Subject: [PATCH] Replace some per-frame physics loops with intrusive lists --- qcsrc/common/physics/movetypes/movetypes.qc | 2 ++ qcsrc/ecs/lib.qh | 9 +++++++-- qcsrc/server/defs.qh | 2 ++ qcsrc/server/g_world.qc | 4 ++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/qcsrc/common/physics/movetypes/movetypes.qc b/qcsrc/common/physics/movetypes/movetypes.qc index 9d32cf3d5..68d4c3660 100644 --- a/qcsrc/common/physics/movetypes/movetypes.qc +++ b/qcsrc/common/physics/movetypes/movetypes.qc @@ -7,6 +7,8 @@ void set_movetype(entity this, int mt) if (mt == MOVETYPE_PHYSICS || mt == MOVETYPE_PUSH || mt == MOVETYPE_FAKEPUSH) { this.move_qcphysics = false; } + if(!IL_CONTAINS(g_moveables, this)) + IL_PUSH(g_moveables, this); // add it to the moveable entities list (even if it doesn't move!) logic: if an object never sets its movetype, we assume it never does anything notable this.movetype = (this.move_qcphysics) ? MOVETYPE_NONE : mt; } #elif defined(CSQC) diff --git a/qcsrc/ecs/lib.qh b/qcsrc/ecs/lib.qh index 2d48e577b..192136b62 100644 --- a/qcsrc/ecs/lib.qh +++ b/qcsrc/ecs/lib.qh @@ -1,24 +1,29 @@ #pragma once +IntrusiveList g_events; +IntrusiveList g_components; +STATIC_INIT(components) { g_events = IL_NEW(); g_components = IL_NEW(); } + /** Components always interpolate from the previous state */ #define COMPONENT(com) \ void com_##com##_interpolate(entity it, float a); \ .bool com_##com -#define FOREACH_COMPONENT(com, body) FOREACH_ENTITY_FLOAT(com_##com, true, body) +#define FOREACH_COMPONENT(com, body) IL_EACH(g_components, it.com_##com, body) #define EVENT(T, args) .bool evt_##T##_listener; .void args evt_##T #define emit(T, ...) \ MACRO_BEGIN \ - FOREACH_ENTITY_FLOAT_ORDERED(evt_##T##_listener, true, it.evt_##T(__VA_ARGS__)); \ + IL_EACH(g_events, it.evt_##T##_listener, it.evt_##T(__VA_ARGS__)); \ MACRO_END #define subscribe(listener, T, fn) \ MACRO_BEGIN \ listener.evt_##T = (fn); \ listener.evt_##T##_listener = true; \ + IL_PUSH(g_events, listener); \ MACRO_END diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index b1d73f6a3..29621f61d 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -412,6 +412,7 @@ IntrusiveList g_locations; IntrusiveList g_saved_team; IntrusiveList g_monster_targets; IntrusiveList g_pathlib_nodes; +IntrusiveList g_moveables; STATIC_INIT(defs) { g_monsters = IL_NEW(); @@ -433,4 +434,5 @@ STATIC_INIT(defs) g_saved_team = IL_NEW(); g_monster_targets = IL_NEW(); g_pathlib_nodes = IL_NEW(); + g_moveables = IL_NEW(); } diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index c3dc5be39..82e67a406 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -2108,7 +2108,7 @@ void Physics_Frame() if(autocvar_sv_freezenonclients) return; - FOREACH_ENTITY_FLOAT(pure_data, false, + IL_EACH(g_moveables, true, { if(IS_CLIENT(it) || it.classname == "" || it.move_movetype == MOVETYPE_PUSH || it.move_movetype == MOVETYPE_FAKEPUSH || it.move_movetype == MOVETYPE_PHYSICS) continue; @@ -2134,7 +2134,7 @@ void Physics_Frame() if(autocvar_sv_gameplayfix_delayprojectiles >= 0) return; - FOREACH_ENTITY_FLOAT(move_qcphysics, true, + IL_EACH(g_moveables, it.move_qcphysics, { if(IS_CLIENT(it) || is_pure(it) || it.classname == "" || it.move_movetype == MOVETYPE_NONE) continue; -- 2.39.2