pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2762 - branches/pingus_sdl/src


From: jsalmon3
Subject: [Pingus-CVS] r2762 - branches/pingus_sdl/src
Date: Thu, 19 Jul 2007 05:23:57 +0200

Author: jsalmon3
Date: 2007-07-19 05:23:47 +0200 (Thu, 19 Jul 2007)
New Revision: 2762

Modified:
   branches/pingus_sdl/src/pingus_main.cpp
   branches/pingus_sdl/src/savegame.cpp
   branches/pingus_sdl/src/savegame.hpp
   branches/pingus_sdl/src/savegame_manager.cpp
Log:
Fixed save games to use sexpr

Modified: branches/pingus_sdl/src/pingus_main.cpp
===================================================================
--- branches/pingus_sdl/src/pingus_main.cpp     2007-07-18 15:57:01 UTC (rev 
2761)
+++ branches/pingus_sdl/src/pingus_main.cpp     2007-07-19 03:23:47 UTC (rev 
2762)
@@ -778,6 +778,8 @@
   PHYSFS_init(argv[0]);
   PHYSFS_addToSearchPath("data", 0);
   PHYSFS_addToSearchPath(".", 0);
+  PHYSFS_addToSearchPath(System::get_statdir().c_str(), 0);
+  PHYSFS_setWriteDir(System::get_statdir().c_str());
 
   executable_name = argv[0];
 

Modified: branches/pingus_sdl/src/savegame.cpp
===================================================================
--- branches/pingus_sdl/src/savegame.cpp        2007-07-18 15:57:01 UTC (rev 
2761)
+++ branches/pingus_sdl/src/savegame.cpp        2007-07-19 03:23:47 UTC (rev 
2762)
@@ -18,7 +18,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <iostream>
-///#include "sexpr_file_writer.hpp"
+#include "sexpr_file_writer.hpp"
 #include "savegame.hpp"
 #include "string_util.hpp"
 
@@ -62,7 +62,7 @@
 
 Savegame::Savegame(FileReader reader)
 {
-  read_xml(reader);
+  read_sexpr(reader);
 }
 
 Savegame::Savegame(std::string arg_levelname, S_Status arg_status, int 
arg_time, int arg_saved_pingus)
@@ -73,9 +73,8 @@
 {
 }
 
-#if 0
 void
-Savegame::write_xml(XMLFileWriter& writer)
+Savegame::write_sexpr(SExprFileWriter& writer)
 {
   writer.begin_section("level");
   writer.write_string ("name", levelname);
@@ -84,10 +83,9 @@
   writer.write_int    ("saved-pingus", saved_pingus);
   writer.end_section();
 }
-#endif 
 
 void
-Savegame::read_xml(FileReader reader)
+Savegame::read_sexpr(FileReader reader)
 {
   reader.read_string ("name", levelname);
   reader.read_enum   ("status", status, string_to_status);

Modified: branches/pingus_sdl/src/savegame.hpp
===================================================================
--- branches/pingus_sdl/src/savegame.hpp        2007-07-18 15:57:01 UTC (rev 
2761)
+++ branches/pingus_sdl/src/savegame.hpp        2007-07-19 03:23:47 UTC (rev 
2762)
@@ -24,7 +24,7 @@
 #include "file_reader.hpp"
 
 
-       class XMLFileWriter;
+class SExprFileWriter;
 
 /** The Savegame class holds savegame informations for a single
     level */
@@ -33,8 +33,8 @@
 private:
 public:
   enum S_Status { FINISHED,   // level is successfully finished
-                ACCESSIBLE, // level is accessible and can be played
-                NONE };      // level is not finished and cannot be accessed
+                  ACCESSIBLE, // level is accessible and can be played
+                  NONE };     // level is not finished and cannot be accessed
 
   static std::string status_to_string(S_Status s);
   static S_Status string_to_status (std::string s);
@@ -49,12 +49,12 @@
   int saved_pingus;
 
   Savegame();
-       ~Savegame() { }
+  ~Savegame() { }
   Savegame(FileReader node);
   Savegame(std::string arg_levelname, S_Status arg_status, int arg_time, int 
arg_saved_pingus);
 
-  void read_xml(FileReader node);
-  void write_xml(XMLFileWriter& xml);
+  void read_sexpr(FileReader node);
+  void write_sexpr(SExprFileWriter& xml);
 };
 
 

