From be53843f506b5f2b1990452b07122e3775a54cde Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 17 Aug 2014 19:05:07 +0200 Subject: [PATCH] Made Console into a Currenton --- src/control/keyboard_manager.cpp | 30 +++++++++++++++--------------- src/supertux/console.cpp | 1 - src/supertux/console.hpp | 9 ++++----- src/supertux/main.cpp | 6 ++---- src/supertux/screen_manager.cpp | 6 +++--- src/util/log.cpp | 2 +- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/control/keyboard_manager.cpp b/src/control/keyboard_manager.cpp index 0fe55b68a..32c947a43 100644 --- a/src/control/keyboard_manager.cpp +++ b/src/control/keyboard_manager.cpp @@ -69,10 +69,10 @@ KeyboardManager::process_key_event(const SDL_KeyboardEvent& event) { if (event.type == SDL_KEYDOWN) { - Console::instance->toggle(); + Console::current()->toggle(); } } - else if (Console::instance->hasFocus()) + else if (Console::current()->hasFocus()) { // if console is open: send key there process_console_key_event(event); @@ -102,10 +102,10 @@ KeyboardManager::process_key_event(const SDL_KeyboardEvent& event) void KeyboardManager::process_text_input_event(const SDL_TextInputEvent& event) { - if (Console::instance->hasFocus()) { + if (Console::current()->hasFocus()) { for(int i = 0; event.text[i] != '\0'; ++i) { - Console::instance->input(event.text[i]); + Console::current()->input(event.text[i]); } } } @@ -117,37 +117,37 @@ KeyboardManager::process_console_key_event(const SDL_KeyboardEvent& event) switch (event.keysym.sym) { case SDLK_RETURN: - Console::instance->enter(); + Console::current()->enter(); break; case SDLK_BACKSPACE: - Console::instance->backspace(); + Console::current()->backspace(); break; case SDLK_TAB: - Console::instance->autocomplete(); + Console::current()->autocomplete(); break; case SDLK_PAGEUP: - Console::instance->scroll(-1); + Console::current()->scroll(-1); break; case SDLK_PAGEDOWN: - Console::instance->scroll(+1); + Console::current()->scroll(+1); break; case SDLK_HOME: - Console::instance->move_cursor(-65535); + Console::current()->move_cursor(-65535); break; case SDLK_END: - Console::instance->move_cursor(+65535); + Console::current()->move_cursor(+65535); break; case SDLK_UP: - Console::instance->show_history(-1); + Console::current()->show_history(-1); break; case SDLK_DOWN: - Console::instance->show_history(+1); + Console::current()->show_history(+1); break; case SDLK_LEFT: - Console::instance->move_cursor(-1); + Console::current()->move_cursor(-1); break; case SDLK_RIGHT: - Console::instance->move_cursor(+1); + Console::current()->move_cursor(+1); break; default: break; diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index 523ffd766..86863903b 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -522,7 +522,6 @@ Console::draw(DrawingContext& context) context.pop_transform(); } -Console* Console::instance = NULL; int Console::inputBufferPosition = 0; std::string Console::inputBuffer; ConsoleStreamBuffer Console::outputBuffer; diff --git a/src/supertux/console.hpp b/src/supertux/console.hpp index 9c608986f..e8599cac2 100644 --- a/src/supertux/console.hpp +++ b/src/supertux/console.hpp @@ -23,6 +23,7 @@ #include #include +#include "util/currenton.hpp" #include "video/font_ptr.hpp" #include "video/surface_ptr.hpp" @@ -31,14 +32,12 @@ class ConsoleStreamBuffer; class ConsoleCommandReceiver; class DrawingContext; -class Console +class Console : public Currenton { public: Console(); ~Console(); - static Console* instance; - static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */ void init_graphics(); @@ -113,8 +112,8 @@ public: int sync() { int result = std::stringbuf::sync(); - if(Console::instance != NULL) - Console::instance->flush(this); + if(Console::current()) + Console::current()->flush(this); return result; } }; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 376e5ee6e..7054f37ce 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -328,7 +328,7 @@ Main::run(int argc, char** argv) } init_sdl(); - Console::instance = new Console(); + Console console; timelog("controller"); g_input_manager = new InputManager(); @@ -345,7 +345,7 @@ Main::run(int argc, char** argv) timelog("audio"); init_audio(); - Console::instance->init_graphics(); + Console::current()->init_graphics(); timelog("scripting"); scripting::init_squirrel(g_config->enable_script_debugger); @@ -421,8 +421,6 @@ Main::run(int argc, char** argv) g_config = NULL; delete g_input_manager; g_input_manager = NULL; - delete Console::instance; - Console::instance = NULL; scripting::exit_squirrel(); delete texture_manager; texture_manager = NULL; diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index ea716ce9d..f680e7a7b 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -137,7 +137,7 @@ ScreenManager::draw(DrawingContext& context) m_screen_fade->draw(context); } - Console::instance->draw(context); + Console::current()->draw(context); if (g_config->show_fps) { @@ -184,7 +184,7 @@ ScreenManager::update_gamelogic(float elapsed_time) m_screen_fade->update(elapsed_time); } - Console::instance->update(elapsed_time); + Console::current()->update(elapsed_time); } void @@ -234,7 +234,7 @@ ScreenManager::process_events() else if (event.key.keysym.sym == SDLK_F1 && event.key.keysym.mod & KMOD_CTRL) { - Console::instance->toggle(); + Console::current()->toggle(); g_config->console_enabled = true; g_config->save(); } diff --git a/src/util/log.cpp b/src/util/log.cpp index cb8ed6db7..0b30709ac 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -26,7 +26,7 @@ LogLevel g_log_level = LOG_WARNING; static std::ostream& get_logging_instance (void) { - if (Console::instance != NULL) + if (Console::current()) return (Console::output); else return (std::cerr); -- 2.11.0