pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src gui_screen.cxx,NONE,1.1 gui_screen.hx


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src gui_screen.cxx,NONE,1.1 gui_screen.hxx,NONE,1.1 Makefile.am,1.86,1.87 client.hxx,1.4,1.5 pingus_main.cxx,1.7,1.8 pingus_menu_manager.cxx,1.6,1.7 pingus_menu_manager.hxx,1.5,1.6 screen.hxx,1.3,1.4 screen_manager.cxx,1.2,1.3 screen_manager.hxx,1.3,1.4 story.cxx,1.2,1.3 story.hxx,1.3,1.4 surface_button.cxx,1.4,1.5 surface_button.hxx,1.4,1.5
Date: 1 Aug 2002 21:40:04 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv6419

Modified Files:
        Makefile.am client.hxx pingus_main.cxx pingus_menu_manager.cxx 
        pingus_menu_manager.hxx screen.hxx screen_manager.cxx 
        screen_manager.hxx story.cxx story.hxx surface_button.cxx 
        surface_button.hxx 
Added Files:
        gui_screen.cxx gui_screen.hxx 
Log Message:
more gui and input cleanup, client is still broken

--- NEW FILE: gui_screen.cxx ---
//  $Id: gui_screen.cxx,v 1.1 2002/08/01 21:40:01 grumbel Exp $
//
//  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 "gui/gui_manager.hxx"
#include "gui_screen.hxx"

using namespace GUI;

GUIScreen::GUIScreen ()
  : gui_manager (new GUIManager ())
{
}

GUIScreen::~GUIScreen ()
{
  delete gui_manager;
}

  /** Draw this screen */
void
GUIScreen::draw ()
{
  gui_manager->draw ();
}

  /** Pass a delta to the screen */
void
GUIScreen::update (const GameDelta& delta)
{
  gui_manager->update (delta);
}

/* EOF */

--- NEW FILE: gui_screen.hxx ---
//  $Id: gui_screen.hxx,v 1.1 2002/08/01 21:40:01 grumbel Exp $
// 
//  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_GUISCREEN_HXX
#define HEADER_PINGUS_GUISCREEN_HXX

#include "screen.hxx"
#include "gui/gui_manager.hxx"

namespace GUI
{
  class GUIManager;
}

class GUIScreen : public Screen
{
protected:
  GUI::GUIManager* gui_manager;

public:
  GUIScreen ();
  virtual ~GUIScreen ();

  /** Draw this screen */
  virtual void draw ();

  /** Pass a delta to the screen */
  virtual void update (const GameDelta& delta);
};

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- Makefile.am 29 Jul 2002 10:44:12 -0000      1.86
+++ Makefile.am 1 Aug 2002 21:40:01 -0000       1.87
@@ -164,6 +164,8 @@
 groundpiece_data.hxx \
 gui_obj.cxx \
 gui_obj.hxx \
+gui_screen.cxx \
+gui_screen.hxx \
 hotspot.cxx \
 hotspot.hxx \
 hotspot_data.cxx \
@@ -280,6 +282,9 @@
 result.hxx \
 screenshot.cxx \
 screenshot.hxx \
+screen.hxx \
+screen_manager.hxx \
+screen_manager.cxx \
 server.cxx \
 server.hxx \
 smallmap.cxx \

Index: client.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/client.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- client.hxx  29 Jul 2002 10:44:12 -0000      1.4
+++ client.hxx  1 Aug 2002 21:40:01 -0000       1.5
@@ -54,7 +54,7 @@
 class TimeDisplay;
 
 /** FIXME: This whole Server/Client concept is a bit screwed */
