pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3592 - trunk/pingus/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3592 - trunk/pingus/src
Date: Mon, 30 Jun 2008 05:13:34 +0200

Author: grumbel
Date: 2008-06-30 05:13:32 +0200 (Mon, 30 Jun 2008)
New Revision: 3592

Removed:
   trunk/pingus/src/demo_recorder.cpp
   trunk/pingus/src/demo_recorder.hpp
Modified:
   trunk/pingus/src/client.cpp
   trunk/pingus/src/pathname.hpp
   trunk/pingus/src/server.cpp
   trunk/pingus/src/server.hpp
   trunk/pingus/src/server_event.cpp
   trunk/pingus/src/server_event.hpp
Log:
Removed DemoRecorder, moved some code over to Server

Modified: trunk/pingus/src/client.cpp
===================================================================
--- trunk/pingus/src/client.cpp 2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/client.cpp 2008-06-30 03:13:32 UTC (rev 3592)
@@ -193,7 +193,7 @@
 Client::do_restart()
 {
   do_replay = true;
-  server->set_finished();
+  server->send_finish_event();
 }
 
 bool
@@ -206,13 +206,13 @@
 Client::set_finished()
 {
   is_finished = true;
-  server->set_finished();
+  server->send_finish_event();
 }
 
 void
 Client:: on_escape_press ()
 {
-  server->set_finished();
+  server->send_finish_event();
 }
 
 void

Deleted: trunk/pingus/src/demo_recorder.cpp
===================================================================
--- trunk/pingus/src/demo_recorder.cpp  2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/demo_recorder.cpp  2008-06-30 03:13:32 UTC (rev 3592)
@@ -1,107 +0,0 @@
-//  $Id$
-//
-//  Pingus - A free Lemmings clone
-//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#include <time.h>
-#include <assert.h>
-#include <iostream>
-#include "system.hpp"
-#include "demo_recorder.hpp"
-#include "server.hpp"
-#include "gettext.h"
-
-
-DemoRecorder::DemoRecorder (Server* server)
-  : record_demo (true)
-{
-  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() + ".xml";
-      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;
-      // This point should only be reachable if we have a bug
-      // somewhere or provide a way to get a PLF without using XMLPLF,
-      // since we don't do that, a bug must be somewhere when we reach
-      // this.
-      assert(!"ERROR: DemoRecorder: Couldn't get levelname, please report this 
as a bug!");
-    }
-}
-
-DemoRecorder::~DemoRecorder ()
-{
-  if (record_demo)
-    {
-      // Write file footer - close events and pingus-demo
-      out << "  )\n"
-          << ")" << std::endl;
-      out.close();
-    }
-}
-
-void
-DemoRecorder::record_event (const ServerEvent& event)
-{
-  if (record_demo)
-    {
-      event.write(out);
-    }
-}
-
-std::string
-DemoRecorder::get_date ()
-{
-  char buffer[32];
-  time_t curtime;
-  struct tm *loctime;
-  curtime = time (NULL);
-  loctime = localtime(&curtime);
-  strftime(buffer, 32, "%Y%m%d-%H%M%S", loctime);
-
-  return std::string(buffer);
-}
-
-
-/* EOF */

Deleted: trunk/pingus/src/demo_recorder.hpp
===================================================================
--- trunk/pingus/src/demo_recorder.hpp  2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/demo_recorder.hpp  2008-06-30 03:13:32 UTC (rev 3592)
@@ -1,59 +0,0 @@
-//  $Id$
-//
-//  Pingus - A free Lemmings clone
-//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#ifndef HEADER_PINGUS_DEMO_RECORDER_HPP
-#define HEADER_PINGUS_DEMO_RECORDER_HPP
-
-#include "pingus.hpp"
-#include <fstream>
-#include <string>
-
-
-class Server;
-class ServerEvent;
-
-class DemoRecorder
-{
-private:
-  /** Set to true to record a demo, set to false to ignore
-      record_event() messages */
-  bool record_demo;
-
-  /** Stream to which the events are written */
-  std::ofstream out;
-
-  /** Filename to which the events are written */
-  std::string   filename;
-
-  std::string get_date();
-public:
-  DemoRecorder(Server* server);
-  ~DemoRecorder();
-
-  void record_event (const ServerEvent& event);
-
-private:
-  DemoRecorder (const DemoRecorder&);
-  DemoRecorder& operator= (const DemoRecorder&);
-};
-
-
-#endif
-
-/* EOF */

