pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r4098 - in trunk/pingus/src/pingus: . screens


From: grumbel at BerliOS
Subject: [Pingus-CVS] r4098 - in trunk/pingus/src/pingus: . screens
Date: Thu, 3 Dec 2009 05:56:38 +0100

Author: grumbel
Date: 2009-12-03 05:56:36 +0100 (Thu, 03 Dec 2009)
New Revision: 4098

Modified:
   trunk/pingus/src/pingus/pingus_demo.cpp
   trunk/pingus/src/pingus/pingus_demo.hpp
   trunk/pingus/src/pingus/pingus_level.cpp
   trunk/pingus/src/pingus/pingus_level.hpp
   trunk/pingus/src/pingus/pingus_level_impl.hpp
   trunk/pingus/src/pingus/screens/demo_session.cpp
   trunk/pingus/src/pingus/screens/game_session.hpp
   trunk/pingus/src/pingus/server.cpp
Log:
Added a checksum to the demo file


Modified: trunk/pingus/src/pingus/pingus_demo.cpp
===================================================================
--- trunk/pingus/src/pingus/pingus_demo.cpp     2009-12-02 23:19:56 UTC (rev 
4097)
+++ trunk/pingus/src/pingus/pingus_demo.cpp     2009-12-03 04:56:36 UTC (rev 
4098)
@@ -21,9 +21,9 @@
 #include "util/pathname.hpp"
 
 PingusDemo::PingusDemo(const Pathname& pathname) :
-  levelname(),
-  checksum(),
-  events()
+  m_levelname(),
+  m_checksum(),
+  m_events()
 {
   std::vector<FileReader> lines = FileReader::parse_many(pathname);
 
@@ -35,17 +35,17 @@
   {
     if (lines.front().get_name() == "level")
     {
-      if (!lines.front().read_string("name", levelname))
+      if (!lines.front().read_string("name", m_levelname))
       {
         throw std::runtime_error("(level (name ...)) entry missing in demo 
file '" + pathname.str() + "'");
       }
 
-      lines.front().read_string("checksum", checksum);
+      lines.front().read_string("checksum", m_checksum);
     }
             
     for(std::vector<FileReader>::iterator i = lines.begin()+1; i != 
lines.end(); ++i)
     {
-      events.push_back(ServerEvent(*i));
+      m_events.push_back(ServerEvent(*i));
     }
   }
 }

Modified: trunk/pingus/src/pingus/pingus_demo.hpp
===================================================================
--- trunk/pingus/src/pingus/pingus_demo.hpp     2009-12-02 23:19:56 UTC (rev 
4097)
+++ trunk/pingus/src/pingus/pingus_demo.hpp     2009-12-03 04:56:36 UTC (rev 
4098)
@@ -24,18 +24,18 @@
 class PingusDemo
 {
 private:
-  std::string levelname;
-  std::string checksum;
+  std::string m_levelname;
+  std::string m_checksum;
+  std::vector<ServerEvent> m_events;
 
-  std::vector<ServerEvent> events;
-
 public:
   PingusDemo(const Pathname& pathname);
 
-  std::string get_levelname() const { return levelname; }
-  std::string get_checksum() const { return checksum; }
+  std::string get_levelname() const { return m_levelname; }
+  std::string get_checksum() const { return m_checksum; }
 
-  std::vector<ServerEvent> get_events() const { return events; }
+  std::vector<ServerEvent> get_events() const { return m_events; }
+
 private:
   PingusDemo (const PingusDemo&);
   PingusDemo& operator= (const PingusDemo&);

Modified: trunk/pingus/src/pingus/pingus_level.cpp
===================================================================
--- trunk/pingus/src/pingus/pingus_level.cpp    2009-12-02 23:19:56 UTC (rev 
4097)
+++ trunk/pingus/src/pingus/pingus_level.cpp    2009-12-03 04:56:36 UTC (rev 
4098)
@@ -22,29 +22,37 @@
 #include "pingus/globals.hpp"
 #include "pingus/pingus_level_impl.hpp"
 #include "util/pathname.hpp"
+#include "util/system.hpp"
 
-PingusLevel::PingusLevel()
-  : impl(new PingusLevelImpl())  
+PingusLevel::PingusLevel() :
+  impl(new PingusLevelImpl())  
 {
 }
 
-PingusLevel::PingusLevel(const Pathname& pathname)
-  : impl(new PingusLevelImpl())
+PingusLevel::PingusLevel(const Pathname& pathname) :
+  impl(new PingusLevelImpl())
 {
   load("", pathname);
 }
 
-PingusLevel::PingusLevel(const std::string& resname,
-                         const Pathname& pathname)
-  : impl(new PingusLevelImpl())
+PingusLevel::PingusLevel(const std::string& resname, const Pathname& pathname) 
:
+  impl(new PingusLevelImpl())
 {
   load(resname, pathname);
 }
 
+std::string
+PingusLevel::get_checksum() const
+{
+  return impl->checksum;
+}
+
 void
 PingusLevel::load(const std::string& resname,
                   const Pathname& pathname)
 {
+  impl->checksum = System::checksum(pathname);
+
   impl->resname = resname;
   FileReader reader = FileReader::parse(pathname);
 

Modified: trunk/pingus/src/pingus/pingus_level.hpp
===================================================================
--- trunk/pingus/src/pingus/pingus_level.hpp    2009-12-02 23:19:56 UTC (rev 
4097)
+++ trunk/pingus/src/pingus/pingus_level.hpp    2009-12-03 04:56:36 UTC (rev 
4098)
@@ -37,6 +37,9 @@
   PingusLevel(const std::string& resname,
               const Pathname& pathname);
 
+  /** Returns a short checksum for the level file */
+  std::string get_checksum() const;
+
   /** Returns the name of the current level, {\em not} the level file name. */
   const std::string& get_levelname() const;
 

Modified: trunk/pingus/src/pingus/pingus_level_impl.hpp
===================================================================
--- trunk/pingus/src/pingus/pingus_level_impl.hpp       2009-12-02 23:19:56 UTC 
(rev 4097)
+++ trunk/pingus/src/pingus/pingus_level_impl.hpp       2009-12-03 04:56:36 UTC 
(rev 4098)
@@ -45,6 +45,8 @@
                     
   std::string resname;
 
+  std::string checksum;
+
   std::string levelname;
   std::string description;
 

Modified: trunk/pingus/src/pingus/screens/demo_session.cpp
===================================================================
--- trunk/pingus/src/pingus/screens/demo_session.cpp    2009-12-02 23:19:56 UTC 
(rev 4097)
+++ trunk/pingus/src/pingus/screens/demo_session.cpp    2009-12-03 04:56:36 UTC 
(rev 4098)
@@ -42,11 +42,11 @@
 public:
   BButton(int x, int y, const std::string& name, 
           boost::function<void (void)> callback_,
-          boost::function<bool(void)> highlight_func_ = &false_func)
-    : SurfaceButton(x, y, name, name + "-pressed", name + "-hover"),
-      highlight("core/demo/highlight"),
-      callback(callback_),
-      highlight_func(highlight_func_)
+          boost::function<bool(void)> highlight_func_ = &false_func) :
+    SurfaceButton(x, y, name, name + "-pressed", name + "-hover"),
+    highlight("core/demo/highlight"),
+    callback(callback_),
+    highlight_func(highlight_func_)
   {}
 
   virtual void draw (DrawingContext& gc) 
@@ -90,10 +90,17 @@
   std::reverse(events.begin(), events.end());
 
   // Create server
-  server   = std::auto_ptr<Server>(new Server(PingusLevel(Pathname("levels/" + 
demo->get_levelname()  + ".pingus", 
-                                                                   
Pathname::DATA_PATH)), 
-                                              false));
+  PingusLevel plf(Pathname("levels/" + demo->get_levelname()  + ".pingus", 
Pathname::DATA_PATH));
 
+  if (plf.get_checksum() != demo->get_checksum())
+  {
+    std::cout << "Warning: checksum missmatch between demo (" 
+              << demo->get_checksum() << ") and level (" 
+              << plf.get_checksum() << ")" << std::endl;
+  }
+
+  server   = std::auto_ptr<Server>(new Server(plf, false));
+
   // Create GUI
   pcounter = new PingusCounter(server.get());
   gui_manager->add(pcounter);

Modified: trunk/pingus/src/pingus/screens/game_session.hpp
===================================================================
--- trunk/pingus/src/pingus/screens/game_session.hpp    2009-12-02 23:19:56 UTC 
(rev 4097)
+++ trunk/pingus/src/pingus/screens/game_session.hpp    2009-12-03 04:56:36 UTC 
(rev 4098)
@@ -110,10 +110,12 @@
   bool get_pause() const;
 
   void resize(const Size&);
+
 private:
   void process_scroll_event (const Input::ScrollEvent&);
   void process_axis_event (const Input::AxisEvent&);
 
+private:
   GameSession (const GameSession&);
   GameSession& operator= (const GameSession&);
 };

Modified: trunk/pingus/src/pingus/server.cpp
===================================================================
--- trunk/pingus/src/pingus/server.cpp  2009-12-02 23:19:56 UTC (rev 4097)
+++ trunk/pingus/src/pingus/server.cpp  2009-12-03 04:56:36 UTC (rev 4098)
@@ -36,16 +36,16 @@
   return std::string(buffer);
 }
 
