From ef2d11978322a5774ffa409f3caee74d1d8646f1 Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Tue, 29 Sep 2020 23:11:50 +0700 Subject: [PATCH] refactor: Rename NavMesh to Pathfinding --- CMakeLists.txt | 4 ++-- src/game/area.cpp | 4 ++-- src/game/area.h | 4 ++-- src/game/area_actions.cpp | 2 +- src/game/{navmesh.cpp => pathfinding.cpp} | 12 ++++++------ src/game/{navmesh.h => pathfinding.h} | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) rename src/game/{navmesh.cpp => pathfinding.cpp} (88%) rename src/game/{navmesh.h => pathfinding.h} (91%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 194ded4d..11813fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,6 @@ set(HEADERS src/game/gui/mainmenu.h src/game/gui/portraitsel.h src/game/gui/target.h - src/game/navmesh.h src/game/module.h src/game/multiplayer/area.h src/game/multiplayer/callbacks.h @@ -93,6 +92,7 @@ set(HEADERS src/game/object/spatial.h src/game/object/trigger.h src/game/object/waypoint.h + src/game/pathfinding.h src/game/paths.h src/game/room.h src/game/script/routines.h @@ -214,7 +214,6 @@ set(SOURCES src/game/multiplayer/game.cpp src/game/multiplayer/objectfactory.cpp src/game/multiplayer/util.cpp - src/game/navmesh.cpp src/game/object/creature.cpp src/game/object/door.cpp src/game/object/factory.cpp @@ -224,6 +223,7 @@ set(SOURCES src/game/object/spatial.cpp src/game/object/trigger.cpp src/game/object/waypoint.cpp + src/game/pathfinding.cpp src/game/paths.cpp src/game/room.cpp src/game/script/routines.cpp diff --git a/src/game/area.cpp b/src/game/area.cpp index f9b757ef..a222b547 100644 --- a/src/game/area.cpp +++ b/src/game/area.cpp @@ -71,7 +71,7 @@ Area::Area(uint32_t id, GameVersion version, ObjectFactory *objectFactory, Scene _version(version), _objectFactory(objectFactory), _sceneGraph(sceneGraph), - _navMesh(new NavMesh()) { + _pathfinding(new Pathfinding()) { assert(_objectFactory); } @@ -140,7 +140,7 @@ void Area::loadPTH() { _sceneGraph->addRoot(aabb); } - _navMesh->load(paths, pointZ); + _pathfinding->load(paths, pointZ); } void Area::loadARE(const GffStruct &are) { diff --git a/src/game/area.h b/src/game/area.h index 96668162..1ff0350a 100644 --- a/src/game/area.h +++ b/src/game/area.h @@ -27,12 +27,12 @@ #include "../script/variable.h" #include "camera/camera.h" -#include "navmesh.h" #include "object/creature.h" #include "object/door.h" #include "object/placeable.h" #include "object/trigger.h" #include "object/waypoint.h" +#include "pathfinding.h" #include "room.h" namespace reone { @@ -143,7 +143,7 @@ private: std::unique_ptr _visibility; CameraStyle _cameraStyle; std::string _music; - std::unique_ptr _navMesh; + std::unique_ptr _pathfinding; std::unordered_map _scripts; std::list _delayed; std::map _events; diff --git a/src/game/area_actions.cpp b/src/game/area_actions.cpp index f38d84a4..a4672b5f 100644 --- a/src/game/area_actions.cpp +++ b/src/game/area_actions.cpp @@ -141,7 +141,7 @@ void Area::selectNextPathPoint(Creature::Path &path) { void Area::updateCreaturePath(Creature &creature, const glm::vec3 &dest) { const glm::vec3 &origin = creature.position(); - vector points(_navMesh->findPath(origin, dest)); + vector points(_pathfinding->findPath(origin, dest)); uint32_t now = SDL_GetTicks(); creature.setPath(dest, move(points), now); diff --git a/src/game/navmesh.cpp b/src/game/pathfinding.cpp similarity index 88% rename from src/game/navmesh.cpp rename to src/game/pathfinding.cpp index 356c89a2..d7c1b7c3 100644 --- a/src/game/navmesh.cpp +++ b/src/game/pathfinding.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -#include "navmesh.h" +#include "pathfinding.h" #include "glm/gtx/norm.hpp" @@ -27,10 +27,10 @@ namespace reone { namespace game { -NavMesh::Edge::Edge(uint16_t toIndex, float length) : toIndex(toIndex), length(length) { +Pathfinding::Edge::Edge(uint16_t toIndex, float length) : toIndex(toIndex), length(length) { } -void NavMesh::load(const Paths &paths, const unordered_map &pointZ) { +void Pathfinding::load(const Paths &paths, const unordered_map &pointZ) { const vector &points = paths.points(); for (uint16_t i = 0; i < points.size(); ++i) { const Paths::Point &point = points[i]; @@ -49,7 +49,7 @@ void NavMesh::load(const Paths &paths, const unordered_map &pointZ) } } -const vector NavMesh::findPath(const glm::vec3 &from, const glm::vec3 &to) const { +const vector Pathfinding::findPath(const glm::vec3 &from, const glm::vec3 &to) const { if (_vertices.empty()) { return vector { from, to }; } @@ -86,7 +86,7 @@ const vector NavMesh::findPath(const glm::vec3 &from, const glm::vec3 return move(path); } -uint16_t NavMesh::getNearestVertex(const glm::vec3 &point) const { +uint16_t Pathfinding::getNearestVertex(const glm::vec3 &point) const { uint16_t index = 0xffff; float minDist = 0.0f; @@ -102,7 +102,7 @@ uint16_t NavMesh::getNearestVertex(const glm::vec3 &point) const { return index; } -void NavMesh::visit(uint16_t index, FindPathContext &ctx) const { +void Pathfinding::visit(uint16_t index, FindPathContext &ctx) const { if (ctx.visited.find(index) != ctx.visited.end()) return; float dist = ctx.fromToDistance[index].second; diff --git a/src/game/navmesh.h b/src/game/pathfinding.h similarity index 91% rename from src/game/navmesh.h rename to src/game/pathfinding.h index a6207c10..a7bb31cb 100644 --- a/src/game/navmesh.h +++ b/src/game/pathfinding.h @@ -31,9 +31,9 @@ namespace reone { namespace game { -class NavMesh { +class Pathfinding { public: - NavMesh() = default; + Pathfinding() = default; void load(const Paths &paths, const std::unordered_map &pointZ); @@ -56,8 +56,8 @@ private: std::vector _vertices; std::unordered_map> _edges; - NavMesh(const NavMesh &) = delete; - NavMesh &operator=(const NavMesh &) = delete; + Pathfinding(const Pathfinding &) = delete; + Pathfinding &operator=(const Pathfinding &) = delete; uint16_t getNearestVertex(const glm::vec3 &point) const; void visit(uint16_t index, FindPathContext &ctx) const;