wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src pathfind.cpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src pathfind.cpp
Date: Sun, 05 Jun 2005 05:32:27 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/06/05 09:32:26

Modified files:
        src            : pathfind.cpp 

Log message:
        Remove dead code and useless assertions. Put more meaningful assertions 
instead, they would have helped at the time we encountered the \"no tunnel in 
Scepter of Fire\" bug.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/pathfind.cpp.diff?tr1=1.69&tr2=1.70&r1=text&r2=text

Patches:
Index: wesnoth/src/pathfind.cpp
diff -u wesnoth/src/pathfind.cpp:1.69 wesnoth/src/pathfind.cpp:1.70
--- wesnoth/src/pathfind.cpp:1.69       Sun Jun  5 07:03:43 2005
+++ wesnoth/src/pathfind.cpp    Sun Jun  5 09:32:26 2005
@@ -1,4 +1,4 @@
-/* $Id: pathfind.cpp,v 1.69 2005/06/05 07:03:43 silene Exp $ */
+/* $Id: pathfind.cpp,v 1.70 2005/06/05 09:32:26 silene Exp $ */
 /*
 Copyright (C) 2003 by David White <address@hidden>
 Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -29,7 +29,7 @@
 
 typedef std::vector<gamemap::location> vector_location;
 typedef std::vector<a_star_node*> vector_a_star_node;
-typedef std::set<gamemap::location>    set_location;
+typedef std::set<gamemap::location> set_location;
 
 // heaps give the biggest element for free, so we want the biggest element to
 // have the smallest cost
@@ -43,12 +43,11 @@
                         vector_location &vectLocation, 
std::set<gamemap::location> const *teleports,
                         size_t &parNbTeleport)
 {
-       a_star_node *locStartNode = NULL;
-       bool locIsCreated = false;
+       bool locIsCreated;
 
        aStarGameWorld.resize_IFN(parWidth, parHeight);
        wassert(aStarGameWorld.empty());
-       locStartNode = aStarGameWorld.getNodeFromLocation(src, locIsCreated);
+       a_star_node *locStartNode = aStarGameWorld.getNodeFromLocation(src, 
locIsCreated);
        wassert(locIsCreated);
        locStartNode->initNode(src, dst, 0.0, NULL, teleports);
 
@@ -64,13 +63,6 @@
        openList.reserve(locAllocSize);
        openList.push_back(locStartNode);
 
-       if (locValueH < 32)
-               locAllocSize = 32;
-       else if (locValueH > 256)
-               locAllocSize = 256;
-       else
-               locAllocSize = locValueH;
-
        if (teleports != NULL)
                parNbTeleport = teleports->size();
        else
@@ -80,16 +72,7 @@
        vectLocation.resize(parNbTeleport + 6);
 
        if (parNbTeleport > 0)
-       {
-               gamemap::location* locLocation;
-
-               locLocation = &vectLocation[6];
-               for (set_location::const_iterator it = teleports->begin(); it 
!= teleports->end(); ++it) {
-                       locLocation->x = (*it).x;
-                       locLocation->y = (*it).y;
-                       ++locLocation;
-               }
-       }
+               std::copy(teleports->begin(), teleports->end(), 
&vectLocation[6]);
 }
 
 static void a_star_explore_neighbours(gamemap::location const &dst, const 
double stop_at,
@@ -100,10 +83,6 @@
                                       a_star_world &aStarGameWorld,
                                       a_star_node *parCurNode, const size_t 
parNbTeleport)
 {
-       //----------------- PRE_CONDITIONS ------------------
-       wassert(parCurNode != NULL);
-       //---------------------------------------------------
-
        typedef std::pair<vector_a_star_node::iterator, 
vector_a_star_node::iterator> pair_node_iter;
 
        a_star_node *locNextNode;
@@ -115,18 +94,10 @@
 
        get_adjacent_tiles(parCurNode->loc, &vectLocation[0]);
 
-       if ((parNbTeleport > 0) && (teleports->count(parCurNode->loc) > 0))
-       {
-               wassert(teleports != NULL);
-               wassert(teleports->size() == parNbTeleport);
-               wassert(vectLocation.size() == parNbTeleport + 6);
+       if (parNbTeleport > 0 && teleports->count(parCurNode->loc) > 0)
                locSize = parNbTeleport + 6;
-       }
        else
-       {
-               wassert(vectLocation.size() >= 6);
                locSize = 6;
-       }
 
        bool broken_heap = false;
        int locNbAdded = 0;
@@ -175,10 +146,8 @@
                            const size_t parHeight, std::set<gamemap::location> 
const *teleports)
 {
        //----------------- PRE_CONDITIONS ------------------
-       wassert(parWidth > 0);
-       wassert(parHeight > 0);
-       wassert(src.valid());
-       wassert(dst.valid());
+       wassert(src.valid(parWidth, parHeight));
+       wassert(dst.valid(parWidth, parHeight));
        wassert(costCalculator != NULL);
        wassert(stop_at <= costCalculator->getNoPathValue());
        //---------------------------------------------------
@@ -192,19 +161,12 @@
        a_star_node *locDestNode = NULL;
        a_star_node *locCurNode = NULL;
 
-       wassert(openList.empty());
-       wassert(aStarGameWorld.empty());
-       assertParanoAstar(aStarGameWorld.reallyEmpty());
-
        LOG_PF << "A* search: " << src << " -> " << dst << '\n';
 
-       if ( (src.valid(int(parWidth), int(parHeight)) == false) ||
-                        (dst.valid(int(parWidth), int(parHeight)) == false) ||
-                        (costCalculator->cost(dst, 0, true) >= stop_at))
-       {
+       if (costCalculator->cost(dst, 0, true) >= stop_at) {
                LOG_PF << "aborted A* search because Start or Dest is 
invalid\n";
                locRoute.move_left = int(costCalculator->getNoPathValue());
-               return (locRoute);
+               return locRoute;
        }
 
        a_star_init(src, dst, openList, aStarGameWorld, parWidth, parHeight, 
vectLocation, teleports, locNbTeleport);
@@ -253,13 +215,7 @@
        openList.clear();
        POSS_AStarNode.reduce();
        aStarGameWorld.clear();
-
-       //----------------- POST_CONDITIONS -----------------
-       wassert(openList.empty());
-       wassert(aStarGameWorld.empty());
-       assertParanoAstar(aStarGameWorld.reallyEmpty());
-       //---------------------------------------------------
-       return (locRoute);
+       return locRoute;
 }
 
 namespace {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]