[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r4135 - in trunk/pingus/src: engine engine/system pingus ut
From: |
grumbel |
Subject: |
[Pingus-CVS] r4135 - in trunk/pingus/src: engine engine/system pingus util |
Date: |
Tue, 1 Feb 2011 19:02:31 +0100 |
Author: grumbel
Date: 2011-02-01 19:02:31 +0100 (Tue, 01 Feb 2011)
New Revision: 4135
Added:
trunk/pingus/src/engine/system/
trunk/pingus/src/engine/system/sdl_system.cpp
trunk/pingus/src/engine/system/sdl_system.hpp
trunk/pingus/src/util/raise_exception.cpp
Modified:
trunk/pingus/src/pingus/pingus_main.cpp
trunk/pingus/src/pingus/pingus_main.hpp
trunk/pingus/src/pingus/savegame_manager.cpp
trunk/pingus/src/pingus/savegame_manager.hpp
trunk/pingus/src/pingus/stat_manager.cpp
trunk/pingus/src/pingus/stat_manager.hpp
Log:
Some cleanup in the init code
Added: trunk/pingus/src/engine/system/sdl_system.cpp
===================================================================
--- trunk/pingus/src/engine/system/sdl_system.cpp
(rev 0)
+++ trunk/pingus/src/engine/system/sdl_system.cpp 2011-02-01 18:02:31 UTC
(rev 4135)
@@ -0,0 +1,52 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include "engine/system/sdl_system.hpp"
+
+#include <iostream>
+
+#include "config.h"
+#include "engine/display/display.hpp"
+#include "math/size.hpp"
+
+SDLSystem::SDLSystem()
+{
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0)
+ {
+ std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
+ exit(1);
+ }
+ else
+ {
+ atexit(SDL_Quit);
+ }
+}
+
+SDLSystem::~SDLSystem()
+{
+}
+
+void
+SDLSystem::init_display(const Size& size, bool fullscreen)
+{
+ Display::set_video_mode(size, fullscreen);
+
+ SDL_WM_SetCaption("Pingus " VERSION " - SDL Edition", 0 /* icon */);
+
+ SDL_EnableUNICODE(1);
+}
+
+/* EOF */
Property changes on: trunk/pingus/src/engine/system/sdl_system.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/pingus/src/engine/system/sdl_system.hpp
===================================================================
--- trunk/pingus/src/engine/system/sdl_system.hpp
(rev 0)
+++ trunk/pingus/src/engine/system/sdl_system.hpp 2011-02-01 18:02:31 UTC
(rev 4135)
@@ -0,0 +1,40 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_PINGUS_ENGINE_SYSTEM_SDL_HPP
+#define HEADER_PINGUS_ENGINE_SYSTEM_SDL_HPP
+
+#include <SDL.h>
+
+class Size;
+
+class SDLSystem
+{
+private:
+public:
+ SDLSystem();
+ ~SDLSystem();
+
+ void init_display(const Size& size, bool fullscreen);
+
+private:
+ SDLSystem(const SDLSystem&);
+ SDLSystem& operator=(const SDLSystem&);
+};
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/engine/system/sdl_system.hpp
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/pingus/src/pingus/pingus_main.cpp
===================================================================
--- trunk/pingus/src/pingus/pingus_main.cpp 2011-02-01 18:01:58 UTC (rev
4134)
+++ trunk/pingus/src/pingus/pingus_main.cpp 2011-02-01 18:02:31 UTC (rev
4135)
@@ -21,6 +21,7 @@
#include "editor/editor_level.hpp"
#include "engine/display/display.hpp"
+#include "engine/system/sdl_system.hpp"
#include "pingus/config_manager.hpp"
#include "pingus/screens/demo_session.hpp"
#include "pingus/screens/pingus_menu.hpp"
@@ -706,8 +707,21 @@
print_greeting_message();
- init_sdl();
- init_pingus();
+ SDLSystem system;
+ if (cmd_options.geometry.is_set())
+ {
+ system.init_display(cmd_options.geometry.get(),
globals::fullscreen_enabled);
+ }
+ else
+ {
+ system.init_display(Size(800, 600), globals::fullscreen_enabled);
+ }
+
+ SavegameManager savegame_manager("savegames/savegames.scm");
+ StatManager stat_manager("savegames/variables.scm");
+ Resource::init();
+ Fonts::init();
+ Sound::PingusSound::init();
// start and run the actual game
start_game();
@@ -716,71 +730,28 @@
{
std::cout << _("Pingus: Out of memory!") << std::endl;
}
-
- catch (const std::exception& a) {
+ catch (const std::exception& a)
+ {
std::cout << _("Pingus: Standard exception caught!:\n") << a.what() <<
std::endl;
}
-
- catch (...) {
+ catch (...)
+ {
std::cout << _("Pingus: Unknown throw caught!") << std::endl;
}
- deinit_pingus();
+ Sound::PingusSound::deinit();
+ Fonts::deinit();
+ WorldObjFactory::deinit();
+ Resource::deinit();
return 0;
}
void
-PingusMain::init_sdl()
-{
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) {
- std::cout << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
- exit(1);
- }
- atexit(SDL_Quit);
-
- Size screen_size(800,600);
- if (cmd_options.geometry.is_set())
- screen_size = cmd_options.geometry.get();
-
- Display::set_video_mode(screen_size, globals::fullscreen_enabled);
-
- SDL_WM_SetCaption("Pingus " VERSION " - SDL Edition", 0 /* icon */);
-
- SDL_EnableUNICODE(1);
-}
-
-void
-PingusMain::deinit_sdl()
-{
-}
-
-void
PingusMain::on_exit_press()
{
std::cout << "Exit pressed" << std::endl;
ScreenManager::instance()->pop_all_screens();
}
-void
-PingusMain::init_pingus()
-{
- SavegameManager::instance();
- StatManager::init();
- Resource::init();
- Fonts::init();
- Sound::PingusSound::init();
-}
-
-void
-PingusMain::deinit_pingus()
-{
- Fonts::deinit();
- Sound::PingusSound::deinit();
- WorldObjFactory::deinit();
- StatManager::deinit();
- SavegameManager::deinit();
- Resource::deinit();
-}
-
/* EOF */
Modified: trunk/pingus/src/pingus/pingus_main.hpp
===================================================================
--- trunk/pingus/src/pingus/pingus_main.hpp 2011-02-01 18:01:58 UTC (rev
4134)
+++ trunk/pingus/src/pingus/pingus_main.hpp 2011-02-01 18:02:31 UTC (rev
4135)
@@ -46,12 +46,7 @@
void print_greeting_message();
- void init_sdl();
- void deinit_sdl();
-
- void init_pingus();
void init_path_finder();
- void deinit_pingus();
PingusMain (const PingusMain&);
PingusMain& operator= (const PingusMain&);
Modified: trunk/pingus/src/pingus/savegame_manager.cpp
===================================================================
--- trunk/pingus/src/pingus/savegame_manager.cpp 2011-02-01 18:01:58 UTC
(rev 4134)
+++ trunk/pingus/src/pingus/savegame_manager.cpp 2011-02-01 18:02:31 UTC
(rev 4135)
@@ -28,22 +28,17 @@
SavegameManager*
SavegameManager::instance()
{
- if (instance_)
- return instance_;
- else
- return (instance_ = new SavegameManager("savegames/savegames.scm"));
+ assert(instance_);
+ return instance_;
}
-void SavegameManager::deinit()
-{
- delete instance_;
- instance_ = 0;
-}
-
SavegameManager::SavegameManager(const std::string& arg_filename) :
filename(System::get_userdir() + arg_filename),
savegames()
{
+ assert(instance_ == 0);
+ instance_ = this;
+
boost::shared_ptr<lisp::Lisp> sexpr;
try
@@ -93,6 +88,8 @@
{
for (SavegameTable::iterator i = savegames.begin(); i != savegames.end ();
++i)
delete *i;
+
+ instance_ = 0;
}
Savegame*
Modified: trunk/pingus/src/pingus/savegame_manager.hpp
===================================================================
--- trunk/pingus/src/pingus/savegame_manager.hpp 2011-02-01 18:01:58 UTC
(rev 4134)
+++ trunk/pingus/src/pingus/savegame_manager.hpp 2011-02-01 18:02:31 UTC
(rev 4135)
@@ -32,7 +32,6 @@
public:
static SavegameManager* instance();
- static void deinit();
SavegameManager(const std::string& filename);
~SavegameManager();
Modified: trunk/pingus/src/pingus/stat_manager.cpp
===================================================================
--- trunk/pingus/src/pingus/stat_manager.cpp 2011-02-01 18:01:58 UTC (rev
4134)
+++ trunk/pingus/src/pingus/stat_manager.cpp 2011-02-01 18:02:31 UTC (rev
4135)
@@ -29,26 +29,10 @@
StatManager*
StatManager::instance()
{
- if (instance_)
- return instance_;
- else
- return (instance_ = new StatManager("savegames/variables.scm"));
+ assert(instance_);
+ return instance_;
}
-void
-StatManager::init()
-{
- StatManager::instance();
-}
-
-void
-StatManager::deinit()
-{
- instance()->flush();
- delete instance_;
- instance_ = 0;
-}
-
std::string
StatManager::get_resname(const std::string& filename)
{
@@ -64,16 +48,21 @@
}
return str;
}
-
+
StatManager::StatManager(const std::string& arg_filename)
: statfilename(System::get_userdir() + arg_filename),
stats()
{
load(statfilename);
+
+ assert(instance_ == 0);
+ instance_ = this;
}
StatManager::~StatManager()
{
+ flush();
+ instance_ = 0;
}
void
Modified: trunk/pingus/src/pingus/stat_manager.hpp
===================================================================
--- trunk/pingus/src/pingus/stat_manager.hpp 2011-02-01 18:01:58 UTC (rev
4134)
+++ trunk/pingus/src/pingus/stat_manager.hpp 2011-02-01 18:02:31 UTC (rev
4135)
@@ -32,13 +32,12 @@
public:
static StatManager* instance();
- static void init();
- static void deinit();
/** Returns the resource name of a worldmap - strips out everything except
after
the last '/' in the full path + filename, and converts periods to dashes
*/
static std::string get_resname(const std::string& filename);
+public:
StatManager(const std::string& filename);
~StatManager();
Added: trunk/pingus/src/util/raise_exception.cpp
===================================================================
--- trunk/pingus/src/util/raise_exception.cpp (rev 0)
+++ trunk/pingus/src/util/raise_exception.cpp 2011-02-01 18:02:31 UTC (rev
4135)
@@ -0,0 +1,38 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include "util/raise_exception.hpp"
+
+std::string log_pretty_print(const std::string& str)
+{
+ // FIXME: very basic, might not work with complex return types
+ std::string::size_type function_start = 0;
+ for(std::string::size_type i = 0; i < str.size(); ++i)
+ {
+ if (str[i] == ' ')
+ {
+ function_start = i+1;
+ }
+ else if (str[i] == '(')
+ {
+ return str.substr(function_start, i - function_start) + "()";
+ }
+ }
+
+ return str.substr(function_start);
+}
+
+/* EOF */
Property changes on: trunk/pingus/src/util/raise_exception.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r4135 - in trunk/pingus/src: engine engine/system pingus util,
grumbel <=