pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3607 - in trunk/pingus/src: . components


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3607 - in trunk/pingus/src: . components
Date: Tue, 1 Jul 2008 03:31:30 +0200

Author: grumbel
Date: 2008-07-01 03:31:23 +0200 (Tue, 01 Jul 2008)
New Revision: 3607

Modified:
   trunk/pingus/src/components/action_button.cpp
   trunk/pingus/src/components/action_button.hpp
   trunk/pingus/src/demo_session.cpp
   trunk/pingus/src/game_session.cpp
   trunk/pingus/src/game_session.hpp
   trunk/pingus/src/server.cpp
   trunk/pingus/src/server.hpp
Log:
Moved pause and fastforward from Server into GameSession

Modified: trunk/pingus/src/components/action_button.cpp
===================================================================
--- trunk/pingus/src/components/action_button.cpp       2008-06-30 23:48:44 UTC 
(rev 3606)
+++ trunk/pingus/src/components/action_button.cpp       2008-07-01 01:31:23 UTC 
(rev 3607)
@@ -22,6 +22,7 @@
 #include "../resource.hpp"
 #include "action_button.hpp"
 #include "../server.hpp"
+#include "../game_session.hpp"
 #include "../world.hpp"
 #include "../display/drawing_context.hpp"
 #include "../display/display.hpp"
@@ -229,9 +230,9 @@
   UNUSED_ARG(x);
   UNUSED_ARG(y);
 }
-
-ForwardButton::ForwardButton(Server* s, int x, int y)
-  : server (s),
+
+ForwardButton::ForwardButton(GameSession* s, int x, int y)
+  : session(s),
     x_pos (x), y_pos (y),
     background  (Resource::load_sprite("core/buttons/hbuttonbgb")),
     backgroundhl(Resource::load_sprite("core/buttons/hbuttonbg"))
