X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fpathlib%2Fmain.qc;h=c033f3f52a6c4f9955becffb46ba20d4aed9e5a6;hb=42a9e3d7ece2c716e5cd6899e90841acb7fb891b;hp=5fef3251f64b568680f124c442a85572d2ee35c0;hpb=530e06120a7b41f6175b1144fedf6903da8c13b0;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/pathlib/main.qc b/qcsrc/server/pathlib/main.qc index 5fef3251f..c033f3f52 100644 --- a/qcsrc/server/pathlib/main.qc +++ b/qcsrc/server/pathlib/main.qc @@ -1,3 +1,9 @@ +#include "main.qh" + +#include "pathlib.qh" +#include "utility.qh" +#include "../command/common.qh" + void pathlib_deletepath(entity start) { entity e; @@ -5,7 +11,7 @@ void pathlib_deletepath(entity start) e = findchainentity(owner, start); while(e) { - e.think = SUB_Remove; + setthink(e, SUB_Remove); e.nextthink = time; e = e.chain; } @@ -17,10 +23,17 @@ const float PATHLIB_NODEEXPIRE = 20; void dumpnode(entity n) { n.is_path_node = false; - n.think = SUB_Remove; + setthink(n, SUB_Remove); n.nextthink = time; } +#if DEBUGPATHING +void pathlib_showpath(entity start); +void pathlib_showpath2(entity path); +void pathlib_showsquare(vector where,float goodsquare,float _lifetime); +#endif + + entity pathlib_mknode(vector where,entity parent) { entity node; @@ -36,7 +49,7 @@ entity pathlib_mknode(vector where,entity parent) node = spawn(); - node.think = SUB_Remove; + setthink(node, SUB_Remove); node.nextthink = time + PATHLIB_NODEEXPIRE; node.is_path_node = true; node.owner = openlist; @@ -47,8 +60,9 @@ entity pathlib_mknode(vector where,entity parent) setorigin(node, where); node.medium = pointcontents(where); +#if DEBUGPATHING pathlib_showsquare(where, 1 ,15); - +#endif ++pathlib_made_cnt; ++pathlib_open_cnt; @@ -65,7 +79,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go if(inwater(parent.origin)) { - dprint("FromWater\n"); + LOG_TRACE("FromWater\n"); pathlib_expandnode = pathlib_expandnode_box; pathlib_movenode = pathlib_swimnode; } @@ -73,13 +87,13 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go { if(inwater(to)) { - dprint("ToWater\n"); + LOG_TRACE("ToWater\n"); pathlib_expandnode = pathlib_expandnode_box; pathlib_movenode = pathlib_walknode; } else { - dprint("LandToLoand\n"); + LOG_TRACE("LandToLoand\n"); //if(edge_check(parent.origin)) // return 0; @@ -92,7 +106,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go node = pathlib_nodeatpoint(to); if(node) { - dprint("NodeAtPoint\n"); + LOG_TRACE("NodeAtPoint\n"); ++pathlib_merge_cnt; if(node.owner == openlist) @@ -119,13 +133,13 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go return 1; } - where = pathlib_movenode(parent.origin, to, 0); + where = pathlib_movenode(parent, parent.origin, to, 0); if (!pathlib_movenode_goodnode) { //pathlib_showsquare(where, 0 ,30); //pathlib_showsquare(parent.origin, 1 ,30); - dprint("pathlib_movenode_goodnode = 0\n"); + LOG_TRACE("pathlib_movenode_goodnode = 0\n"); return 0; } @@ -133,18 +147,20 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go if(pathlib_nodeatpoint(where)) { - dprint("NAP WHERE :",vtos(where),"\n"); - dprint("not NAP TO:",vtos(to),"\n"); - dprint("NAP-NNAP:",ftos(vlen(to-where)),"\n\n"); + LOG_TRACE("NAP WHERE :",vtos(where),"\n"); + LOG_TRACE("not NAP TO:",vtos(to),"\n"); + LOG_TRACE("NAP-NNAP:",ftos(vlen(to-where)),"\n\n"); return 0; } if(doedge) - if (!tile_check(where)) + if (!tile_check(parent, where)) { - dprint("tile_check fail\n"); + LOG_TRACE("tile_check fail\n"); +#if DEBUGPATHING pathlib_showsquare(where, 0 ,30); +#endif return 0; } @@ -164,7 +180,7 @@ float pathlib_makenode_adaptive(entity parent,vector start, vector to, vector go { if(node.pathlib_node_g > g) { - //pathlib_movenode(where,node.origin,0); + //pathlib_movenode(node, where,node.origin,0); //if(pathlib_movenode_goodnode) //{ //mark_error(node.origin + '0 0 128',30); @@ -235,7 +251,7 @@ void pathlib_close_node(entity node,vector goal) if(node.owner == closedlist) { - dprint("Pathlib: Tried to close a closed node!\n"); + LOG_TRACE("Pathlib: Tried to close a closed node!\n"); return; } @@ -247,11 +263,11 @@ void pathlib_close_node(entity node,vector goal) node.owner = closedlist; - if(vlen(node.origin - goal) <= pathlib_gridsize) + if(vdist(node.origin - goal, <=, pathlib_gridsize)) { vector goalmove; - goalmove = pathlib_walknode(node.origin,goal,1); + goalmove = pathlib_walknode(node, node.origin, goal, 1); if(pathlib_movenode_goodnode) { goal_node = node; @@ -320,9 +336,9 @@ float buildpath_nodefilter_directional(vector n,vector c,vector p) return 0; } -float buildpath_nodefilter_moveskip(vector n,vector c,vector p) +float buildpath_nodefilter_moveskip(entity this, vector n,vector c,vector p) { - pathlib_walknode(p,n,1); + pathlib_walknode(this, p, n, 1); if(pathlib_movenode_goodnode) return 1; @@ -363,7 +379,7 @@ entity path_build(entity next, vector where, entity prev, entity start) return path; } -entity pathlib_astar(vector from,vector to) +entity pathlib_astar(entity this, vector from,vector to) { entity path, start, end, open, n, ln; float ptime, ftime, ctime; @@ -426,8 +442,8 @@ entity pathlib_astar(vector from,vector to) pathlib_movecost_waterfactor = 25000000; pathlib_foundgoal = 0; - movenode_boxmax = self.maxs * 1.1; - movenode_boxmin = self.mins * 1.1; + movenode_boxmax = this.maxs * 1.1; + movenode_boxmin = this.mins * 1.1; movenode_stepsize = pathlib_gridsize * 0.25; @@ -451,16 +467,15 @@ entity pathlib_astar(vector from,vector to) to.y = fsnap(to.y, pathlib_gridsize); //to_z += 32; - dprint("AStar init\n"); + LOG_TRACE("AStar init\n"); path = pathlib_mknode(from, world); pathlib_close_node(path, to); if(pathlib_foundgoal) { - dprint("AStar: Goal found on first node!\n"); + LOG_TRACE("AStar: Goal found on first node!\n"); - open = spawn(); + open = new(path_end); open.owner = open; - open.classname = "path_end"; setorigin(open,path.origin); pathlib_cleanup(); @@ -470,7 +485,7 @@ entity pathlib_astar(vector from,vector to) if(pathlib_expandnode(path, from, to) <= 0) { - dprint("AStar path fail.\n"); + LOG_TRACE("AStar path fail.\n"); pathlib_cleanup(); return world; @@ -488,11 +503,11 @@ entity pathlib_astar(vector from,vector to) { if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime) { - dprint("Path took to long to compute!\n"); - dprint("Nodes - created: ", ftos(pathlib_made_cnt),"\n"); - dprint("Nodes - open: ", ftos(pathlib_open_cnt),"\n"); - dprint("Nodes - merged: ", ftos(pathlib_merge_cnt),"\n"); - dprint("Nodes - closed: ", ftos(pathlib_closed_cnt),"\n"); + LOG_TRACE("Path took to long to compute!\n"); + LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt),"\n"); + LOG_TRACE("Nodes - open: ", ftos(pathlib_open_cnt),"\n"); + LOG_TRACE("Nodes - merged: ", ftos(pathlib_merge_cnt),"\n"); + LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt),"\n"); pathlib_cleanup(); return world; @@ -509,7 +524,7 @@ entity pathlib_astar(vector from,vector to) if(pathlib_foundgoal) { - dprint("Target found. Rebuilding and filtering path...\n"); + LOG_TRACE("Target found. Rebuilding and filtering path...\n"); ftime = gettime(GETTIME_REALTIME); ptime = ftime - ptime; @@ -533,29 +548,29 @@ entity pathlib_astar(vector from,vector to) ctime = gettime(GETTIME_REALTIME) - ctime; -#ifdef DEBUGPATHING +#if DEBUGPATHING pathlib_showpath2(start); - dprint("Time used - pathfinding: ", ftos(ptime),"\n"); - dprint("Time used - rebuild & filter: ", ftos(ftime),"\n"); - dprint("Time used - cleanup: ", ftos(ctime),"\n"); - dprint("Time used - total: ", ftos(ptime + ftime + ctime),"\n"); - dprint("Time used - # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime)),"\n\n"); - dprint("Nodes - created: ", ftos(pathlib_made_cnt),"\n"); - dprint("Nodes - open: ", ftos(pathlib_open_cnt),"\n"); - dprint("Nodes - merged: ", ftos(pathlib_merge_cnt),"\n"); - dprint("Nodes - closed: ", ftos(pathlib_closed_cnt),"\n"); - dprint("Nodes - searched: ", ftos(pathlib_searched_cnt),"\n"); - dprint("Nodes bestopen searched: ", ftos(pathlib_bestopen_seached),"\n"); - dprint("Nodes bestcash - hits: ", ftos(pathlib_bestcash_hits),"\n"); - dprint("Nodes bestcash - save: ", ftos(pathlib_bestcash_saved),"\n"); - dprint("AStar done.\n"); + LOG_TRACE("Time used - pathfinding: ", ftos(ptime),"\n"); + LOG_TRACE("Time used - rebuild & filter: ", ftos(ftime),"\n"); + LOG_TRACE("Time used - cleanup: ", ftos(ctime),"\n"); + LOG_TRACE("Time used - total: ", ftos(ptime + ftime + ctime),"\n"); + LOG_TRACE("Time used - # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime)),"\n\n"); + LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt),"\n"); + LOG_TRACE("Nodes - open: ", ftos(pathlib_open_cnt),"\n"); + LOG_TRACE("Nodes - merged: ", ftos(pathlib_merge_cnt),"\n"); + LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt),"\n"); + LOG_TRACE("Nodes - searched: ", ftos(pathlib_searched_cnt),"\n"); + LOG_TRACE("Nodes bestopen searched: ", ftos(pathlib_bestopen_seached),"\n"); + LOG_TRACE("Nodes bestcash - hits: ", ftos(pathlib_bestcash_hits),"\n"); + LOG_TRACE("Nodes bestcash - save: ", ftos(pathlib_bestcash_saved),"\n"); + LOG_TRACE("AStar done.\n"); #endif return start; } } - dprint("A* Faild to find a path! Try a smaller gridsize.\n"); + LOG_TRACE("A* Faild to find a path! Try a smaller gridsize.\n"); pathlib_cleanup();