pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3598 - in trunk/pingus: . src src/components
Date: Mon, 30 Jun 2008 21:41:28 +0200

Author: grumbel
Date: 2008-06-30 21:41:27 +0200 (Mon, 30 Jun 2008)
New Revision: 3598

Modified:
   trunk/pingus/SConstruct
   trunk/pingus/src/capture_rectangle.cpp
   trunk/pingus/src/capture_rectangle.hpp
   trunk/pingus/src/client.cpp
   trunk/pingus/src/client.hpp
   trunk/pingus/src/components/playfield.cpp
   trunk/pingus/src/components/playfield.hpp
   trunk/pingus/src/components/smallmap.cpp
   trunk/pingus/src/demo_session.cpp
   trunk/pingus/src/demo_session.hpp
Log:
Cleaned up some relationships between ButtonPanel and Playfield, also cleaned 
up DemoSession

Modified: trunk/pingus/SConstruct
===================================================================
--- trunk/pingus/SConstruct     2008-06-30 18:52:17 UTC (rev 3597)
+++ trunk/pingus/SConstruct     2008-06-30 19:41:27 UTC (rev 3598)
@@ -77,8 +77,7 @@
 'src/credits.cpp', 
 'src/debug.cpp', 
 'src/debug_stream.cpp', 
-# 'demo_player.cpp', 
-# 'demo_session.cpp', 
+'src/demo_session.cpp', 
 'src/direction.cpp', 
 'src/display/drawing_context.cpp', 
 'src/display/scene_context.cpp', 

Modified: trunk/pingus/src/capture_rectangle.cpp
===================================================================
--- trunk/pingus/src/capture_rectangle.cpp      2008-06-30 18:52:17 UTC (rev 
3597)
+++ trunk/pingus/src/capture_rectangle.cpp      2008-06-30 19:41:27 UTC (rev 
3598)
@@ -23,24 +23,25 @@
 #include "resource.hpp"
 #include "capture_rectangle.hpp"
 #include "pingu_action.hpp"
-#include "components/button_panel.hpp"
+#include "client.hpp"
 #include "globals.hpp"
+#include "server.hpp"
 #include "display/scene_context.hpp"
 #include "fonts.hpp"
-
-CaptureRectangle::CaptureRectangle (ButtonPanel* arg_button_panel)
-  : pingu(0),
+
+CaptureRectangle::CaptureRectangle(Client* client_)
+  : client(client_),
+    pingu(0),
     owner_id(0),
     good(Resource::load_sprite("game/cursors/capgood")),
     bad(Resource::load_sprite("game/cursors/capbad")),
     arrow_left(Resource::load_sprite("game/cursors/arrow_left")),
     arrow_right(Resource::load_sprite("game/cursors/arrow_right")),
-    button_panel(arg_button_panel),
     font(Fonts::courier_small)
 {
 }
 
-CaptureRectangle::~CaptureRectangle ()
+CaptureRectangle::~CaptureRectangle()
 {
 }
 
@@ -50,7 +51,7 @@
   if (pingu && pingu->catchable())
     {
       // Draw the capture rectangle
-      if (pingu->change_allowed(button_panel->get_action_name()))
+      if (pingu->change_allowed(client->get_action_name()))
         {
           sc.color().draw(good, pingu->get_center_pos() + Vector3f(0, 0, 
1000));
         }
@@ -106,5 +107,5 @@
         }
     }
 }
-
+
 /* EOF */

Modified: trunk/pingus/src/capture_rectangle.hpp
===================================================================
--- trunk/pingus/src/capture_rectangle.hpp      2008-06-30 18:52:17 UTC (rev 
3597)
+++ trunk/pingus/src/capture_rectangle.hpp      2008-06-30 19:41:27 UTC (rev 
3598)
@@ -24,12 +24,12 @@
 class Pingu;
 class PinguAction;
 class Pingu;
-class ButtonPanel;
+class Client;
 class DrawingContext;
 
 #include "font.hpp"
 #include "sprite.hpp"
-
+
 /** The rectangle that is shown when the mouse cursor is above a
     pingu. The rectangle shows the current pingu direction along with
     the current active action.
@@ -37,6 +37,7 @@
 class CaptureRectangle
 {
 private:
+  Client*     client;
   Pingu*      pingu;
   std::string action_str;
 
@@ -48,11 +49,10 @@
   Sprite arrow_left;
   Sprite arrow_right;
 
-  ButtonPanel* button_panel;
   Font font;
 
 public:
-  CaptureRectangle(ButtonPanel*);
+  CaptureRectangle(Client*);
   ~CaptureRectangle();
 
   void set_pingu(Pingu* pingu);
@@ -63,8 +63,7 @@
   CaptureRectangle (const CaptureRectangle&);
   CaptureRectangle& operator= (const CaptureRectangle&);
 };
-
-
+
 #endif
 
 /* EOF */

