pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src Makefile.am,1.98,1.99 prefab.cxx,1.2,


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src Makefile.am,1.98,1.99 prefab.cxx,1.2,1.3 prefab.hxx,1.2,1.3 worldobj_data_factory.cxx,1.12,1.13 xml_helper.hxx,1.9,1.10 xml_plf.cxx,1.14,1.15 xml_plf.hxx,1.6,1.7
Date: 15 Sep 2002 20:33:48 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv21042

Modified Files:
        Makefile.am prefab.cxx prefab.hxx worldobj_data_factory.cxx 
        xml_helper.hxx xml_plf.cxx xml_plf.hxx 
Log Message:
- some more prefab stuff

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- Makefile.am 15 Sep 2002 16:49:20 -0000      1.98
+++ Makefile.am 15 Sep 2002 20:33:45 -0000      1.99
@@ -338,8 +338,6 @@
 worldobj_data.hxx \
 worldobj_data_factory.cxx \
 worldobj_data_factory.hxx \
-worldobj_group_data.cxx \
-worldobj_group_data.hxx \
 xml_helper.cxx \
 xml_helper.hxx \
 xml_plf.cxx \

Index: prefab.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/prefab.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- prefab.cxx  15 Sep 2002 16:49:20 -0000      1.2
+++ prefab.cxx  15 Sep 2002 20:33:45 -0000      1.3
@@ -20,10 +20,13 @@
 #include <iostream>
 #include "xml_helper.hxx"
 #include "prefab.hxx"
-#include "worldobj_group_data.hxx"
+#include "worldobjsdata/worldobj_group_data.hxx"
+#include "worldobj_data_factory.hxx"
 #include "path_manager.hxx"
+#include "pingus_error.hxx"
 
 Prefab::Prefab (const std::string& filename)
+  : data (0)
 {
   std::cout << "Prefab::create: " << filename << std::endl;
   xmlDocPtr doc = xmlParseFile(filename.c_str ());
@@ -31,15 +34,66 @@
   if (doc)
     {
       xmlNodePtr cur = doc->ROOT;
-      WorldObjGroupData* group = new WorldObjGroupData (doc, cur);
-      //const EditorObjLst& temp = group->create_EditorObj ();
-      //editor_objs.insert(editor_objs.end(),temp.begin(), temp.end());
-      //delete group;
+      
+      cur = XMLhelper::skip_blank (cur);
+
+      if (XMLhelper::equal_str(cur->name, "pingus-prefab"))
+       {
+         cur = cur->children;
+
+         while (cur)
+           {
+             cur = XMLhelper::skip_blank (cur);
+            
+             if (XMLhelper::equal_str (cur->name, "name"))
+               {
+                 name = XMLhelper::parse_string (doc, cur);
+               }
+             else if (XMLhelper::equal_str (cur->name, "description"))
+               {
+                 description = XMLhelper::parse_string (doc, cur);
+               }
+             else if (XMLhelper::equal_str (cur->name, "uid"))
+               {
+                 uid = XMLhelper::parse_string (doc, cur);
+               }
+             else if (XMLhelper::equal_str (cur->name, "thumbnail"))
+               {
+                 std::cout << "Prefab: thumbnail handling not implemented" << 
std::endl;
+               }
+             else if (XMLhelper::equal_str (cur->name, "object"))
+               {
+                 if (data)
+                   {
+                     std::cout << "Prefab: object defined twice! Overwriting 
first object!" << std::endl;
+                     delete data; 
+                   }
+
+                 data = WorldObjDataFactory::instance ()->create (doc, 
cur->children);
+               }
+             else
+               {
+                 std::cout << "Prefab: Unhandled: " << cur->name << std::endl;
+               }
+ 
+             cur = cur->next;
+           }
+       }
+      else
+       {
+         //std::cout << "Prefab: Not a valid prefab file" << std::endl;
+         PingusError::raise ("Prefab: Not a valid prefab file");
+       }
     }
   else
     {
       std::cout << "ObjectManager::add_prefab_from_file: read error: " << 
filename << std::endl;
     }
+}
+
+Prefab::~Prefab ()
+{
+  delete data;
 }
 
 Prefab*

