From: Ingo Ruhnke Date: Thu, 19 Nov 2009 18:29:12 +0000 (+0000) Subject: Move some more globals to supertux/globals.hpp X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=78bd3d0cb3619297dcab7a9763b40a1da4c6cda2;p=supertux.git Move some more globals to supertux/globals.hpp SVN-Revision: 6055 --- diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 245feac38..fa2fad434 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -36,8 +36,6 @@ #include "scripting/squirrel_util.hpp" #include "scripting/time_scheduler.hpp" -extern float g_game_speed; - namespace Scripting { SQInteger display(HSQUIRRELVM vm) @@ -89,7 +87,7 @@ void abort_screenfade() std::string translate(const std::string& text) { - return dictionary_manager.get_dictionary().translate(text); + return dictionary_manager->get_dictionary().translate(text); } void display_text_file(const std::string& filename) diff --git a/src/sprite/sprite_manager.cpp b/src/sprite/sprite_manager.cpp index 0ef214a20..eab67111e 100644 --- a/src/sprite/sprite_manager.cpp +++ b/src/sprite/sprite_manager.cpp @@ -21,8 +21,6 @@ #include "util/file_system.hpp" #include "util/reader.hpp" -SpriteManager* sprite_manager = NULL; - SpriteManager::SpriteManager() : sprites() { diff --git a/src/sprite/sprite_manager.hpp b/src/sprite/sprite_manager.hpp index d6f5a8803..520da88ff 100644 --- a/src/sprite/sprite_manager.hpp +++ b/src/sprite/sprite_manager.hpp @@ -41,8 +41,6 @@ private: SpriteData* load(const std::string& filename); }; -extern SpriteManager* sprite_manager; - #endif /* EOF */ diff --git a/src/supertux/globals.cpp b/src/supertux/globals.cpp index a89efb1e1..44359595e 100644 --- a/src/supertux/globals.cpp +++ b/src/supertux/globals.cpp @@ -19,7 +19,7 @@ SDL_Surface* g_screen; JoystickKeyboardController* g_main_controller = 0; -tinygettext::DictionaryManager dictionary_manager; +tinygettext::DictionaryManager* dictionary_manager = 0; int SCREEN_WIDTH; int SCREEN_HEIGHT; @@ -35,4 +35,11 @@ Config* g_config = 0; float game_time = 0; float real_time = 0; +TileManager* tile_manager = NULL; +TileSet* current_tileset = NULL; + +SpriteManager* sprite_manager = NULL; + +float g_game_speed = 1.0f; + /* EOF */ diff --git a/src/supertux/globals.hpp b/src/supertux/globals.hpp index 86a62b4a4..f6b9dfc8a 100644 --- a/src/supertux/globals.hpp +++ b/src/supertux/globals.hpp @@ -17,13 +17,17 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_GLOBALS_HPP #define HEADER_SUPERTUX_SUPERTUX_GLOBALS_HPP -#include - +typedef struct SDL_Surface SDL_Surface; +namespace tinygettext { class DictionaryManager; } class Config; class JoystickKeyboardController; -class SoundManager; +class PlayerStatus; class ScreenManager; +class SoundManager; +class SpriteManager; class TextureManager; +class TileManager; +class TileSet; /** The width of the display (this is a logical value, not the physical value, since aspect_ration and projection_area might @@ -48,9 +52,23 @@ extern SoundManager* sound_manager; extern Config* g_config; +extern tinygettext::DictionaryManager* dictionary_manager; + extern float game_time; extern float real_time; +extern TileManager *tile_manager; + +/** this is only set while loading a map */ +extern TileSet *current_tileset; + +// global player state +extern PlayerStatus* player_status; + +extern SpriteManager* sprite_manager; + +extern float g_game_speed; + #endif /* EOF */ diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index d4c4f4679..bef5b08cb 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -66,15 +66,17 @@ Main::init_config() void Main::init_tinygettext() { + dictionary_manager = new tinygettext::DictionaryManager(); tinygettext::Log::set_log_info_callback(0); - dictionary_manager.set_filesystem(std::auto_ptr(new PhysFSFileSystem)); + dictionary_manager->set_filesystem(std::auto_ptr(new PhysFSFileSystem)); - dictionary_manager.add_directory("locale"); - dictionary_manager.set_charset("UTF-8"); + dictionary_manager->add_directory("locale"); + dictionary_manager->set_charset("UTF-8"); // Config setting "locale" overrides language detection - if (g_config->locale != "") { - dictionary_manager.set_language(tinygettext::Language::from_name(g_config->locale)); + if (g_config->locale != "") + { + dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); } } diff --git a/src/supertux/menu/language_menu.cpp b/src/supertux/menu/language_menu.cpp index 5b1fef398..136a28468 100644 --- a/src/supertux/menu/language_menu.cpp +++ b/src/supertux/menu/language_menu.cpp @@ -39,7 +39,7 @@ LanguageMenu::LanguageMenu() add_entry(MNID_LANGUAGE_ENGLISH, "English"); int mnid = MNID_LANGUAGE_NEXT; - std::set languages = dictionary_manager.get_languages(); + std::set languages = dictionary_manager->get_languages(); for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { add_entry(mnid++, i->get_name()); @@ -59,7 +59,7 @@ LanguageMenu::menu_action(MenuItem* item) tinygettext::Language language = tinygettext::Language::from_spec(locale->lang, locale->country, locale->variant); FL_FreeLocale(&locale); - dictionary_manager.set_language(language); + dictionary_manager->set_language(language); g_config->locale = language.str(); g_config->save(); MenuManager::pop_current(); @@ -67,21 +67,21 @@ LanguageMenu::menu_action(MenuItem* item) else if (item->id == MNID_LANGUAGE_ENGLISH) // english { g_config->locale = "en"; - dictionary_manager.set_language(tinygettext::Language::from_name(g_config->locale)); + dictionary_manager->set_language(tinygettext::Language::from_name(g_config->locale)); g_config->save(); MenuManager::pop_current(); } else { int mnid = MNID_LANGUAGE_NEXT; - std::set languages = dictionary_manager.get_languages(); + std::set languages = dictionary_manager->get_languages(); for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { if (item->id == mnid++) { g_config->locale = i->str(); - dictionary_manager.set_language(*i); + dictionary_manager->set_language(*i); g_config->save(); MenuManager::pop_current(); break; diff --git a/src/supertux/player_status.hpp b/src/supertux/player_status.hpp index 454ac1706..3f46b5381 100644 --- a/src/supertux/player_status.hpp +++ b/src/supertux/player_status.hpp @@ -66,9 +66,6 @@ private: PlayerStatus& operator=(const PlayerStatus&); }; -// global player state -extern PlayerStatus* player_status; - #endif /* EOF */ diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index d43ce30e0..011d9bc0f 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -40,8 +40,6 @@ static const Uint32 TICKS_PER_FRAME = (Uint32) (1000.0 / LOGICAL_FPS); /** don't skip more than every 2nd frame */ static const int MAX_FRAME_SKIP = 2; -float g_game_speed = 1.0f; - ScreenManager::ScreenManager() : waiting_threads(), running(), diff --git a/src/supertux/tile_manager.cpp b/src/supertux/tile_manager.cpp index 926693204..ac31395e0 100644 --- a/src/supertux/tile_manager.cpp +++ b/src/supertux/tile_manager.cpp @@ -23,9 +23,6 @@ #include "lisp/list_iterator.hpp" #include "supertux/tile_set.hpp" -TileManager* tile_manager = NULL; -TileSet* current_tileset = NULL; - TileManager::TileManager() : tilesets() { diff --git a/src/supertux/tile_manager.hpp b/src/supertux/tile_manager.hpp index c93a039b1..8d081ee36 100644 --- a/src/supertux/tile_manager.hpp +++ b/src/supertux/tile_manager.hpp @@ -39,10 +39,6 @@ public: TileSet* parse_tileset_definition(const Reader& reader); }; -extern TileManager *tile_manager; -/** this is only set while loading a map */ -extern TileSet *current_tileset; - #endif /* EOF */ diff --git a/src/util/gettext.hpp b/src/util/gettext.hpp index 876ce03d2..4a84f243f 100644 --- a/src/util/gettext.hpp +++ b/src/util/gettext.hpp @@ -17,18 +17,33 @@ #ifndef HEADER_SUPERTUX_UTIL_GETTEXT_HPP #define HEADER_SUPERTUX_UTIL_GETTEXT_HPP -#include "tinygettext/tinygettext.hpp" +#include +#include -extern tinygettext::DictionaryManager dictionary_manager; +#include "supertux/globals.hpp" static inline const char* _(const char* message) { - return dictionary_manager.get_dictionary().translate(message); + if (dictionary_manager) + { + return dictionary_manager->get_dictionary().translate(message); + } + else + { + return message; + } } static inline std::string _(const std::string& message) { - return dictionary_manager.get_dictionary().translate(message); + if (dictionary_manager) + { + return dictionary_manager->get_dictionary().translate(message); + } + else + { + return message; + } } #endif /* _LIBGETTEXT_H */