pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3604 - in trunk/pingus: . src src/components
Date: Tue, 1 Jul 2008 01:35:17 +0200

Author: grumbel
Date: 2008-07-01 01:35:14 +0200 (Tue, 01 Jul 2008)
New Revision: 3604

Removed:
   trunk/pingus/src/client.cpp
   trunk/pingus/src/client.hpp
Modified:
   trunk/pingus/SConstruct
   trunk/pingus/src/capture_rectangle.cpp
   trunk/pingus/src/capture_rectangle.hpp
   trunk/pingus/src/components/button_panel.cpp
   trunk/pingus/src/components/button_panel.hpp
   trunk/pingus/src/components/playfield.cpp
   trunk/pingus/src/components/playfield.hpp
   trunk/pingus/src/components/smallmap.cpp
   trunk/pingus/src/components/smallmap.hpp
   trunk/pingus/src/components/time_display.cpp
   trunk/pingus/src/components/time_display.hpp
   trunk/pingus/src/game_session.cpp
   trunk/pingus/src/game_session.hpp
Log:
Merged GameSession and Client

Modified: trunk/pingus/SConstruct
===================================================================
--- trunk/pingus/SConstruct     2008-06-30 23:11:51 UTC (rev 3603)
+++ trunk/pingus/SConstruct     2008-06-30 23:35:14 UTC (rev 3604)
@@ -57,7 +57,6 @@
 # 'blitter_test.cpp', 
 'src/capture_rectangle.cpp', 
 'src/cheat.cpp', 
-'src/client.cpp', 
 'src/col_map.cpp', 
 'src/collider.cpp', 
 'src/config_manager.cpp', 

Modified: trunk/pingus/src/capture_rectangle.cpp
===================================================================
--- trunk/pingus/src/capture_rectangle.cpp      2008-06-30 23:11:51 UTC (rev 
3603)
+++ trunk/pingus/src/capture_rectangle.cpp      2008-06-30 23:35:14 UTC (rev 
3604)
@@ -23,14 +23,14 @@
 #include "resource.hpp"
 #include "capture_rectangle.hpp"
 #include "pingu_action.hpp"
-#include "client.hpp"
+#include "game_session.hpp"
 #include "globals.hpp"
 #include "server.hpp"
 #include "display/scene_context.hpp"
 #include "fonts.hpp"
 
-CaptureRectangle::CaptureRectangle(Client* client_)
-  : client(client_),
+CaptureRectangle::CaptureRectangle(GameSession* session_)
+  : session(session_),
     pingu(0),
     owner_id(0),
     good(Resource::load_sprite("game/cursors/capgood")),