@@ -244,7 +245,7 @@
 void
 ForwardButton::draw (DrawingContext& gc)
 {
-  if (server->get_fast_forward())
+  if (session->get_fast_forward())
     {
       gc.draw(backgroundhl, Vector2i(x_pos, y_pos));
     }
@@ -272,14 +273,14 @@
 void
 ForwardButton::on_primary_button_click (int x, int y)
 {
-  server->set_fast_forward(!server->get_fast_forward());
+  session->set_fast_forward(!session->get_fast_forward());
 
   UNUSED_ARG(x);
   UNUSED_ARG(y);
 }
-
-PauseButton::PauseButton(Server* s, int x, int y)
-  : server (s),
+
+PauseButton::PauseButton(GameSession* s, int x, int y)
+  : session(s),
     x_pos(x), y_pos(y),
     background  (Resource::load_sprite("core/buttons/hbuttonbgb")),
     backgroundhl(Resource::load_sprite("core/buttons/hbuttonbg"))
@@ -292,7 +293,7 @@
 void
 PauseButton::draw (DrawingContext& gc)
 {
-  if (server->get_pause())
+  if (session->get_pause())
     {
       gc.draw(backgroundhl, Vector2i(x_pos, y_pos));
     }
@@ -320,7 +321,7 @@
 void
 PauseButton::on_primary_button_click (int x, int y)
 {
-  server->set_pause(!server->get_pause());
+  session->set_pause(!session->get_pause());
 
   UNUSED_ARG(x);
   UNUSED_ARG(y);

Modified: trunk/pingus/src/components/action_button.hpp
===================================================================
--- trunk/pingus/src/components/action_button.hpp       2008-06-30 23:48:44 UTC 
(rev 3606)
+++ trunk/pingus/src/components/action_button.hpp       2008-07-01 01:31:23 UTC 
(rev 3607)
@@ -27,6 +27,7 @@
 #include "../gui/component.hpp"
 
 class Server;
+class GameSession;
 class ActionHolder;
 class Vector;
 
@@ -38,10 +39,10 @@
 {
 private:
   Server* server;
-  int   x_pos;
-  int   y_pos;
-  bool  pressed;
-  float press_time;
+  int    x_pos;
+  int    y_pos;
+  bool   pressed;
+  float  press_time;
   Sprite sprite;
   Sprite background;
   Sprite backgroundhl;
@@ -69,7 +70,7 @@
 class ForwardButton : public GUI::Component
 {
 private:
-  Server* server;
+  GameSession* session;
   int x_pos;
   int y_pos;
   Sprite surface;
@@ -77,7 +78,7 @@
   Sprite backgroundhl;
 
 public:
-  ForwardButton(Server*, int x, int y);
+  ForwardButton(GameSession*, int x, int y);
   virtual ~ForwardButton();
 
   void draw(DrawingContext& gc);
@@ -98,7 +99,7 @@
 class PauseButton : public GUI::Component
 {
 private:
-  Server* server;
+  GameSession* session;
   int x_pos;
   int y_pos;
   Sprite surface;
@@ -106,7 +107,7 @@
   Sprite backgroundhl;
 
 public:
-  PauseButton(Server*, int x, int y);
+  PauseButton(GameSession*, int x, int y);
   virtual ~PauseButton();
 
   void draw(DrawingContext& gc);

Modified: trunk/pingus/src/demo_session.cpp
===================================================================
--- trunk/pingus/src/demo_session.cpp   2008-06-30 23:48:44 UTC (rev 3606)
+++ trunk/pingus/src/demo_session.cpp   2008-07-01 01:31:23 UTC (rev 3607)
@@ -137,7 +137,7 @@
       event.send(server.get());
       events.pop_back();
     }
-
+  
   // Check for unexpected things (might happen if the demo file is broken)
   if (!events.empty() && events.back().time_stamp < server->get_time())
     {
@@ -160,7 +160,7 @@
 DemoSession::on_fast_forward_press()
 {
   std::cout << "Fast Forward Pressed: " << events.size() << " " << 
server->get_time() << std::endl;
-  server->set_fast_forward(!server->get_fast_forward());
+  //server->set_fast_forward(!server->get_fast_forward());
 }
 
 void

Modified: trunk/pingus/src/game_session.cpp
===================================================================
--- trunk/pingus/src/game_session.cpp   2008-06-30 23:48:44 UTC (rev 3606)
+++ trunk/pingus/src/game_session.cpp   2008-07-01 01:31:23 UTC (rev 3607)
@@ -48,7 +48,9 @@
     pcounter     (0),
     playfield    (0),
     time_display (0),
-    small_map    (0)
+    small_map    (0),
+    pause(false),
+    fast_forward(false)
 {
   server = std::auto_ptr<Server>(new Server(plf));
 
@@ -82,8 +84,8 @@
   gui_manager->add(time_display, true);
 
   gui_manager->add(new ArmageddonButton(get_server(), Display::get_width() - 
40,     Display::get_height() - 62), true);
-  gui_manager->add(new ForwardButton   (get_server(), Display::get_width() - 
40 * 2, Display::get_height() - 62), true);
-  gui_manager->add(new PauseButton     (get_server(), Display::get_width() - 
40 * 3, Display::get_height() - 62), true);
+  gui_manager->add(new ForwardButton   (this, Display::get_width() - 40 * 2, 
Display::get_height() - 62), true);
+  gui_manager->add(new PauseButton     (this, Display::get_width() - 40 * 3, 
Display::get_height() - 62), true);
 }
 
 GameSession::~GameSession ()
@@ -91,7 +93,7 @@
 }
 
 void
-GameSession::update_server(const GameDelta& delta)
+GameSession::update_server(float delta)
 {
   // FIXME: Timing code could need another rewrite...
   if (server->is_finished())
@@ -128,7 +130,7 @@
   else
     {
       // how much time we have to account for while doing world updates
-      int time_passed = int(delta.get_time() * 1000) + world_delay;
+      int time_passed = int(delta * 1000) + world_delay;
       // how much time each world update represents
       int update_time = game_speed;
 
@@ -142,7 +144,7 @@
              ++i)
           {
             // This updates the world and all objects
-            server->update ();
+            update_server();
           }
       }
 
@@ -154,7 +156,7 @@
       int world_updates = 0;
 
       while ((world_updates+1)*update_time <= time_passed) {
-        server->update ();
+        update_server();
         world_updates++;
       }
       // save how far behind is the world compared to the actual time
@@ -164,6 +166,23 @@
 }
 
 void
+GameSession::update_server()
+{
+  if (!pause)
+    {
+      if (fast_forward)
+        {
+          for (int i = 0; i < 4; ++i)
+            server->update();
+        }
+      else
+        {
+            server->update();
+        }
+    }
+}
+
+void
 GameSession::draw_background (DrawingContext& gc)
 {
   Rect rect = playfield->get_rect();
@@ -189,8 +208,7 @@
 void
 GameSession::update (const GameDelta& delta)
 {
-  update_server(delta);
-
+  update_server(delta.get_time());
   GUIScreen::update(delta);
   process_events(delta);
 }
@@ -296,13 +314,13 @@
 void
 GameSession:: on_pause_press ()
 {
-  server->set_pause (!server->get_pause ());
+  pause = !pause;
 }
 
 void
 GameSession::on_fast_forward_press ()
 {
-  server->set_fast_forward(!server->get_fast_forward());
+  fast_forward = !fast_forward;
 }
 
 void
@@ -352,5 +370,29 @@
 {
   return button_panel->get_action_name();
 }
+
+void
+GameSession::set_fast_forward(bool value)
+{
+  fast_forward = value;
+}
+
+bool
+GameSession::get_fast_forward() const
+{
+  return fast_forward;
+}
+
+void
+GameSession::set_pause(bool value)
+{
+  pause = value;
+}
+
+bool
+GameSession::get_pause() const
+{
+  return pause;
+}
 
 /* EOF */

Modified: trunk/pingus/src/game_session.hpp
===================================================================
--- trunk/pingus/src/game_session.hpp   2008-06-30 23:48:44 UTC (rev 3606)
+++ trunk/pingus/src/game_session.hpp   2008-07-01 01:31:23 UTC (rev 3607)
@@ -56,14 +56,17 @@
   Playfield*     playfield;
   TimeDisplay*   time_display;
   SmallMap*      small_map;
-  bool enabled;
 
+  bool pause;
+  bool fast_forward;
+
 public:
   GameSession(const PingusLevel& arg_plf, bool arg_show_result_screen);
   ~GameSession ();
 
   /** Pass a delta to the screen */
-  void update_server(const GameDelta& delta);
+  void update_server(float delta);
+  void update_server();
 
   // -- Client stuff
 
@@ -92,6 +95,12 @@
 
   Actions::ActionName get_action_name() const;
 
+  void set_fast_forward(bool value);
+  bool get_fast_forward() const;
+
+  void set_pause(bool value);
+  bool get_pause() const;
+
 private:
   void process_events (const GameDelta& events);
   void process_scroll_event (const Input::ScrollEvent&);

Modified: trunk/pingus/src/server.cpp
===================================================================
--- trunk/pingus/src/server.cpp 2008-06-30 23:48:44 UTC (rev 3606)
+++ trunk/pingus/src/server.cpp 2008-07-01 01:31:23 UTC (rev 3607)
@@ -45,9 +45,7 @@
   : plf(arg_plf),
     world(new World (plf)),
     action_holder (plf),
-    goal_manager(new GoalManager(this)),
-    fast_forward(false),
-    pause(false)
+    goal_manager(new GoalManager(this))
 {
 }
 
@@ -64,24 +62,8 @@
 void
 Server::update()
 {
-  if (fast_forward && !pause)
-    {
-      // To let the game run faster we just update it multiple
-      // times
-      for (int i = 0; i < 4; ++i)
-       {
-          world->update();
-          goal_manager->update();
-       }
-    }
-  else
-    {
-      if (!pause)
-        {
-          world->update();
-          goal_manager->update();
-        }
-    }
+  world->update();
+  goal_manager->update();
 }
 
 void
@@ -131,36 +113,10 @@
 }
 
 void
-Server::set_fast_forward(bool value)
-{
-  fast_forward = value;
-}
-
-bool
-Server::get_fast_forward()
-{
-  return fast_forward;
-}
-
-void
-Server::set_pause(bool value)
-{
-  pause = value;
-}
-
-bool
-Server::get_pause()
-{
-  return pause;
-}
-
-void
 Server::send_finish_event()
 {
   record(ServerEvent::make_finish_event(get_time()));
-
   goal_manager->set_abort_goal();
-  set_pause(false);
 }
 
 #if 0

Modified: trunk/pingus/src/server.hpp
===================================================================
--- trunk/pingus/src/server.hpp 2008-06-30 23:48:44 UTC (rev 3606)
+++ trunk/pingus/src/server.hpp 2008-07-01 01:31:23 UTC (rev 3607)
@@ -42,9 +42,6 @@
 
   std::auto_ptr<GoalManager>  goal_manager;
 
-  bool fast_forward;
-  bool pause; 
-
 public:
   Server(const PingusLevel& arg_plf);
   ~Server();
@@ -68,12 +65,6 @@
   void send_armageddon_event();
   void send_pingu_action_event(Pingu* pingu, Actions::ActionName action);
 
-  void set_fast_forward(bool value);
-  bool get_fast_forward();
-
-  void set_pause(bool);
-  bool get_pause();
-
 private:
   void record(const ServerEvent& event);
 





reply via email to

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