[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/worldmap drawable.cxx,NONE,1.1 drawab
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/worldmap drawable.cxx,NONE,1.1 drawable.hxx,NONE,1.1 drawable_factory.cxx,NONE,1.1 drawable_factory.hxx,NONE,1.1 pathfinder.hxx,NONE,1.1 sprite_drawable.cxx,NONE,1.1 sprite_drawable.hxx,NONE,1.1 surface_drawable.cxx,NONE,1.1 surface_drawable.hxx,NONE,1.1 |
Date: |
12 Oct 2002 23:37:26 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv15791
Added Files:
drawable.cxx drawable.hxx drawable_factory.cxx
drawable_factory.hxx pathfinder.hxx sprite_drawable.cxx
sprite_drawable.hxx surface_drawable.cxx surface_drawable.hxx
Log Message:
- started with the worldmap rewirte, worldmap is now broken and will not work
for the next few days
--- NEW FILE: drawable.cxx ---
// $Id: drawable.cxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "drawable.hxx"
/* EOF */
--- NEW FILE: drawable.hxx ---
// $Id: drawable.hxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PINGUS_DRAWABLE_HXX
#define HEADER_PINGUS_DRAWABLE_HXX
#include "../pingus_error.hxx"
#include "../xml_helper.hxx"
class GraphicContext;
namespace WorldMapNS {
/** An drawable object on the worldmap, such has a background or a
sprite, interface only */
class Drawable
{
private:
/** The symbolic id of the drawable */
std::string name;
/** True if object should be visible, false otherwise */
bool visible;
public:
Drawable(std::string arg_name)
: name(arg_name),
visible(true)
{
}
Drawable(xmlDocPtr doc, xmlNodePtr cur)
: visible(true)
{
if (!XMLhelper::get_prop (cur, "id", name))
{
PingusError::raise("Drawable: Couldn't get name of object");
}
}
virtual ~Drawable() {}
bool is_visible() { return visible; }
std::string get_name() { return name; }
virtual void draw(GraphicContext& gc) =0;
virtual void update() =0;
private:
Drawable (const Drawable&);
Drawable operator= (const Drawable&);
};
} // namespace WorldMapNS
#endif
/* EOF */
--- NEW FILE: drawable_factory.cxx ---
// $Id: drawable_factory.cxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 "../xml_helper.hxx"
#include "surface_drawable.hxx"
#include "sprite_drawable.hxx"
#include "drawable_factory.hxx"
namespace WorldMapNS {
Drawable*
DrawableFactory::create(xmlDocPtr doc, xmlNodePtr cur)
{
if (XMLhelper::equal_str(cur->name, "surface"))
{
return new SurfaceDrawable(doc, cur);
}
else
{
std::cout << "DrawableFactory::create(): Can't create " << cur->name <<
std::endl;
return 0;
}
}
} // namespace WorldMapNS
/* EOF */
--- NEW FILE: drawable_factory.hxx ---
// $Id: drawable_factory.hxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_DRAWABLE_FACTORY_HXX
#define HEADER_DRAWABLE_FACTORY_HXX
#include "../libxmlfwd.hxx"
#include "drawable.hxx"
namespace WorldMapNS {
/** */
class DrawableFactory
{
private:
public:
/** Create a new drawable */
static Drawable* create(xmlDocPtr doc, xmlNodePtr cur);
private:
DrawableFactory (const DrawableFactory&);
DrawableFactory& operator= (const DrawableFactory&);
};
} // namespace WorldMapNS
#endif
/* EOF */
--- NEW FILE: pathfinder.hxx ---
// $Id: pathfinder.hxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PATHFINDER_HXX
#define HEADER_PATHFINDER_HXX
#include <queue>
#include "graph.hxx"
/** */
template<class T>
class Pathfinder
{
public:
class NodeStat
{
public:
enum { CLOSED, UNKNOWN, OPEN} status;
NodeHandle parent;
int cost;
NodeHandle handle;
NodeStat ()
: status (UNKNOWN),
parent(-1),
cost(0),
handle (-1)
{
}
};
private:
Graph<T>& graph;
NodeHandle start;
std::priority_queue<NodeHandle> open_nodes;
std::vector<NodeStat> stat_graph;
public:
Pathfinder (Graph<T>& g, NodeHandle s)
: graph (g), start (s)
{
stat_graph.resize (graph.max_node_handler_value());
push_to_open (start);
while (!open_nodes.empty())
{
NodeHandle 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 ();
e != node.next.end ();
++e)
{
NodeHandle 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;
if (stat.status == NodeStat::OPEN
&& stat.cost <= new_cost)
{
// do nothing, already now a better path
}
else
{
stat_graph[child_node].parent = current;
stat_graph[child_node].cost = new_cost;
if (!is_open (child_node))
push_to_open (child_node);
}
}
}
std::cout << "---DONE---" << std::endl;
}
std::vector<NodeHandle> get_path (NodeHandle end)
{
std::vector<NodeHandle> path;
NodeHandle handle = end;
do
{
path.push_back(handle);
std::cout << "Handle: " << handle
<< " Parent: " << stat_graph[handle].parent << std::endl;
if (handle == start)
{
std::reverse (path.begin (), path.end ());
return path;
}
else if (handle == -1)
{
// no path found
return std::vector<NodeHandle>();
}
else
{
handle = stat_graph[handle].parent;
}
}
while (1);
}
void push_to_open (NodeHandle handle)
{
open_nodes.push (handle);
stat_graph[handle].status = NodeStat::OPEN;
}
bool is_open (NodeHandle handle)
{
return stat_graph[handle].status == NodeStat::OPEN;
}
private:
Pathfinder (const Pathfinder&);
Pathfinder operator= (const Pathfinder&);
};
#endif
/* EOF */
--- NEW FILE: sprite_drawable.cxx ---
// $Id: sprite_drawable.cxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../graphic_context.hxx"
#include "sprite_drawable.hxx"
namespace WorldMapNS {
SpriteDrawable::SpriteDrawable(xmlDocPtr doc, xmlNodePtr cur)
: Drawable(doc, cur)
{
}
void
SpriteDrawable::draw(GraphicContext& gc)
{
gc.draw(sprite, pos);
}
} // namespace WorldMapNS
/* EOF */
--- NEW FILE: sprite_drawable.hxx ---
// $Id: sprite_drawable.hxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_SPRITE_DRAWABLE_HXX
#define HEADER_SPRITE_DRAWABLE_HXX
#include "../sprite.hxx"
#include "../vector.hxx"
#include "drawable.hxx"
namespace WorldMapNS {
/** */
class SpriteDrawable : public Drawable
{
private:
Sprite sprite;
Vector pos;
public:
SpriteDrawable(xmlDocPtr doc, xmlNodePtr cur);
~SpriteDrawable();
void draw(GraphicContext& gc);
void update()
{
sprite.update();
}
private:
SpriteDrawable (const SpriteDrawable&);
SpriteDrawable operator= (const SpriteDrawable&);
};
} // namespace WorldMapNS
#endif
/* EOF */
--- NEW FILE: surface_drawable.cxx ---
// $Id: surface_drawable.cxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 "../xml_helper.hxx"
#include "../pingus_resource.hxx"
#include "../graphic_context.hxx"
#include "surface_drawable.hxx"
namespace WorldMapNS {
SurfaceDrawable::SurfaceDrawable(xmlDocPtr doc, xmlNodePtr cur)
: Drawable(doc, cur)
{
cur = cur->children;
while(cur)
{
if (XMLhelper::equal_str(cur->name, "surface"))
{
ResDescriptor desc = XMLhelper::parse_surface(doc, cur);
surface = PingusResource::load_surface(desc);
}
else if (XMLhelper::equal_str(cur->name, "position"))
{
pos = XMLhelper::parse_vector(doc, cur);
}
else
{
std::cout << "Uknown: " << cur->name << std::endl;
}
cur = cur->next;
cur = XMLhelper::skip_blank(cur);
}
}
void
SurfaceDrawable::update()
{
}
void
SurfaceDrawable::draw(GraphicContext& gc)
{
if (surface)
{
gc.draw(surface, pos);
}
}
} // namespace WorldMapNS
/* EOF */
--- NEW FILE: surface_drawable.hxx ---
// $Id: surface_drawable.hxx,v 1.1 2002/10/12 23:37:23 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_SURFACE_DRAWABLE_HXX
#define HEADER_SURFACE_DRAWABLE_HXX
#include <ClanLib/Display/Display/surface.h>
#include "../vector.hxx"
#include "drawable.hxx"
namespace WorldMapNS {
/** */
class SurfaceDrawable : public Drawable
{
private:
CL_Surface surface;
Vector pos;
public:
SurfaceDrawable(xmlDocPtr doc, xmlNodePtr cur);
void update();
void draw(GraphicContext&);
private:
SurfaceDrawable (const SurfaceDrawable&);
SurfaceDrawable& operator= (const SurfaceDrawable&);
};
} // namespace WorldMapNS
#endif
/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/worldmap drawable.cxx,NONE,1.1 drawable.hxx,NONE,1.1 drawable_factory.cxx,NONE,1.1 drawable_factory.hxx,NONE,1.1 pathfinder.hxx,NONE,1.1 sprite_drawable.cxx,NONE,1.1 sprite_drawable.hxx,NONE,1.1 surface_drawable.cxx,NONE,1.1 surface_drawable.hxx,NONE,1.1,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/worldmap dot_factory.cxx,NONE,1.1 dot_factory.hxx,NONE,1.1 path_graph.cxx,NONE,1.1 path_graph.hxx,NONE,1.1 Makefile.am,1.4,1.5 graph.hxx,1.13,1.14 manager.cxx,1.14,1.15 manager.hxx,1.12,1.13 node.hxx,1.9,1.10 pingus.cxx,1.10,1.11 pingus.hxx,1.13,1.14 stat.cxx,1.13,1.14 stat.hxx,1.9,1.10 worldmap.cxx,1.15,1.16 worldmap.hxx,1.14,1.15
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus configure.in,1.73,1.74
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/worldmap dot_factory.cxx,NONE,1.1 dot_factory.hxx,NONE,1.1 path_graph.cxx,NONE,1.1 path_graph.hxx,NONE,1.1 Makefile.am,1.4,1.5 graph.hxx,1.13,1.14 manager.cxx,1.14,1.15 manager.hxx,1.12,1.13 node.hxx,1.9,1.10 pingus.cxx,1.10,1.11 pingus.hxx,1.13,1.14 stat.cxx,1.13,1.14 stat.hxx,1.9,1.10 worldmap.cxx,1.15,1.16 worldmap.hxx,1.14,1.15
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus configure.in,1.73,1.74
- Index(es):