@@ -51,7 +51,7 @@
   if (pingu && pingu->catchable())
     {
       // Draw the capture rectangle
-      if (client && pingu->change_allowed(client->get_action_name()))
+      if (session && pingu->change_allowed(session->get_action_name()))
         {
           sc.color().draw(good, pingu->get_center_pos() + Vector3f(0, 0, 
1000));
         }

Modified: trunk/pingus/src/capture_rectangle.hpp
===================================================================
--- trunk/pingus/src/capture_rectangle.hpp      2008-06-30 23:11:51 UTC (rev 
3603)
+++ trunk/pingus/src/capture_rectangle.hpp      2008-06-30 23:35:14 UTC (rev 
3604)
@@ -20,15 +20,15 @@
 #ifndef HEADER_PINGUS_CAPTURE_RECTANGLE_HPP
 #define HEADER_PINGUS_CAPTURE_RECTANGLE_HPP
 
+#include "font.hpp"
+#include "sprite.hpp"
+
 class Font;
 class Pingu;
 class PinguAction;
 class Pingu;
-class Client;
+class GameSession;
 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
@@ -37,7 +37,7 @@
 class CaptureRectangle
 {
 private:
-  Client*     client;
+  GameSession*  session;
   Pingu*      pingu;
   std::string action_str;
 
@@ -52,7 +52,7 @@
   Font font;
 
 public:
-  CaptureRectangle(Client*);
+  CaptureRectangle(GameSession*);
   ~CaptureRectangle();
 
   void set_pingu(Pingu* pingu);

Deleted: trunk/pingus/src/client.cpp
===================================================================
--- trunk/pingus/src/client.cpp 2008-06-30 23:11:51 UTC (rev 3603)
+++ trunk/pingus/src/client.cpp 2008-06-30 23:35:14 UTC (rev 3604)
@@ -1,270 +0,0 @@
-//  $Id$
-//
-//  Pingus - A free Lemmings clone
-//  Copyright (C) 1999 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 <iostream>
-#include "globals.hpp"
-#include "components/playfield.hpp"
-#include "timer.hpp"
-#include "server.hpp"
-#include "resource.hpp"
-#include "sound/sound.hpp"
-#include "components/time_display.hpp"
-#include "components/pingus_counter.hpp"
-#include "components/smallmap.hpp"
-#include "display/cursor.hpp"
-#include "display/display.hpp"
-#include "components/button_panel.hpp"
-#include "world.hpp"
-#include "math.hpp"
-#include "gui/gui_manager.hpp"
-#include "client.hpp"
-
-Client::Client(Server* s)
-  : server       (s),
-    is_finished  (false),
-    button_panel (0),
-    pcounter     (0),
-    playfield    (0),
-    time_display (0),
-    small_map    (0)
-{
-  Timer timer("Client UI generation");
-
-  // These object will get deleted by the gui_manager
-  button_panel = new ButtonPanel(this, 2, Display::get_height()/2);
-
-  int world_width  = server->get_world()->get_width();
-  int world_height = server->get_world()->get_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);
-  time_display = new TimeDisplay(this);
-
-  gui_manager->add(playfield,    true);
-  gui_manager->add(button_panel, true);
-  gui_manager->add(pcounter,     true);
-  gui_manager->add(small_map,    true);
-  gui_manager->add(time_display, true);
-
-  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);
-
-  timer.stop();
-}
-
-Client::~Client()
-{
-}
-
-void
-Client::draw_background (DrawingContext& gc)
-{
-  Rect rect = playfield->get_rect();
-  
-  if (rect != Rect(Vector2i(0,0), Size(Display::get_width(), 
Display::get_height())))
-    { // Draw a black border around the playfield when the playfield is 
smaller then the screen
-      Color border_color(0, 0, 0);
-      // top
-      gc.draw_fillrect(0, 0, Display::get_width(), rect.top,
-                       border_color);
-      // bottom
-      gc.draw_fillrect(0, rect.bottom, Display::get_width(), 
Display::get_height(),
-                       border_color);
-      // left
-      gc.draw_fillrect(0, rect.top, rect.left, rect.bottom,
-                       border_color);
-      // right
-      gc.draw_fillrect(rect.right, rect.top, Display::get_width(), rect.bottom,
-                       border_color);
-    }
-}
-
-void
-Client::update (const GameDelta& delta)
-{
-  GUIScreen::update(delta);
-  process_events(delta);
-}
-
-void
-Client::process_events (const GameDelta& delta)
-{
-  const Input::EventLst& events = delta.get_events();
-
-  for (Input::EventLst::const_iterator i = events.begin();
-       i != events.end();
-       ++i)
-    {
-      //std::cout << "Events: " << (*i)->get_type () << std::endl;
-
-      switch (i->type)
-       {
-          case Input::BUTTON_EVENT_TYPE:
-          {
-            const Input::ButtonEvent& ev = i->button;
-
-            if (ev.state == Input::BUTTON_PRESSED)
-              {
-                if (ev.name >= Input::ACTION_1_BUTTON && ev.name <= 
Input::ACTION_10_BUTTON)
-                  {
-                    button_panel->set_button(ev.name - Input::ACTION_1_BUTTON);
-                  }
-                else if (ev.name == Input::ACTION_DOWN_BUTTON)
-                  {
-                    button_panel->next_action();
-                  }
-                else if (ev.name == Input::ACTION_UP_BUTTON)
-                  {
-                    button_panel->previous_action();
-                  }
-              }
-          }
-         break;
-
-       case Input::POINTER_EVENT_TYPE:
-                                       // Ignore, is handled in GUIScreen
-         break;
-
-       case Input::AXIS_EVENT_TYPE:
-          // ???
-         process_axis_event (i->axis);
-         break;
-
-        case Input::SCROLLER_EVENT_TYPE:
-          process_scroll_event(i->scroll);
-          break;
-
-        case Input::KEYBOARD_EVENT_TYPE:
-          break;
-
-       default:
-         // unhandled event
-         std::cout << "Client::process_events (): unhandled event: " << 
i->type << std::endl;
-         break;
-       }
-    }
-}
-
-void
-Client::process_scroll_event (const Input::ScrollEvent& ev)
-{
-  playfield->scroll(static_cast<int>(-ev.x_delta),
-                    static_cast<int>(-ev.y_delta));
-}
-
-void
-Client::process_axis_event (const Input::AxisEvent& event)
-{
-  // std::cout << "Client::process_axis_event ()" << std::endl;
-  UNUSED_ARG(event);
-}
-
-void
-Client::do_restart()
-{
-  server->send_finish_event();
-}
-
-bool
-Client::finished()
-{
-  return is_finished;
-}
-
-void
-Client::set_finished()
-{
-  is_finished = true;
-  server->send_finish_event();
-}
-
-void
-Client:: on_escape_press ()
-{
-  server->send_finish_event();
-}
-
-void
-Client:: on_pause_press ()
-{
-  server->set_pause (!server->get_pause ());
-}
-
-void
-Client::on_fast_forward_press ()
-{
-  server->set_fast_forward(!server->get_fast_forward());
-}
-
-void
-Client::on_armageddon_press ()
-{
-  server->send_armageddon_event();
-}
-
-void
-Client::on_action_axis_move (float move)
-{
-  if (move > 0)
-    button_panel->next_action ();
-  else if (move < 0)
-    button_panel->previous_action ();
-}
-
-void
-Client::on_startup ()
-{
-  is_finished = false;
-
-  if (maintainer_mode)
-    std::cout << "Starting Music: " << server->get_plf().get_music() << 
std::endl;
-
-  if (server->get_plf().get_music() == "none")
-    {
-      Sound::PingusSound::stop_music();
-    }
-  else
-    {
-      Sound::PingusSound::play_music(server->get_plf().get_music());
-    }
-
-  if (verbose)
-    std::cout << "Client: Entering main_loop. Startup time: "
-             << SDL_GetTicks() << " msec." << std::endl;
-}
-
-void
-Client::on_shutdown ()
-{
-}
-
-Actions::ActionName
-Client::get_action_name() const
-{
-  return button_panel->get_action_name();
-}
-
-/* EOF */