-class Client
+class Client : public GUIScreen
 {
 private:
   

Index: pingus_main.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_main.cxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pingus_main.cxx     30 Jul 2002 14:57:25 -0000      1.7
+++ pingus_main.cxx     1 Aug 2002 21:40:01 -0000       1.8
@@ -71,7 +71,7 @@
 #include "debug.hxx"
 #include "editor/editor.hxx"
 #include "boost/smart_ptr.hpp"
-#include "pingus_menu_manager.hxx"
+#include "screen_manager.hxx"
 #include "sound_dummy.hxx"
 #include "action_data.hxx"
 
@@ -842,9 +842,12 @@
 
   // show the main menu, the rest of the game is spawn from there
   try {
-    PingusMenuManager menu;
+    //PingusMenuManager menu;
     // This is the main loop
-    menu.display ();
+    //menu.display ();
+    std::cout << "PingusMain::start screen manager" << std::endl;
+    ScreenManager::instance ()->display ();
+    std::cout << "PingusMain::quit game and screen_manager" << std::endl;
   }
   
   catch (const CL_Error& err) {

Index: pingus_menu_manager.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_menu_manager.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- pingus_menu_manager.cxx     30 Jul 2002 14:57:25 -0000      1.6
+++ pingus_menu_manager.cxx     1 Aug 2002 21:40:01 -0000       1.7
@@ -26,6 +26,8 @@
 #include "input/controller.hxx"
 #include "pingus_menu_manager.hxx"
 
+PingusMenuManager* PingusMenuManager::instance_ = 0;
+
 PingusMenuManager::PingusMenuManager ()
   : event_register_counter (0),
     intro (this), mainmenu (this), optionmenu (this), background (this), story 
(this),
@@ -131,6 +133,7 @@
 }
 */
 
+/*
 void 
 PingusMenuManager::display ()
 {
@@ -154,12 +157,6 @@
       // the scrolling (for example when starting a level and then
       // after some minutes going back to the menu would cause delta's
       // from >100, not nice)
-      if (time_delta > 1.0)
-       {
-         std::cout << "PingusMenuManager: detected large delta (" << time_delta
-                   << "), ignoring and doing frameskip" << std::endl;
-         continue;
-       }
 
       GameDelta delta (time_delta, input_controller.get_events ());
 
@@ -181,6 +178,24 @@
     }
   unregister_events ();
 }
+*/
+void
+PingusMenuManager::draw ()
+{
+  for (MenuStackIter i = menu_stack.begin (); i != menu_stack.end (); ++i)
+    (*i)->draw ();
+}
+
+void
+PingusMenuManager::update (const GameDelta& delta)
+{
+  // We copy the menu_stack so that we don't invalidate our
+  // iterators when menu's are removed/added in update()
+  std::vector<PingusSubMenu *> tmp_menu_stack = menu_stack;
+
+  for (MenuStackIter i = tmp_menu_stack.begin (); i != tmp_menu_stack.end (); 
++i)
+    (*i)->update (delta);
+}
 
 void 
 PingusMenuManager::set_menu (PingusSubMenu * menu)
@@ -277,6 +292,15 @@
 
   if (loop == false)
   fadeout ();*/
+}
+
+PingusMenuManager*
+PingusMenuManager::instance ()
+{
+  if (instance_)
+    return instance_;
+  else
+    return instance_ = new PingusMenuManager ();
 }
 
 /* EOF */

Index: pingus_menu_manager.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus_menu_manager.hxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pingus_menu_manager.hxx     30 Jul 2002 14:57:25 -0000      1.5
+++ pingus_menu_manager.hxx     1 Aug 2002 21:40:01 -0000       1.6
@@ -26,12 +26,15 @@
 #include "pingus_menu.hxx"
 #include "intro.hxx"
 #include "option_menu.hxx"
+#include "game_delta.hxx"
+#include "screen.hxx"
 
 class PingusSubMenu;
 
-class PingusMenuManager
+class PingusMenuManager : public Screen
 {
 private:
+  static PingusMenuManager* instance_;
   /** Menu stack. the menu on top is .end (), the bottom menu .begin () */
   std::vector<PingusSubMenu *> menu_stack;
   typedef std::vector<PingusSubMenu *>::iterator MenuStackIter;
@@ -46,6 +49,8 @@
 
   /// Unregister all event-handling stuff
   void unregister_events ();
+  PingusMenuManager ();
+
 public:
   /* Menu's FIXME: These shouldn't get exported to the outsite,
      instead only handles (enum's) should be visible */
@@ -56,11 +61,7 @@
   Story story;
   ExitMenu exitmenu;
 
-  PingusMenuManager ();
-  ~PingusMenuManager ();
-
-  /// Display the menu (this is basically the game's main loop)
-  void display ();
+  virtual ~PingusMenuManager ();
 
   /// Disable events
   void enable_events ();
@@ -69,6 +70,9 @@
 
   void fadeout ();
 
+  void draw ();
+  void update (const GameDelta&);
+
   // !FIXME! Should use controller instead
   /*
   void on_button_press (CL_InputDevice*,const CL_Key &);
@@ -90,6 +94,8 @@
   /** Add's a new menu to the menu stack. This is used for yes/no
       dialoges and such things.*/
   void push_menu (PingusSubMenu * menu);
+
+  static PingusMenuManager* instance ();
 };
 
 #endif

Index: screen.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/screen.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- screen.hxx  2 Jul 2002 16:06:51 -0000       1.3
+++ screen.hxx  1 Aug 2002 21:40:01 -0000       1.4
@@ -20,27 +20,22 @@
 #ifndef HEADER_PINGUS_SCREEN_HXX
 #define HEADER_PINGUS_SCREEN_HXX
 
