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 Makefile.am,1.7,1.8 dot.hxx,


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldmap Makefile.am,1.7,1.8 dot.hxx,1.2,1.3 drawable.hxx,1.3,1.4 path_graph.cxx,1.3,1.4 pathfinder.hxx,1.1,1.2 surface_drawable.hxx,1.1,1.2 worldmap.cxx,1.17,1.18
Date: 13 Oct 2002 14:19:28 -0000

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

Modified Files:
        Makefile.am dot.hxx drawable.hxx path_graph.cxx pathfinder.hxx 
        surface_drawable.hxx worldmap.cxx 
Log Message:
Worldmap z-pos sorting works now, pathfinding might work also, time to build a 
new worldmap...

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Makefile.am 13 Oct 2002 01:09:18 -0000      1.7
+++ Makefile.am 13 Oct 2002 14:19:25 -0000      1.8
@@ -31,7 +31,8 @@
 path_graph.hxx path_graph.cxx \
 dot_factory.hxx dot_factory.cxx \
 dot.hxx dot.cxx \
-level_dot.hxx level_dot.cxx
+level_dot.hxx level_dot.cxx \
+pathfinder.hxx
 
 #node.cxx
 #node.hxx

Index: dot.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/dot.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dot.hxx     13 Oct 2002 13:34:40 -0000      1.2
+++ dot.hxx     13 Oct 2002 14:19:25 -0000      1.3
@@ -36,7 +36,7 @@
 
 public:
   Dot(xmlDocPtr doc, xmlNodePtr cur);
-
+  float get_z_pos() const { return pos.z; }
 private:
   Dot (const Dot&);
   Dot& operator= (const Dot&);

Index: drawable.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/drawable.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- drawable.hxx        13 Oct 2002 13:34:40 -0000      1.3
+++ drawable.hxx        13 Oct 2002 14:19:25 -0000      1.4
@@ -67,6 +67,8 @@
   virtual void draw(GraphicContext& gc) =0;
   virtual void update() =0;
 
+  virtual float get_z_pos() const =0;
+  
 private:
   Drawable (const Drawable&);
   Drawable operator= (const Drawable&);

Index: path_graph.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- path_graph.cxx      13 Oct 2002 13:34:40 -0000      1.3
+++ path_graph.cxx      13 Oct 2002 14:19:25 -0000      1.4
@@ -23,6 +23,7 @@
 #include "dot.hxx"
 #include "dot_factory.hxx"
 #include "worldmap.hxx"
+#include "pathfinder.hxx"
 #include "path_graph.hxx"
 
 namespace WorldMapNS {
@@ -154,8 +155,14 @@
 }
 
 std::vector<Vector>
-PathGraph::get_path(NodeId start, NodeId end)
+PathGraph::get_path(NodeId start_id, NodeId end_id)
 {
+  Node<Dot*>& start = graph.resolve_node(start_id);
+  Node<Dot*>& end   = graph.resolve_node(end_id);
+
+  Pathfinder<Dot*, Path*> pathfinder(graph, start_id);
+  std::vector<NodeId> path = pathfinder.get_path(end_id);
+
   // insert pathfinding magic here...
   return std::vector<Vector>();
 }

Index: pathfinder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pathfinder.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pathfinder.hxx      12 Oct 2002 23:37:23 -0000      1.1
+++ pathfinder.hxx      13 Oct 2002 14:19:25 -0000      1.2
@@ -23,8 +23,10 @@
 #include <queue>
 #include "graph.hxx"
 
