]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix a crash and a bunch of warnings when fancy pathing is enabled
authorMario <mario@smbclan.net>
Sat, 24 Jun 2017 02:38:15 +0000 (12:38 +1000)
committerMario <mario@smbclan.net>
Sat, 24 Jun 2017 02:38:15 +0000 (12:38 +1000)
qcsrc/common/turrets/turret/ewheel.qc
qcsrc/server/defs.qh
qcsrc/server/pathlib/main.qc
qcsrc/server/pathlib/movenode.qc
qcsrc/server/pathlib/pathlib.qh
qcsrc/server/pathlib/utility.qc

index fd85e68decfac5a33accfbb5e001be40d9a75111..403a0ddf6c2bedcefa2a23b8e20d993710137786 100644 (file)
@@ -140,10 +140,9 @@ spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this)
 
 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
 {
-    float vz;
     vector wish_angle, real_angle;
 
-    vz = it.velocity_z;
+    float vz = it.velocity_z;
 
     it.angles_x = anglemods(it.angles_x);
     it.angles_y = anglemods(it.angles_y);
index 7f0c2610f9ab40aa46d4c90aaa162fa99b5763a5..a6ca911bdc64fe4d5cbe29ae4d8bb149348b349e 100644 (file)
@@ -482,3 +482,6 @@ STATIC_INIT(g_saved_team) { g_saved_team = IL_NEW(); }
 
 IntrusiveList g_monster_targets;
 STATIC_INIT(g_monster_targets) { g_monster_targets = IL_NEW(); }
+
+IntrusiveList g_pathlib_nodes;
+STATIC_INIT(g_pathlib_nodes) { g_pathlib_nodes = IL_NEW(); }
index 833ad9b3f33bba542bc8cafbfdd2598f14fd79ad..706e10d9e249135e73764dcda180f4f0ac8519f3 100644 (file)
@@ -6,6 +6,9 @@
 
 void pathlib_deletepath(entity start)
 {
+    if(!start)
+        return;
+
     FOREACH_ENTITY_ENT(owner, start,
     {
         setthink(it, SUB_Remove);
@@ -17,6 +20,8 @@ const float PATHLIB_NODEEXPIRE = 20; // 0.05
 
 void dumpnode(entity n)
 {
+    if(n.is_path_node)
+        IL_REMOVE(g_pathlib_nodes, n);
     n.is_path_node = false;
     setthink(n, SUB_Remove);
     n.nextthink    = time;
@@ -44,6 +49,7 @@ entity pathlib_mknode(vector where,entity parent)
 
     setthink(node, SUB_Remove);
     node.nextthink    = time + PATHLIB_NODEEXPIRE;
+    IL_PUSH(g_pathlib_nodes, node);
     node.is_path_node = true;
     node.owner        = openlist;
     node.path_prev    = parent;
@@ -69,7 +75,7 @@ bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goa
 
     if(inwater(parent.origin))
     {
-        LOG_TRACE("FromWater");
+        LOG_DEBUG("FromWater");
         pathlib_expandnode = pathlib_expandnode_box;
         pathlib_movenode   = pathlib_swimnode;
     }
@@ -77,13 +83,13 @@ bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goa
     {
         if(inwater(to))
         {
-            LOG_TRACE("ToWater");
+            LOG_DEBUG("ToWater");
             pathlib_expandnode = pathlib_expandnode_box;
             pathlib_movenode   = pathlib_walknode;
         }
         else
         {
-            LOG_TRACE("LandToLoand");
+            LOG_DEBUG("LandToLoand");
             //if(edge_check(parent.origin))
             //    return 0;
 
@@ -96,7 +102,7 @@ bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goa
     entity node = pathlib_nodeatpoint(to);
     if(node)
     {
-        LOG_TRACE("NodeAtPoint");
+        LOG_DEBUG("NodeAtPoint");
         ++pathlib_merge_cnt;
 
         if(node.owner == openlist)
@@ -129,7 +135,7 @@ bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goa
     {
         //pathlib_showsquare(where, 0 ,30);
         //pathlib_showsquare(parent.origin, 1 ,30);
-        LOG_TRACE("pathlib_movenode_goodnode = 0");
+        LOG_DEBUG("pathlib_movenode_goodnode = 0");
         return false;
     }
 
@@ -137,9 +143,9 @@ bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goa
 
     if(pathlib_nodeatpoint(where))
     {
-        LOG_TRACE("NAP WHERE :",vtos(where));
-        LOG_TRACE("not NAP TO:",vtos(to));
-        LOG_TRACE("NAP-NNAP:",ftos(vlen(to-where)));
+        LOG_DEBUG("NAP WHERE :",vtos(where));
+        LOG_DEBUG("not NAP TO:",vtos(to));
+        LOG_DEBUG("NAP-NNAP:",ftos(vlen(to-where)));
         return false;
     }
 
@@ -147,7 +153,7 @@ bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goa
     if(dodge)
         if (!tile_check(parent, where))
         {
-            LOG_TRACE("tile_check fail");
+            LOG_DEBUG("tile_check fail");
 #if DEBUGPATHING
             pathlib_showsquare(where, 0 ,30);
 #endif
@@ -263,19 +269,21 @@ void pathlib_cleanup()
 
     //return;
 
-    FOREACH_ENTITY_FLOAT(is_path_node, true,
+    IL_EACH(g_pathlib_nodes, it.is_path_node,
     {
        dumpnode(it);
     });
 
+    IL_CLEAR(g_pathlib_nodes);
+
     if(openlist)
         delete(openlist);
 
     if(closedlist)
         delete(closedlist);
 
-    openlist       = NULL;
-    closedlist     = NULL;
+    openlist = NULL;
+    closedlist = NULL;
 }
 
 float Cosine_Interpolate(float a, float b, float c)
@@ -283,7 +291,7 @@ float Cosine_Interpolate(float a, float b, float c)
        float ft = c * 3.1415927;
        float f = (1 - cos(ft)) * 0.5;
 
-       return  a*(1-f) + b*f;
+       return a*(1-f) + b*f;
 }
 
 bool buildpath_nodefilter_directional(vector n,vector c,vector p)
@@ -421,18 +429,18 @@ entity pathlib_astar(entity this, vector from, vector to)
 
     from.x = fsnap(from.x, pathlib_gridsize);
     from.y = fsnap(from.y, pathlib_gridsize);
-    //from_z += 32;
+    //from.z += 32;
 
     to.x = fsnap(to.x, pathlib_gridsize);
     to.y = fsnap(to.y, pathlib_gridsize);
-    //to_z += 32;
+    //to.z += 32;
 
-    LOG_TRACE("AStar init");
+    LOG_DEBUG("AStar init");
     entity path = pathlib_mknode(from, NULL);
     pathlib_close_node(path, to);
     if(pathlib_foundgoal)
     {
-        LOG_TRACE("AStar: Goal found on first node!");
+        LOG_DEBUG("AStar: Goal found on first node!");
 
         open           = new(path_end);
         open.owner     = open;
@@ -463,7 +471,7 @@ entity pathlib_astar(entity this, vector from, vector to)
     {
         if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime)
         {
-            LOG_TRACE("Path took to long to compute!");
+            LOG_TRACE("Path took too long to compute!");
             LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt));
             LOG_TRACE("Nodes -    open: ", ftos(pathlib_open_cnt));
             LOG_TRACE("Nodes -  merged: ", ftos(pathlib_merge_cnt));
@@ -484,7 +492,7 @@ entity pathlib_astar(entity this, vector from, vector to)
 
         if(pathlib_foundgoal)
         {
-            LOG_TRACE("Target found. Rebuilding and filtering path...");
+            LOG_DEBUG("Target found. Rebuilding and filtering path...");
             float ftime = gettime(GETTIME_REALTIME);
             ptime = ftime - ptime;
 
index ca9180eefa096c6e6f67976354d5bbbabde83ea2..f27ab4879dad2dedeea575b1146248ae291ca4c9 100644 (file)
@@ -86,7 +86,7 @@ vector pathlib_walknode(entity this, vector start, vector end, float doedge)
 {
     vector point;
 
-    LOG_TRACE("Walking node from ", vtos(start), " to ", vtos(end));
+    LOG_DEBUG("Walking node from ", vtos(start), " to ", vtos(end));
 
     pathlib_movenode_goodnode = false;
 
index a014c7ce2ab0c57874ac0be849538ad4899b8341..21ef8b3cbc5286f50a89ca72dde12a3454c7f7a1 100644 (file)
@@ -26,7 +26,7 @@ entity closedlist;
 entity goal_node;
 entity start_node;
 
-.float is_path_node;
+.bool is_path_node;
 .float pathlib_node_g;
 .float pathlib_node_h;
 .float pathlib_node_f;
index 9ebaac9f275830a8115f4ac661165cd8f4235a6b..da64db697345b9a2cd70f0ef100ef6ff6409661b 100644 (file)
@@ -28,12 +28,14 @@ entity pathlib_nodeatpoint(vector where)
     where.x = fsnap(where.x,pathlib_gridsize);
     where.y = fsnap(where.y,pathlib_gridsize);
 
-    FOREACH_ENTITY_RADIUS(where, pathlib_gridsize * 0.5, it.is_path_node,
+    entity found = NULL; // TODO: using FOREACH_ENTITY_RADIUS here causes mutex loop warnings, this may need a proper fix!
+    IL_EACH(g_pathlib_nodes, it.is_path_node && vdist(it.origin - where, <, pathlib_gridsize * 0.5),
     {
-       return it;
+       found = it;
+        break;
     });
 
-    return NULL;
+    return found;
 }
 
 bool tile_check_cross(entity this, vector where)