Deleted: trunk/pingus/src/client.hpp
===================================================================
--- trunk/pingus/src/client.hpp 2008-06-30 23:11:51 UTC (rev 3603)
+++ trunk/pingus/src/client.hpp 2008-06-30 23:35:14 UTC (rev 3604)
@@ -1,103 +0,0 @@
-//  $Id$
-//
-//  Pingus - A free Lemmings clone
-//  Copyright (C) 1999 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_CLIENT_HPP
-#define HEADER_PINGUS_CLIENT_HPP
-
-#include "pingu_enums.hpp"
-#include "screen/gui_screen.hpp"
-
-namespace Input {
-struct ButtonEvent;
-struct PointerEvent;
-struct ScrollEvent;
-struct AxisEvent;
-struct KeyboardEvent;
-} // namespace Input
-
-namespace GUI {
-class RootGUIManager;
-} // namespace GUI
-
-class Vector;
-class ButtonPanel;
-class Cursor;
-class PingusCounter;
-class Playfield;
-class Server;
-class SmallMap;
-class TimeDisplay;
-
-/** FIXME: This whole Server/Client concept is a bit screwed */
-class Client : public GUIScreen
-{
-private:
-  Server* server;
-
-  bool is_finished;
-
-  ButtonPanel*   button_panel;
-  PingusCounter* pcounter;
-  Playfield*     playfield;
-  TimeDisplay*   time_display;
-  SmallMap*      small_map;
-  bool enabled;
-
-public:
-  Client(Server* s);
-  virtual ~Client();
-
-  Server* get_server() { return server; }
-  Playfield* get_playfield() { return playfield; }
-
-  void do_restart();
-  bool finished();
-  void set_finished();
-
-  /** Update all parts of the world */
-  void update (const GameDelta&);
-  void draw_background (DrawingContext& gc);
-
-  ButtonPanel* get_button_panel () { return button_panel; }
-
-  // Overloaded GUIScreen stuff
-  void on_startup ();
-  void on_shutdown ();
-
-  void on_pause_press ();
-  void on_fast_forward_press ();
-  void on_armageddon_press ();
-  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&);
-  void process_axis_event (const Input::AxisEvent&);
-
-  Client (const Client&);
-  Client& operator= (const Client&);
-};
-
-
-#endif
-
-/* EOF */