Modified: trunk/pingus/src/client.cpp
===================================================================
--- trunk/pingus/src/client.cpp 2008-06-30 18:52:17 UTC (rev 3597)
+++ trunk/pingus/src/client.cpp 2008-06-30 19:41:27 UTC (rev 3598)
@@ -33,7 +33,8 @@
 #include "world.hpp"
 #include "math.hpp"
 #include "gui/gui_manager.hpp"
-
+#include "client.hpp"
+
 Client::Client(Server * s)
   : server       (s),
     skip_frame   (0),
@@ -53,10 +54,11 @@
   int world_width  = server->get_world()->get_width();
   int world_height = server->get_world()->get_height();
 
-  playfield    = new Playfield(this, 
Rect(Vector2i(Math::max((Display::get_width()  - world_width)/2,  0),
-                                                   
Math::max((Display::get_height() - world_height)/2, 0)), 
-                                          Size(Math::min(Display::get_width(), 
 world_width),
-                                               
Math::min(Display::get_height(), world_height))));
+  playfield    = new Playfield(server, this,
+                               Rect(Vector2i(Math::max((Display::get_width()  
- world_width)/2,  0),
+                                             Math::max((Display::get_height() 
- world_height)/2, 0)), 
+                                    Size(Math::min(Display::get_width(),  
world_width),
+                                         Math::min(Display::get_height(), 
world_height))));
 
   pcounter     = new PingusCounter(get_server());
   small_map    = new SmallMap(this);
@@ -71,8 +73,6 @@
   gui_manager->add(new ArmageddonButton(server, Display::get_width() - 40,     
Display::get_height() - 62), true);
   gui_manager->add(new ForwardButton   (server, Display::get_width() - 40 * 2, 
Display::get_height() - 62), true);
   gui_manager->add(new PauseButton     (server, Display::get_width() - 40 * 3, 
Display::get_height() - 62), true);
-  // Connect the button_panel with the playfield
-  playfield->set_server(server);
 
   timer.stop();
 }
@@ -272,5 +272,10 @@
 {
 }
 
-
+Actions::ActionName
+Client::get_action_name() const
+{
+  return button_panel->get_action_name();
+}
+
 /* EOF */

Modified: trunk/pingus/src/client.hpp
===================================================================
--- trunk/pingus/src/client.hpp 2008-06-30 18:52:17 UTC (rev 3597)
+++ trunk/pingus/src/client.hpp 2008-06-30 19:41:27 UTC (rev 3598)
@@ -20,6 +20,7 @@
 #ifndef HEADER_PINGUS_CLIENT_HPP
 #define HEADER_PINGUS_CLIENT_HPP
 
+#include "pingu_enums.hpp"
 #include "screen/gui_screen.hpp"
 
 namespace Input {
@@ -89,6 +90,7 @@
   void on_escape_press ();
   void on_action_axis_move (float);
 
+  Actions::ActionName get_action_name() const;
 private:
   void process_events (const GameDelta& events);
   void process_scroll_event (const Input::ScrollEvent&);

Modified: trunk/pingus/src/components/playfield.cpp
===================================================================
--- trunk/pingus/src/components/playfield.cpp   2008-06-30 18:52:17 UTC (rev 
3597)
+++ trunk/pingus/src/components/playfield.cpp   2008-06-30 19:41:27 UTC (rev 
3598)
@@ -25,30 +25,28 @@
 #include "../display/scene_context.hpp"
 #include "../world.hpp"
 #include "../server.hpp"
-#include "../server.hpp"
 #include "../pingu.hpp"
 #include "../display/display.hpp"
-#include "button_panel.hpp"
+#include "client.hpp"
 #include "playfield.hpp"
 
-Playfield::Playfield (Client* client_, const Rect& rect_)
+Playfield::Playfield(Server* server_, Client* client_, const Rect& rect_)
   : RectComponent(rect_),
+    server(server_),
     client(client_),
-    buttons(client->get_button_panel()),
     current_pingu(0),
     // We keep the SceneContext has member variable so that we don't
     // have to reallocate it every frame, which is quite a costly operation
     scene_context(new SceneContext()),
     state(rect),
-    cap(client->get_button_panel())
+    capture_rectangle(client)
 {
-  world              = client->get_server()->get_world();
   mouse_scrolling    = false;
 
-  state.set_limit(Rect(Vector2i(0, 0), Size(world->get_width(), 
world->get_height())));
+  state.set_limit(Rect(Vector2i(0, 0), Size(server->get_world()->get_width(), 
server->get_world()->get_height())));
 
   // FIXME: Temporary workaround till start-pos is integrated a bit more 
properly
-  state.set_pos(world->get_start_pos(0));
+  state.set_pos(server->get_world()->get_start_pos(0));
 }
 
 Playfield::~Playfield()
@@ -66,10 +64,10 @@
  
   state.push(*scene_context);
 
-  cap.set_pingu(current_pingu);
-  cap.draw(*scene_context);
+  capture_rectangle.set_pingu(current_pingu);
+  capture_rectangle.draw(*scene_context);
 
-  world->draw(*scene_context);
+  server->get_world()->draw(*scene_context);
  
   // Draw the scrolling band
   if (mouse_scrolling && !drag_drop_scrolling)
@@ -100,14 +98,14 @@
 }
 
 Pingu*
