[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldmap Makefile.am,1.9,1.10 graph.h
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldmap Makefile.am,1.9,1.10 graph.hxx,1.16,1.17 path_graph.cxx,1.7,1.8 path_graph.hxx,1.3,1.4 pathfinder.hxx,1.2,1.3 pingus.cxx,1.12,1.13 pingus.hxx,1.14,1.15 worldmap.cxx,1.19,1.20 worldmap.hxx,1.16,1.17 |
Date: |
13 Oct 2002 23:02:33 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv22337/worldmap
Modified Files:
Makefile.am graph.hxx path_graph.cxx path_graph.hxx
pathfinder.hxx pingus.cxx pingus.hxx worldmap.cxx worldmap.hxx
Log Message:
- some more worldmap stuff (not working, but compiles)
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Makefile.am 13 Oct 2002 16:39:17 -0000 1.9
+++ Makefile.am 13 Oct 2002 23:02:29 -0000 1.10
@@ -33,7 +33,8 @@
dot.hxx dot.cxx \
level_dot.hxx level_dot.cxx \
pathfinder.hxx \
-path_drawable.hxx path_drawable.cxx
+path_drawable.hxx path_drawable.cxx \
+graph.cxx
#node.cxx
#node.hxx
Index: graph.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/graph.hxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- graph.hxx 13 Oct 2002 19:28:34 -0000 1.16
+++ graph.hxx 13 Oct 2002 23:02:29 -0000 1.17
@@ -51,14 +51,14 @@
class Edge
{
public:
- NodeId prev;
- NodeId next;
+ NodeId source;
+ NodeId destination;
int cost;
EdgeType data;
- Edge (const EdgeType& arg_data, const NodeId& p, const NodeId& n, int c)
- : prev (p), next (n), cost (c), data(arg_data)
+ Edge (const EdgeType& arg_data, const NodeId& s, const NodeId& d, int c)
+ : source (s), destination (d), cost (c), data(arg_data)
{
}
};
@@ -134,6 +134,19 @@
return nodes[node];
}
+ Edge<EdgeType>& resolve_edge(const NodeId& source, const NodeId& destination)
+ {
+ // FIXME: this could be done faster with an adjacense matrix
+ for (typename std::vector<Edge<EdgeType> >::iterator i = edges.begin();
+ i != edges.end(); ++i)
+ {
+ if (i->source == source
+ && i->destination == destination)
+ return *i;
+ }
+ assert(false);
+ }
+
/* FIXME: This might give problems under MSVC, so it could be better to not
use it */
template<class Func>
void for_each_node (Func func)
Index: path_graph.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.cxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- path_graph.cxx 13 Oct 2002 20:25:00 -0000 1.7
+++ path_graph.cxx 13 Oct 2002 23:02:29 -0000 1.8
@@ -143,7 +143,6 @@
}
Path full_path;
-
full_path.push_back(graph.resolve_node(lookup_node(source)).data->get_pos());
full_path.insert(full_path.end(), path->begin(), path->end());
full_path.push_back(graph.resolve_node(lookup_node(destination)).data->get_pos());
@@ -168,7 +167,7 @@
}
}
-std::vector<Vector>
+std::vector<NodeId>
PathGraph::get_path(NodeId start_id, NodeId end_id)
{
//Node<Dot*>& start = graph.resolve_node(start_id);
@@ -177,8 +176,9 @@
Pathfinder<Dot*, Path*> pathfinder(graph, start_id);
std::vector<NodeId> path = pathfinder.get_path(end_id);
- // insert pathfinding magic here...
- return std::vector<Vector>();
+ assert(path.size() > 0);
+
+ return path;
}
EdgeId
@@ -209,6 +209,12 @@
{
return i->second;
}
+}
+
+Dot*
+PathGraph::get_dot(NodeId id)
+{
+ return graph.resolve_node(id).data;
}
} // namespace WorldMapNS
Index: path_graph.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- path_graph.hxx 13 Oct 2002 19:28:34 -0000 1.3
+++ path_graph.hxx 13 Oct 2002 23:02:29 -0000 1.4
@@ -40,8 +40,11 @@
private:
WorldMap* worldmap;
+public:
// FIXME: Memory leak? Where do we free stuff data inside the graph?
+ // FIXME: shouldn't be public
Graph<Dot*, Path*> graph;
+private:
// FIXME: This could/should probally be moved inside the graph (or not?!)
/** Map to look up node names and get the coresponding id's */
@@ -58,12 +61,14 @@
/** @return a list of positions to walk to reach node \a end, by
starting from \a start */
- std::vector<Vector> get_path(NodeId start, NodeId end);
+ std::vector<NodeId> get_path(NodeId start, NodeId end);
+
+ Dot* get_dot(NodeId id);
-private:
EdgeId lookup_edge(const std::string& name);
NodeId lookup_node(const std::string& name);
+private:
void parse_nodes(xmlDocPtr doc, xmlNodePtr cur);
void parse_edges(xmlDocPtr doc, xmlNodePtr cur);
Index: pathfinder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pathfinder.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pathfinder.hxx 13 Oct 2002 14:19:25 -0000 1.2
+++ pathfinder.hxx 13 Oct 2002 23:02:29 -0000 1.3
@@ -74,7 +74,7 @@
e != node.next.end ();
++e)
{
- NodeId child_node = graph.resolve_edge(*e).next;
+ NodeId child_node = graph.resolve_edge(*e).destination;
NodeStat& stat = stat_graph[child_node];
int new_cost = stat_graph[current].cost +
graph.resolve_edge(*e).cost;
Index: pingus.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pingus.cxx 13 Oct 2002 20:25:00 -0000 1.12
+++ pingus.cxx 13 Oct 2002 23:02:29 -0000 1.13
@@ -17,16 +17,22 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <math.h>
+#include "../boost/smart_ptr.hpp"
#include "../graphic_context.hxx"
+#include "dot.hxx"
#include "pingus.hxx"
-#include "../boost/smart_ptr.hpp"
namespace WorldMapNS {
-Pingus::Pingus ()
+Pingus::Pingus (PathGraph* arg_path)
: Drawable("pingus"),
+ path(arg_path),
sprite ("Pingus/walker0", "pingus", 20.0f, Sprite::RIGHT)
{
+ pos.x = 320;
+ pos.y = 200;
+
sprite.set_align (-sprite.get_width()/2, 4 - sprite.get_height());
}
@@ -42,15 +48,17 @@
}
void
-Pingus::update (float delta)
+Pingus::update ()
{
- sprite.update (delta);
+ float delta = 0.25f;
+
+ sprite.update ();
+ update_walk(delta);
}
void
Pingus::update_walk (float delta)
{
-#if TODO
// Update the position
edge_path_position += velocity * delta;
@@ -63,34 +71,58 @@
else // edge is traveled, now go to the next node
{
source_node = target_node;
- target_node = node_path.top ();
- node_path.pop ();
+ target_node = node_path.back ();
+ node_path.pop_back ();
edge_path_position = 0.0f;
- edge_path = get_edge (source_node, target_node)->data;
- edge_path_lenght = calc_edge_path_length ();
+
+ // Generate the new edges path
+ edge_path.clear();
+
+ Edge<Path*>& edge = path->graph.resolve_edge(source_node,
target_node);
+ Path* partial_path = edge.data;
+
+
edge_path.push_back(path->graph.resolve_node(source_node).data->get_pos());
+ edge_path.insert(edge_path.end(), partial_path->begin(),
partial_path->end());
+
edge_path.push_back(path->graph.resolve_node(target_node).data->get_pos());
+
+ edge_path_length = calc_edge_path_length();
}
}
// Recalc pingu position on the screen
pos = calc_pos ();
-#else
-UNUSED_ARG(delta);
-#endif
+}
+
+float
+Pingus::calc_edge_path_length()
+{
+ float length = 0;
+ Path::iterator prev = edge_path.begin();
+ for(Path::iterator next = prev + 1; next != edge_path.end(); ++next)
+ {
+ length += sqrt(prev->x * next->x
+ + prev->y * next->y);
+ prev = next;
+ }
+ return length;
}
bool
Pingus::walk_to_node (NodeId target)
{
-#if TODO
- if (current_node) // pingu stands still
+ if (current_node != NoNode) // pingu stands still
{
- node_path = worldmap->find_path (current_node, target);
+ node_path = path->get_path (current_node, target);
+ // FIXME: Edge path and co get invalid here
+ return true;
}
else // pingu between two nodes
{
- node_path1 = worldmap->find_path (source_node, target);
- node_path2 = worldmap->find_path (target_node, target);
+ assert(false);
+#if 0
+ std::vector<NodeId> node_path1 = path->get_path (source_node, target);
+ std::vector<NodeId> node_path2 = path->get_path (target_node, target);
// Select the shorter path
if (length (node_path1) < length (node_path2))
@@ -98,55 +130,62 @@
node_path = node_path1;
// Reverse the pingu
- swap(target_node, source_node);
+ std::swap(target_node, source_node);
std::reverse(edge_path.begin (), edge_path.end ());
edge_path_position = edge_path_lenght - edge_path_position;
}
else
{ // walk to target_node
node_path = node_path2;
- }
- }
-#else
- UNUSED_ARG(target);
+ }
#endif
- return false;
+ return false;
+ }
}
Vector
Pingus::calc_pos ()
{
-#if TODO
if (current_node) // pingu stands still
{
- return current_node->get_pos ();
+ return path->graph.resolve_node(current_node).data->get_pos ();
}
else // between two nodes
{
- iterator current = edge_path.begin ();
- iterator next = edge_path.begin () + 1;
+ Path::iterator current = edge_path.begin ();
+ Path::iterator next = edge_path.begin () + 1;
float comp_length = 0.0f;
- while (next != end)
+ while (next != edge_path.end())
{
- float length = line_length (current, next);
+ float length = 10; // FIXME: line_length (current, next);
if (comp_length + length > edge_path_position)
{
float perc = (edge_path_position - comp_length) // length to
walk from current node
/ length;
- return interpol (current, next, perc);
+ return Vector(); // FIXME: interpol (current, next, perc);
}
++current;
++next;
}
assert (!"This shouldn't happen, traveled bejoint target node");
- return target_node->get_pos ();
+ return path->graph.resolve_node(target_node).data->get_pos ();
}
-#endif
- return Vector();
+}
+
+void
+Pingus::set_position (NodeId node)
+{
+ pos = path->get_dot(node)->get_pos();
+}
+
+float
+Pingus::get_z_pos() const
+{
+ return 2000.0f;
}
} // namespace WorldMapNS
Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.hxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- pingus.hxx 12 Oct 2002 23:34:43 -0000 1.14
+++ pingus.hxx 13 Oct 2002 23:02:29 -0000 1.15
@@ -27,7 +27,7 @@
#include "../vector.hxx"
#include "../pingus.hxx"
#include "drawable.hxx"
-#include "graph.hxx"
+#include "path_graph.hxx"
namespace boost {
template <class T> class shared_ptr;
@@ -40,9 +40,10 @@
class Pingus : public Drawable
{
private:
+ PathGraph* path;
Sprite sprite;
- /** The node on which the pingu currently stands, 0 if the pingu is
+ /** The node on which the pingu currently stands, NoNode if the pingu is
currently on the move to another node */
NodeId current_node;
@@ -59,8 +60,9 @@
represented as a array of positions */
std::vector<NodeId> node_path;
- /** The path which represents an edge between two nodes */
- std::vector<Vector> edge_path;
+ /** The path which represents an edge between two nodes, it includes
+ both source and destinations position, so it is complete */
+ Path edge_path;
/** The length of the edge_path in pixels */
float edge_path_length;
@@ -74,22 +76,21 @@
/** Current position of the pingu, only for caching purpose */
Vector pos;
- Vector velocity;
+ float velocity;
public:
- Pingus ();
+ /** */
+ Pingus (PathGraph* arg_path);
~Pingus ();
void draw (GraphicContext& gc);
+ void update ();
- void update_walk (float delta);
-
/** @return true if the node is reachable, false otherwise */
bool walk_to_node (NodeId target);
/** calculate the position of the pingu */
Vector calc_pos ();
- void update (float delta);
/** @return the node on which the pingu is currently standing, 0 is
returned if the pingu is currently between two nodes */
@@ -98,9 +99,14 @@
}
/** Set the pingu to the position of a given node */
- void set_position (NodeId node);
+ void set_position (NodeId node);
+
+ float get_z_pos() const;
private:
+ void update_walk (float delta);
+ float calc_edge_path_length();
+
Pingus (const Pingus&);
Pingus& operator= (const Pingus&);
};
Index: worldmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- worldmap.cxx 13 Oct 2002 20:25:00 -0000 1.19
+++ worldmap.cxx 13 Oct 2002 23:02:29 -0000 1.20
@@ -63,6 +63,17 @@
cur = XMLhelper::skip_blank(cur);
parse_file(doc, cur);
+
+ pingus = new Pingus(path_graph);
+ pingus->set_position(path_graph->lookup_node("levelnode_3"));
+
+ add_drawable(pingus);
+}
+
+WorldMap::~WorldMap()
+{
+ //delete pingus;
+ //delete path_graph;
}
void
Index: worldmap.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.hxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- worldmap.hxx 13 Oct 2002 01:09:18 -0000 1.16
+++ worldmap.hxx 13 Oct 2002 23:02:29 -0000 1.17
@@ -52,6 +52,8 @@
typedef std::vector<Drawable*> ObjectLst;
typedef std::vector<Drawable*> DrawableLst;
+ Pingus* pingus;
+
/** The graph that represents the path on the map */
PathGraph* path_graph;
@@ -65,8 +67,9 @@
ObjectLst objects;
public:
/** Load the given*/
- WorldMap (const std::string& filename);
-
+ WorldMap(const std::string& filename);
+ ~WorldMap();
+
void draw (GraphicContext& gc);
void update ();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldmap Makefile.am,1.9,1.10 graph.hxx,1.16,1.17 path_graph.cxx,1.7,1.8 path_graph.hxx,1.3,1.4 pathfinder.hxx,1.2,1.3 pingus.cxx,1.12,1.13 pingus.hxx,1.14,1.15 worldmap.cxx,1.19,1.20 worldmap.hxx,1.16,1.17,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/actions angel.cxx,1.14,1.15 basher.cxx,1.21,1.22 blocker.cxx,1.14,1.15 boarder.cxx,1.12,1.13 bomber.cxx,1.20,1.21 bomber.hxx,1.15,1.16 bridger.cxx,1.23,1.24 bridger.hxx,1.16,1.17 climber.cxx,1.17,1.18 digger.cxx,1.17,1.18 drown.cxx,1.11,1.12 exiter.cxx,1.11,1.12 faller.cxx,1.29,1.30 floater.cxx,1.20,1.21 jumper.cxx,1.16,1.17 laser_kill.cxx,1.12,1.13 miner.cxx,1.15,1.16 rocket_launcher.cxx,1.11,1.12 slider.cxx,1.15,1.16 smashed.cxx,1.11,1.12 smashed.hxx,1.12,1.13 splashed.cxx,1.11,1.12 splashed.hxx,1.12,1.13 superman.cxx,1.9,1.10 teleported.cxx,1.10,1.11 teleported.hxx,1.11,1.12 waiter.cxx,1.11,1.12 waiter.hxx,1.11,1.12 walker.cxx,1.28,1.29
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/doc/comments grumbel.xml,1.1,1.2
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/actions angel.cxx,1.14,1.15 basher.cxx,1.21,1.22 blocker.cxx,1.14,1.15 boarder.cxx,1.12,1.13 bomber.cxx,1.20,1.21 bomber.hxx,1.15,1.16 bridger.cxx,1.23,1.24 bridger.hxx,1.16,1.17 climber.cxx,1.17,1.18 digger.cxx,1.17,1.18 drown.cxx,1.11,1.12 exiter.cxx,1.11,1.12 faller.cxx,1.29,1.30 floater.cxx,1.20,1.21 jumper.cxx,1.16,1.17 laser_kill.cxx,1.12,1.13 miner.cxx,1.15,1.16 rocket_launcher.cxx,1.11,1.12 slider.cxx,1.15,1.16 smashed.cxx,1.11,1.12 smashed.hxx,1.12,1.13 splashed.cxx,1.11,1.12 splashed.hxx,1.12,1.13 superman.cxx,1.9,1.10 teleported.cxx,1.10,1.11 teleported.hxx,1.11,1.12 waiter.cxx,1.11,1.12 waiter.hxx,1.11,1.12 walker.cxx,1.28,1.29
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/doc/comments grumbel.xml,1.1,1.2
- Index(es):