Modified: trunk/pingus/src/components/button_panel.cpp
===================================================================
--- trunk/pingus/src/components/button_panel.cpp        2008-06-30 23:11:51 UTC 
(rev 3603)
+++ trunk/pingus/src/components/button_panel.cpp        2008-06-30 23:35:14 UTC 
(rev 3604)
@@ -21,7 +21,7 @@
 #include <algorithm>
 #include "../globals.hpp"
 #include "../server.hpp"
-#include "../client.hpp"
+#include "../game_session.hpp"
 #include "button_panel.hpp"
 
 
@@ -33,15 +33,14 @@
   }
 };
 
-ButtonPanel::ButtonPanel(Client* c, int arg_x_pos, int arg_y_pos)
-  : client(c),
-    server(client->get_server()),
+ButtonPanel::ButtonPanel(GameSession* s, int arg_x_pos, int arg_y_pos)
+  : session(s),
     left_pressed(0),
     last_press(0),
     x_pos (arg_x_pos),
     y_pos (arg_y_pos)
 {
-  ActionHolder* aholder = server->get_action_holder();
+  ActionHolder* aholder = session->get_server()->get_action_holder();
 
   std::vector<ActionName> actions = aholder->get_available_actions();
 

Modified: trunk/pingus/src/components/button_panel.hpp
===================================================================
--- trunk/pingus/src/components/button_panel.hpp        2008-06-30 23:11:51 UTC 
(rev 3603)
+++ trunk/pingus/src/components/button_panel.hpp        2008-06-30 23:35:14 UTC 
(rev 3604)
@@ -21,17 +21,14 @@
 #define HEADER_PINGUS_BUTTON_PANEL_HPP
 
 #include <vector>
-
 #include "action_button.hpp"
 
-
-class Client;
-
+class GameSession;
+
 class ButtonPanel : public GUI::Component
 {
 private:
-  Client* client;
-  Server* server;
+  GameSession* session;
 
   std::vector<ActionButton*> a_buttons;
   typedef std::vector<ActionButton*>::iterator AButtonIter;
@@ -43,7 +40,7 @@
   int x_pos, y_pos;
 
 public:
-  ButtonPanel(Client* c, int arg_x_pos, int arg_y_pos);
+  ButtonPanel(GameSession* s, int arg_x_pos, int arg_y_pos);
   virtual ~ButtonPanel();
 
   void on_primary_button_press(int x, int y);
@@ -68,8 +65,7 @@
   ButtonPanel (const ButtonPanel&);
   ButtonPanel& operator= (const ButtonPanel&);
 };
-
-
+
 #endif
 
 /* EOF */

Modified: trunk/pingus/src/components/playfield.cpp
===================================================================
--- trunk/pingus/src/components/playfield.cpp   2008-06-30 23:11:51 UTC (rev 
3603)
+++ trunk/pingus/src/components/playfield.cpp   2008-06-30 23:35:14 UTC (rev 
3604)
@@ -27,19 +27,19 @@
 #include "../server.hpp"
 #include "../pingu.hpp"
 #include "../display/display.hpp"
-#include "client.hpp"
+#include "../game_session.hpp"
 #include "playfield.hpp"
 
-Playfield::Playfield(Server* server_, Client* client_, const Rect& rect_)
+Playfield::Playfield(Server* server_, GameSession* session_, const Rect& rect_)
   : RectComponent(rect_),
     server(server_),
-    client(client_),
+    session(session_),
     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),
