From 86c102f3d2b15ef10a2744dbe8b196b9d8ecaaab Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Fri, 3 Feb 2012 15:09:28 +0000 Subject: [PATCH 1/2] [Add] Working some more on AStar pathfinding. This is going to get messy. --- src/libUnuk/Engine/Pathfinding.cpp | 22 ++++++++++++++++ src/libUnuk/Engine/Pathfinding.h | 40 ++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/libUnuk/Engine/Pathfinding.cpp b/src/libUnuk/Engine/Pathfinding.cpp index b2ae6c4..b10acdf 100644 --- a/src/libUnuk/Engine/Pathfinding.cpp +++ b/src/libUnuk/Engine/Pathfinding.cpp @@ -1 +1,23 @@ #include "Pathfinding.h" + +template +AStarSearch::AStarSearch(void) : + _state(SEARCH_STATE_NOT_INITIALISED), + _currentSolutionNode(NULL), + _allocateNodeCount(0), + _cancelRequest(false) {} + +template +AStarSearch::~AStarSearch(void) { + +} + +template +void AStarSearch::SetStartAndGoalStates(UserState& start, UserState& goal) { + +} + +template +unsigned int AStarSearch::SearchStep(void) { + +} diff --git a/src/libUnuk/Engine/Pathfinding.h b/src/libUnuk/Engine/Pathfinding.h index 3e2d616..4c6a78c 100644 --- a/src/libUnuk/Engine/Pathfinding.h +++ b/src/libUnuk/Engine/Pathfinding.h @@ -25,6 +25,7 @@ public: }; // A node representing a possible state in the search. +public: class Node { public: // Keep a record of successor nodes. @@ -51,6 +52,7 @@ public: public: AStarSearch(void); + ~AStarSearch(void); int GetState(void) { return _state; } @@ -103,7 +105,41 @@ public: int GetStepCount(void) {return _steps; } private: - int _state; + // Called when a search fails or is cancelled to free up all unused memory. + void FreeAllNodes(void); + + /* + * Called when the search ends. A lot of nodes may + * be created that are still present when the search + * ends. They will be deleted with this method. + */ + void FreeUnusedNodes(void); + + // Data. +private: + // Heap. + vector _openList; + vector _closedList; + vector _successors; + + // State. + unsigned int _state; + + // Count steps. + int _steps; + + // Start/Goal state pointers. + Node* _start; + Node* _goal; + + Node* _currentSolutionNode; + + // Debug + typename vector::iterator iterDbgOpen; + typename vector::iterator iterDbgClosed; + + // Count memory allocations and free. + int _allocateNodeCount; + bool _cancelRequest; - int _steps; }; From fa83500d151a11ec557961451281f06fd158a7b8 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Fri, 3 Feb 2012 15:15:54 +0000 Subject: [PATCH 2/2] [Fix] Changed typename to class in template paremeter list. --- src/libUnuk/Engine/Pathfinding.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libUnuk/Engine/Pathfinding.cpp b/src/libUnuk/Engine/Pathfinding.cpp index b10acdf..d956eb5 100644 --- a/src/libUnuk/Engine/Pathfinding.cpp +++ b/src/libUnuk/Engine/Pathfinding.cpp @@ -1,23 +1,28 @@ #include "Pathfinding.h" -template +template AStarSearch::AStarSearch(void) : _state(SEARCH_STATE_NOT_INITIALISED), _currentSolutionNode(NULL), _allocateNodeCount(0), _cancelRequest(false) {} -template +template AStarSearch::~AStarSearch(void) { } -template +template void AStarSearch::SetStartAndGoalStates(UserState& start, UserState& goal) { } -template +template unsigned int AStarSearch::SearchStep(void) { } + +template +bool AStarSearch::AddSuccessor(UserState& state) { + +}