Make railgunhit a bool and reduce a find loop to intrusiveness using less than sanita...
authorMario <mario@smbclan.net>
Sat, 20 May 2017 10:07:18 +0000 (20:07 +1000)
committerMario <mario@smbclan.net>
Sat, 20 May 2017 10:07:18 +0000 (20:07 +1000)
.gitlab-ci.yml
qcsrc/common/triggers/target/location.qc
qcsrc/common/turrets/turret/tesla_weapon.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc

index 8599460..8f78b5e 100644 (file)
@@ -29,7 +29,7 @@ test_sv_game:
     - wget -O data/maps/stormkeep.waypoints https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints
     - wget -O data/maps/stormkeep.waypoints.cache https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints.cache
     - make
-    - EXPECT=16ecb14f9a9d01196fe1c0cc9e04868e
+    - EXPECT=d00c303596d1be0274375bc5b87619d6
     - HASH=$(${ENGINE} -noconfig -nohome +exec serverbench.cfg
       | tee /dev/stderr
       | grep '^:'
index 5259276..5774f45 100644 (file)
@@ -9,6 +9,8 @@ spawnfunc(target_location)
     // eventually support: count, teamgame selectors, line of sight?
 
     target_push_init(this);
+
+    IL_PUSH(g_locations, this);
 }
 
 spawnfunc(info_location)
@@ -17,5 +19,7 @@ spawnfunc(info_location)
     this.message = this.netname;
 
     target_push_init(this);
+
+    IL_PUSH(g_locations, this);
 }
 #endif
index 1d90562..7e6fda7 100644 (file)
@@ -44,7 +44,7 @@ METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, .enti
 
         IL_EACH(g_railgunhit, it.railgunhit,
         {
-            it.railgunhit = 0;
+            it.railgunhit = false;
         });
         IL_CLEAR(g_railgunhit);
     }
@@ -76,7 +76,7 @@ entity toast(entity actor, entity from, float range, float damage)
     {
         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;
+        etarget.railgunhit = true;
         IL_PUSH(g_railgunhit, etarget);
     }
 
index 08f1d20..c8e5f62 100644 (file)
@@ -86,7 +86,7 @@ const float MAX_DAMAGEEXTRARADIUS = 16;
 .float         dmg;
 
 // for railgun damage (hitting multiple enemies)
-.float railgunhit;
+.bool railgunhit;
 .float railgunhitsolidbackup;
 .vector railgunhitloc;
 
@@ -473,3 +473,6 @@ STATIC_INIT(g_railgunhit) { g_railgunhit = IL_NEW(); }
 
 IntrusiveList g_ladders;
 STATIC_INIT(g_ladders) { g_ladders = IL_NEW(); }
+
+IntrusiveList g_locations;
+STATIC_INIT(g_locations) { g_locations = IL_NEW(); }
index 419d3be..c66a632 100644 (file)
@@ -112,65 +112,53 @@ void GameLogClose()
     }
 }
 
-entity findnearest(vector point, .string field, string value, vector axismod)
+entity findnearest(vector point, bool checkitems, vector axismod)
 {
-    entity localhead;
-    float i;
-    float j;
-    float len;
     vector dist;
+    int num_nearest = 0;
 
-    float num_nearest;
-    num_nearest = 0;
-
-    localhead = find(NULL, field, value);
-    while (localhead)
+    IL_EACH(((checkitems) ? g_items : g_locations), ((checkitems) ? (it.target == "###item###") : (it.classname == "target_location")),
     {
-        if ((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
-            dist = localhead.oldorigin;
+       if ((it.items == IT_KEY1 || it.items == IT_KEY2) && it.target == "###item###")
+            dist = it.oldorigin;
         else
-            dist = localhead.origin;
+            dist = it.origin;
         dist = dist - point;
         dist = dist.x * axismod.x * '1 0 0' + dist.y * axismod.y * '0 1 0' + dist.z * axismod.z * '0 0 1';
-        len = vlen(dist);
+        float len = vlen2(dist);
 
-        for (i = 0; i < num_nearest; ++i)
+        int l;
+        for (l = 0; l < num_nearest; ++l)
         {
-            if (len < nearest_length[i])
+            if (len < nearest_length[l])
                 break;
         }
 
         // now i tells us where to insert at
         //   INSERTION SORT! YOU'VE SEEN IT! RUN!
-        if (i < NUM_NEAREST_ENTITIES)
+        if (l < NUM_NEAREST_ENTITIES)
         {
-            for (j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
+            for (int j = NUM_NEAREST_ENTITIES - 1; j >= l; --j)
             {
                 nearest_length[j + 1] = nearest_length[j];
                 nearest_entity[j + 1] = nearest_entity[j];
             }
-            nearest_length[i] = len;
-            nearest_entity[i] = localhead;
+            nearest_length[l] = len;
+            nearest_entity[l] = it;
             if (num_nearest < NUM_NEAREST_ENTITIES)
                 num_nearest = num_nearest + 1;
         }
-
-        localhead = find(localhead, field, value);
-    }
+    });
 
     // now use the first one from our list that we can see
-    for (i = 0; i < num_nearest; ++i)
+    for (int j = 0; j < num_nearest; ++j)
     {
-        traceline(point, nearest_entity[i].origin, true, NULL);
+        traceline(point, nearest_entity[j].origin, true, NULL);
         if (trace_fraction == 1)
         {
-            if (i != 0)
-            {
-                LOG_TRACE("Nearest point (");
-                LOG_TRACE(nearest_entity[0].netname);
-                LOG_TRACE(") is not visible, using a visible one.");
-            }
-            return nearest_entity[i];
+            if (j != 0)
+                LOG_TRACEF("Nearest point (%s) is not visible, using a visible one.", nearest_entity[0].netname);
+            return nearest_entity[j];
         }
     }
 
@@ -194,17 +182,13 @@ entity findnearest(vector point, .string field, string value, vector axismod)
 
 string NearestLocation(vector p)
 {
-    entity loc;
-    string ret;
-    ret = "somewhere";
-    loc = findnearest(p, classname, "target_location", '1 1 1');
+    string ret = "somewhere";
+    entity loc = findnearest(p, false, '1 1 1');
     if (loc)
-    {
         ret = loc.message;
-    }
     else
     {
-        loc = findnearest(p, target, "###item###", '1 1 4');
+        loc = findnearest(p, true, '1 1 4');
         if (loc)
             ret = loc.netname;
     }