]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Replace some findfloat loops with intrusive lists where possible
authorMario <mario@smbclan.net>
Wed, 17 May 2017 21:01:18 +0000 (07:01 +1000)
committerMario <mario@smbclan.net>
Wed, 17 May 2017 21:01:18 +0000 (07:01 +1000)
qcsrc/common/turrets/turret/tesla_weapon.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc
qcsrc/server/miscfunctions.qh
qcsrc/server/steerlib.qc
qcsrc/server/steerlib.qh
qcsrc/server/weapons/tracing.qc

index a173d8b675cbd590d1defb4ef85f424542fc736b..1d90562ae6de5af785797bdd17534b9cfdcb59c8 100644 (file)
@@ -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;
index e210151dce99f3a6e8a5cb1dd9531ebc489c51c1..d8747d0b426010a3bb1e4e6034bd67b98b0ef45f 100644 (file)
@@ -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(); }
index afa6d1044d0df10203217bee9d8020e35c077eb2..419d3be7a76b119e374c6ef9b6b815579ba660bc 100644 (file)
@@ -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)
 {
index 1e2dc57f095ee8202e6271122a5bdc063c638d7c..33d5c14f315020e1aedb5baf860663380a9c9886 100644 (file)
@@ -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(); }
index f986fa2a84f7930b3f732964b4bd8a86aaecd4c9..3418a2c4e375a80c0506dcf58400018c918297fd 100644 (file)
@@ -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
 
index 4beb69f6328ba6c337d3b34e803104464e8a73d3..89ffb698ec6ca763d97f8ad899ddec5a6ed82ae8 100644 (file)
@@ -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(); }
index b37e1578e2878ed0011c4fe22d59cf42eee168ad..8e4f88b8cd3d8c4fcf957b1a154e815a4d5158a8 100644 (file)
@@ -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));