X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fpathlib%2Futility.qc;h=151fb44b56abec6096379d63b351b42a315e7d9a;hb=677328b0b1e53bdd5868d5020d2f7e52cf8c2d42;hp=7bdc70877420a38d60bd7ce7b3da04e99abe4c28;hpb=82dbcadfd0556053b74638f2e3ae2e57103ddf26;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/pathlib/utility.qc b/qcsrc/server/pathlib/utility.qc index 7bdc70877..151fb44b5 100644 --- a/qcsrc/server/pathlib/utility.qc +++ b/qcsrc/server/pathlib/utility.qc @@ -1,165 +1,121 @@ -float fsnap(float val,float fsize) -{ - return rint(val / fsize) * fsize; -} - -vector vsnap(vector point,float fsize) -{ - vector vret; +#include "utility.qh" - vret.x = rint(point.x / fsize) * fsize; - vret.y = rint(point.y / fsize) * fsize; - vret.z = ceil(point.z / fsize) * fsize; +#include +#include +#include "pathlib.qh" - return vret; -} - -float location_isok(vector point, float water_isok, float air_isok) +bool location_isok(vector point, bool waterok, bool air_isok) { - float pc,pc2; - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) - return 0; - - pc = pointcontents(point); - pc2 = pointcontents(point - '0 0 1'); - - switch(pc) - { - case CONTENT_SOLID: - break; - - case CONTENT_SLIME: - break; - - case CONTENT_LAVA: - break; - - case CONTENT_SKY: - break; - - case CONTENT_EMPTY: - if (pc2 == CONTENT_SOLID) - return 1; - - if (pc2 == CONTENT_EMPTY) - if(air_isok) - return 1; - - if (pc2 == CONTENT_WATER) - if(water_isok) - return 1; - - break; - - case CONTENT_WATER: - if (water_isok) - return 1; - - break; - } - - return 0; + return false; + + int pc = pointcontents(point); + int pc2 = pointcontents(point - '0 0 1'); + + if(pc == CONTENT_EMPTY && pc2 == CONTENT_SOLID) + return true; + if(pc == CONTENT_EMPTY && pc2 == CONTENT_WATER && waterok) + return true; + if(pc == CONTENT_EMPTY && pc2 == CONTENT_EMPTY && air_isok) + return true; + if(pc == CONTENT_WATER && waterok) + return true; + return false; } entity pathlib_nodeatpoint(vector where) { - entity node; - ++pathlib_searched_cnt; where.x = fsnap(where.x,pathlib_gridsize); where.y = fsnap(where.y,pathlib_gridsize); - node = findradius(where,pathlib_gridsize * 0.5); - while(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), { - if(node.is_path_node == true) - return node; + found = it; + break; + }); - node = node.chain; - } - - return world; + return found; } -float tile_check_cross(vector where) +bool tile_check_cross(entity this, vector where) { - vector p,f,r; - - f = PLIB_FORWARD * tile_check_size; - r = PLIB_RIGHT * tile_check_size; + vector p; + vector f = PLIB_FORWARD * tile_check_size; + vector r = PLIB_RIGHT * tile_check_size; // forward-right p = where + f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (!location_isok(trace_endpos, 1, 0)) - return 0; + return false; // Forward-left p = where + f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (!location_isok(trace_endpos, 1, 0)) - return 0; + return false; // Back-right p = where - f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (!location_isok(trace_endpos, 1 ,0)) - return 0; + return false; //Back-left p = where - f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (!location_isok(trace_endpos, 1, 0)) - return 0; + return false; - return 1; + return true; } -float tile_check_plus(vector where) +bool tile_check_plus(entity this, vector where) { - vector p,f,r; + vector p; - f = PLIB_FORWARD * tile_check_size; - r = PLIB_RIGHT * tile_check_size; + vector f = PLIB_FORWARD * tile_check_size; + vector r = PLIB_RIGHT * tile_check_size; // forward p = where + f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (!location_isok(trace_endpos,1,0)) - return 0; + return false; //left p = where - r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (!location_isok(trace_endpos,1,0)) - return 0; + return false; // Right p = where + r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (!location_isok(trace_endpos,1,0)) - return 0; + return false; //Back p = where - f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (!location_isok(trace_endpos,1,0)) - return 0; + return false; - return 1; + return true; } -float tile_check_plus2(vector where) +float tile_check_plus2(entity this, vector where) { - vector p,f,r; - float i = 0, e = 0; + vector p; + int j = 0, e = 0; - f = PLIB_FORWARD * pathlib_gridsize; - r = PLIB_RIGHT * pathlib_gridsize; + vector f = PLIB_FORWARD * pathlib_gridsize; + vector r = PLIB_RIGHT * pathlib_gridsize; //#define pathlib_node_edgeflag_left 2 //#define pathlib_node_edgeflag_right 4 @@ -168,90 +124,90 @@ float tile_check_plus2(vector where) // forward p = where + f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (location_isok(trace_endpos,1,0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_forward; } //left p = where - r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (location_isok(trace_endpos,1,0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_left; } // Right p = where + r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (location_isok(trace_endpos,1,0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_right; } //Back p = where - f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,self); + traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); if (location_isok(trace_endpos,1,0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_back; } // forward-right p = where + f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (location_isok(trace_endpos, 1, 0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_forwardright; } // Forward-left p = where + f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (location_isok(trace_endpos, 1, 0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_forwardleft; } // Back-right p = where - f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (location_isok(trace_endpos, 1 ,0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_backright; } //Back-left p = where - f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, self); + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); if (location_isok(trace_endpos, 1, 0)) { - ++i; + ++j; e |= pathlib_node_edgeflag_backleft; } - if(i == 0) + if(j == 0) e = pathlib_node_edgeflag_none; return e; } -float tile_check_star(vector where) +bool tile_check_star(entity this, vector where) { - if(tile_check_plus(where)) - return tile_check_cross(where); + if(tile_check_plus(this, where)) + return tile_check_cross(this, where); - return 0; + return false; }