changeset 292:6362c6812580

combine routepathersearch and search class to clean up the code.
author wenlin_fife@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 26 Jun 2009 18:04:57 +0000
parents 89c71d202ab7
children 66df2422a8b0
files engine/core/pathfinder/routepather/routepather.cpp engine/core/pathfinder/routepather/routepather.h engine/core/pathfinder/routepather/routepathersearch.cpp engine/core/pathfinder/routepather/routepathersearch.h engine/core/pathfinder/search.h
diffstat 5 files changed, 71 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/pathfinder/routepather/routepather.cpp	Wed Jun 24 14:12:50 2009 +0000
+++ b/engine/core/pathfinder/routepather/routepather.cpp	Fri Jun 26 18:04:57 2009 +0000
@@ -129,14 +129,14 @@
 			if(m_sessions.empty()) {
 				break;
 			}
-			Search* priority_session = m_sessions.getPriorityElement().first;
+			RoutePatherSearch* priority_session = m_sessions.getPriorityElement().first;
 			if(!sessionIdValid(priority_session->getSessionId())) {
 				delete priority_session;
 				m_sessions.popElement();
 				continue;
 			}
 			priority_session->updateSearch();
-			if(priority_session->getSearchStatus() == Search::search_status_complete) {
+			if(priority_session->getSearchStatus() == RoutePatherSearch::search_status_complete) {
 				const int session_id = priority_session->getSessionId();
 				Path newPath = priority_session->calcPath();
 				newPath.erase(newPath.begin());
@@ -144,7 +144,7 @@
 				invalidateSessionId(session_id);
 				delete priority_session;
 				m_sessions.popElement();
-			} else if(priority_session->getSearchStatus() == Search::search_status_failed) {
+			} else if(priority_session->getSearchStatus() == RoutePatherSearch::search_status_failed) {
 				const int session_id = priority_session->getSessionId();
 				invalidateSessionId(session_id);
 				delete priority_session;
--- a/engine/core/pathfinder/routepather/routepather.h	Wed Jun 24 14:12:50 2009 +0000
+++ b/engine/core/pathfinder/routepather/routepather.h	Fri Jun 26 18:04:57 2009 +0000
@@ -92,7 +92,7 @@
 		std::string getName() const { return "RoutePather"; };		
 	private:
 		typedef std::list<Location> Path;
-		typedef PriorityQueue<Search*, int> SessionQueue;
+		typedef PriorityQueue<RoutePatherSearch*, int> SessionQueue;
 		typedef std::list<int> SessionList;
 		typedef std::map<int, Path> PathMap;
 		typedef std::map<Layer*, SearchSpace*> SearchSpaceMap;
--- a/engine/core/pathfinder/routepather/routepathersearch.cpp	Wed Jun 24 14:12:50 2009 +0000
+++ b/engine/core/pathfinder/routepather/routepathersearch.cpp	Fri Jun 26 18:04:57 2009 +0000
@@ -40,7 +40,7 @@
 
 namespace FIFE {
 	RoutePatherSearch::RoutePatherSearch(const int session_id, const Location& from, const Location& to, SearchSpace* searchSpace)
-		: Search(session_id, from, to, searchSpace), m_destCoordInt(0), m_startCoordInt(0), m_next(0)  {
+		: m_destCoordInt(0), m_startCoordInt(0), m_next(0), m_to(to), m_from(from), m_sessionId(session_id), m_searchspace(searchSpace) {
 		m_startCoordInt = m_searchspace->convertCoordToInt(from.getLayerCoordinates());
 		int max_index = m_searchspace->getMaxIndex();
 		m_destCoordInt = m_searchspace->convertCoordToInt(to.getLayerCoordinates());
@@ -49,6 +49,10 @@
 		m_sf.resize(max_index + 1, -1);
 		m_gCosts.resize(max_index + 1, 0.0f);
 		m_heuristic = Heuristic::getHeuristic(searchSpace->getLayer()->getCellGrid()->getType());
+             //   m_to = to;
+             //   m_from = from;
+             //   m_sessionId = session_id;
+             //   m_searchspace = searchSpace;
 	}
 
 	void RoutePatherSearch::updateSearch() {
--- a/engine/core/pathfinder/routepather/routepathersearch.h	Wed Jun 24 14:12:50 2009 +0000
+++ b/engine/core/pathfinder/routepather/routepathersearch.h	Fri Jun 26 18:04:57 2009 +0000
@@ -30,7 +30,7 @@
 // These includes are split up in two parts, separated by one empty line
 // First block: files included from the FIFE root src directory
 // Second block: files included from the same folder
-#include "pathfinder/search.h"
+//#include "pathfinder/search.h"
 #include "util/structures/priorityqueue.h"
 
 namespace FIFE {
@@ -43,13 +43,73 @@
 	 *
 	 * For now this class uses offline A*, however eventually this will be switched over to RTA*.
 	 */
-	class RoutePatherSearch : public Search {
+	class RoutePatherSearch {
 	public:
 		RoutePatherSearch(const int session_id, const Location& from, const Location& to, SearchSpace* searchSpace);
 
+                typedef std::list<Location> Path;
+                /** An enumeration of the different status the search can be in.
+                 *
+                 */
+                enum SearchStatus {
+                        search_status_failed,
+                        search_status_complete,
+                        search_status_incomplete
+                };
+
 		virtual void updateSearch();
 
 		virtual Path calcPath();
+
+                /** Retrieves the session id.
+                 *
+                 * @return The searches session id in the pather.
+                 */
+                int getSessionId() const {
+                        return m_sessionId;
+                }
+
+                /** Retrieves the pather.
+                 *
+                 * @return A pointer to the abstract pather which
+                 */
+                SearchSpace* getSearchSpace() const {
+                        return m_searchspace;
+                }
+
+                /** A small function which returns the current status of the search.
+                 *
+                 * @return An integer value representing the status, which is enumerated by this class.
+                 */
+                int getSearchStatus() const {
+                        return m_status;
+                }
+
+         protected:
+
+                /** Sets the current status of the search.
+                 *
+                 * @param status The status to set.
+                 */
+                void setSearchStatus(const SearchStatus status) {
+                        m_status = status;
+                }
+
+                //A location object representing where the search started.
+                Location                m_to;
+
+                //A location object representing where the search ended.
+                Location                m_from;
+
+                //An integer containing the session id for this search.
+                int                             m_sessionId;
+
+                //A pointer to the pather that owns this search.
+                SearchSpace*    m_searchspace;
+
+                //An enumeration of the searches current status.
+                SearchStatus    m_status;
+
 	private:
 		//The class to use to calculate the heuristic value.
 		Heuristic*                m_heuristic;
--- a/engine/core/pathfinder/search.h	Wed Jun 24 14:12:50 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2005-2008 by the FIFE team                              *
- *   http://www.fifengine.de                                               *
- *   This file is part of FIFE.                                            *
- *                                                                         *
- *   FIFE is free software; you can redistribute it and/or                 *
- *   modify it under the terms of the GNU Lesser General Public            *
- *   License as published by the Free Software Foundation; either          *
- *   version 2.1 of the License, or (at your option) any later version.    *
- *                                                                         *
- *   This library is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
- *   Lesser General Public License for more details.                       *
- *                                                                         *
- *   You should have received a copy of the GNU Lesser General Public      *
- *   License along with this library; if not, write to the                 *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
- ***************************************************************************/
-
-#ifndef FIFE_PATHFINDER_SEARCH
-#define FIFE_PATHFINDER_SEARCH
-
-// Standard C++ library includes
-#include <vector>
-
-// 3rd party library includes
-
-// FIFE includes
-// These includes are split up in two parts, separated by one empty line
-// First block: files included from the FIFE root src directory
-// Second block: files included from the same folder
-#include "model/structures/location.h"
-
-namespace FIFE {
-
-	class SearchSpace;
-
-	/** A base class that all searches must derive from.
-	 *
-	 */
-	class Search {
-	public:
-		typedef std::list<Location> Path;
-		/** An enumeration of the different status the search can be in.
-		 *
-		 */
-		enum SearchStatus {
-			search_status_failed,
-			search_status_complete,
-			search_status_incomplete 
-		};
-		/** Constructor.
-		 *
-		 * @param session_id The id in the pather that references this session.
-		 * @param from The location where the search should be started from.
-		 * @param to The location where the search should finish.
-		 * @param pather A pointer to the pather controlling this session.
-		 */
-		Search(const int session_id, const Location& from, const Location& to, SearchSpace* searchspace) 
-			: m_to(to), m_from(from), m_sessionId(session_id), m_searchspace(searchspace),
-			m_status(search_status_incomplete) {
-		}
-
-		/** Destructor.
-		 *
-		 */
-		virtual ~Search() {}
-
-		/** Retrieves the session id.
-		 *
-		 * @return The searches session id in the pather.
-		 */
-		int getSessionId() const {
-			return m_sessionId;
-		}
-
-		/** Retrieves the pather.
-		 *
-		 * @return A pointer to the abstract pather which
-		 */
-		SearchSpace* getSearchSpace() const {
-			return m_searchspace;
-		}
-
-		/** A small function which returns the current status of the search.
-		 *
-		 * @return An integer value representing the status, which is enumerated by this class.
-		 */
-		int getSearchStatus() const {
-			return m_status;
-		}
-
-
-		/** Updates the search and returns the next part of the path or the entire path if the
-		 * algorithm is offline.
-		 *
-		 * @return A vector of Location objects representing the path.
-		 */
-		virtual void updateSearch() = 0;
-
-		/** Calculates a path generated by a search.
-		 *
-		 * Creates a path and returns it.
-		 */
-		virtual Path calcPath() = 0;
-	protected:
-
-		/** Sets the current status of the search.
-		 *
-		 * @param status The status to set.
-		 */
-		void setSearchStatus(const SearchStatus status) {
-			m_status = status;
-		}
-
-		//A location object representing where the search started.
-		Location		m_to; 
-
-		//A location object representing where the search ended.
-		Location		m_from;
-
-		//An integer containing the session id for this search.
-		int				m_sessionId;
-
-		//A pointer to the pather that owns this search.
-		SearchSpace*    m_searchspace;
-
-		//An enumeration of the searches current status.
-		SearchStatus	m_status;
-	};
-
-}
-
-#endif