[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.cxx,1.10,1.11 graph.hx
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.cxx,1.10,1.11 graph.hxx,1.17,1.18 path_drawable.cxx,1.3,1.4 path_graph.cxx,1.8,1.9 pathfinder.hxx,1.3,1.4 pingus.cxx,1.13,1.14 pingus.hxx,1.15,1.16 worldmap.cxx,1.20,1.21 |
Date: |
14 Oct 2002 00:38:24 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv26927/src/worldmap
Modified Files:
graph.cxx graph.hxx path_drawable.cxx path_graph.cxx
pathfinder.hxx pingus.cxx pingus.hxx worldmap.cxx
Log Message:
- some more worldmap fixes, pingu walks now (but incorrectly...)
Index: graph.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/graph.cxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- graph.cxx 12 Oct 2002 23:43:20 -0000 1.10
+++ graph.cxx 14 Oct 2002 00:38:22 -0000 1.11
@@ -22,6 +22,7 @@
namespace WorldMapNS {
const NodeId NoNode = -1;
+const EdgeId NoEdge = -1;
} // namespace WorldMapNS
Index: graph.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/graph.hxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- graph.hxx 13 Oct 2002 23:02:29 -0000 1.17
+++ graph.hxx 14 Oct 2002 00:38:22 -0000 1.18
@@ -29,6 +29,7 @@
typedef int EdgeId;
extern const NodeId NoNode;
+extern const EdgeId NoEdge;
template<class NodeType>
class Node
@@ -125,12 +126,14 @@
Edge<EdgeType>& resolve_edge (const EdgeId& node)
{
+ // FIXME: No error handling
return edges[node];
}
/** Translates a NodeId into the corresponding Node */
Node<NodeType>& resolve_node (const NodeId& node)
{
+ // FIXME: No error handling
return nodes[node];
}
@@ -144,6 +147,7 @@
&& i->destination == destination)
return *i;
}
+ std::cout << "couldn't resolve edge: source=" << source << " destination="
<< destination << std::endl;
assert(false);
}
Index: path_drawable.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_drawable.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- path_drawable.cxx 13 Oct 2002 20:25:00 -0000 1.3
+++ path_drawable.cxx 14 Oct 2002 00:38:22 -0000 1.4
@@ -33,15 +33,15 @@
{
Path::iterator prev = path.begin();
- std::cout << "<<<<<< Path start" << std::endl;
+ //std::cout << "<<<<<< Path start" << std::endl;
for(Path::iterator next = prev + 1; next != path.end(); ++next)
{
- std::cout << "Pos: " << *prev << " " << *next << std::endl;
+ //std::cout << "Pos: " << *prev << " " << *next << std::endl;
gc.draw_line(*prev, *next,
1.0, 1.0, 1.0);
prev = next;
}
- std::cout << ">>>>>> Path end" << std::endl;
+ //std::cout << ">>>>>> Path end" << std::endl;
}
void
Index: path_graph.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- path_graph.cxx 13 Oct 2002 23:02:29 -0000 1.8
+++ path_graph.cxx 14 Oct 2002 00:38:22 -0000 1.9
@@ -188,7 +188,7 @@
if (i == edge_lookup.end())
{
std::cout << "Couldn't find EdgeId for: " << name << std::endl;
- return 0;
+ return NoEdge;
}
else
{
@@ -203,7 +203,7 @@
if (i == node_lookup.end())
{
std::cout << "Couldn't find NodeId for: " << name << std::endl;
- return 0;
+ return NoNode;
}
else
{
Index: pathfinder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pathfinder.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pathfinder.hxx 13 Oct 2002 23:02:29 -0000 1.3
+++ pathfinder.hxx 14 Oct 2002 00:38:22 -0000 1.4
@@ -96,6 +96,8 @@
std::cout << "---DONE---" << std::endl;
}
+ /** The nodes to walk to reach end is returned in reverse order! so
+ you have to handle the vector like a stack with .back() == .top() */
std::vector<NodeId> get_path (NodeId end)
{
std::vector<NodeId> path;
@@ -109,7 +111,7 @@
if (handle == start)
{
- std::reverse (path.begin (), path.end ());
+ //std::reverse (path.begin (), path.end ());
return path;
}
else if (handle == -1)
Index: pingus.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.cxx,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- pingus.cxx 13 Oct 2002 23:02:29 -0000 1.13
+++ pingus.cxx 14 Oct 2002 00:38:22 -0000 1.14
@@ -17,6 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <iostream>
#include <math.h>
#include "../boost/smart_ptr.hpp"
#include "../graphic_context.hxx"
@@ -50,16 +51,20 @@
void
Pingus::update ()
{
- float delta = 0.25f;
+ float delta = 0.025f;
sprite.update ();
- update_walk(delta);
+ if (current_node == NoNode)
+ update_walk(delta);
}
void
Pingus::update_walk (float delta)
{
- // Update the position
+ float velocity = 50.0f;
+
+ std::cout << "Updating Walk: " << edge_path_position << "/" <<
edge_path_length << std::endl;
+ // Update the edge_path_position
edge_path_position += velocity * delta;
if (edge_path_position > edge_path_length) // target reached
@@ -70,23 +75,7 @@
}
else // edge is traveled, now go to the next node
{
- source_node = target_node;
- target_node = node_path.back ();
- node_path.pop_back ();
-
- edge_path_position = 0.0f;
-
- // 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();
+ update_edge_path();
}
}
@@ -97,12 +86,12 @@
float
Pingus::calc_edge_path_length()
{
+ std::cout << "Edgepath size: " << edge_path.size() << std::endl;
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);
+ length += distance(*prev, *next);
prev = next;
}
return length;
@@ -114,7 +103,13 @@
if (current_node != NoNode) // pingu stands still
{
node_path = path->get_path (current_node, target);
- // FIXME: Edge path and co get invalid here
+
+ // Simulate that we just reached current_node, then update the edge_path
+ target_node = node_path.back(); // equal to current_node;
+ node_path.pop_back();
+ update_edge_path();
+
+ current_node = NoNode;
return true;
}
else // pingu between two nodes
@@ -146,7 +141,7 @@
Vector
Pingus::calc_pos ()
{
- if (current_node) // pingu stands still
+ if (current_node != NoNode) // pingu stands still
{
return path->graph.resolve_node(current_node).data->get_pos ();
}
@@ -158,14 +153,14 @@
float comp_length = 0.0f;
while (next != edge_path.end())
{
- float length = 10; // FIXME: line_length (current, next);
+ float length = distance(*current, *next);
if (comp_length + length > edge_path_position)
{
float perc = (edge_path_position - comp_length) // length to
walk from current node
/ length;
- return Vector(); // FIXME: interpol (current, next, perc);
+ return interpolate (*current, *next, perc);
}
++current;
@@ -176,16 +171,52 @@
}
}
+float
+Pingus::distance(const Vector& a, const Vector& b)
+{
+ return fabsf(sqrt((a.x * b.x) + (a.y * b.y)));
+}
+
+Vector
+Pingus::interpolate(const Vector& a, const Vector& b, float perc)
+{
+ Vector c = b - a;
+ return a + (c * perc);
+}
+
void
Pingus::set_position (NodeId node)
{
pos = path->get_dot(node)->get_pos();
+ current_node = node;
+ std::cout << "Pingu Pos: " << pos << std::endl;
+ walk_to_node(0);
}
float
Pingus::get_z_pos() const
{
return 2000.0f;
+}
+
+void
+Pingus:: update_edge_path()
+{
+ // Update source and target nodes
+ source_node = target_node;
+ target_node = node_path.back ();
+ node_path.pop_back (); // remove target node from list of nodes
+
+ edge_path_position = 0.0f;
+ edge_path.clear();
+
+ Path* partial_path = path->graph.resolve_edge(source_node, target_node).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();
}
} // namespace WorldMapNS
Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.hxx,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pingus.hxx 13 Oct 2002 23:02:29 -0000 1.15
+++ pingus.hxx 14 Oct 2002 00:38:22 -0000 1.16
@@ -53,7 +53,9 @@
NodeId source_node;
/** The node to which the pingu is currently walking, value is
- undefined when the pingu is currently standing on a node */
+ undefined when the pingu is currently standing on a node. This
+ is not the final target node (aka node_path.back()), but instead
+ the end node of an edge */
NodeId target_node;
/** The node path to walk. The edge between two nodes is itself
@@ -76,7 +78,6 @@
/** Current position of the pingu, only for caching purpose */
Vector pos;
- float velocity;
public:
/** */
Pingus (PathGraph* arg_path);
@@ -105,7 +106,14 @@
private:
void update_walk (float delta);
+ void update_edge_path();
float calc_edge_path_length();
+
+ /** */
+ Vector interpolate(const Vector& a, const Vector& b, float perc);
+
+ float distance(const Vector& a, const Vector& b);
+
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.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- worldmap.cxx 13 Oct 2002 23:02:29 -0000 1.20
+++ worldmap.cxx 14 Oct 2002 00:38:22 -0000 1.21
@@ -65,7 +65,7 @@
parse_file(doc, cur);
pingus = new Pingus(path_graph);
- pingus->set_position(path_graph->lookup_node("levelnode_3"));
+ pingus->set_position(path_graph->lookup_node("leveldot_3"));
add_drawable(pingus);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.cxx,1.10,1.11 graph.hxx,1.17,1.18 path_drawable.cxx,1.3,1.4 path_graph.cxx,1.8,1.9 pathfinder.hxx,1.3,1.4 pingus.cxx,1.13,1.14 pingus.hxx,1.15,1.16 worldmap.cxx,1.20,1.21,
grumbel <=