From: Mario Date: Wed, 17 May 2017 21:01:18 +0000 (+1000) Subject: Replace some findfloat loops with intrusive lists where possible X-Git-Tag: xonotic-v0.8.5~2768^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0b4fa7abe542b881c843e3d72e5435fccad8207a;p=xonotic%2Fxonotic-data.pk3dir.git Replace some findfloat loops with intrusive lists where possible --- diff --git a/qcsrc/common/turrets/turret/tesla_weapon.qc b/qcsrc/common/turrets/turret/tesla_weapon.qc index a173d8b67..1d90562ae 100644 --- a/qcsrc/common/turrets/turret/tesla_weapon.qc +++ b/qcsrc/common/turrets/turret/tesla_weapon.qc @@ -42,50 +42,42 @@ METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, .enti } - FOREACH_ENTITY_FLOAT(railgunhit, 1, + IL_EACH(g_railgunhit, it.railgunhit, { it.railgunhit = 0; }); + IL_CLEAR(g_railgunhit); } } entity toast(entity actor, entity from, float range, float damage) { - entity e; + float dd = range + 1; entity etarget = NULL; - float d,dd; - float r; - - dd = range + 1; - - e = findradius(from.origin,range); - while (e) + FOREACH_ENTITY_RADIUS(from.origin, range, it != from && !it.railgunhit, { - if ((e.railgunhit != 1) && (e != from)) + float r = turret_validate_target(actor, it, actor.target_validate_flags); + if(r > 0) { - r = turret_validate_target(actor,e,actor.target_validate_flags); - if (r > 0) + traceline(from.origin, 0.5 * (it.absmin + it.absmax), MOVE_WORLDONLY, from); + if(trace_fraction == 1.0) { - traceline(from.origin,0.5 * (e.absmin + e.absmax),MOVE_WORLDONLY,from); - if (trace_fraction == 1.0) + float d = vlen(it.origin - from.origin); + if(d < dd) { - d = vlen(e.origin - from.origin); - if (d < dd) - { - dd = d; - etarget = e; - } + dd = d; + etarget = it; } } } - e = e.chain; - } + }); if (etarget) { - te_csqc_lightningarc(from.origin,etarget.origin); + te_csqc_lightningarc(from.origin, etarget.origin); Damage(etarget, actor, actor, damage, DEATH_TURRET_TESLA.m_id, etarget.origin, '0 0 0'); etarget.railgunhit = 1; + IL_PUSH(g_railgunhit, etarget); } return etarget; diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index e210151dc..d8747d0b4 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -467,3 +467,6 @@ STATIC_INIT(g_bot_dodge) { g_bot_dodge = IL_NEW(); } IntrusiveList g_damagedbycontents; STATIC_INIT(g_damagedbycontents) { g_damagedbycontents = IL_NEW(); } + +IntrusiveList g_railgunhit; +STATIC_INIT(g_railgunhit) { g_railgunhit = IL_NEW(); } diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index afa6d1044..419d3be7a 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -44,16 +44,19 @@ void crosshair_trace_plusvisibletriggers(entity pl) { it.solid = SOLID_BSP; it.ctrace_solidchanged = true; + IL_PUSH(g_ctrace_changed, it); } }); crosshair_trace(pl); - FOREACH_ENTITY_FLOAT(ctrace_solidchanged, true, + IL_EACH(g_ctrace_changed, it.ctrace_solidchanged, { it.solid = SOLID_TRIGGER; it.ctrace_solidchanged = false; }); + + IL_CLEAR(g_ctrace_changed); } void WarpZone_crosshair_trace(entity pl) { diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index 1e2dc57f0..33d5c14f3 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -333,3 +333,6 @@ entity initialize_entity_first; float sound_allowed(float dest, entity e); void InitializeEntity(entity e, void(entity this) func, float order); + +IntrusiveList g_ctrace_changed; +STATIC_INIT(g_ctrace_changed) { g_ctrace_changed = IL_NEW(); } diff --git a/qcsrc/server/steerlib.qc b/qcsrc/server/steerlib.qc index f986fa2a8..3418a2c4e 100644 --- a/qcsrc/server/steerlib.qc +++ b/qcsrc/server/steerlib.qc @@ -526,6 +526,8 @@ void spawn_flocker(entity this) flocker.health = 10; flocker.pos1 = normalize(flocker.velocity + randomvec() * 0.1); + IL_PUSH(g_flockers, flocker); + this.cnt = this.cnt -1; } @@ -559,7 +561,7 @@ void flocker_hunter_think(entity this) if(!this.enemy) { - FOREACH_ENTITY_FLOAT(flock_id, this.flock_id, + IL_EACH(g_flockers, it.flock_id == this.flock_id, { if(it == this.owner || it == ee) continue; @@ -610,6 +612,9 @@ spawnfunc(flockerspawn) this.enemy.nextthink = time + 10; this.enemy.flock_id = this.flock_id; this.enemy.owner = this; + + IL_PUSH(g_flockers, this); + IL_PUSH(g_flockers, this.enemy); } #endif diff --git a/qcsrc/server/steerlib.qh b/qcsrc/server/steerlib.qh index 4beb69f63..89ffb698e 100644 --- a/qcsrc/server/steerlib.qh +++ b/qcsrc/server/steerlib.qh @@ -5,3 +5,6 @@ vector steerlib_arrive(entity this, vector point, float maximal_distance); vector steerlib_attract2(entity this, vector point, float min_influense, float max_distance, float max_influense); //vector steerlib_pull(entity this, vector point); + +IntrusiveList g_flockers; +STATIC_INIT(g_flockers) { g_flockers = IL_NEW(); } diff --git a/qcsrc/server/weapons/tracing.qc b/qcsrc/server/weapons/tracing.qc index b37e1578e..8e4f88b8c 100644 --- a/qcsrc/server/weapons/tracing.qc +++ b/qcsrc/server/weapons/tracing.qc @@ -234,6 +234,7 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector break; // make the entity non-solid so we can hit the next one + IL_PUSH(g_railgunhit, trace_ent); trace_ent.railgunhit = true; trace_ent.railgunhitloc = end; trace_ent.railgunhitsolidbackup = trace_ent.solid; @@ -253,7 +254,7 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector float endq3surfaceflags = trace_dphitq3surfaceflags; // find all the entities the railgun hit and restore their solid state - FOREACH_ENTITY_FLOAT(railgunhit, true, + IL_EACH(g_railgunhit, it.railgunhit, { it.solid = it.railgunhitsolidbackup; }); @@ -287,8 +288,10 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector } // find all the entities the railgun hit and hurt them - FOREACH_ENTITY_FLOAT(railgunhit, true, + IL_EACH(g_railgunhit, it.railgunhit, { + // removal from the list is handled below + // get the details we need to call the damage function vector hitloc = it.railgunhitloc; @@ -312,6 +315,8 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector it.railgundistance = 0; }); + IL_CLEAR(g_railgunhit); + // calculate hits and fired shots for hitscan accuracy_add(this, this.(weaponentity).m_weapon.m_id, 0, min(bdamage, totaldmg));