diff --git a/server/gameserver/mapinstance.cc b/server/gameserver/mapinstance.cc index bc3f2024..1e08c593 100644 --- a/server/gameserver/mapinstance.cc +++ b/server/gameserver/mapinstance.cc @@ -16,7 +16,6 @@ #include "roommgr.h" -static const int MAX_POLYS = 256; static const int NAV_ERROR_NEARESTPOLY = -2; static const int NAV_ERROR = -1; @@ -260,7 +259,6 @@ int MapInstance::FindStraightPath(int layer, return NAV_ERROR_NEARESTPOLY; } - dtPolyRef polys[MAX_POLYS]; int npolys; float straightPath[MAX_POLYS * 3]; unsigned char straightPathFlags[MAX_POLYS]; @@ -274,7 +272,7 @@ int MapInstance::FindStraightPath(int layer, startNearestPt, endNearestPt, &filter, - polys, + polys_, &npolys, MAX_POLYS); nstraightPath = 0; @@ -284,13 +282,13 @@ int MapInstance::FindStraightPath(int layer, float epos1[3]; dtVcopy(epos1, endNearestPt); - if (polys[npolys-1] != endRef) { - navmesh_query_->closestPointOnPoly(polys[npolys-1], endNearestPt, epos1, 0); + if (polys_[npolys-1] != endRef) { + navmesh_query_->closestPointOnPoly(polys_[npolys-1], endNearestPt, epos1, 0); } navmesh_query_->findStraightPath(startNearestPt, endNearestPt, - polys, + polys_, npolys, straightPath, straightPathFlags, @@ -357,8 +355,6 @@ int MapInstance::FindRandomPointAroundCircle(int layer, int MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point) { - float hitPoint[3]; - float spos[3]; spos[0] = start.x; spos[1] = start.y; @@ -384,31 +380,29 @@ int MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& end } float t = 0; - float hitNormal[3]; - memset(hitNormal, 0, sizeof(hitNormal)); + memset(hit_normal_, 0, sizeof(hit_normal_)); - dtPolyRef polys[MAX_POLYS]; int npolys; - navmesh_query_->raycast(startRef, spos, epos, &filter, &t, hitNormal, polys, &npolys, MAX_POLYS); + navmesh_query_->raycast(startRef, spos, epos, &filter, &t, hit_normal_, polys_, &npolys, MAX_POLYS); if (t > 1) { return NAV_ERROR; } else { // Hit - hitPoint[0] = spos[0] + (epos[0] - spos[0]) * t; - hitPoint[1] = spos[1] + (epos[1] - spos[1]) * t; - hitPoint[2] = spos[2] + (epos[2] - spos[2]) * t; + hit_pos_[0] = spos[0] + (epos[0] - spos[0]) * t; + hit_pos_[1] = spos[1] + (epos[1] - spos[1]) * t; + hit_pos_[2] = spos[2] + (epos[2] - spos[2]) * t; if (npolys) { float h = 0; - navmesh_query_->getPolyHeight(polys[npolys-1], hitPoint, &h); - hitPoint[1] = h; + navmesh_query_->getPolyHeight(polys_[npolys-1], hit_pos_, &h); + hit_pos_[1] = h; } } - hit_point.x = hitPoint[0]; - hit_point.y = hitPoint[1]; - hit_point.z = hitPoint[2]; + hit_point.x = hit_pos_[0]; + hit_point.y = hit_pos_[1]; + hit_point.z = hit_pos_[2]; return 1; } diff --git a/server/gameserver/mapinstance.h b/server/gameserver/mapinstance.h index 77088f18..305c53df 100644 --- a/server/gameserver/mapinstance.h +++ b/server/gameserver/mapinstance.h @@ -8,6 +8,8 @@ namespace MetaData struct Map; } +const int MAX_POLYS = 256; + class Entity; class Obstacle; class MapService; @@ -47,6 +49,10 @@ class MapInstance dtNavMesh* navmesh_ = nullptr; dtNavMeshQuery* navmesh_query_ = nullptr; + float hit_normal_[3]; + float hit_pos_[3]; + dtPolyRef polys_[MAX_POLYS]; + int current_uniid_ = 0; std::map uniid_hash_;