-Playfield::current_pingu_find (const Vector2f& pos)
+Playfield::current_pingu_find(const Vector2f& pos)
 {
   double min_dist = 500.0;
   double dist;
   Pingu* c_pingu = 0;
 
-  for (PinguIter pingu = world->get_pingus()->begin();
-       pingu != world->get_pingus()->end();
+  for (PinguIter pingu = server->get_world()->get_pingus()->begin();
+       pingu != server->get_world()->get_pingus()->end();
        ++pingu)
     {
       if ((*pingu)->is_over(static_cast<int>(pos.x), static_cast<int>(pos.y)))
@@ -131,7 +129,7 @@
   if (!mouse_scrolling)
     {
       current_pingu = current_pingu_find(state.screen2world(mouse_pos));
-      cap.set_pingu(current_pingu);
+      capture_rectangle.set_pingu(current_pingu);
     }
   else
     {
@@ -179,7 +177,7 @@
 
   if (current_pingu)
     {
-      server->send_pingu_action_event(current_pingu, 
buttons->get_action_name());
+      server->send_pingu_action_event(current_pingu, 
client->get_action_name());
     }
 }
 
@@ -241,12 +239,6 @@
     }
 }
 
-void
-Playfield::set_server(Server* s)
-{
-  server = s;
-}
-
 Vector2i
 Playfield::get_pos() const
 {

Modified: trunk/pingus/src/components/playfield.hpp
===================================================================
--- trunk/pingus/src/components/playfield.hpp   2008-06-30 18:52:17 UTC (rev 
3597)
+++ trunk/pingus/src/components/playfield.hpp   2008-06-30 19:41:27 UTC (rev 
3598)
@@ -20,7 +20,6 @@
 #ifndef HEADER_PINGUS_PLAYFIELD_HPP
 #define HEADER_PINGUS_PLAYFIELD_HPP
 
-#include "../client.hpp"
 #include "../graphic_context_state.hpp"
 #include "../gui/rect_component.hpp"
 #include "../capture_rectangle.hpp"
@@ -28,6 +27,7 @@
 class Pingu;
 class World;
 class Server;
+class Client;
 class ButtonPanel;
 class Controller;
 class View;
@@ -36,24 +36,18 @@
 class Playfield : public GUI::RectComponent
 {
 private:
-  friend class Client;
-
   Server* server;
   Client* client;
 
-  ButtonPanel* buttons;
-  World*       world;
-  View*        view;
-
   Pingu* current_pingu;
   bool mouse_scrolling;
-  int scroll_speed;
+  int  scroll_speed;
 
   Vector2i scroll_center;
 
   SceneContext* scene_context;
   GraphicContextState state;
-  CaptureRectangle cap;
+  CaptureRectangle capture_rectangle;
 
   std::vector<Rect> clipping_rectangles;
   
@@ -61,7 +55,7 @@
   Vector2f old_state_pos;
 
 public:
-  Playfield (Client*, const Rect& rect);
+  Playfield(Server*, Client*, const Rect& rect);
   virtual ~Playfield();
 
   /** Returns the point onto which the Playfield is currently focused
@@ -85,9 +79,6 @@
   void do_scrolling();
   void disable_scroll_mode();
 
-  /// Members used to communicate between different screen objs
-  void set_server(Server*);
-
   bool is_at (int x, int y) { UNUSED_ARG(x); UNUSED_ARG(y); return true; }
   Rect get_rect() const { return rect; }
   void update_layout() {}

Modified: trunk/pingus/src/components/smallmap.cpp
===================================================================
--- trunk/pingus/src/components/smallmap.cpp    2008-06-30 18:52:17 UTC (rev 
3597)
+++ trunk/pingus/src/components/smallmap.cpp    2008-06-30 19:41:27 UTC (rev 
3598)
@@ -17,6 +17,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "../client.hpp"
 #include "../pingu_holder.hpp"
 #include "../display/display.hpp"
 #include "../display/drawing_context.hpp"
@@ -31,8 +32,7 @@
 #include "../globals.hpp"
 #include "playfield.hpp"
 #include "smallmap.hpp"
-
-
+
 SmallMap::SmallMap(Client* c)
   : client(c),
     gc_ptr(0)
@@ -201,6 +201,5 @@
 {
   has_focus = false;
 }
-
-
+
 /* EOF */

Modified: trunk/pingus/src/demo_session.cpp
===================================================================
--- trunk/pingus/src/demo_session.cpp   2008-06-30 18:52:17 UTC (rev 3597)
+++ trunk/pingus/src/demo_session.cpp   2008-06-30 19:41:27 UTC (rev 3598)
@@ -18,43 +18,43 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "math.hpp"
-#include "xml_pdf.hpp"
 #include "server.hpp"
+#include "pathname.hpp"
 #include "world.hpp"
 #include "demo_player.hpp"
 #include "components/pingus_counter.hpp"
 #include "gui/gui_manager.hpp"
 #include "display/scene_context.hpp"
+#include "pingus_demo.hpp"
 #include "demo_session.hpp"
 
-DemoSession::DemoSession(const std::string& filename)
+DemoSession::DemoSession(const Pathname& pathname)
 {
   // Load Demo file
-  pdf    = new XMLPDF(filename);
+  demo = std::auto_ptr<PingusDemo>(new PingusDemo(pathname));
 
   // Create server
-  server      = new Server(pdf->get_plf());
-  demo_player = new DemoPlayer(server, pdf);
+  server   = std::auto_ptr<Server>(new 
Server(PingusLevel(Pathname(demo->get_levelname(), Pathname::DATA_PATH))));
 
   // Create GUI
-  pcounter = new PingusCounter(server);
-  gui_manager->add (pcounter, true);
+  pcounter = new PingusCounter(server.get());
+  gui_manager->add(pcounter, true);
 }
 
 DemoSession::~DemoSession()
 {
-  delete server;
-  delete pdf;
 }
 
 /** 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);
 
@@ -66,6 +66,7 @@
 
   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();
@@ -80,14 +81,15 @@
                    world->get_height() - 1 - sc->get_height()/2.0f);
 
   sc->set_offset(-x_of, -y_of);
-#endif
 
+
   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 */
@@ -98,15 +100,38 @@
 
   // FIXME: Duplicate all timing code here?!
   server->update();
-  demo_player->update();
+  update_demo();
 
   int skip_count = 0;
-  while (CL_Keyboard::get_keycode(CL_KEY_SPACE) && skip_count < 10)
+  while (1) //CL_Keyboard::get_keycode(CL_KEY_SPACE) && skip_count < 10)
     {
       ++skip_count;
       server->update();
-      demo_player->update();
+      update_demo();
     }
 }
+
+void
+DemoSession::update_demo()
+{
+#if 0
+  while(!events.empty() && events.back().time_stamp == server->get_time())
+    {
+      ServerEvent& event = events.back();
+
+      std::cout << "Sending: ";
+      event.write(std::cout);
+
+      event.send(server);
+      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())
+    {
+      std::cout << "DemoPlayer Bug: We missed a timestamp: " << 
events.back().time_stamp << std::endl;
+    }
+#endif 
+}
 
 /* EOF */

Modified: trunk/pingus/src/demo_session.hpp
===================================================================
--- trunk/pingus/src/demo_session.hpp   2008-06-30 18:52:17 UTC (rev 3597)
+++ trunk/pingus/src/demo_session.hpp   2008-06-30 19:41:27 UTC (rev 3598)
@@ -20,30 +20,31 @@
 #ifndef HEADER_PINGUS_DEMO_SESSION_HPP
 #define HEADER_PINGUS_DEMO_SESSION_HPP
 
+#include <memory>
 #include "screen/gui_screen.hpp"
 
-
 class Server;
 class XMLPDF;
 class DemoPlayer;
 class PingusCounter;
-
+class PingusDemo;
+class Playfield;
+
 /** 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
     loaded and the level will be played automatically. */
 class DemoSession : public GUIScreen
 {
 private:
-  XMLPDF*     pdf;
-  Server*     server;
-  DemoPlayer* demo_player;
+  std::auto_ptr<Server>   server;
+  std::auto_ptr<PingusDemo> demo;
 
-  // GUI stuff
   PingusCounter* pcounter;
+  Playfield*     playfield;
 
 public:
   /** @param filename the complete filename of the demo file */
-  DemoSession(const std::string& filename);
+  DemoSession(const Pathname& pathname);
   ~DemoSession();
 
   /** Draw this screen */
@@ -51,13 +52,13 @@
 
   /** Pass a delta to the screen */
   void update(float delta);
+  void update_demo();
 
 private:
   DemoSession (const DemoSession&);
   DemoSession& operator= (const DemoSession&);
 };
-
-
+
 #endif
 
 /* EOF */





reply via email to

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