-    capture_rectangle(client)
+    capture_rectangle(session)
 {
   mouse_scrolling    = false;
 
@@ -173,13 +173,13 @@
 void
 Playfield::on_primary_button_press(int x, int y)
 {
-  if (client)
+  if (session)
     {
       current_pingu = current_pingu_find(state.screen2world( Vector2i(x,y) ));
 
       if (current_pingu) 
         {
-          server->send_pingu_action_event(current_pingu, 
client->get_action_name());
+          server->send_pingu_action_event(current_pingu, 
session->get_action_name());
         }
     }
 }

Modified: trunk/pingus/src/components/playfield.hpp
===================================================================
--- trunk/pingus/src/components/playfield.hpp   2008-06-30 23:11:51 UTC (rev 
3603)
+++ trunk/pingus/src/components/playfield.hpp   2008-06-30 23:35:14 UTC (rev 
3604)
@@ -27,7 +27,7 @@
 class Pingu;
 class World;
 class Server;
-class Client;
+class GameSession;
 class ButtonPanel;
 class Controller;
 class View;
@@ -37,7 +37,7 @@
 {
 private:
   Server* server;
-  Client* client;
+  GameSession* session;
 
   Pingu* current_pingu;
   bool mouse_scrolling;
@@ -55,7 +55,7 @@
   Vector2f old_state_pos;
 
 public:
-  Playfield(Server*, Client*, const Rect& rect);
+  Playfield(Server*, GameSession*, const Rect& rect);
   virtual ~Playfield();
 
   /** Returns the point onto which the Playfield is currently focused

Modified: trunk/pingus/src/components/smallmap.cpp
===================================================================
--- trunk/pingus/src/components/smallmap.cpp    2008-06-30 23:11:51 UTC (rev 
3603)
+++ trunk/pingus/src/components/smallmap.cpp    2008-06-30 23:35:14 UTC (rev 
3604)
@@ -17,7 +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 "../game_session.hpp"
 #include "../pingu_holder.hpp"
 #include "../display/display.hpp"
 #include "../display/drawing_context.hpp"
@@ -33,8 +33,8 @@
 #include "playfield.hpp"
 #include "smallmap.hpp"
 
-SmallMap::SmallMap(Client* c)
-  : client(c),
+SmallMap::SmallMap(GameSession* session_)
+  : session(session_),
     gc_ptr(0)
 {
   int max_width = 175;
@@ -43,7 +43,7 @@
   int min_height = 70;
   int min_width = 100;
 
-  World* world = client->get_server()->get_world();
+  World* world = session->get_server()->get_world();
 
   // Scaling values used in order to keep the aspect ratio
   int x_scaling = world->get_width()  / max_width;
@@ -65,7 +65,7 @@
   x_pos   = 5;
   y_pos   = Display::get_height() - height - 5;
 
-  image = new SmallMapImage(c->get_server(), width, height);
+  image = new SmallMapImage(session->get_server(), width, height);
 
   scroll_mode = false;
 }
@@ -82,8 +82,8 @@
   // long 'gc' will be alive. Should use a DrawingContext for caching.
   gc_ptr = &gc;
 
-  World* const& world  = client->get_server()->get_world();
-  Playfield* playfield = client->get_playfield();
+  World* const& world  = session->get_server()->get_world();
+  Playfield* playfield = session->get_playfield();
   
   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));
 
-  client->get_server()->get_world()->draw_smallmap(this);
+  session->get_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 = client->get_server()->get_world();
+  World* world = session->get_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 = client->get_server()->get_world();
+  World* world = session->get_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);
 
-      client->get_playfield()->set_viewpoint(cx, cy);
+      session->get_playfield()->set_viewpoint(cx, cy);
     }
 }
 
@@ -176,10 +176,10 @@
 
   // set view to the given COs
   int cx, cy;
-  World* world = client->get_server()->get_world();
+  World* world = session->get_server()->get_world();
   cx = (x - x_pos) * int(world->get_width()) / width;
   cy = (y - y_pos) * int(world->get_height()) / height ;
-  client->get_playfield()->set_viewpoint(cx, cy);
+  session->get_playfield()->set_viewpoint(cx, cy);
 }
 
 void

Modified: trunk/pingus/src/components/smallmap.hpp
===================================================================
--- trunk/pingus/src/components/smallmap.hpp    2008-06-30 23:11:51 UTC (rev 
3603)
+++ trunk/pingus/src/components/smallmap.hpp    2008-06-30 23:35:14 UTC (rev 
3604)
@@ -23,7 +23,7 @@
 #include "../sprite.hpp"
 #include "../gui/component.hpp"
 
-class Client;
+class GameSession;
 class Vector3f;
 class SmallMapImage;
 
@@ -31,7 +31,7 @@
 class SmallMap : public GUI::Component
 {
 private:
-  Client* client;
+  GameSession* session;
 
   /** Graphic surface of the exit */
   Sprite exit_sur;
@@ -63,7 +63,7 @@
   DrawingContext* gc_ptr;
 
 public:
-  SmallMap(Client* c);
+  SmallMap(GameSession* c);
   virtual ~SmallMap();
 
   /*{ @name Stuff called from the GUIManager */
@@ -75,7 +75,7 @@
   void on_pointer_enter ();
   void on_pointer_leave ();
 
-  void set_client(Client* c);
+  void set_session(GameSession* c);
 
   bool is_at (int x, int y);
   bool mouse_over();

Modified: trunk/pingus/src/components/time_display.cpp
===================================================================
--- trunk/pingus/src/components/time_display.cpp        2008-06-30 23:11:51 UTC 
(rev 3603)
+++ trunk/pingus/src/components/time_display.cpp        2008-06-30 23:35:14 UTC 
(rev 3604)
@@ -25,15 +25,14 @@
 #include "../resource.hpp"
 #include "../world.hpp"
 #include "../server.hpp"
-#include "../client.hpp"
+#include "../game_session.hpp"
 #include "../game_time.hpp"
 #include "../string_util.hpp"
 #include "../fonts.hpp"
 
 #include "time_display.hpp"
-
-
-TimeDisplay::TimeDisplay (Client* c)
+
+TimeDisplay::TimeDisplay (GameSession* c)
   : server(c->get_server()),
     infinity_symbol(Resource::load_sprite("core/misc/infinity"))
 {
@@ -65,6 +64,5 @@
       gc.print_right(font, Display::get_width() - 30, 3, time_string, 150);
     }
 }
-
-
+
 /* EOF */

Modified: trunk/pingus/src/components/time_display.hpp
===================================================================
--- trunk/pingus/src/components/time_display.hpp        2008-06-30 23:11:51 UTC 
(rev 3603)
+++ trunk/pingus/src/components/time_display.hpp        2008-06-30 23:35:14 UTC 
(rev 3604)
@@ -24,7 +24,7 @@
 
 class Font;
 class Server;
-class Client;
+class GameSession;
 class DrawingContext;
 
 class TimeDisplay : public GUI::Component
@@ -35,7 +35,7 @@
   Sprite infinity_symbol;
 
 public:
-  TimeDisplay(Client* c);
+  TimeDisplay(GameSession* c);
   virtual ~TimeDisplay() {}
 
   void draw(DrawingContext& gc);

Modified: trunk/pingus/src/game_session.cpp
===================================================================
--- trunk/pingus/src/game_session.cpp   2008-06-30 23:11:51 UTC (rev 3603)
+++ trunk/pingus/src/game_session.cpp   2008-06-30 23:35:14 UTC (rev 3604)
@@ -19,8 +19,18 @@
 
 #include <iostream>
 #include "screen/screen_manager.hpp"
-#include "client.hpp"
 #include "server.hpp"
+#include "gui/gui_manager.hpp"
+#include "display/display.hpp"
+
+#include "components/button_panel.hpp"
+#include "components/pingus_counter.hpp"
+#include "components/time_display.hpp"
+#include "components/smallmap.hpp"
+#include "components/playfield.hpp"
+
+#include "sound/sound.hpp"
+#include "math.hpp"
 #include "game_session.hpp"
 #include "resource.hpp"
 #include "pingu_holder.hpp"
@@ -32,42 +42,56 @@
 
 GameSession::GameSession (const PingusLevel& arg_plf, bool 
arg_show_result_screen)
   : plf(arg_plf),
-    show_result_screen(arg_show_result_screen)
+    show_result_screen(arg_show_result_screen),
+    is_finished  (false),
+    button_panel (0),
+    pcounter     (0),
+    playfield    (0),
+    time_display (0),
+    small_map    (0)
 {
   server = std::auto_ptr<Server>(new Server(plf));
-  client = std::auto_ptr<Client>(new Client(server.get()));
 
   // the world is initially on time
   world_delay = 0;
 
   pout(PINGUS_DEBUG_LOADING) << "GameSession" << std::endl;
-}
 
-GameSession::~GameSession ()
-{
-}
+  // -- Client stuff
+  
+  // These object will get deleted by the gui_manager
+  button_panel = new ButtonPanel(this, 2, Display::get_height()/2);
 
-void
-GameSession::on_startup()
-{
-  client->on_startup();
-}
+  int world_width  = server->get_world()->get_width();
+  int world_height = server->get_world()->get_height();
 
-void
-GameSession::on_shutdown()
-{
-  client->on_shutdown();
+  playfield    = new Playfield(get_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);
+  time_display = new TimeDisplay(this);
+
+  gui_manager->add(playfield,    true);
+  gui_manager->add(button_panel, true);
+  gui_manager->add(pcounter,     true);
+  gui_manager->add(small_map,    true);
+  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);
 }
 