-#error "Don't used this the moment, its underdevelopment and not compilable"
-
 #include "game_delta.hxx"
 
-namespace Pingus
+/** A interface for screens. A screen is a Pingus 'thing' which gets
+    complete controll over the display and input. Examples of
+    screens are the PingusMenu or a PingusGameSession */
+class Screen
 {
-  /** A interface for screens. A screen is a Pingus 'thing' which gets
-      complete controll over the display and input. Examples of
-      screens are the PingusMenu or a PingusGameSession */
-  class Screen
-  {
-  private:
+private:
     
-  public:
-    /** Draw this screen */
-    void draw () =0;
+public:
+  /** Draw this screen */
+  virtual void draw () =0;
 
-    /** Pass a delta to the screen */
-    void update (const GameDelta& delta) =0;
-  };
-}
+  /** Pass a delta to the screen */
+  virtual void update (const GameDelta& delta) =0;
+};
 
 #endif
 

Index: screen_manager.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/screen_manager.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- screen_manager.cxx  13 Jun 2002 19:53:21 -0000      1.2
+++ screen_manager.cxx  1 Aug 2002 21:40:01 -0000       1.3
@@ -17,12 +17,20 @@
 //  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 "input/controller.hxx"
+#include "delta_manager.hxx"
+#include "game_delta.hxx"
+#include "screen.hxx"
+#include "display.hxx"
+#include "pingus_menu_manager.hxx"
 #include "screen_manager.hxx"
 
-using namespace Pingus;
+ScreenManager* ScreenManager::instance_ = 0;
 
 ScreenManager::ScreenManager ()
 {
+  push_screen (PingusMenuManager::instance (), false);
 }
 
 ScreenManager::~ScreenManager ()
@@ -32,31 +40,73 @@
 void
 ScreenManager::display ()
 {
-  while (screen_stack.size () > 0)
+  Input::Controller input_controller("../doc/mycontroller.xml");
+  DeltaManager delta_manager;
+
+  // Main loop for the menu
+  while (!screens.empty())
     {
-      Screen* screen = screen_stack.top ();
+      Screen* current_screen = screens.back ().first;
+      float time_delta = delta_manager.getset ();
 
-      screen->draw ();
-      screen->update ();
-    }
+      if (time_delta > 1.0)
+       {
+         std::cout << "PingusMenuManager: detected large delta (" << time_delta
+                   << "), ignoring and doing frameskip" << std::endl;
+         continue;
+       }
+
+      GameDelta delta (time_delta, input_controller.get_events ());
+
+      input_controller.update (time_delta);
+
+      CL_System::keep_alive ();
+      current_screen->draw ();
+      current_screen->update (delta);
+
+      Display::flip_display ();
+      // Stupid hack to make this thing take less CPU
+      CL_System::sleep (0);
+    } 
 }
 
-int 
-ScreenManager::number_of_screens ()
+ScreenManager*
+ScreenManager::instance ()
 {
-  return screen_stack.size ();
+  if (instance_)
+    return instance_;
+  else
+    return instance_ = new ScreenManager ();
 }
 
 void
-ScreenManager::push_screen (Screen* screen)
+ScreenManager::push_screen (Screen* screen, bool delete_screen)
 {
-  screen_stack.push (screen);
+  screens.push_back (std::pair<Screen*, bool> (screen, delete_screen));
 }
 
 void
 ScreenManager::pop_screen ()
 {
-  screen_stack.pop ();
+  Screen* current_screen = screens.back ().first;
+  bool    delete_screen  = screens.back ().second;
+
+  if (delete_screen)
+    delete current_screen;
+
+  screens.pop_back ();
+}
+
+void
+ScreenManager::replace_screen (Screen* screen, bool delete_screen)
+{
+  Screen* current_screen = screens.back ().first;
+  bool    delete_c_screen  = screens.back ().second;
+
+  if (delete_c_screen)
+    delete current_screen;
+
+  screens.back () = std::pair<Screen*, bool>(screen, delete_screen);
 }
 
 /* EOF */

Index: screen_manager.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/screen_manager.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- screen_manager.hxx  2 Jul 2002 16:06:51 -0000       1.3
+++ screen_manager.hxx  1 Aug 2002 21:40:01 -0000       1.4
@@ -20,36 +20,39 @@
 #ifndef HEADER_PINGUS_SCREEN_MANAGER_HXX
 #define HEADER_PINGUS_SCREEN_MANAGER_HXX
 
-#error "Don't used this the moment, its underdevelopment and not compilable"
+#include <vector>
 
