pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3674 - in trunk/pingus/src: . editor worldmap


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3674 - in trunk/pingus/src: . editor worldmap
Date: Sat, 5 Jul 2008 03:00:08 +0200

Author: grumbel
Date: 2008-07-05 03:00:06 +0200 (Sat, 05 Jul 2008)
New Revision: 3674

Modified:
   trunk/pingus/src/editor/level_properties.cpp
   trunk/pingus/src/pingu_action.cpp
   trunk/pingus/src/worldmap/pingus_worldmap.cpp
   trunk/pingus/src/worldmap/pingus_worldmap.hpp
   trunk/pingus/src/worldmap/worldmap.cpp
   trunk/pingus/src/worldmap/worldmap.hpp
   trunk/pingus/src/worldmap/worldmap_screen.cpp
   trunk/pingus/src/worldmap/worldmap_screen.hpp
   trunk/pingus/src/worldmap/worldmap_story.hpp
Log:
Move .worldmap parsing into PingusWorldmap (not yet fully complete)

Modified: trunk/pingus/src/editor/level_properties.cpp
===================================================================
--- trunk/pingus/src/editor/level_properties.cpp        2008-07-04 19:09:34 UTC 
(rev 3673)
+++ trunk/pingus/src/editor/level_properties.cpp        2008-07-05 01:00:06 UTC 
(rev 3674)
@@ -155,7 +155,7 @@
 void
 LevelProperties::on_number_to_save_change(const std::string& str)
 {
-  int num;
+  int num = 0;
   if (StringUtil::from_string(str, num))
     {
       level->set_number_to_save(num);
@@ -170,7 +170,7 @@
 void
 LevelProperties::on_number_of_pingus_change(const std::string& str)
 {
-  int num;
+  int num = 0;
   if (StringUtil::from_string(str, num))
     {
       level->set_number_of_pingus(num);

Modified: trunk/pingus/src/pingu_action.cpp
===================================================================
--- trunk/pingus/src/pingu_action.cpp   2008-07-04 19:09:34 UTC (rev 3673)
+++ trunk/pingus/src/pingu_action.cpp   2008-07-05 01:00:06 UTC (rev 3674)
@@ -89,7 +89,7 @@
        {
          collision = true;
          break;
-       }
+        }
     }
 
   return collision;

Modified: trunk/pingus/src/worldmap/pingus_worldmap.cpp
===================================================================
--- trunk/pingus/src/worldmap/pingus_worldmap.cpp       2008-07-04 19:09:34 UTC 
(rev 3673)
+++ trunk/pingus/src/worldmap/pingus_worldmap.cpp       2008-07-05 01:00:06 UTC 
(rev 3674)
@@ -15,11 +15,18 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <string>
+#include "../pingus_error.hpp"
+#include "../file_reader.hpp"
+#include "drawable_factory.hpp"
 #include "pingus_worldmap.hpp"
+
+using namespace WorldmapNS;
 
 class PingusWorldmapImpl
 {
 public:
+  std::string filename;
+
   std::string name;
   std::string short_name;
   std::string description;
@@ -32,6 +39,11 @@
   std::string default_node;
   std::string final_node;
 
+  FileReader intro_story;
+  FileReader end_story;
+  FileReader path_graph;
+
+  std::vector<FileReader> objects;
 };
 
 PingusWorldmap::PingusWorldmap()
@@ -39,10 +51,49 @@
 }
 
 PingusWorldmap::PingusWorldmap(const Pathname& pathname)
+  : impl(new PingusWorldmapImpl())
 {
+  parse_file(FileReader::parse(pathname));
 }
+ 
+void
+PingusWorldmap::parse_file(FileReader reader)
+{
+  if (reader.get_name() == "pingus-worldmap")
+    {
+      if (!reader.read_section("graph", impl->path_graph))
+        {
+          PingusError::raise("Worldmap: " + impl->filename + " is missed 
'graph' section");
+        }
 
+      impl->objects = reader.read_section("objects").get_sections();
 
+      parse_properties(reader.read_section("head"));
+
+      reader.read_section("intro_story", impl->intro_story);
+      reader.read_section("end_story", impl->end_story);
+    }
+  else
+    {
+      PingusError::raise("Worldmap:" + impl->filename + ": not a Worldmap 
file");
+    }
+}
+
+void
+PingusWorldmap::parse_properties(FileReader reader)
+{
+  reader.read_string("music",  impl->music);
+  reader.read_string("author", impl->author);
+  reader.read_string("name",   impl->name);
+  reader.read_string("short-name", impl->short_name);
+  reader.read_string("email",  impl->email);
+  reader.read_int("width",     impl->width);
+  reader.read_int("height",    impl->height);
+
+  reader.read_string("default-node", impl->default_node);
+  reader.read_string("final-node",   impl->final_node);
+}
+
 std::string
 PingusWorldmap::get_name() const 
 {
@@ -102,5 +153,17 @@
 {
   return impl->final_node;
 }
+
+FileReader
+PingusWorldmap::get_graph() const
+{
+  return impl->path_graph;
+}
+
+const std::vector<FileReader>&
+PingusWorldmap::get_objects() const
+{
+  return impl->objects;
+}
 
 /* EOF */

Modified: trunk/pingus/src/worldmap/pingus_worldmap.hpp
===================================================================
--- trunk/pingus/src/worldmap/pingus_worldmap.hpp       2008-07-04 19:09:34 UTC 
(rev 3673)
+++ trunk/pingus/src/worldmap/pingus_worldmap.hpp       2008-07-05 01:00:06 UTC 
(rev 3674)
@@ -24,13 +24,14 @@
 
 class PingusWorldmapImpl;
 
-/** */
+/** PingusWorldmap is responisble for loading .worldmap files, its
+    analog to PingusLevel */
 class PingusWorldmap
 {
-private:
 public:
   PingusWorldmap();
   PingusWorldmap(const Pathname& pathname);
+  PingusWorldmap(FileReader reader);
 
   std::string get_name() const;
   std::string get_short_name() const;
@@ -43,11 +44,16 @@
 
   std::string get_default_node() const;
   std::string get_final_node() const;
+  
+  FileReader get_intro_story() const;
+  FileReader get_end_story() const;
 
-  WorldmapNS::WorldmapStory get_intro_story() const;
-  WorldmapNS::WorldmapStory get_end_story() const;
+  FileReader get_graph() const;
+  const std::vector<FileReader>& get_objects() const;
 
-  WorldmapNS::PathGraph get_graph() const;
+private:
+  void parse_file(FileReader reader);
+  void parse_properties(FileReader reader);
 
 protected:
   boost::shared_ptr<PingusWorldmapImpl> impl;

Modified: trunk/pingus/src/worldmap/worldmap.cpp
===================================================================
--- trunk/pingus/src/worldmap/worldmap.cpp      2008-07-04 19:09:34 UTC (rev 
3673)
+++ trunk/pingus/src/worldmap/worldmap.cpp      2008-07-05 01:00:06 UTC (rev 
3674)
@@ -58,58 +58,13 @@
 {
   current_ = this;
 
-  parse_file(FileReader::parse(path_manager.complete(filename)));
+  worldmap = PingusWorldmap(Pathname(filename, Pathname::DATA_PATH));
 
-  pingus = new Pingus(path_graph);
-  set_starting_node();
-  add_drawable(pingus);
-
-  gc_state.set_limit(Rect(Vector2i(0, 0), Size(width, height)));
-}
-
-Worldmap::~Worldmap()
-{
-  for (DrawableLst::iterator i = drawables.begin (); i != drawables.end (); 
++i)
+  // Create all objects
+  const std::vector<FileReader>& object_reader = worldmap.get_objects();
+  for(std::vector<FileReader>::const_iterator i = object_reader.begin(); i != 
object_reader.end(); ++i)
     {
-      delete (*i);
-    }
-  delete intro_story;
-  delete end_story;
-  delete path_graph;
-}
-
-void
-Worldmap::parse_file(FileReader reader)
-{
-  if (reader.get_name() == "pingus-worldmap")
-    {
-      parse_graph(reader.read_section("graph"));
-      parse_objects(reader.read_section("objects"));
-      parse_properties(reader.read_section("head"));
-      intro_story = new WorldmapStory(reader.read_section("intro_story"));
-      end_story   = new WorldmapStory(reader.read_section("end_story"));
-    }
-  else
-    {
-      PingusError::raise("Worldmap:" + filename + ": not a Worldmap file");
-    }
-
-  if (!path_graph)
-    {
-      PingusError::raise("Worldmap: " + filename + " missed Graph");
-    }
-}
-
-void
-Worldmap::parse_objects(FileReader reader)
-{
-  const std::vector<FileReader>& childs = reader.get_sections();
-  
-  for(std::vector<FileReader>::const_iterator i = childs.begin(); 
-      i != childs.end(); ++i)
-    {
       Drawable* drawable = DrawableFactory::create(*i);
-
       if (drawable)
         {
           objects.push_back(drawable);
@@ -120,31 +75,26 @@
           std::cout << "Worldmap::parse_objects: Parse Error" << std::endl;
         }
     }
-}
 
-void
-Worldmap::parse_graph(FileReader reader)
-{
-  path_graph = new PathGraph(this, reader);
+  FileReader path_graph_reader = worldmap.get_graph();
+  path_graph = new PathGraph(this, path_graph_reader);
+
+  default_node = path_graph->lookup_node(worldmap.get_default_node());
+  final_node   = path_graph->lookup_node(worldmap.get_final_node());
+
+  pingus = new Pingus(path_graph);
+  set_starting_node();
+  add_drawable(pingus);
+
+  gc_state.set_limit(Rect(Vector2i(0, 0), Size(worldmap.get_width(), 
worldmap.get_height())));
 }
 
-void
-Worldmap::parse_properties(FileReader reader)
+Worldmap::~Worldmap()
 {
-  reader.read_string("music", music);
-  reader.read_string("author", author);
-  reader.read_string("name", name);
-  reader.read_string("short-name", short_name);
-  reader.read_string("email", email);
-  reader.read_int("width", width);
-  reader.read_int("height", height);
-
-  // Get beginning and ending nodes.
-  std::string node_name;
-  reader.read_string("default-node", node_name);
-  default_node = path_graph->lookup_node(node_name);
-  reader.read_string("final-node", node_name);
-  final_node = path_graph->lookup_node(node_name);
+  for (DrawableLst::iterator i = drawables.begin (); i != drawables.end (); 
++i)
+      delete (*i);
+  
+  delete path_graph;
 }
 
 void
@@ -152,6 +102,8 @@
 {
   Vector3f pingu_pos = pingus->get_pos();
   float min, max;
+  int width  = worldmap.get_width();
+  int height = worldmap.get_height();
 
   if (width >= gc.get_width())
     {
@@ -205,7 +157,7 @@
 void
 Worldmap::on_startup()
 {
-  Sound::PingusSound::play_music(music);
+  Sound::PingusSound::play_music(worldmap.get_music());
   update_locked_nodes();
 }
 
@@ -216,18 +168,6 @@
 }
 
 void
-Worldmap::remove_drawable(Drawable* drawable)
-{
-  UNUSED_ARG(drawable);
-}
-
-void
-Worldmap::set_pingus(NodeId id)
-{
-  UNUSED_ARG(id);
-}
-
-void
 Worldmap::on_pointer_move(int x, int y)
 {
   mouse_x = x;
@@ -278,7 +218,7 @@
                 }
               else
                 {
-                  StatManager::instance()->set_string(short_name + 
"-current-node", dot->get_name());
+                  
StatManager::instance()->set_string(worldmap.get_short_name() + 
"-current-node", dot->get_name());
                 }
             }
           else
@@ -356,7 +296,7 @@
   path_graph->graph.for_each_node(unlock_nodes(path_graph));
 
   bool credits_unlocked = false;
-  StatManager::instance()->get_bool(short_name + "-endstory-seen", 
credits_unlocked);
+  StatManager::instance()->get_bool(worldmap.get_short_name() + 
"-endstory-seen", credits_unlocked);
 
   if (!credits_unlocked)
     {
@@ -366,7 +306,7 @@
         {
           if (dot->finished())
             {
-              ScreenManager::instance()->replace_screen(new 
StoryScreen(get_end_story()), true);
+              ScreenManager::instance()->replace_screen(new 
StoryScreen(end_story), true);
             }
         }
       else
@@ -385,7 +325,7 @@
   NodeId id;
   std::string node_name;
 
-  if (StatManager::instance()->get_string(short_name + "-current-node", 
node_name))
+  if (StatManager::instance()->get_string(worldmap.get_short_name() + 
"-current-node", node_name))
     {
       // Just in case that level doesn't exist, look it up.
       id = path_graph->lookup_node(node_name);
@@ -424,6 +364,18 @@
     }
 }
 
+int
+Worldmap::get_width()  const
+{
+  return worldmap.get_width();
+}
+
+int
+Worldmap::get_height() const
+{
+  return worldmap.get_height();
+}
+
 } // namespace WorldmapNS
 
 /* EOF */

Modified: trunk/pingus/src/worldmap/worldmap.hpp
===================================================================
--- trunk/pingus/src/worldmap/worldmap.hpp      2008-07-04 19:09:34 UTC (rev 
3673)
+++ trunk/pingus/src/worldmap/worldmap.hpp      2008-07-05 01:00:06 UTC (rev 
3674)
@@ -22,6 +22,7 @@
 #include "../file_reader.hpp"
 #include "../display/drawing_context.hpp"
 #include "../graphic_context_state.hpp"
+#include "pingus_worldmap.hpp"
 
 class Font;
 class DrawingContext;
@@ -44,6 +45,8 @@
 class Worldmap
 {
 private:
+  PingusWorldmap worldmap;
+
   /** name of the file to parse */
   std::string filename;
 
@@ -53,16 +56,6 @@
   typedef std::vector<Drawable*>   ObjectLst;
   typedef std::vector<Drawable*> DrawableLst;
 
-  int width;
-  int height;
-
-  std::string name;
-  std::string short_name;
-  std::string author;
-  std::string email;
-  std::string music;
-
-  // Beginning and ending nodes are configurable by the XML file.
   NodeId default_node;
   NodeId final_node;
 
@@ -85,23 +78,16 @@
   int mouse_x;
   int mouse_y;
 
-private:
-  static Worldmap* current_; 
 public:
-  static Worldmap* current() { return current_; }
-
   /** Load the given*/
   Worldmap(const std::string& filename);
   ~Worldmap();
 
   Pingus* get_pingus() { return pingus; }
-  WorldmapStory* get_intro_story() const { return intro_story; }
-  WorldmapStory* get_end_story() const { return end_story; }
 
   void on_startup();
 
   std::string get_filename() const { return filename; }
-  std::string get_shortname() const { return short_name; }
 
   bool is_final_map();
 
@@ -114,12 +100,7 @@
   /** Return the current levelname for use in GUI */
   std::string get_levelname();
 
-  /** The the pingu to the given Node */
-  void set_pingus(NodeId id);
-
-  /** FIXME: Memory leak?! */
   void add_drawable(Drawable* drawable);
-  void remove_drawable(Drawable* drawable);
 
   /** @return the shortest path between node1 and node2  */
   std::vector<EdgeId> find_path (NodeId node1, NodeId node2);
@@ -129,31 +110,21 @@
   void on_secondary_button_press(int x, int y);
   void on_pointer_move(int x, int y);
 
-  int get_width()  const { return width; }
-  int get_height() const { return height; }
+  int get_width()  const;
+  int get_height() const;
 
 private:
-  /** Parses a Worldmap XML file */
-  void parse_file(FileReader reader);
-
-  /** Parse the object section of the Worldmap XML file, it contains
-      Sprites, Backgrounds and other things */
-  void parse_objects(FileReader reader);
-
-  /** Parse the graph section of the Worldmap XML file, it contains
-      the path where the Pingu can walk on. */
-  void parse_graph(FileReader reader);
-
-  /** Parse the propertie section of a Worldmap XML file, it contains
-      meta data such as the author or the name of the Worldmap */
-  void parse_properties(FileReader reader);
-
   /** Unlock nodes according to the finished ones */
   void update_locked_nodes();
 
   /** Sets the starting level on the worldmap.  Either take it from the 
StatManager
       or use the "default-node" option from the XML file */
   void set_starting_node();
+
+private:
+  static Worldmap* current_; 
+public:
+  static Worldmap* current() { return current_; }
 };
 
 } // namespace WorldmapNS

Modified: trunk/pingus/src/worldmap/worldmap_screen.cpp
===================================================================
--- trunk/pingus/src/worldmap/worldmap_screen.cpp       2008-07-04 19:09:34 UTC 
(rev 3673)
+++ trunk/pingus/src/worldmap/worldmap_screen.cpp       2008-07-05 01:00:06 UTC 
(rev 3674)
@@ -108,8 +108,10 @@
 void
 WorldmapScreenCreditsButton::on_click()
 {
+#if 0
   ScreenManager::instance()->replace_screen
     (new StoryScreen(worldmap_screen->get_worldmap()->get_end_story()), true);
+#endif
 }
 
 WorldmapScreenStoryButton::WorldmapScreenStoryButton(WorldmapScreen* 
worldmap_screen)
@@ -138,8 +140,10 @@
 void
 WorldmapScreenStoryButton::on_click()
 {
+#if 0
   ScreenManager::instance()->replace_screen
     (new StoryScreen(worldmap_screen->get_worldmap()->get_intro_story()), 
true);
+#endif
 }
 
 WorldmapScreenCloseButton::WorldmapScreenCloseButton(WorldmapScreen* 
worldmap_screen)
@@ -184,10 +188,7 @@
 WorldmapScreenEnterButton::on_pointer_enter()
 {
   SurfaceButton::on_pointer_enter();
-  if (!worldmap_screen->get_worldmap()->get_pingus()->is_walking())
-    {
-      Sound::PingusSound::play_sound ("tick");
-    }
+  Sound::PingusSound::play_sound ("tick");
 }
 
 void
@@ -238,8 +239,7 @@
   worldmap = new Worldmap(filename);
        
   bool credits_unlocked = false;
-  StatManager::instance()->get_bool(worldmap->get_shortname() + 
"-endstory-seen", 
-                                    credits_unlocked);
+  //StatManager::instance()->get_bool(worldmap->get_short_name() + 
"-endstory-seen", credits_unlocked);
   if (credits_unlocked)
     {
       gui_manager->add(new WorldmapScreenCreditsButton(this), true);
@@ -299,14 +299,6 @@
                   worldmap->get_levelname());
 }
 
-void
-WorldmapScreen::change_map (const std::string& filename, NodeId node)
-{
-  // Create the new worldmap and make it the current one
-  new_worldmap = new Worldmap (path_manager.complete("worldmaps/" + filename));
-  new_worldmap->set_pingus (node);
-}
-
 Rect
 WorldmapScreen::get_trans_rect() const
 {

Modified: trunk/pingus/src/worldmap/worldmap_screen.hpp
===================================================================
--- trunk/pingus/src/worldmap/worldmap_screen.hpp       2008-07-04 19:09:34 UTC 
(rev 3673)
+++ trunk/pingus/src/worldmap/worldmap_screen.hpp       2008-07-05 01:00:06 UTC 
(rev 3674)
@@ -68,13 +68,6 @@
 
   Worldmap* get_worldmap() { return worldmap; }
 
-  /** Change the current map to the given map
-
-      @param filename the filename of the new map, filename must be
-      @param filename relative to the worldmap directory
-      @param filename Example: "volcano.pingus" */
-  void change_map (const std::string& filename, NodeId node);
-
   Rect get_trans_rect() const;
 
 private:

Modified: trunk/pingus/src/worldmap/worldmap_story.hpp
===================================================================
--- trunk/pingus/src/worldmap/worldmap_story.hpp        2008-07-04 19:09:34 UTC 
(rev 3673)
+++ trunk/pingus/src/worldmap/worldmap_story.hpp        2008-07-05 01:00:06 UTC 
(rev 3674)
@@ -30,9 +30,7 @@
 
   StoryPage(ResDescriptor arg_image, std::string arg_text, std::string 
arg_name = "")
     : image(arg_image), text(arg_text), page_name(arg_name)
-  {
-               
-  }
+  {}
 
   ResDescriptor image;
   std::string   text;
@@ -58,7 +56,7 @@
 
 };
 
-}      // namespace WorldmapNS
+} // namespace WorldmapNS
 
 #endif
 





reply via email to

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