[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.hxx,1.18,1.19 manager.
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.hxx,1.18,1.19 manager.cxx,1.16,1.17 path_graph.cxx,1.9,1.10 path_graph.hxx,1.4,1.5 pathfinder.hxx,1.4,1.5 pingus.cxx,1.16,1.17 pingus.hxx,1.16,1.17 worldmap.cxx,1.21,1.22 |
Date: |
15 Oct 2002 15:48:51 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv18757/worldmap
Modified Files:
graph.hxx manager.cxx path_graph.cxx path_graph.hxx
pathfinder.hxx pingus.cxx pingus.hxx worldmap.cxx
Log Message:
walking on the worldmap finally works! :)
Index: graph.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/graph.hxx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- graph.hxx 14 Oct 2002 00:38:22 -0000 1.18
+++ graph.hxx 15 Oct 2002 15:48:49 -0000 1.19
@@ -54,11 +54,11 @@
public:
NodeId source;
NodeId destination;
- int cost;
+ float cost;
EdgeType data;
- Edge (const EdgeType& arg_data, const NodeId& s, const NodeId& d, int c)
+ Edge (const EdgeType& arg_data, const NodeId& s, const NodeId& d, float c)
: source (s), destination (d), cost (c), data(arg_data)
{
}
@@ -97,7 +97,7 @@
return NodeId (nodes.size ()-1);
}
- EdgeId add_edge (const EdgeType& data, const NodeId& a, const NodeId& b, int
cost)
+ EdgeId add_edge (const EdgeType& data, const NodeId& a, const NodeId& b,
float cost)
{
Edge<EdgeType> new_edge (data, a, b, cost);
edges.push_back (new_edge);
@@ -106,7 +106,7 @@
}
std::pair<EdgeId, EdgeId>
- add_bi_edge (const EdgeType& data, const NodeId& a, const NodeId& b, int
cost)
+ add_bi_edge (const EdgeType& data, const NodeId& a, const NodeId& b, float
cost)
{
std::pair<EdgeId, EdgeId> ret;
ret.first = add_edge (data, a, b, cost);
Index: manager.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/manager.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- manager.cxx 13 Oct 2002 20:25:00 -0000 1.16
+++ manager.cxx 15 Oct 2002 15:48:49 -0000 1.17
@@ -92,7 +92,7 @@
void
WorldMapManager::WorldMapComponent::on_primary_button_press (int x, int y)
{
- std::cout << "Buton press" << std::endl;
+ //std::cout << "Buton press" << std::endl;
/** Fixme: insert Co. translation here */
WorldMapManager::instance ()->worldmap->on_primary_button_press (x, y);
}
Index: path_graph.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- path_graph.cxx 14 Oct 2002 00:38:22 -0000 1.9
+++ path_graph.cxx 15 Oct 2002 15:48:49 -0000 1.10
@@ -81,6 +81,9 @@
// add the dot to the list of drawables
worldmap->add_drawable(dot);
+
+ // FIXME: should be use this for freeing the stuff?
+ dots.push_back(dot);
}
else
{
@@ -146,16 +149,40 @@
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());
+
+ // FIXME: merge this together with the Pingus::distance() stuff in a
seperate Path class
+ float cost = 0;
+ {
+ //std::cout << "Edgepath size: " << edge_path.size() << std::endl;
+ Path::iterator prev = full_path.begin();
+ for(Path::iterator next = prev + 1; next != full_path.end();
++next)
+ {
+ float x = prev->x - next->x;
+ float y = prev->y - next->y;
+
+ float distance = fabsf(sqrt((x * x) + (y * y)));
+ cost += distance;
+ prev = next;
+ }
+ }
// FIXME: Memory leak
worldmap->add_drawable(new PathDrawable(full_path));
// FIXME: No error checking,
- std::pair<EdgeId, EdgeId> id
- = graph.add_bi_edge(path, // FIXME: Memory leak!
- lookup_node(source), lookup_node(destination),
- 0 /* costs */);
- edge_lookup[name] = id.first;
+ EdgeId id1 = graph.add_edge(path, // FIXME: Memory leak!
+ lookup_node(destination),
lookup_node(source),
+ cost /* costs */);
+
+ EdgeId id2 = graph.add_edge(new Path(path->rbegin(), path->rend()),
// FIXME: Memory leak!
+ lookup_node(source),
lookup_node(destination),
+ cost /* costs */);
+
+ std::cout << "Cost: " << cost << std::endl;
+
+ // FIXME: edge lookup is flawed, since we have different edges in
both directions
+
+ edge_lookup[name] = id1;
}
else
{
@@ -215,6 +242,20 @@
PathGraph::get_dot(NodeId id)
{
return graph.resolve_node(id).data;
+}
+
+Dot*
+PathGraph::get_dot(float x_pos, float y_pos)
+{
+ for(std::vector<Dot*>::iterator i = dots.begin(); i != dots.end(); ++i)
+ {
+ float x = x_pos - (*i)->get_pos().x;
+ float y = y_pos - (*i)->get_pos().y;
+
+ if (sqrt(x*x + y*y) < 30.0f)
+ return *i;
+ }
+ return 0;
}
} // namespace WorldMapNS
Index: path_graph.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/path_graph.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- path_graph.hxx 13 Oct 2002 23:02:29 -0000 1.4
+++ path_graph.hxx 15 Oct 2002 15:48:49 -0000 1.5
@@ -26,10 +26,9 @@
#include "../libxmlfwd.hxx"
#include "graph.hxx"
-class Dot;
-
namespace WorldMapNS {
+class Dot;
class WorldMap;
typedef std::vector<Vector> Path;
@@ -44,6 +43,8 @@
// FIXME: Memory leak? Where do we free stuff data inside the graph?
// FIXME: shouldn't be public
Graph<Dot*, Path*> graph;
+
+ std::vector<Dot*> dots;
private:
// FIXME: This could/should probally be moved inside the graph (or not?!)
@@ -63,7 +64,11 @@
starting from \a start */
std::vector<NodeId> get_path(NodeId start, NodeId end);
+ /** Get a node by it id */
Dot* get_dot(NodeId id);
+
+ /** Get a node by its position */
+ Dot* get_dot(float x, float y);
EdgeId lookup_edge(const std::string& name);
NodeId lookup_node(const std::string& name);
Index: pathfinder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pathfinder.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pathfinder.hxx 14 Oct 2002 00:38:22 -0000 1.4
+++ pathfinder.hxx 15 Oct 2002 15:48:49 -0000 1.5
@@ -36,7 +36,7 @@
enum { CLOSED, UNKNOWN, OPEN} status;
NodeId parent;
- int cost;
+ float cost;
NodeId handle;
NodeStat ()
@@ -76,7 +76,7 @@
{
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;
+ float new_cost = stat_graph[current].cost +
graph.resolve_edge(*e).cost;
if (stat.status == NodeStat::OPEN
&& stat.cost <= new_cost)
Index: pingus.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- pingus.cxx 15 Oct 2002 13:58:31 -0000 1.16
+++ pingus.cxx 15 Oct 2002 15:48:49 -0000 1.17
@@ -63,7 +63,7 @@
{
float velocity = 50.0f;
- std::cout << "Updating Walk: " << edge_path_position << "/" <<
edge_path_length << std::endl;
+ //std::cout << "Updating Walk: " << edge_path_position << "/" <<
edge_path_length << std::endl;
// Update the edge_path_position
edge_path_position += velocity * delta;
@@ -196,7 +196,7 @@
pos = path->get_dot(node)->get_pos();
current_node = node;
std::cout << "Pingu Pos: " << pos << std::endl;
- walk_to_node(0);
+ //walk_to_node(0);
}
float
@@ -224,6 +224,12 @@
edge_path.push_back(path->graph.resolve_node(target_node).data->get_pos());
edge_path_length = calc_edge_path_length();
+}
+
+bool
+Pingus::is_walking()
+{
+ return current_node == NoNode;
}
} // namespace WorldMapNS
Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.hxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- pingus.hxx 14 Oct 2002 00:38:22 -0000 1.16
+++ pingus.hxx 15 Oct 2002 15:48:49 -0000 1.17
@@ -92,6 +92,7 @@
/** calculate the position of the pingu */
Vector calc_pos ();
+ bool is_walking();
/** @return the node on which the pingu is currently standing, 0 is
returned if the pingu is currently between two nodes */
Index: worldmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- worldmap.cxx 14 Oct 2002 00:38:22 -0000 1.21
+++ worldmap.cxx 15 Oct 2002 15:48:49 -0000 1.22
@@ -37,6 +37,7 @@
#include "worldmap.hxx"
#include "drawable_factory.hxx"
#include "drawable.hxx"
+#include "dot.hxx"
#include "path_graph.hxx"
namespace WorldMapNS {
@@ -199,8 +200,18 @@
void
WorldMap::on_primary_button_press(int x, int y)
{
- UNUSED_ARG(x);
- UNUSED_ARG(y);
+ std::cout << "<position>\n"
+ << " <x-pos>" << x << "</x-pos>\n"
+ << " <y-pos>" << y << "</y-pos>\n"
+ << " <z-pos>0</z-pos>\n"
+ << "</position>\n\n" << std::endl;
+
+ Dot* dot = path_graph->get_dot(x, y);
+ if (dot)
+ {
+ std::cout << "Clicked on: " << dot->get_name() << std::endl;
+ pingus->walk_to_node(path_graph->lookup_node(dot->get_name()));
+ }
}
} // namespace WorldMapNS
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldmap graph.hxx,1.18,1.19 manager.cxx,1.16,1.17 path_graph.cxx,1.9,1.10 path_graph.hxx,1.4,1.5 pathfinder.hxx,1.4,1.5 pingus.cxx,1.16,1.17 pingus.hxx,1.16,1.17 worldmap.cxx,1.21,1.22,
grumbel <=