-static std::auto_ptr<std::ostream> get_demostream(const std::string& levelname)
+static std::auto_ptr<std::ostream> get_demostream(const PingusLevel& plf)
 {
-  std::string flat_levelname = levelname;
+  std::string flat_levelname = plf.get_resname();
 
   // 'Flatten' the levelname so that we don't need directories
   for (std::string::iterator i = flat_levelname.begin(); i != 
flat_levelname.end(); ++i)
     if (*i == '/')
       *i = '_';
 
-  std::string filename = System::get_userdir() + "demos/" + get_date_string() 
+ "-" + flat_levelname + ".pingus-demo";
+  std::string filename = System::get_userdir() + "demos/" + flat_levelname + 
"-" + get_date_string() + ".pingus-demo";
 
   std::auto_ptr<std::ofstream> out(new std::ofstream(filename.c_str()));
   
@@ -60,7 +60,8 @@
     std::cout << "DemoRecorder: Writing demo to: " << filename << std::endl;
 
     // Write file header
-    *out << "(level (name \"" << levelname << "\"))\n";
+    *out << "(level (name \"" << plf.get_resname() << "\"))\n";
+    *out << "(checksum \"" << plf.get_checksum() << "\")\n";
     return std::auto_ptr<std::ostream>(out.release());
   }
 }
@@ -74,7 +75,7 @@
 {
   if (record_demo)
   {
-    demostream = get_demostream(plf.get_resname());
+    demostream = get_demostream(plf);
   }
 }
 





reply via email to

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