diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2015-04-03 00:48:56 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2015-04-03 01:07:01 +0200 |
commit | 82cc9c0cf2cdb8de17233a2ea943a5247d5da305 (patch) | |
tree | af341aed11c15ac3ab54de6c62e56251c859d76f /src/menu/application.cpp | |
parent | 263ef7f8c7085b90f8d21e3dfc2598ed7340e73d (diff) | |
download | usdx-82cc9c0cf2cdb8de17233a2ea943a5247d5da305.tar.gz usdx-82cc9c0cf2cdb8de17233a2ea943a5247d5da305.tar.xz usdx-82cc9c0cf2cdb8de17233a2ea943a5247d5da305.zip |
menu/application: Remove singleton.
The singleton pattern should not be used in most cases, because it
behaves like global variables.
Diffstat (limited to 'src/menu/application.cpp')
-rw-r--r-- | src/menu/application.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/src/menu/application.cpp b/src/menu/application.cpp index 92e6b8a8..520ea27f 100644 --- a/src/menu/application.cpp +++ b/src/menu/application.cpp @@ -41,14 +41,19 @@ namespace usdx log4cpp::Category& Application::log = log4cpp::Category::getInstance("usdx.menu.application"); - Application* Application::instance = NULL; + Config* Application::config = NULL; - Application::Application(Container* parent) - : Container(parent), config(NULL), display(NULL), fps_manager(NULL), + boost::thread::id Application::gl_thread; + + Application::Application(void) + : Container(NULL), display(NULL), fps_manager(NULL), running(false), frames_per_second(50) { log4cpp::PropertyConfigurator::configure("log4cpp.property"); - config = new Config(); + + if (config == NULL) { + config = new Config(); + } set_size(config->get_graphics_resolution()); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); @@ -67,41 +72,23 @@ namespace usdx } SDL_Quit(); - - // reset instance to be able to recreate the singleton - instance = NULL; - } - - Application* Application::get_instance(void) - { - if (! instance) { - instance = new Application(NULL); - } - - return instance; - } - - void Application::free(void) - { - delete instance; - instance = NULL; } Config* Application::get_config(void) { - return get_instance()->config; + return config; } bool Application::is_gl_thread(void) { - return boost::this_thread::get_id() == get_instance()->gl_thread; + return boost::this_thread::get_id() == gl_thread; } void Application::main_loop(SDL_Surface* display) { SDL_Event event; EventManager event_manager; - MouseManager mouse_manager(event_manager); + MouseManager mouse_manager(this, event_manager); event_thread = boost::thread(boost::bind(&EventManager::handle_events, &event_manager)); SoftwareMousePointer pointer(this, &event_manager); |