Author: alink
Date: Thu May 14 03:08:28 2009
New Revision: 35624

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35624&view=rev
Log:
Fix first A* search on a new map runs on incorrectly initialized nodes.

Modified:
    trunk/src/astarsearch.cpp

Modified: trunk/src/astarsearch.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/astarsearch.cpp?rev=35624&r1=35623&r2=35624&view=diff
==============================================================================
--- trunk/src/astarsearch.cpp (original)
+++ trunk/src/astarsearch.cpp Thu May 14 03:08:28 2009
@@ -52,7 +52,9 @@
        // and clean the definition of these numbers
 }
 
-static unsigned search_counter;
+// values 0 and 1 mean uninitialized
+const unsigned bad_search_counter = 0;
+static unsigned search_counter = bad_search_counter;
 
 struct node {
        double g, h, t;
@@ -70,7 +72,7 @@
                , t(1e25)
                , curr()
                , prev()
-               , in(search_counter)
+               , in(bad_search_counter)
        {
        }
        node(double s, const map_location &c, const map_location &p, const 
map_location &dst, bool i) :
@@ -133,11 +135,13 @@
        std::vector<map_location> locs(6 + teleports.size());
        std::copy(teleports.begin(), teleports.end(), locs.begin() + 6);
 
+       // increment search_counter but skip the range equivalent to 
uninitialized
        search_counter += 2;
-       if (search_counter == 0) search_counter = 2;
+       if (search_counter - bad_search_counter <= 1u)
+               search_counter += 2;
 
        static std::vector<node> nodes;
-       nodes.resize(width * height);
+       nodes.resize(width * height);  // this create uninitalized nodes
 
        indexer index(width, height);
        comp node_comp(nodes);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to