pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/worldmap path.cxx,1.1,1.2 path.hxx,1.


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldmap path.cxx,1.1,1.2 path.hxx,1.1,1.2 path_graph.cxx,1.12,1.13 pathfinder.hxx,1.7,1.8 pingus.cxx,1.18,1.19
Date: 15 Oct 2002 21:48:46 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv6226/worldmap

Modified Files:
        path.cxx path.hxx path_graph.cxx pathfinder.hxx pingus.cxx 
Log Message:
fixed little problem with pathfinding if pingu is between two nodes
removed some debug cout's

Index: path.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- path.cxx    15 Oct 2002 19:13:33 -0000      1.1
+++ path.cxx    15 Oct 2002 21:48:43 -0000      1.2
@@ -23,6 +23,7 @@
 namespace WorldMapNS {
 
 Path::Path()
+  : path_length_valid (false)
 {
 }
 
@@ -34,6 +35,21 @@
 
 float
 Path::length()
+{
+  if (path_length_valid)
+    {
+      return path_length;
+    }
+  else
+    {
+      path_length = calc_length ();
+      path_length_valid = true;
+      return path_length;
+    }
+}
+  
+float
+Path::calc_length()
 {
   if (vec.empty())
     {

Index: path.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- path.hxx    15 Oct 2002 19:13:33 -0000      1.1
+++ path.hxx    15 Oct 2002 21:48:43 -0000      1.2
@@ -32,6 +32,11 @@
 private:
   typedef std::vector<Vector> Vec;
   Vec vec;
+  
+  bool  path_length_valid;
+  float path_length;
+
+  float calc_length();
 public:
   typedef Vec::iterator iterator;
   typedef Vec::reverse_iterator reverse_iterator;
@@ -50,14 +55,28 @@
   Vector at(float vec_position);
 
   bool empty() { return vec.empty(); }
-  void clear() { vec.clear(); }
+  void clear() { path_length_valid = false; vec.clear(); }
+
   iterator begin() { return vec.begin(); }
   iterator end() { return vec.end(); }
   reverse_iterator rbegin() { return vec.rbegin(); }
   reverse_iterator rend() { return vec.rend(); }
-  void push_back(const Vector& v) { vec.push_back(v); };
-  void insert(Path& p) { vec.insert(vec.end(), p.vec.begin(), p.vec.end()); };
-  void reverse_insert(Path& p) { vec.insert(vec.end(), p.vec.rbegin(), 
p.vec.rend()); };
+
+  void push_back(const Vector& v) { 
+    path_length_valid = false; 
+    vec.push_back(v);
+  }
+
+  void insert(Path& p) {
+    path_length_valid = false; 
+    vec.insert(vec.end(), p.vec.begin(), p.vec.end()); 
+  }
+
+  void reverse_insert(Path& p) { 
+    path_length_valid = false; 
+    vec.insert(vec.end(), p.vec.rbegin(), p.vec.rend()); 
+  }
+
   void reverse();
 };
 

Index: path_graph.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- path_graph.cxx      15 Oct 2002 19:13:33 -0000      1.12
+++ path_graph.cxx      15 Oct 2002 21:48:43 -0000      1.13
@@ -167,7 +167,7 @@
                                       lookup_node(source), 
lookup_node(destination), 
                                       cost /* costs */);
           
-          std::cout << "Cost: " << cost << std::endl;
+          //std::cout << "Cost: " << cost << std::endl;
 
           // FIXME: edge lookup is flawed, since we have different edges in 
both directions
 

Index: pathfinder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pathfinder.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pathfinder.hxx      15 Oct 2002 19:13:33 -0000      1.7
+++ pathfinder.hxx      15 Oct 2002 21:48:43 -0000      1.8
@@ -63,7 +63,7 @@
 
     bool operator()(NodeId a, NodeId b)
     {
-      std::cout << "Coast: " << pathfinder.stat_graph[a].cost << " " << 
pathfinder.stat_graph[b].cost << std::endl;
+      //std::cout << "Coast: " << pathfinder.stat_graph[a].cost << " " << 
pathfinder.stat_graph[b].cost << std::endl;
       return pathfinder.stat_graph[a].cost > pathfinder.stat_graph[b].cost;
     }
   };
@@ -85,8 +85,8 @@
        NodeId current = open_nodes.top ();
        open_nodes.pop ();
 
-       std::cout << "Current Node: " << current << " "
-                 << stat_graph[current].cost << std::endl;
+       //std::cout << "Current Node: " << current << " "
+        //<< stat_graph[current].cost << std::endl;
 
        Node<T>& node = graph.resolve_node (current);
        for (std::vector<EdgeId>::iterator e = node.next.begin ();
@@ -112,7 +112,7 @@
              }
          }
       }
-    std::cout << "---DONE---" << std::endl;
+    //std::cout << "---DONE---" << std::endl;
   }
 
   /** The nodes to walk to reach end is returned in reverse order! so
@@ -125,8 +125,8 @@
     do
       {
        path.push_back(handle);
-       std::cout << "Handle: " << handle 
-                 << " Parent: " << stat_graph[handle].parent << std::endl;
+       //std::cout << "Handle: " << handle 
+        //<< " Parent: " << stat_graph[handle].parent << std::endl;
 
        if (handle == start)
          {

Index: pingus.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.cxx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pingus.cxx  15 Oct 2002 19:13:33 -0000      1.18
+++ pingus.cxx  15 Oct 2002 21:48:43 -0000      1.19
@@ -88,7 +88,10 @@
 {
   if (current_node != NoNode) // pingu stands still
     {
-      node_path = path->get_path (current_node, target).path;
+      const PathfinderResult& res = path->get_path (current_node, target);
+
+      std::cout << "XXXXXXX Path cost: " << res.cost << std::endl;
+      node_path = res.path;
 
       // Simulate that we just reached current_node, then update the edge_path
       target_node = node_path.back(); // equal to current_node;
@@ -120,7 +123,8 @@
           PathfinderResult node_path2 = path->get_path (target_node, target);
        
           // Select the shorter path
-          if (node_path1.cost < node_path2.cost)
+          if (node_path1.cost + edge_path_position
+              < node_path2.cost + (edge_path.length() - edge_path_position))
             { // walk to source node, which means to reverse the pingu
               node_path = node_path1.path;
 
@@ -159,8 +163,6 @@
 {
   pos = path->get_dot(node)->get_pos();
   current_node = node;
-  std::cout << "Pingu Pos: " << pos << std::endl;
-  //walk_to_node(0);
 }
 
 float





reply via email to

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