-bool
-GameSession::draw(DrawingContext& gc)
+GameSession::~GameSession ()
 {
-  client->draw (gc);
-  return true;
 }
 
 void
-GameSession::update (const GameDelta& delta)
+GameSession::update_server(const GameDelta& delta)
 {
   // FIXME: Timing code could need another rewrite...
   if (server->is_finished())
@@ -137,33 +161,198 @@
       world_delay = time_passed - (world_updates*update_time);
 
       // Client is independend of the update limit, well, not completly...
-      client->update(delta);
+      //client->update(delta);
     }
 }
 
 void
-GameSession::on_pause_press ()
+GameSession::draw_background (DrawingContext& gc)
 {
-  client->on_pause_press ();
+  Rect rect = playfield->get_rect();
+  
+  if (rect != Rect(Vector2i(0,0), Size(Display::get_width(), 
Display::get_height())))
+    { // Draw a black border around the playfield when the playfield is 
smaller then the screen
+      Color border_color(0, 0, 0);
+      // top
+      gc.draw_fillrect(0, 0, Display::get_width(), rect.top,
+                       border_color);
+      // bottom
+      gc.draw_fillrect(0, rect.bottom, Display::get_width(), 
Display::get_height(),
+                       border_color);
+      // left
+      gc.draw_fillrect(0, rect.top, rect.left, rect.bottom,
+                       border_color);
+      // right
+      gc.draw_fillrect(rect.right, rect.top, Display::get_width(), rect.bottom,
+                       border_color);
+    }
 }
 
 void