Index: prefab.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/prefab.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- prefab.hxx  15 Sep 2002 16:49:20 -0000      1.2
+++ prefab.hxx  15 Sep 2002 20:33:45 -0000      1.3
@@ -34,11 +34,18 @@
 class Prefab
 {
 private:
+  WorldObjData* data;
+
+  std::string name;
+  std::string description;
+  std::string uid;
 public:
   /** Create a Prefab object from a given prefab description file
       @param filename The fully qualitfied filename of the prefab
       description file */
   Prefab (const std::string& filename);
+
+  ~Prefab ();
 
   /** Create a prefab object from a given uid, name must be the uniq
       identifer of the prefab, like "stony-entrance", not a

Index: worldobj_data_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobj_data_factory.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- worldobj_data_factory.cxx   15 Sep 2002 09:54:33 -0000      1.12
+++ worldobj_data_factory.cxx   15 Sep 2002 20:33:45 -0000      1.13
@@ -31,6 +31,8 @@
 #include "entrance_data.hxx"
 #include "worldobj_data_factory.hxx"
 
+#include "worldobjsdata/worldobj_group_data.hxx"
+#include "exit_data.hxx"
 #include "worldobjsdata/bumper_data.hxx"
 #include "worldobjsdata/conveyor_belt_data.hxx"
 #include "worldobjsdata/fake_exit_data.hxx"
@@ -65,6 +67,8 @@
       new WorldObjDataFactoryImpl<LiquidData>("liquid");
       new WorldObjDataFactoryImpl<HotspotData>("hotspot");
       new WorldObjDataFactoryImpl<EntranceData>("entrance");
+      new WorldObjDataFactoryImpl<ExitData>("exit");
+      new WorldObjDataFactoryImpl<WorldObjGroupData>("group");
 
       // traps
       new WorldObjDataFactoryImpl<BumperData>("bumper");

Index: xml_helper.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_helper.hxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- xml_helper.hxx      10 Sep 2002 21:03:32 -0000      1.9
+++ xml_helper.hxx      15 Sep 2002 20:33:45 -0000      1.10
@@ -63,10 +63,18 @@
 public:
   static std::string encode_entities (const std::string& arg_str);
 
+  /** @return if \a cur is a blank-node, goto the next, else return \a
+      cur */
   static xmlNodePtr skip_blank (xmlNodePtr cur);
   
+  /** Compare a xmlChar* string with a char* one 
+      @return true if both strings are equal */
   static bool equal_str (const xmlChar* comp, const char* orig);
   
+  /** @return the value of the attribute with the name \a name, caller
+      must free the returned  value via xmlFree()
+
+      FIXME: any reason we don't return a std::string here? */
   static char* get_prop (xmlNodePtr cur, const char* name);
 
   /// A set of function to parse an xml file

Index: xml_plf.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_plf.cxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- xml_plf.cxx 10 Sep 2002 21:03:32 -0000      1.14
+++ xml_plf.cxx 15 Sep 2002 20:33:45 -0000      1.15
@@ -24,7 +24,7 @@
 #include "pingus_error.hxx"
 #include "string_converter.hxx"
 #include "worldobj_data_factory.hxx"
-#include "worldobj_group_data.hxx"
+#include "worldobjsdata/worldobj_group_data.hxx"
 #include "exit_data.hxx"
 #include "entrance_data.hxx"
 #include "hotspot_data.hxx"
@@ -54,14 +54,14 @@
   /*
   // Free all the allocated memory
   for(vector<BackgroundData*>::iterator i = backgrounds.begin ();
-      i != backgrounds.end ();
-      i++)
-    delete *i;
+  i != backgrounds.end ();
+  i++)
+  delete *i;
 
   for(vector<WorldObjData*>::iterator i = worldobjs_data.begin ();
-      i != worldobjs_data.end ();
-      i++)
-    delete *i;
+  i != worldobjs_data.end ();
+  i++)
+  delete *i;
   */
 }
 
@@ -93,7 +93,9 @@
              continue;
            }
 
-         //puts("global loop");
+         // FIXME: This can mostly be unified with the
+         // WorldObjDataFactory, exit, backgrounds, etc. are all
+         // WorldObjs
          if (XMLhelper::equal_str(cur->name, "global"))
            {
              parse_global(cur);
@@ -136,7 +138,7 @@
            }
          else if (XMLhelper::equal_str(cur->name, "group"))
            {
-             parse_group(cur);
+             worldobjs_data.push_back (new WorldObjGroupData (doc, cur));
            }
          else if (XMLhelper::equal_str(cur->name, "start-position"))
            {
@@ -211,63 +213,6 @@
     }
     
   weathers.push_back(weather);
-}
-
-void
-XMLPLF::parse_group (xmlNodePtr cur)
-{
-  cur = cur->children;
-
-  WorldObjGroupData* group = new WorldObjGroupData;
-
-  while (cur)
-    {
-      if (xmlIsBlankNode(cur)) 
-       {
-         cur = cur->next;
-         continue;
-       }
-      
-      if (XMLhelper::equal_str(cur->name, "groundpiece"))
-       {
-         parse_groundpiece(cur);
-       }
-      else if (XMLhelper::equal_str(cur->name, "exit"))
-       {
-         group->add (new ExitData (doc, cur));
-       }
-      else if (XMLhelper::equal_str(cur->name, "entrance"))
-       {
-         group->add (new EntranceData (doc, cur));
-       }
-      else if (XMLhelper::equal_str(cur->name, "trap"))
-       {
-         parse_traps (cur);
-       }
-      else if (XMLhelper::equal_str(cur->name, "hotspot"))
-       {
-         group->add(new HotspotData (doc, cur));
-       }
-      else if (XMLhelper::equal_str(cur->name, "liquid"))
-       {
-         group->add(new LiquidData (doc, cur));
-       }
-      else if (XMLhelper::equal_str(cur->name, "group"))
-       {
-         parse_group(cur);
-       }
-      else if (XMLhelper::equal_str(cur->name, "worldobj"))
-       {
-         group->add(WorldObjDataFactory::instance ()->create(doc, cur));
-       }
-      else
-       {
-         printf("Unhandled: %s\n", reinterpret_cast<const char*>(cur->name));
-       }
-      cur = cur->next;
-    }
-
-  worldobjs_data.push_back (group);
 }
 
 void 

Index: xml_plf.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_plf.hxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- xml_plf.hxx 8 Sep 2002 18:13:04 -0000       1.6
+++ xml_plf.hxx 15 Sep 2002 20:33:45 -0000      1.7
@@ -34,7 +34,6 @@
   void parse_actions     (xmlNodePtr cur);
   void parse_global      (xmlNodePtr cur);
   void parse_groundpiece (xmlNodePtr cur);
-  void parse_group       (xmlNodePtr cur);
   void parse_start_pos   (xmlNodePtr cur);
   void parse_weather     (xmlNodePtr cur);
 





reply via email to

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