pingus-cvs
[Top][All Lists]
Advanced

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

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


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

Author: grumbel
Date: 2008-07-01 03:43:36 +0200 (Tue, 01 Jul 2008)
New Revision: 3608

Modified:
   trunk/pingus/src/components/smallmap.cpp
   trunk/pingus/src/components/smallmap.hpp
   trunk/pingus/src/demo_session.cpp
   trunk/pingus/src/demo_session.hpp
   trunk/pingus/src/game_session.cpp
Log:
Moved fastforward and pause from Server to the GameSession/DemoSession, added 
SmallMap to demo playback

Modified: trunk/pingus/src/components/smallmap.cpp
===================================================================
--- trunk/pingus/src/components/smallmap.cpp    2008-07-01 01:31:23 UTC (rev 
3607)
+++ trunk/pingus/src/components/smallmap.cpp    2008-07-01 01:43:36 UTC (rev 
3608)
@@ -33,8 +33,9 @@
 #include "playfield.hpp"
 #include "smallmap.hpp"
 
-SmallMap::SmallMap(GameSession* session_)
-  : session(session_),
+SmallMap::SmallMap(Server* server_, Playfield* playfield_)
+  : server(server_),
+    playfield(playfield_),
     gc_ptr(0)
 {
   int max_width = 175;
@@ -43,7 +44,7 @@
   int min_height = 70;
   int min_width = 100;
 
-  World* world = session->get_server()->get_world();
+  World* world = server->get_world();
 
   // Scaling values used in order to keep the aspect ratio
   int x_scaling = world->get_width()  / max_width;
@@ -65,7 +66,7 @@
   x_pos   = 5;
   y_pos   = Display::get_height() - height - 5;
 
-  image = new SmallMapImage(session->get_server(), width, height);
+  image = new SmallMapImage(server, width, height);
 
   scroll_mode = false;
 }
@@ -82,8 +83,7 @@
   // long 'gc' will be alive. Should use a DrawingContext for caching.
   gc_ptr = &gc;
 
-  World* const& world  = session->get_server()->get_world();
-  Playfield* playfield = session->get_playfield();
+  World* const& world  = server->get_world();
   
   Vector2i of = playfield->get_pos();
   Rect rect;
@@ -116,7 +116,7 @@
   gc.draw_rect(rect.left, rect.top, rect.right, rect.bottom,
                Color(0, 255, 0));
 
-  session->get_server()->get_world()->draw_smallmap(this);
+  server->get_world()->draw_smallmap(this);
 
   // Draw Pingus
   PinguHolder* pingus = world->get_pingus();
@@ -140,7 +140,7 @@
 void
 SmallMap::draw_sprite(Sprite sprite, Vector3f pos)
 {
-  World* world = session->get_server()->get_world();
+  World* world = server->get_world();
   float x = x_pos + (pos.x * width  / world->get_width());
   float y = y_pos + (pos.y * height / world->get_height());
 
@@ -158,14 +158,14 @@
 SmallMap::on_pointer_move (int x, int y)
 {
   int cx, cy;
-  World* world = session->get_server()->get_world();
+  World* world = server->get_world();
 
   if (scroll_mode)
     {
       cx = (x - x_pos) * static_cast<int>(world->get_width()  / width);
       cy = (y - y_pos) * static_cast<int>(world->get_height() / height);
 
-      session->get_playfield()->set_viewpoint(cx, cy);
+      playfield->set_viewpoint(cx, cy);
     }
 }
 
@@ -176,10 +176,10 @@
 
   // set view to the given COs
   int cx, cy;
-  World* world = session->get_server()->get_world();
+  World* world = server->get_world();
   cx = (x - x_pos) * int(world->get_width()) / width;
   cy = (y - y_pos) * int(world->get_height()) / height ;
-  session->get_playfield()->set_viewpoint(cx, cy);
+  playfield->set_viewpoint(cx, cy);
 }
 
 void

Modified: trunk/pingus/src/components/smallmap.hpp
===================================================================
--- trunk/pingus/src/components/smallmap.hpp    2008-07-01 01:31:23 UTC (rev 
3607)
+++ trunk/pingus/src/components/smallmap.hpp    2008-07-01 01:43:36 UTC (rev 
3608)
@@ -23,7 +23,8 @@
 #include "../sprite.hpp"
 #include "../gui/component.hpp"
 
-class GameSession;
+class Playfield;
+class Server;
 class Vector3f;
 class SmallMapImage;
 
@@ -31,7 +32,8 @@
 class SmallMap : public GUI::Component
 {
 private:
-  GameSession* session;
+  Server*    server;
+  Playfield* playfield;
 
   /** Graphic surface of the exit */
   Sprite exit_sur;
@@ -63,7 +65,7 @@
   DrawingContext* gc_ptr;
 
 public:
-  SmallMap(GameSession* c);
+  SmallMap(Server*, Playfield*);
   virtual ~SmallMap();
 
   /*{ @name Stuff called from the GUIManager */
@@ -75,8 +77,6 @@
   void on_pointer_enter ();
   void on_pointer_leave ();
 
-  void set_session(GameSession* c);
-
   bool is_at (int x, int y);
   bool mouse_over();
 

Modified: trunk/pingus/src/demo_session.cpp
===================================================================
--- trunk/pingus/src/demo_session.cpp   2008-07-01 01:31:23 UTC (rev 3607)
+++ trunk/pingus/src/demo_session.cpp   2008-07-01 01:43:36 UTC (rev 3608)
@@ -27,11 +27,14 @@
 #include "display/scene_context.hpp"
 #include "pingus_demo.hpp"
 #include "components/playfield.hpp"
+#include "components/smallmap.hpp"
 #include "screen/screen_manager.hpp"
 #include "display/display.hpp"
 #include "demo_session.hpp"
 
 DemoSession::DemoSession(const Pathname& pathname)
+  : pause(false),
+    fast_forward(false)
 {
   // Load Demo file
   demo = std::auto_ptr<PingusDemo>(new PingusDemo(pathname));
@@ -57,59 +60,15 @@
                                       Math::min(Display::get_height(), 
world_height))));
 
   gui_manager->add(playfield, true);
