pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3615 - in trunk/pingus: data/demos src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3615 - in trunk/pingus: data/demos src
Date: Tue, 1 Jul 2008 19:14:41 +0200

Author: grumbel
Date: 2008-07-01 19:14:39 +0200 (Tue, 01 Jul 2008)
New Revision: 3615

Modified:
   trunk/pingus/data/demos/test.pingus-demo
   trunk/pingus/src/demo_session.cpp
   trunk/pingus/src/game_session.cpp
   trunk/pingus/src/server.cpp
   trunk/pingus/src/server.hpp
Log:
Demos are now automatically saved

Modified: trunk/pingus/data/demos/test.pingus-demo
===================================================================
--- trunk/pingus/data/demos/test.pingus-demo    2008-07-01 14:12:46 UTC (rev 
3614)
+++ trunk/pingus/data/demos/test.pingus-demo    2008-07-01 17:14:39 UTC (rev 
3615)
@@ -1,4 +1,4 @@
-(level (name "levels/tutorial/snow20-grumbel.pingus"))
+(level (name "tutorial/snow20-grumbel"))
 (pingu-action (time 679) (id 0) (action "basher"))
 (pingu-action (time 1053) (id 0) (action "blocker"))
 (pingu-action (time 2089) (id 1) (action "blocker"))

Modified: trunk/pingus/src/demo_session.cpp
===================================================================
--- trunk/pingus/src/demo_session.cpp   2008-07-01 14:12:46 UTC (rev 3614)
+++ trunk/pingus/src/demo_session.cpp   2008-07-01 17:14:39 UTC (rev 3615)
@@ -43,7 +43,8 @@
   std::reverse(events.begin(), events.end());
 
   // Create server
-  server   = std::auto_ptr<Server>(new 
Server(PingusLevel(Pathname(demo->get_levelname(), Pathname::DATA_PATH))));
+  server   = std::auto_ptr<Server>(new Server(PingusLevel(Pathname("levels/" + 
demo->get_levelname()  + ".pingus", 
+                                                                   
Pathname::DATA_PATH)), false));
 
   // Create GUI
   pcounter = new PingusCounter(server.get());

Modified: trunk/pingus/src/game_session.cpp
===================================================================
--- trunk/pingus/src/game_session.cpp   2008-07-01 14:12:46 UTC (rev 3614)
+++ trunk/pingus/src/game_session.cpp   2008-07-01 17:14:39 UTC (rev 3615)
@@ -52,7 +52,7 @@
     pause(false),
     fast_forward(false)
 {
-  server = std::auto_ptr<Server>(new Server(plf));
+  server = std::auto_ptr<Server>(new Server(plf, true));
 
   // the world is initially on time
   world_delay = 0;

Modified: trunk/pingus/src/server.cpp
===================================================================
--- trunk/pingus/src/server.cpp 2008-07-01 14:12:46 UTC (rev 3614)
+++ trunk/pingus/src/server.cpp 2008-07-01 17:14:39 UTC (rev 3615)
@@ -18,6 +18,8 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <iostream>
+#include <fstream>
+#include "system.hpp"
 #include "pingu.hpp"
 #include "globals.hpp"
 #include "server.hpp"
@@ -27,7 +29,6 @@
 
 using Actions::action_from_string;
 
-#if 0
 static std::string get_date_string ()
 {
   char buffer[32];
@@ -39,14 +40,47 @@
 
   return std::string(buffer);
 }
-#endif
 
-Server::Server(const PingusLevel& arg_plf)
+static std::auto_ptr<std::ostream> get_demostream(const std::string& levelname)
+{
+  std::string flat_levelname = levelname;
+
+  // '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::auto_ptr<std::ofstream> out(new std::ofstream(filename.c_str()));
+  
+  if (!(*out.get()))
+    {
+      std::cout << "DemoRecorder: Error: Couldn't write DemoFile '" << filename
+                << "', demo recording will be disabled" << std::endl;
+      return std::auto_ptr<std::ostream>();
+    }
+  else
+    {
+      std::cout << "DemoRecorder: Writing demo to: " << filename << std::endl;
+
+      // Write file header
+      *out << "(level (name \"" << levelname << "\"))\n";
+      return std::auto_ptr<std::ostream>(out.release());
+    }
+}
+
+Server::Server(const PingusLevel& arg_plf,
+               bool record_demo)
   : plf(arg_plf),
     world(new World (plf)),
     action_holder (plf),
     goal_manager(new GoalManager(this))
 {
+  if (record_demo)
+    {
+      demostream = get_demostream(plf.get_resname());
+    }
 }
 
 Server::~Server ()
@@ -91,7 +125,8 @@
 void
 Server::record(const ServerEvent& event)
 {
-  event.write(std::cout);  
+  if (demostream.get())
+  event.write(*demostream);
 }
 
 bool
@@ -118,44 +153,5 @@
   record(ServerEvent::make_finish_event(get_time()));
   goal_manager->set_abort_goal();
 }
-
-#if 0
-  std::string levelname = server->get_plf().get_resname();
-  std::string flat_levelname = levelname;
-
-  // '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 = '_';
-
-  if (!levelname.empty())
-    {
-      std::string filename = System::get_userdir() + "demos/" + flat_levelname 
+ "-" + get_date_string() + ".pingus-demo";
-      out.open(filename.c_str());
-
-      if (!out)
-       {
-          record_demo = false;
-         std::cout << "DemoRecorder: Error: Couldn't write DemoFile '" << 
filename
-                    << "', demo recording will be disabled" << std::endl;
-       }
-      else
-        {
-          std::cout << "DemoRecorder: Writing demo to: " << filename << 
std::endl;
-          record_demo = true;
-
-          // Write file header
-          out << "(pingus-demo\n"
-              << "  (level " << levelname << ")\n"
-              << "  (events " << std::endl;
-        }
-    }
-  else
-    {
-      record_demo = false;
-
-    }
-#endif
 
-
 /* EOF */

Modified: trunk/pingus/src/server.hpp
===================================================================
--- trunk/pingus/src/server.hpp 2008-07-01 14:12:46 UTC (rev 3614)
+++ trunk/pingus/src/server.hpp 2008-07-01 17:14:39 UTC (rev 3615)
@@ -41,9 +41,10 @@
   ActionHolder action_holder;
 
   std::auto_ptr<GoalManager>  goal_manager;
+  std::auto_ptr<std::ostream> demostream;
 
 public:
-  Server(const PingusLevel& arg_plf);
+  Server(const PingusLevel& arg_plf, bool record_demo);
   ~Server();
 
   void update();





reply via email to

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