-namespace Pingus
+class Screen;
+
+class ScreenManager
 {
-  class ScreenManager
-  {
-  private:
-    /** The stack of screens */
-    std::stack<Screen*> screen_stack;
-  public:
-    ScreenManager ();
-    ~ScreenManager ();
+private:
+  static ScreenManager* instance_;
 
-    /** Start the screen manager and let it take controll, this will
-       not return until the screen stack is empty. */
-    void display ();
+  /** Screen stack (first is the screen, second is delete_screen,
+      which tells if the screen should be deleted onces it got poped
+      or replaced) */
+  std::vector<std::pair<Screen*, bool> > screens;
 
-    int number_of_screens ();
+  ScreenManager ();
+public:
+  ~ScreenManager ();
 
-    /** Replace the current screen */
-    void replace_screen (Screen*);
+  /** Start the screen manager and let it take controll, this will
+      not return until the somebody signals a quit() */
+  void display ();
+
+  /** Replace the current screen */
+  void replace_screen (Screen*, bool delete_screen = false);
     
-    /** Add a screen on top of another screen */
-    void push_screen (Screen*);
+  /** Add a screen on top of another screen */
+  void push_screen (Screen*, bool delete_screen = false);
 
-    /** Remove the current screen */
-    void pop_screen ();
-  };
-  
-}
+  /** Remove the current screen and fall back to the last one */
+  void pop_screen ();
+
+  static ScreenManager* instance ();
+};
 
 #endif
 

Index: story.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/story.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- story.cxx   13 Jun 2002 14:25:12 -0000      1.2
+++ story.cxx   1 Aug 2002 21:40:01 -0000       1.3
@@ -21,6 +21,7 @@
 #include <ClanLib/Display/Font/font.h>
 #include "pingus_resource.hxx"
 #include "pingus_menu_manager.hxx"
+#include "screen_manager.hxx"
 #include "worldmap/manager.hxx"
 
 Story::Story(PingusMenuManager* manager)
@@ -118,14 +119,24 @@
 }
 
 void 
-Story::on_button_press (CL_InputDevice* /*device*/,const CL_Key& /*key*/)
+Story::unhandled_event ()
 {
-  manager->disable_events ();
+  // FIXME: Since we havn't yet a button to continue with the story,
+  // we contiune on the first unhandled event (most likly a button
+  // press
+
   // FIXME: This looks ugly... 
-  Pingus::WorldMapManager worldmap_manager;
-  worldmap_manager.display();
-  manager->enable_events ();
+  ScreenManager::instance()->push_screen(Pingus::WorldMapManager::instance ());
+  //worldmap_manager.display();
+  //manager->enable_events ();
   manager->set_menu (&manager->mainmenu);
+}
+
+bool
+Story::is_at (int x, int y)
+{
+  std::cout << "bla" << std::endl; 
+  return true;
 }
 
 /* EOF */

Index: story.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/story.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- story.hxx   29 Jul 2002 22:17:53 -0000      1.3
+++ story.hxx   1 Aug 2002 21:40:01 -0000       1.4
@@ -45,13 +45,15 @@
 
   void preload () { init (); }
 
-  void on_button_press (CL_InputDevice*,const CL_Key &); 
-
   void draw ();
   void update (float delta);
 
   /// Display a string at the right position
   void display_string(std::string);
+
+  bool is_at (int x, int y);
+
+  void unhandled_event ();
 };
 
 #endif

Index: surface_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/surface_button.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- surface_button.cxx  29 Jul 2002 22:29:22 -0000      1.4
+++ surface_button.cxx  1 Aug 2002 21:40:01 -0000       1.5
@@ -334,7 +334,6 @@
 StoryButton::StoryButton (PingusMenu* menu)
   : menu (menu)
 {
-
   // x_pos = CL_Display::get_width() * 150 / 640; 
   // y_pos = CL_Display::get_height() * 430 / 480;
 

Index: surface_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/surface_button.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- surface_button.hxx  29 Jul 2002 22:17:53 -0000      1.4
+++ surface_button.hxx  1 Aug 2002 21:40:01 -0000       1.5
@@ -23,7 +23,6 @@
 #include <string>
 #include <ClanLib/Display/Display/surface.h>
 
-#include "worldmap/manager.hxx"
 #include "multiplayer_config.hxx"
 #include "gui/component.hxx"
 
@@ -123,7 +122,6 @@
 {
 private:
   PingusMenu* menu;
-  Pingus::WorldMapManager worldmap_manager;
 public:
   StoryButton(PingusMenu* menu);
   ~StoryButton();




reply via email to

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