+
+  small_map    = new SmallMap(server.get(), playfield);
+  gui_manager->add(small_map, true);
 }
 
 DemoSession::~DemoSession()
 {
 }
 
-/** Draw this screen */
-void
-DemoSession::draw_background(DrawingContext& gc)
-{
-#if 0
-  World* world = server->get_world();
-  
-  SceneContext* sc = new SceneContext();
-
-
-  if (CL_Keyboard::get_keycode(CL_KEY_LEFT))
-    sc->translate(10.0, 0.0);
-
-  if(CL_Keyboard::get_keycode(CL_KEY_RIGHT))
-    sc->translate(-10.0, 0.0);
-
-  if(CL_Keyboard::get_keycode(CL_KEY_UP))
-    sc->translate(0.0, 10.0);
-
-  if(CL_Keyboard::get_keycode(CL_KEY_DOWN))
-    sc->translate(0.0, -10.0);
-#endif 
-
-#if 0 // FIXME
-  float x_of = -sc->get_x_offset();
-  float y_of = -sc->get_y_offset();
-
-  x_of = Math::mid(sc->get_width()/2.0f,
-                   x_of,
-                   world->get_width() - 1 - sc->get_width()/2.0f);
-
-  y_of = Math::mid(sc->get_height()/2.0f,
-                   y_of,
-                   world->get_height() - 1 - sc->get_height()/2.0f);
-
-  sc->set_offset(-x_of, -y_of);
-
-
-  world->draw(*sc);
-  while (CL_Keyboard::get_keycode(CL_KEY_D))
-    {
-      world->draw(*sc);
-      CL_System::keep_alive();
-    }
-#endif
-}
-
 /** Pass a delta to the screen */
 void
 DemoSession::update(float delta)
@@ -117,8 +76,23 @@
   UNUSED_ARG(delta);
 
   // FIXME: Duplicate all timing code here?!
-  server->update();
-  update_demo();
+
+  if (!pause)
+    {
+      if (fast_forward)
+        {
+          for (int i = 0; i < 4; ++i)
+            {
+              server->update();
+              update_demo();
+            }
+        }
+      else
+        {
+          server->update();
+          update_demo();
+        }
+    }
 }
 
 void
@@ -148,19 +122,26 @@
 void
 DemoSession::on_pause_press()
 {
-  std::cout << "Pause Pressed" << std::endl;
-  for(std::vector<ServerEvent>::iterator i = events.begin(); i != 
events.end(); ++i)
+  if (0)
     {
-      std::cout << "Event: ";
-      i->write(std::cout);      
+      for(std::vector<ServerEvent>::iterator i = events.begin(); i != 
events.end(); ++i)
+        {
+          std::cout << "Event: ";
+          i->write(std::cout);      
+        }
     }
+
+  pause = !pause;
+
 }
 
 void
 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());
+  if (0)
+    std::cout << "Fast Forward Pressed: " << events.size() << " " << 
server->get_time() << std::endl;
+
+  fast_forward = !fast_forward;
 }
 
 void

Modified: trunk/pingus/src/demo_session.hpp
===================================================================
--- trunk/pingus/src/demo_session.hpp   2008-07-01 01:31:23 UTC (rev 3607)
+++ trunk/pingus/src/demo_session.hpp   2008-07-01 01:43:36 UTC (rev 3608)
@@ -31,6 +31,7 @@
 class PingusCounter;
 class PingusDemo;
 class Playfield;
+class SmallMap;
 
 /** A DemoSession is analog to a GameSession, but instead of loading a
     level and letting the player play a game, a demo file will be
@@ -44,15 +45,16 @@
 
   PingusCounter* pcounter;
   Playfield*     playfield;
+  SmallMap*      small_map;
+  
+  bool pause;
+  bool fast_forward;
 
 public:
   /** @param filename the complete filename of the demo file */
   DemoSession(const Pathname& pathname);
   ~DemoSession();
 
-  /** Draw this screen */
-  void draw_background(DrawingContext& gc);
-
   /** Pass a delta to the screen */
   void update(float delta);
   void update_demo();

Modified: trunk/pingus/src/game_session.cpp
===================================================================
--- trunk/pingus/src/game_session.cpp   2008-07-01 01:31:23 UTC (rev 3607)
+++ trunk/pingus/src/game_session.cpp   2008-07-01 01:43:36 UTC (rev 3608)
@@ -74,7 +74,7 @@
                                          Math::min(Display::get_height(), 
world_height))));
 
   pcounter     = new PingusCounter(get_server());
-  small_map    = new SmallMap(this);
+  small_map    = new SmallMap(get_server(), playfield);
   time_display = new TimeDisplay(this);
 
   gui_manager->add(playfield,    true);





reply via email to

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