Modified: trunk/pingus/src/pathname.hpp
===================================================================
--- trunk/pingus/src/pathname.hpp       2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/pathname.hpp       2008-06-30 03:13:32 UTC (rev 3592)
@@ -26,7 +26,7 @@
 #include <string>
 #include "SDL.h"
 
-/** Simple class to allow a distinction of paths that rever to the
+/** Simple class to allow a distinction of paths that refer to the
  *  filesystem and paths that refer to the datadir, it also hides
  *  path_manager from the rest of the code. */
 class Pathname

Modified: trunk/pingus/src/server.cpp
===================================================================
--- trunk/pingus/src/server.cpp 2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/server.cpp 2008-06-30 03:13:32 UTC (rev 3592)
@@ -17,42 +17,48 @@
 //  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 "pingu.hpp"
 #include "globals.hpp"
 #include "server.hpp"
 #include "game_time.hpp"
 #include "world.hpp"
-#include "demo_recorder.hpp"
 #include "goal_manager.hpp"
 
-
 using Actions::action_from_string;
+
+#if 0
+static std::string get_date_string ()
+{
+  char buffer[32];
+  time_t curtime;
+  struct tm *loctime;
+  curtime = time (NULL);
+  loctime = localtime(&curtime);
+  strftime(buffer, 32, "%Y%m%d-%H%M%S", loctime);
 
+  return std::string(buffer);
+}
+#endif
+
 Server::Server(const PingusLevel& arg_plf)
   : plf(arg_plf),
     world(new World (plf)),
     action_holder (plf),
     goal_manager(new GoalManager(this)),
-    demo_recorder(0),
     fast_forward(false),
     pause(false)
 {
-  if (enable_demo_recording)
-    demo_recorder = new DemoRecorder(this);
 }
 
 Server::~Server ()
 {
-  // Demo Server is exited and writes down its log
-  delete goal_manager;
-  delete demo_recorder;
-  delete world;
 }
 
 World*
 Server::get_world()
 {
-  return world;
+  return world.get();
 }
 
 void
@@ -81,15 +87,16 @@
 void
 Server::send_armageddon_event ()
 {
+  record(ServerEvent::make_armageddon_event(get_time()));
+
   world->armageddon();
-
-  if (demo_recorder)
-    
demo_recorder->record_event(ServerEvent::make_armageddon_event(get_time()));
 }
 
 void
 Server::send_pingu_action_event (Pingu* pingu, Actions::ActionName action)
 {
+  record(ServerEvent::make_pingu_action_event(get_time(), pingu->get_id(), 
action));
+
   if (action_holder.pop_action(action))
     {
       if (!(pingu->request_set_action(action)))
@@ -97,11 +104,12 @@
          action_holder.push_action(action);
        }
     }
+}
 
-  if (demo_recorder)
-    
demo_recorder->record_event(ServerEvent::make_pingu_action_event(get_time(),
-                                                                     
pingu->get_id(),
-                                                                     action));
+void
+Server::record(const ServerEvent& event)
+{
+  event.write(std::cout);  
 }
 
 bool
@@ -147,10 +155,60 @@
 }
 
 void
-Server::set_finished ()
+Server::send_finish_event()
 {
+  record(ServerEvent::make_finish_event(get_time()));
+
   goal_manager->set_abort_goal();
   set_pause(false);
 }
 
+#if 0
+
+DemoRecorder::DemoRecorder (Server* server)
+  : record_demo (true)
+{
+  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() + ".xml";
+      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;
+      // This point should only be reachable if we have a bug
+      // somewhere or provide a way to get a PLF without using XMLPLF,
+      // since we don't do that, a bug must be somewhere when we reach
+      // this.
+      assert(!"ERROR: DemoRecorder: Couldn't get levelname, please report this 
as a bug!");
+    }
+}
+
+#endif
+
 /* EOF */

Modified: trunk/pingus/src/server.hpp
===================================================================
--- trunk/pingus/src/server.hpp 2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/server.hpp 2008-06-30 03:13:32 UTC (rev 3592)
@@ -23,8 +23,8 @@
 #include "server_event.hpp"
 #include "action_holder.hpp"
 #include "pingus_level.hpp"