+GameSession::update (const GameDelta& delta)
+{
+  update_server(delta);
+
+  GUIScreen::update(delta);
+  process_events(delta);
+}
+
+void
+GameSession::process_events (const GameDelta& delta)
+{
+  const Input::EventLst& events = delta.get_events();
+
+  for (Input::EventLst::const_iterator i = events.begin();
+       i != events.end();
+       ++i)
+    {
+      //std::cout << "Events: " << (*i)->get_type () << std::endl;
+
+      switch (i->type)
+       {
+          case Input::BUTTON_EVENT_TYPE:
+          {
+            const Input::ButtonEvent& ev = i->button;
+
+            if (ev.state == Input::BUTTON_PRESSED)
+              {
+                if (ev.name >= Input::ACTION_1_BUTTON && ev.name <= 
Input::ACTION_10_BUTTON)
+                  {
+                    button_panel->set_button(ev.name - Input::ACTION_1_BUTTON);
+                  }
+                else if (ev.name == Input::ACTION_DOWN_BUTTON)
+                  {
+                    button_panel->next_action();
+                  }
+                else if (ev.name == Input::ACTION_UP_BUTTON)
+                  {
+                    button_panel->previous_action();
+                  }
+              }
+          }
+         break;
+
+       case Input::POINTER_EVENT_TYPE:
+                                       // Ignore, is handled in GUIScreen
+         break;
+
+       case Input::AXIS_EVENT_TYPE:
+          // ???
+         process_axis_event (i->axis);
+         break;
+
+        case Input::SCROLLER_EVENT_TYPE:
+          process_scroll_event(i->scroll);
+          break;
+
+        case Input::KEYBOARD_EVENT_TYPE:
+          break;
+
+       default:
+         // unhandled event
+         std::cout << "GameSession::process_events (): unhandled event: " << 
i->type << std::endl;
+         break;
+       }
+    }
+}
+
+void
+GameSession::process_scroll_event (const Input::ScrollEvent& ev)
+{
+  playfield->scroll(static_cast<int>(-ev.x_delta),
+                    static_cast<int>(-ev.y_delta));
+}
+
+void
+GameSession::process_axis_event (const Input::AxisEvent& event)
+{
+  // std::cout << "GameSession::process_axis_event ()" << std::endl;
+  UNUSED_ARG(event);
+}
+
+void
+GameSession::do_restart()
+{
+  server->send_finish_event();
+}
+
+bool
+GameSession::finished()
+{
+  return is_finished;
+}
+
+void
+GameSession::set_finished()
+{
+  is_finished = true;
+  server->send_finish_event();
+}
+
+void
+GameSession:: on_escape_press ()
+{
+  server->send_finish_event();
+}
+
+void
+GameSession:: on_pause_press ()
+{
+  server->set_pause (!server->get_pause ());
+}
+
+void
 GameSession::on_fast_forward_press ()
 {
-  client->on_fast_forward_press ();
+  server->set_fast_forward(!server->get_fast_forward());
 }
 
 void
 GameSession::on_armageddon_press ()
 {
-  client->on_armageddon_press ();
+  server->send_armageddon_event();
 }
 
 void