Modified: branches/pingus_sdl/src/savegame_manager.cpp
===================================================================
--- branches/pingus_sdl/src/savegame_manager.cpp        2007-07-18 15:57:01 UTC 
(rev 2761)
+++ branches/pingus_sdl/src/savegame_manager.cpp        2007-07-19 03:23:47 UTC 
(rev 2762)
@@ -17,14 +17,15 @@
 //  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 <fstream>
 #include <assert.h>
 #include "system.hpp"
 #include "pingus_error.hpp"
-////#include "xml_file_reader.hpp"
-///#include "xml_file_writer.hpp"
+#include "sexpr_file_reader.hpp"
+#include "sexpr_file_writer.hpp"
 #include "savegame_manager.hpp"
+#include "lisp/lisp.hpp"
+#include "lisp/parser.hpp"
+#include "physfs/physfs_stream.hpp"
 
 
 SavegameManager* SavegameManager::instance_ = 0;
@@ -35,57 +36,54 @@
   if (instance_)
     return instance_;
   else
-    return (instance_ = new SavegameManager(System::get_statdir() + 
"savegames/savegames.xml"));
+    return (instance_ = new SavegameManager("savegames/savegames.xml"));
 }
 
 void SavegameManager::deinit()
 {
-       delete instance_;
-       instance_ = 0;
+  delete instance_;
+  instance_ = 0;
 }
 
 SavegameManager::SavegameManager(const std::string& arg_filename)
   : filename(arg_filename)
 {
-#if 0
-  try 
+  boost::shared_ptr<lisp::Lisp> sexpr = lisp::Parser::parse(arg_filename);
+  if (!sexpr)
     {
-      CL_DomDocument doc(new CL_InputSource_File(filename), true);
-      CL_DomElement root = doc.get_document_element();
-      if (root.get_tag_name() != "pingus-savegame")
+      PingusError::raise("SavegameManager: Couldn't find savegame file '" +
+        filename + "', starting with an empty one.");
+      return;
+    }
+
+  SExprFileReader reader(sexpr->get_list_elem(0));
+
+  if (reader.get_name() != "pingus-savegame")
+    {
+      PingusError::raise("Error: " + filename + ": not a (pingus-savegame) 
file");
+    }
+  else
+    {
+      const std::vector<FileReader>& sections = reader.get_sections();
+      for(std::vector<FileReader>::const_iterator i = sections.begin();
+          i != sections.end(); ++i)
         {
-          PingusError::raise("Error: " + filename + ": not a <pingus-savegame> 
file");
-        }
-      else
-        {
-          XMLFileReader reader(root);
-          const std::vector<FileReader>& sections = reader.get_sections();
-          for(std::vector<FileReader>::const_iterator i = sections.begin();
-              i != sections.end(); ++i)
-            {
-              Savegame* savegame = new Savegame(*i);
-              SavegameTable::iterator j = savegames.find(savegame->levelname);
+          Savegame* savegame = new Savegame(*i);
+          SavegameTable::iterator j = savegames.find(savegame->levelname);
 
-              if (j != savegames.end())
-                {
-                  std::cout << "SavegameManager: name collision: " << 
savegame->levelname << std::endl;
-                  delete j->second;
-                  j->second = savegame;
-                }
-              else
-                {
-                  //std::cout << "SavegameManager: Loading savegame for: " << 
savegame->levelname << std::endl;
-                  savegames[savegame->levelname] = savegame;
-                }
+          if (j != savegames.end())
+            {
+              std::cout << "SavegameManager: name collision: " << 
savegame->levelname << std::endl;
+              delete j->second;
+              j->second = savegame;
             }
+          else
+            {
+              //std::cout << "SavegameManager: Loading savegame for: " << 
savegame->levelname << std::endl;
+              savegames[savegame->levelname] = savegame;
+            }
         }
-    } 
-  catch (...) 
-    {
-      std::cout << "SavegameManager: Couldn't find savegame file '" << filename
-                << "', starting with a empty one." << std::endl;
     }
-#endif
 }
 
 SavegameManager::~SavegameManager()
@@ -137,20 +135,18 @@
 void
 SavegameManager::flush()
 {
-#if 0
-  std::ofstream out(filename.c_str());
-  XMLFileWriter xml(out);
+  OFileStream out(filename);
+  SExprFileWriter sfw(out);
 
-  xml.begin_section("pingus-savegame");
+  sfw.begin_section("pingus-savegame");
 
   for(SavegameTable::iterator i = savegames.begin(); i != savegames.end(); ++i)
     {
       assert(i->second);
-      i->second->write_xml(xml);
+      i->second->write_sexpr(sfw);
     }
 
-  xml.end_section();   // pingus-savegame
-#endif 
+  sfw.end_section();   // pingus-savegame
 }
 
 





reply via email to

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