+namespace WorldMapNS {
+
 /** */
-template<class T>
+template<class T, class C>
 class Pathfinder
 {
 public:
@@ -33,9 +35,9 @@
   public:
     enum { CLOSED, UNKNOWN, OPEN} status;
 
-    NodeHandle parent;
+    NodeId parent;
     int cost;
-    NodeHandle handle;
+    NodeId handle;
 
     NodeStat ()
       : status (UNKNOWN),
@@ -47,13 +49,13 @@
   };
 
 private:
-  Graph<T>& graph;
-  NodeHandle start;
-  std::priority_queue<NodeHandle> open_nodes;
+  Graph<T, C>& graph;
+  NodeId start;
+  std::priority_queue<NodeId> open_nodes;
   std::vector<NodeStat>   stat_graph;
   
 public:
-  Pathfinder (Graph<T>& g, NodeHandle s)
+  Pathfinder (Graph<T, C>& g, NodeId s)
     : graph (g), start (s)
   {
     stat_graph.resize (graph.max_node_handler_value());
@@ -61,18 +63,18 @@
 
     while (!open_nodes.empty())
       {
-       NodeHandle current = open_nodes.top ();
+       NodeId current = open_nodes.top ();
        open_nodes.pop ();
 
        std::cout << "Current Node: " << current << " "
                  << stat_graph[current].cost << std::endl;
 
        Node<T>& node = graph.resolve_node (current);
-       for (std::vector<EdgeHandle>::iterator e = node.next.begin ();
+       for (std::vector<EdgeId>::iterator e = node.next.begin ();
             e != node.next.end ();
             ++e)
          {
-           NodeHandle child_node = graph.resolve_edge(*e).next;
+           NodeId child_node = graph.resolve_edge(*e).next;
            NodeStat& stat = stat_graph[child_node];
            int new_cost = stat_graph[current].cost + 
graph.resolve_edge(*e).cost;
            
@@ -94,10 +96,10 @@
     std::cout << "---DONE---" << std::endl;
   }
 
-  std::vector<NodeHandle> get_path (NodeHandle end) 
+  std::vector<NodeId> get_path (NodeId end) 
   {
-    std::vector<NodeHandle> path;
-    NodeHandle handle = end;
+    std::vector<NodeId> path;
+    NodeId handle = end;
     
     do
       {
@@ -113,7 +115,7 @@
        else if (handle == -1)
          {
            // no path found
-           return  std::vector<NodeHandle>();
+           return  std::vector<NodeId>();
          }
        else
          {
@@ -123,13 +125,13 @@
     while (1);
   }
 
-  void push_to_open (NodeHandle handle)
+  void push_to_open (NodeId handle)
   {
     open_nodes.push (handle);
     stat_graph[handle].status = NodeStat::OPEN;
   }
 
-  bool is_open (NodeHandle handle)
+  bool is_open (NodeId handle)
   {
     return stat_graph[handle].status == NodeStat::OPEN;
   }
@@ -138,6 +140,8 @@
   Pathfinder (const Pathfinder&);
   Pathfinder operator= (const Pathfinder&);
 };
+
+} // namespace WorldMapNS
 
 #endif
 

Index: surface_drawable.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/surface_drawable.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- surface_drawable.hxx        12 Oct 2002 23:37:23 -0000      1.1
+++ surface_drawable.hxx        13 Oct 2002 14:19:25 -0000      1.2
@@ -38,6 +38,7 @@
   void update();
   void draw(GraphicContext&);
 
+  float get_z_pos() const { return pos.z; }
 private:
   SurfaceDrawable (const SurfaceDrawable&);
   SurfaceDrawable& operator= (const SurfaceDrawable&);

Index: worldmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- worldmap.cxx        13 Oct 2002 01:09:18 -0000      1.17
+++ worldmap.cxx        13 Oct 2002 14:19:25 -0000      1.18
@@ -41,6 +41,14 @@
 
 namespace WorldMapNS {
 
+struct z_pos_sorter
+{
+  bool operator()(Drawable* a, Drawable* b)
+  {
+    return a->get_z_pos() < b->get_z_pos();
+  }
+};
+
 WorldMap::WorldMap(const std::string& arg_filename) 
   : filename(arg_filename)
 {
@@ -142,6 +150,8 @@
 void
 WorldMap::draw (GraphicContext& gc)
 {
+  std::stable_sort(drawables.begin(), drawables.end(), z_pos_sorter());
+
   for (DrawableLst::iterator i = drawables.begin (); i != drawables.end (); 
++i)
     {
       (*i)->draw (gc);





reply via email to

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