-GameSession::on_escape_press ()
+GameSession::on_action_axis_move (float move)
 {
-  client->on_escape_press ();
+  if (move > 0)
+    button_panel->next_action ();
+  else if (move < 0)
+    button_panel->previous_action ();
 }
 
+void
+GameSession::on_startup ()
+{
+  is_finished = false;
 
+  if (maintainer_mode)
+    std::cout << "Starting Music: " << server->get_plf().get_music() << 
std::endl;
+
+  if (server->get_plf().get_music() == "none")
+    {
+      Sound::PingusSound::stop_music();
+    }
+  else
+    {
+      Sound::PingusSound::play_music(server->get_plf().get_music());
+    }
+
+  if (verbose)
+    std::cout << "GameSession: Entering main_loop. Startup time: "
+             << SDL_GetTicks() << " msec." << std::endl;
+}
+
+void
+GameSession::on_shutdown ()
+{
+}
+
+Actions::ActionName
+GameSession::get_action_name() const
+{
+  return button_panel->get_action_name();
+}
+
 /* EOF */

Modified: trunk/pingus/src/game_session.hpp
===================================================================
--- trunk/pingus/src/game_session.hpp   2008-06-30 23:11:51 UTC (rev 3603)
+++ trunk/pingus/src/game_session.hpp   2008-06-30 23:35:14 UTC (rev 3604)
@@ -22,15 +22,20 @@
 
 #include <string>
 #include <memory>
-#include "screen/screen.hpp"
+#include "screen/gui_screen.hpp"
 #include "pingus_level.hpp"
+#include "pingu_enums.hpp"
 
-class Client;
+class ButtonPanel;
+class PingusCounter;
+class Playfield;
+class TimeDisplay;
+class SmallMap;
 class Server;
 
 /** You can use this class to start up a game session, which consist
     of a single level. */
-class GameSession : public Screen
+class GameSession : public GUIScreen
 {
 private:
   /// The level data
@@ -41,33 +46,57 @@
   /// The server
   std::auto_ptr<Server> server;
 
-  /// The client
-  std::auto_ptr<Client> client;
-
   int world_delay; ///< how many milliseconds is the world behind the actual 
time
 
+  // -- Client stuff
+  bool is_finished;
+
+  ButtonPanel*   button_panel;
+  PingusCounter* pcounter;
+  Playfield*     playfield;
+  TimeDisplay*   time_display;
+  SmallMap*      small_map;
+  bool enabled;
+
 public:
   GameSession(const PingusLevel& arg_plf, bool arg_show_result_screen);
-
-  /** Clean up */
   ~GameSession ();
 
-  // Overloaded Screen functions
-  /** Draw this screen */
-  bool draw(DrawingContext& gc);
-
   /** Pass a delta to the screen */
-  void update (const GameDelta& delta);
+  void update_server(const GameDelta& delta);
 
-  void on_startup();
-  void on_shutdown();
+  // -- Client stuff
 
+  Server*    get_server() { return server.get(); }
+  Playfield* get_playfield() { return playfield; }
+
+  void do_restart();
+  bool finished();
+  void set_finished();
+
+  /** Update all parts of the world */
+  void update (const GameDelta&);
+  void draw_background (DrawingContext& gc);
+
+  ButtonPanel* get_button_panel () { return button_panel; }
+
+  // Overloaded GUIScreen stuff
+  void on_startup ();
+  void on_shutdown ();
+
   void on_pause_press ();
   void on_fast_forward_press ();
   void on_armageddon_press ();
   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&);
+  void process_axis_event (const Input::AxisEvent&);
+
   GameSession (const GameSession&);
   GameSession& operator= (const GameSession&);
 };





reply via email to

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