Skip to content

Commit

Permalink
Turned AddonManager into a Currenton
Browse files Browse the repository at this point in the history
There is currently a bit of a dependency problem between InputManager,
AddonManager and Config reading that prevents reading of config on
startup.
  • Loading branch information
Grumbel committed Aug 17, 2014
1 parent 4e70d57 commit 1ca7a41
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
7 changes: 0 additions & 7 deletions src/addon/addon_manager.cpp
Expand Up @@ -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()
Expand Down
16 changes: 6 additions & 10 deletions src/addon/addon_manager.hpp
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <vector>

#include "util/currenton.hpp"
#include "util/reader_fwd.hpp"
#include "util/writer_fwd.hpp"

Expand All @@ -28,9 +29,12 @@ class Addon;
/**
* Checks for, installs and removes Add-ons
*/
class AddonManager
class AddonManager : public Currenton<AddonManager>
{
public:
AddonManager();
~AddonManager();

/**
* returns a list of installed Add-ons
*/
Expand Down Expand Up @@ -76,11 +80,6 @@ class AddonManager
*/
void load_addons();

/**
* Returns the shared AddonManager instance
*/
static AddonManager& get_instance();

/**
* Write AddonManager configuration to Lisp
*/
Expand All @@ -91,12 +90,9 @@ class AddonManager
*/
void read(const Reader& lisp);

protected:
private:
std::vector<Addon*> addons;
std::vector<std::string> ignored_addon_filenames;

AddonManager();
~AddonManager();
};

#endif
Expand Down
27 changes: 18 additions & 9 deletions src/supertux/gameconfig.cpp
Expand Up @@ -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(),
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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");
}
Expand Down
12 changes: 8 additions & 4 deletions src/supertux/gameconfig.hpp
Expand Up @@ -31,10 +31,10 @@ class Config

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 */
Expand All @@ -53,15 +53,19 @@ class Config
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;
bool enable_script_debugger;
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
Expand Down
3 changes: 2 additions & 1 deletion src/supertux/main.cpp
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/supertux/menu/addon_menu.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -134,7 +134,7 @@ AddonMenu::menu_action(MenuItem* item)
{
try
{
AddonManager::get_instance().check_online();
AddonManager::current()->check_online();
refresh();
set_active_item(index);
}
Expand All @@ -153,7 +153,7 @@ AddonMenu::menu_action(MenuItem* item)
{
try
{
AddonManager::get_instance().install(&addon);
AddonManager::current()->install(&addon);
}
catch (std::exception& e)
{
Expand All @@ -165,7 +165,7 @@ AddonMenu::menu_action(MenuItem* item)
{
try
{
AddonManager::get_instance().enable(&addon);
AddonManager::current()->enable(&addon);
}
catch (std::exception& e)
{
Expand All @@ -177,7 +177,7 @@ AddonMenu::menu_action(MenuItem* item)
{
try
{
AddonManager::get_instance().disable(&addon);
AddonManager::current()->disable(&addon);
}
catch (std::exception& e)
{
Expand Down

0 comments on commit 1ca7a41

Please sign in to comment.