From: Mario Date: Sat, 24 Jun 2017 02:38:15 +0000 (+1000) Subject: Fix a crash and a bunch of warnings when fancy pathing is enabled X-Git-Tag: xonotic-v0.8.5~2702 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bad136c27b2f10dd2d4761f07b17d3a7f586a051;p=xonotic%2Fxonotic-data.pk3dir.git Fix a crash and a bunch of warnings when fancy pathing is enabled --- diff --git a/qcsrc/common/turrets/turret/ewheel.qc b/qcsrc/common/turrets/turret/ewheel.qc index fd85e68de..403a0ddf6 100644 --- a/qcsrc/common/turrets/turret/ewheel.qc +++ b/qcsrc/common/turrets/turret/ewheel.qc @@ -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); diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 7f0c2610f..a6ca911bd 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -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(); } diff --git a/qcsrc/server/pathlib/main.qc b/qcsrc/server/pathlib/main.qc index 833ad9b3f..706e10d9e 100644 --- a/qcsrc/server/pathlib/main.qc +++ b/qcsrc/server/pathlib/main.qc @@ -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; diff --git a/qcsrc/server/pathlib/movenode.qc b/qcsrc/server/pathlib/movenode.qc index ca9180eef..f27ab4879 100644 --- a/qcsrc/server/pathlib/movenode.qc +++ b/qcsrc/server/pathlib/movenode.qc @@ -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; diff --git a/qcsrc/server/pathlib/pathlib.qh b/qcsrc/server/pathlib/pathlib.qh index a014c7ce2..21ef8b3cb 100644 --- a/qcsrc/server/pathlib/pathlib.qh +++ b/qcsrc/server/pathlib/pathlib.qh @@ -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; diff --git a/qcsrc/server/pathlib/utility.qc b/qcsrc/server/pathlib/utility.qc index 9ebaac9f2..da64db697 100644 --- a/qcsrc/server/pathlib/utility.qc +++ b/qcsrc/server/pathlib/utility.qc @@ -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)