From acd2359096833bb78b4fdfaa43749c27a67bf6f8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 22 Aug 2010 20:13:30 +0000 Subject: [PATCH] - added performance logging to regular pathfinder --- source/glest_game/ai/path_finder.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 4a05dea4..61cccf15 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -18,11 +18,13 @@ #include "map.h" #include "unit.h" #include "unit_type.h" +#include "platform_common.h" #include "leak_dumper.h" using namespace std; using namespace Shared::Graphics; using namespace Shared::Util; +using namespace Shared::PlatformCommon; namespace Glest{ namespace Game{ @@ -143,6 +145,8 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos){ //route a unit using A* algorithm TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){ + Chrono chrono; + chrono.start(); nodePoolCount= 0; const Vec2i finalPos= computeNearestFreePos(unit, targetPos); @@ -169,6 +173,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){ bool nodeLimitReached= false; Node *node= NULL; + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + while(!nodeLimitReached){ //b1) is open nodes is empty => failed to find the path @@ -213,6 +219,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){ } }//while + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld, openNodes.empty() = %d, pathFound = %d, nodeLimitReached = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),openNodes.empty(),pathFound,nodeLimitReached); + Node *lastNode= node; //if consumed all nodes find best node (to avoid strage behaviour) @@ -224,6 +232,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){ } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //check results of path finding TravelState ts; UnitPathInterface *path= unit->getPath(); @@ -251,6 +261,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){ } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //clean nodes openNodes.clear(); closedNodes.clear();