Made Console into a Currenton
authorIngo Ruhnke <grumbel@gmail.com>
Sun, 17 Aug 2014 17:05:07 +0000 (19:05 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Sun, 17 Aug 2014 20:34:30 +0000 (22:34 +0200)
src/control/keyboard_manager.cpp
src/supertux/console.cpp
src/supertux/console.hpp
src/supertux/main.cpp
src/supertux/screen_manager.cpp
src/util/log.cpp

index 0fe55b6..32c947a 100644 (file)
@@ -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;
index 523ffd7..8686390 100644 (file)
@@ -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;
index 9c60898..e8599ca 100644 (file)
@@ -23,6 +23,7 @@
 #include <sstream>
 #include <vector>
 
+#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<Console>
 {
 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;
   }
 };
index 376e5ee..7054f37 100644 (file)
@@ -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;
index ea716ce..f680e7a 100644 (file)
@@ -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();
         }
index cb8ed6d..0b30709 100644 (file)
@@ -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);