From 8248399e782e50a2d45ce28b5175eb3e1d476568 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 23 Dec 2015 20:39:36 +1000 Subject: [PATCH] Improve server performance a bit --- qcsrc/lib/iter.qh | 16 ++++++++++++++-- qcsrc/lib/net.qh | 5 +++-- qcsrc/server/sv_main.qc | 18 +++++++----------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/qcsrc/lib/iter.qh b/qcsrc/lib/iter.qh index 790c3929d..223522504 100644 --- a/qcsrc/lib/iter.qh +++ b/qcsrc/lib/iter.qh @@ -59,14 +59,17 @@ #if defined(CSQC) entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403; + entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403; entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450; #elif defined(SVQC) entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #403; + entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403; entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450; #elif defined(MENUQC) entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #26; entity(.entity fld, entity match, .entity tofield) findchainentity_tofield = #27; + entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #27; entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #88; #endif @@ -91,10 +94,19 @@ } \ } MACRO_END -#define FOREACH_ENTITY_FLAGS(fld, flags, body) \ +#define FOREACH_ENTITY_FLOAT(fld, match, body) \ MACRO_BEGIN { \ int i = 0; \ - for (entity it = _findchainflags_tofield(fld, flags, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ + for (entity it = _findchainfloat_tofield(fld, match, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ + { \ + LAMBDA(body) \ + } \ + } MACRO_END + +#define FOREACH_ENTITY_FLAGS(fld, match, body) \ + MACRO_BEGIN { \ + int i = 0; \ + for (entity it = _findchainflags_tofield(fld, match, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ LAMBDA(body) \ } \ diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 9782ba313..d870ef1f9 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -147,8 +147,9 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } void UncustomizeEntitiesRun() { - for (entity e = NULL; (e = findfloat(e, uncustomizeentityforclient_set, 1)); ) - WITH(entity, self, e, e.uncustomizeentityforclient()); + FOREACH_ENTITY_FLOAT(uncustomizeentityforclient_set, true, LAMBDA( + WITH(entity, self, it, it.uncustomizeentityforclient()); + )); } STRING_ITERATOR(g_buf, string_null, 0); diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index ded24016f..cb3488489 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -116,15 +116,12 @@ void CreatureFrame_FallDamage(entity this) void CreatureFrame_All() { - for(entity e = world; (e = findfloat(e, damagedbycontents, true)); ) - { - if (e.movetype == MOVETYPE_NOCLIP) { continue; } - - CreatureFrame_Liquids(e); - CreatureFrame_FallDamage(e); - - e.oldvelocity = e.velocity; - } + FOREACH_ENTITY_FLOAT(damagedbycontents, true, LAMBDA( + if(it.movetype == MOVETYPE_NOCLIP) continue; + CreatureFrame_Liquids(it); + CreatureFrame_FallDamage(it); + it.oldvelocity = it.velocity; + )); } void Pause_TryPause(bool ispaused) @@ -191,8 +188,7 @@ void StartFrame() } #endif - for(entity e = world; (e = findfloat(e, csqcprojectile_clientanimate, 1)); ) - CSQCProjectile_Check(e); + FOREACH_ENTITY_FLOAT(csqcprojectile_clientanimate, true, LAMBDA(CSQCProjectile_Check(it))); if(RedirectionThink()) return; -- 2.39.2