From 6affe7344b92ac580ab557fca253a804a2d3d0a1 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Fri, 3 Feb 2012 16:19:03 +0000 Subject: [PATCH] [Add] Laying out a lovely foundation.. Getting dirty with some generic programming. --- src/libUnuk/Engine/Pathfinding.cpp | 112 +++++++++++++++++++++++++++++ src/libUnuk/Engine/Pathfinding.h | 4 ++ 2 files changed, 116 insertions(+) diff --git a/src/libUnuk/Engine/Pathfinding.cpp b/src/libUnuk/Engine/Pathfinding.cpp index d956eb5..388807c 100644 --- a/src/libUnuk/Engine/Pathfinding.cpp +++ b/src/libUnuk/Engine/Pathfinding.cpp @@ -9,7 +9,33 @@ AStarSearch::AStarSearch(void) : template AStarSearch::~AStarSearch(void) { + _cancelRequest= false; + _start = AllocateNode(); + _goal = AllocateNode(); + + assert((_start != NULL && _goal != NULL)); + + _start->_UserState = _start; + _goal->_UserState = _goal; + + _state = SEARCH_STATE_SEARCHING; + + // Initialise the AStar specific parts of the start node. + // You only need to fill out the state information. + _start->g = 0; + _start->h = _start->_UserState.GoalDistanceEstimate(_goal->_UserState); + _start->f = _start->g + _start->h; + _start->parent = 0; + + // Push the start node onto the open list. + _openList.push_back(_start); // Heap is now unsorted. + + // Sort back element into the heap. + push_heap(_openList.begin(), _openList.end(), HeapCompare_f()); + + // Initialise counter for the search steps. + _steps = 0; } template @@ -26,3 +52,89 @@ template bool AStarSearch::AddSuccessor(UserState& state) { } + +template +void AStarSearch::FreeSolutionNodes(void) { + +} + +template +UserState* AStarSearch::GetSolutionStart(void) { + +} + +template +UserState* AStarSearch::GetSolutionNext(void) { + +} + +template +UserState* AStarSearch::GetSolutionEnd(void) { + +} + +template +UserState* AStarSearch::GetSolutionPrev(void) { + +} + +template +UserState* AStarSearch::GetOpenListStart(void) { + +} + +template +UserState* AStarSearch::GetOpenListStart(float& f, float& g, float& h) { + +} + +template +UserState* AStarSearch::GetOpenListNext(void) { + +} + +template +UserState* AStarSearch::GetOpenListNext(float& f, float& g, float& h) { + +} + +template +UserState* AStarSearch::GetClosedListStart(void) { + +} + +template +UserState* AStarSearch::GetClosedListStart(float& f, float& g, float& h) { + +} + +template +UserState* AStarSearch::GetClosedListNext(void) { + +} + +template +UserState* AStarSearch::GetClosedListNext(float& f, float& g, float& h) { + +} + +// Private. +template +void AStarSearch::FreeAllNodes(void) { + +} + +template +void AStarSearch::FreeUnusedNodes(void) { + +} + +//template +//Node* AStarSearch::AllocateNode(void) { +// +//} + +//template +//void Node::FreeNode(Node* node) { +// +//} diff --git a/src/libUnuk/Engine/Pathfinding.h b/src/libUnuk/Engine/Pathfinding.h index 4c6a78c..09761bb 100644 --- a/src/libUnuk/Engine/Pathfinding.h +++ b/src/libUnuk/Engine/Pathfinding.h @@ -115,6 +115,10 @@ private: */ void FreeUnusedNodes(void); + Node* AllocateNode(void); + + void FreeNode(Node* node); + // Data. private: // Heap.