+#include <memory>
 
-
 class Pingu;
 class World;
 class DemoRecorder;
@@ -35,17 +35,15 @@
 {
 protected:
   PingusLevel plf;
-  World* world;
+  std::auto_ptr<World> world;
 
   /** Manager class for the number of available actions */
   ActionHolder action_holder;
 
-  GoalManager* goal_manager;
+  std::auto_ptr<GoalManager>  goal_manager;
 
-  DemoRecorder* demo_recorder;
-
   bool fast_forward;
-  bool pause;
+  bool pause; 
 
 public:
   Server(const PingusLevel& arg_plf);
@@ -66,9 +64,7 @@
 
   /** set the server into the finshed state, this is used when you
       press ESCAPE inside a game */
-  void set_finished();
-
-  /* Event handling stuff */
+  void send_finish_event();
   void send_armageddon_event();
   void send_pingu_action_event(Pingu* pingu, Actions::ActionName action);
 
@@ -79,6 +75,8 @@
   bool get_pause();
 
 private:
+  void record(const ServerEvent& event);
+
   Server (const Server&);
   Server& operator= (const Server&);
 };

Modified: trunk/pingus/src/server_event.cpp
===================================================================
--- trunk/pingus/src/server_event.cpp   2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/server_event.cpp   2008-06-30 03:13:32 UTC (rev 3592)
@@ -24,7 +24,7 @@
 #include "world.hpp"
 #include "pingu_holder.hpp"
 #include "string_util.hpp"
-
+
 ServerEvent::ServerEvent() :
        type(PINGU_ACTION_EVENT),
        time_stamp(0),
@@ -62,6 +62,11 @@
     case ARMAGEDDON_EVENT:
       out << "  (armageddon (time " << time_stamp << "))" << std::endl;
       break;
+
+    case FINISH_EVENT:
+      out << "  (finish (time " << time_stamp << "))" << std::endl;
+      break;
+
     case PINGU_ACTION_EVENT:
       out << "  (pingu-action "
           << "(time " << time_stamp << ") "
@@ -69,12 +74,22 @@
           << "(action \"" << Actions::action_to_string(pingu_action) << "\"))"
           << std::endl;
       break;
-    default:
+
+      default:
       assert(!"Unknown type");
     }
 }
 
 ServerEvent
+ServerEvent::make_finish_event(int t)
+{
+  ServerEvent event;
+  event.type       = FINISH_EVENT;
+  event.time_stamp = t;
+  return event; 
+}
+
+ServerEvent
 ServerEvent::make_armageddon_event(int t)
 {
   ServerEvent event;
@@ -102,6 +117,11 @@
     case ARMAGEDDON_EVENT:
       server->send_armageddon_event();
       break;
+
+    case FINISH_EVENT:
+      server->send_finish_event();      
+      break;
+
     case PINGU_ACTION_EVENT:
       {
        Pingu* pingu = server->get_world()->get_pingus()->get_pingu(pingu_id);
@@ -116,10 +136,10 @@
          }
       }
       break;
+
     default:
       assert(!"Unknown type");
     }
 }
-
-
+
 /* EOF */

Modified: trunk/pingus/src/server_event.hpp
===================================================================
--- trunk/pingus/src/server_event.hpp   2008-06-30 02:52:58 UTC (rev 3591)
+++ trunk/pingus/src/server_event.hpp   2008-06-30 03:13:32 UTC (rev 3592)
@@ -30,11 +30,12 @@
 /** This class represents an event that the Server can recieve from
     the client. Only actions and armageddon are here, the rest happens
     Client internal and the server knows nothing about it (scrolling,
-    pause, fastforward, etc.) FIXME: this is only half true... */
+    etc.) FIXME: this is only half true... */
 class ServerEvent
 {
 public:
   enum Type { ARMAGEDDON_EVENT,
+              FINISH_EVENT,
              PINGU_ACTION_EVENT };
 
   /** The type of event */
@@ -62,6 +63,7 @@
   void send(Server*);
 
   // Pseudo constructors
+  static ServerEvent make_finish_event(int time);
   static ServerEvent make_armageddon_event(int time);
   static ServerEvent make_pingu_action_event(int t, int id, 
Actions::ActionName action);
 };





reply via email to

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