From: Ingo Ruhnke Date: Sun, 17 Aug 2014 21:52:12 +0000 (+0200) Subject: Turned AddonManager into a Currenton X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1ca7a41254b95a52083b63496b8a18048ee55253;p=supertux.git Turned AddonManager into a Currenton There is currently a bit of a dependency problem between InputManager, AddonManager and Config reading that prevents reading of config on startup. --- diff --git a/src/addon/addon_manager.cpp b/src/addon/addon_manager.cpp index c614ddffa..70877b58b 100644 --- a/src/addon/addon_manager.cpp +++ b/src/addon/addon_manager.cpp @@ -61,13 +61,6 @@ size_t my_curl_physfs_write(void *ptr, size_t size, size_t nmemb, void *f_p) } #endif -AddonManager& -AddonManager::get_instance() -{ - static AddonManager instance; - return instance; -} - AddonManager::AddonManager() : addons(), ignored_addon_filenames() diff --git a/src/addon/addon_manager.hpp b/src/addon/addon_manager.hpp index 3cebc8c1d..22a2db19c 100644 --- a/src/addon/addon_manager.hpp +++ b/src/addon/addon_manager.hpp @@ -20,6 +20,7 @@ #include #include +#include "util/currenton.hpp" #include "util/reader_fwd.hpp" #include "util/writer_fwd.hpp" @@ -28,9 +29,12 @@ class Addon; /** * Checks for, installs and removes Add-ons */ -class AddonManager +class AddonManager : public Currenton { public: + AddonManager(); + ~AddonManager(); + /** * returns a list of installed Add-ons */ @@ -77,11 +81,6 @@ public: void load_addons(); /** - * Returns the shared AddonManager instance - */ - static AddonManager& get_instance(); - - /** * Write AddonManager configuration to Lisp */ void write(Writer& writer); @@ -91,12 +90,9 @@ public: */ void read(const Reader& lisp); -protected: +private: std::vector addons; std::vector ignored_addon_filenames; - - AddonManager(); - ~AddonManager(); }; #endif diff --git a/src/supertux/gameconfig.cpp b/src/supertux/gameconfig.cpp index f7fa917c3..8df30bba1 100644 --- a/src/supertux/gameconfig.cpp +++ b/src/supertux/gameconfig.cpp @@ -39,7 +39,7 @@ Config::Config() : sound_enabled(true), music_enabled(true), console_enabled(false), - random_seed(0), // set by time(), by default (unless in config) + random_seed(0), // set by time(), by default (unless in config) start_level(), enable_script_debugger(false), start_demo(), @@ -59,7 +59,9 @@ Config::load() const lisp::Lisp* config_lisp = root->get_lisp("supertux-config"); if(!config_lisp) + { throw std::runtime_error("File is not a supertux-config file"); + } config_lisp->get("profile", profile); config_lisp->get("show_fps", show_fps); @@ -68,7 +70,8 @@ Config::load() config_lisp->get("random_seed", random_seed); const lisp::Lisp* config_video_lisp = config_lisp->get_lisp("video"); - if(config_video_lisp) { + if(config_video_lisp) + { config_video_lisp->get("fullscreen", use_fullscreen); std::string video_string; config_video_lisp->get("video", video_string); @@ -95,13 +98,15 @@ Config::load() } const lisp::Lisp* config_control_lisp = config_lisp->get_lisp("control"); - if(config_control_lisp && InputManager::current()) { + if(config_control_lisp && InputManager::current()) + { InputManager::current()->read(*config_control_lisp); } const lisp::Lisp* config_addons_lisp = config_lisp->get_lisp("addons"); - if(config_addons_lisp) { - AddonManager::get_instance().read(*config_addons_lisp); + if(config_addons_lisp && AddonManager::current()) + { + AddonManager::current()->read(*config_addons_lisp); } } @@ -141,15 +146,19 @@ Config::save() writer.write("music_enabled", music_enabled); writer.end_list("audio"); - if(InputManager::current()) { + if (InputManager::current()) + { writer.start_list("control"); InputManager::current()->write(writer); writer.end_list("control"); } - writer.start_list("addons"); - AddonManager::get_instance().write(writer); - writer.end_list("addons"); + if (AddonManager::current()) + { + writer.start_list("addons"); + AddonManager::current()->write(writer); + writer.end_list("addons"); + } writer.end_list("supertux-config"); } diff --git a/src/supertux/gameconfig.hpp b/src/supertux/gameconfig.hpp index c26e5a5c6..ee032d45a 100644 --- a/src/supertux/gameconfig.hpp +++ b/src/supertux/gameconfig.hpp @@ -31,10 +31,10 @@ public: int profile; - // the width/height to be used to display the game in fullscreen + /** the width/height to be used to display the game in fullscreen */ Size fullscreen_size; - // refresh rate for use in fullscreen, 0 for auto + /** refresh rate for use in fullscreen, 0 for auto */ int fullscreen_refresh_rate; /** the width/height of the window managers window */ @@ -53,7 +53,8 @@ public: bool music_enabled; bool console_enabled; - int random_seed; // initial random seed. 0 ==> set from time() + /** initial random seed. 0 ==> set from time() */ + int random_seed; /** this variable is set if supertux should start in a specific level */ std::string start_level; @@ -61,7 +62,10 @@ public: std::string start_demo; std::string record_demo; - std::string locale; /**< force SuperTux language to this locale, e.g. "de". A file "data/locale/xx.po" must exist for this to work. An empty string means autodetect. */ + /** force SuperTux language to this locale, e.g. "de". A file + "data/locale/xx.po" must exist for this to work. An empty string + means autodetect. */ + std::string locale; }; #endif diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index b1e75632f..5fc1db113 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -309,7 +309,8 @@ Main::launch_game() Resources resources; timelog("addons"); - AddonManager::get_instance().load_addons(); + AddonManager addon_manager; + addon_manager.load_addons(); timelog(0); diff --git a/src/supertux/menu/addon_menu.cpp b/src/supertux/menu/addon_menu.cpp index a32d78311..8ec3f4bc8 100644 --- a/src/supertux/menu/addon_menu.cpp +++ b/src/supertux/menu/addon_menu.cpp @@ -46,7 +46,7 @@ AddonMenu::refresh() { clear(); - AddonManager& adm = AddonManager::get_instance(); + AddonManager& adm = *AddonManager::current(); // refresh list of addons m_addons = adm.get_addons(); @@ -134,7 +134,7 @@ AddonMenu::menu_action(MenuItem* item) { try { - AddonManager::get_instance().check_online(); + AddonManager::current()->check_online(); refresh(); set_active_item(index); } @@ -153,7 +153,7 @@ AddonMenu::menu_action(MenuItem* item) { try { - AddonManager::get_instance().install(&addon); + AddonManager::current()->install(&addon); } catch (std::exception& e) { @@ -165,7 +165,7 @@ AddonMenu::menu_action(MenuItem* item) { try { - AddonManager::get_instance().enable(&addon); + AddonManager::current()->enable(&addon); } catch (std::exception& e) { @@ -177,7 +177,7 @@ AddonMenu::menu_action(MenuItem* item) { try { - AddonManager::get_instance().disable(&addon); + AddonManager::current()->disable(&addon); } catch (std::exception& e) {