RetroFE constructor arguments set to pass by reference.

This commit is contained in:
emb 2015-01-01 14:54:01 -06:00
parent 9a56630d46
commit 511c774ffc
13 changed files with 54 additions and 61 deletions

View File

@ -5,7 +5,7 @@
#include "../Database/Configuration.h"
#include "../Utility/Log.h"
UserInput::UserInput(Configuration *c)
UserInput::UserInput(Configuration &c)
: Config(c)
{
}
@ -54,7 +54,7 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key)
std::string configKey = "controls." + keyDescription;
if(!Config->GetProperty(configKey, description))
if(!Config.GetProperty(configKey, description))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Missing property " + configKey);
}

View File

@ -24,7 +24,7 @@ public:
KeyCodeQuit
};
UserInput(Configuration *c);
UserInput(Configuration &c);
virtual ~UserInput();
bool Initialize();
SDL_Scancode GetScancode(KeyCode_E key);
@ -34,5 +34,5 @@ private:
bool MapKey(std::string keyDescription, KeyCode_E key);
std::map<KeyCode_E, SDL_Scancode> KeyMap;
Configuration *Config;
Configuration &Config;
};

View File

@ -17,8 +17,8 @@
#include <cstring>
#endif
Launcher::Launcher(RetroFE *p)
: Config(p->GetConfiguration())
Launcher::Launcher(RetroFE &p, Configuration &c)
: Config(c)
, RetroFEInst(p)
{
}
@ -120,7 +120,7 @@ bool Launcher::ExecuteCommand(std::string executable, std::string args, std::str
Logger::Write(Logger::ZONE_INFO, "Launcher", " from within folder: " + currentDirectory);
//todo: use delegation instead of depending on knowing the RetroFE class (tie to an interface)
RetroFEInst->LaunchEnter();
RetroFEInst.LaunchEnter();
#ifdef WIN32
STARTUPINFO startupInfo;
@ -165,7 +165,7 @@ bool Launcher::ExecuteCommand(std::string executable, std::string args, std::str
}
Logger::Write(Logger::ZONE_INFO, "Launcher", "Completed");
RetroFEInst->LaunchExit();
RetroFEInst.LaunchExit();
return retVal;
}
@ -175,7 +175,7 @@ bool Launcher::GetLauncherName(std::string &launcherName, std::string collection
std::string launcherKey = "collections." + collection + ".launcher";
// find the launcher for the particular item
if(!Config->GetProperty(launcherKey, launcherName))
if(!Config.GetProperty(launcherKey, launcherName))
{
std::stringstream ss;
@ -208,7 +208,7 @@ bool Launcher::GetLauncherExecutable(std::string &executable, std::string &curre
{
std::string executableKey = "launchers." + launcherName + ".executable";
if(!Config->GetProperty(executableKey, executable))
if(!Config.GetProperty(executableKey, executable))
{
return false;
}
@ -216,7 +216,7 @@ bool Launcher::GetLauncherExecutable(std::string &executable, std::string &curre
std::string currentDirectoryKey = "launchers." + launcherName + ".currentDirectory";
currentDirectory = Utils::GetDirectory(executable);
Config->GetProperty(currentDirectoryKey, currentDirectory);
Config.GetProperty(currentDirectoryKey, currentDirectory);
return true;
}
@ -225,7 +225,7 @@ bool Launcher::GetLauncherArgs(std::string &args, std::string launcherName)
{
std::string argsKey = "launchers." + launcherName + ".arguments";
if(!Config->GetProperty(argsKey, args))
if(!Config.GetProperty(argsKey, args))
{
Logger::Write(Logger::ZONE_ERROR, "Launcher", "No arguments specified for: " + argsKey);
@ -238,7 +238,7 @@ bool Launcher::GetExtensions(std::string &extensions, std::string collection)
{
std::string extensionsKey = "collections." + collection + ".list.extensions";
if(!Config->GetProperty(extensionsKey, extensions))
if(!Config.GetProperty(extensionsKey, extensions))
{
Logger::Write(Logger::ZONE_ERROR, "Launcher", "No extensions specified for: " + extensionsKey);
return false;
@ -256,7 +256,7 @@ bool Launcher::GetCollectionDirectory(std::string &directory, std::string collec
std::string itemsPathValue;
// find the items path folder (i.e. ROM path)
if(!Config->GetPropertyAbsolutePath(itemsPathKey, itemsPathValue))
if(!Config.GetPropertyAbsolutePath(itemsPathKey, itemsPathValue))
{
directory = "";
}

View File

@ -12,7 +12,7 @@ class RetroFE;
class Launcher
{
public:
Launcher(RetroFE *p);
Launcher(RetroFE &p, Configuration &c);
bool Run(std::string collection, Item *collectionItem);
private:
@ -35,6 +35,6 @@ private:
std::string itemDirectory,
std::string itemCollectionName);
Configuration *Config;
RetroFE *RetroFEInst;
Configuration &Config;
RetroFE &RetroFEInst;
};

View File

@ -22,7 +22,7 @@
//todo: remove coupling from configuration data (if possible)
ScrollingList::ScrollingList(Configuration *c,
ScrollingList::ScrollingList(Configuration &c,
float scaleX,
float scaleY,
Font *font,
@ -403,7 +403,7 @@ void ScrollingList::AllocateTexture(ComponentItemBinding *s)
t = new VideoComponent(videoPath, item->GetFullTitle(), ScaleX, ScaleY);
}
*/
if(!t && Config->GetPropertyAbsolutePath(collectionKey, imagePath))
if(!t && Config.GetPropertyAbsolutePath(collectionKey, imagePath))
{
ImageBuilder imageBuild;
t = imageBuild.CreateImage(imagePath, item->GetName(), ScaleX, ScaleY);

View File

@ -31,7 +31,7 @@ public:
};
ScrollingList(Configuration *c, float scaleX, float scaleY, Font *font, SDL_Color fontColor, std::string layoutKey, std::string CollectionName, std::string imageType);
ScrollingList(Configuration &c, float scaleX, float scaleY, Font *font, SDL_Color fontColor, std::string layoutKey, std::string CollectionName, std::string imageType);
virtual ~ScrollingList();
void AllocateTexture(ComponentItemBinding *s);
void DeallocateTexture(ComponentItemBinding *s);
@ -92,7 +92,7 @@ private:
void UpdateOffset(float dt);
std::string Collection;
Configuration *Config;
Configuration &Config;
float ScaleX;
float ScaleY;
Font *FontInst;

View File

@ -25,7 +25,7 @@
using namespace rapidxml;
PageBuilder::PageBuilder(std::string layoutKey, std::string collection, Configuration *c, FontCache *fc)
PageBuilder::PageBuilder(std::string layoutKey, std::string collection, Configuration &c, FontCache *fc)
: LayoutKey(layoutKey)
, Collection(collection)
, Config(c)
@ -100,10 +100,10 @@ Page *PageBuilder::BuildPage()
{
//todo: reuse from ComponentBuilder. Not sure how since it relies on knowing the collection
std::string fontPropertyKey = "layouts." + LayoutKey + ".font";
Config->SetProperty(fontPropertyKey, fontXml->value());
Config.SetProperty(fontPropertyKey, fontXml->value());
Font = Config->ConvertToAbsolutePath(
Config->GetAbsolutePath() + "/Layouts/" + LayoutKey + "/",
Font = Config.ConvertToAbsolutePath(
Config.GetAbsolutePath() + "/Layouts/" + LayoutKey + "/",
fontXml->value());
Logger::Write(Logger::ZONE_DEBUG, "Layout", "Layout font set to " + Font);
@ -377,14 +377,14 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName,
if(type && (tagName == "reloadableVideo" || tagName == "reloadableImage"))
{
std::string configImagePath = "collections." + Collection + ".media." + type->value();
if(!Config->GetPropertyAbsolutePath(configImagePath, reloadableImagePath))
if(!Config.GetPropertyAbsolutePath(configImagePath, reloadableImagePath))
{
Logger::Write(Logger::ZONE_ERROR, "Layout", "Cannot process reloadable images because property \"" + configImagePath + "\" does not exist");
}
std::string configVideoPath = "collections." + Collection + ".media.video";
if(!Config->GetPropertyAbsolutePath(configVideoPath, reloadableVideoPath))
if(!Config.GetPropertyAbsolutePath(configVideoPath, reloadableVideoPath))
{
Logger::Write(Logger::ZONE_WARNING, "Layout", "Could not find videos folder as \"" + configVideoPath + "\" does not exist");
}

View File

@ -18,7 +18,7 @@ class Configuration;
class PageBuilder
{
public:
PageBuilder(std::string layoutKey, std::string collection, Configuration *c, FontCache *fc);
PageBuilder(std::string layoutKey, std::string collection, Configuration &c, FontCache *fc);
virtual ~PageBuilder();
Page *BuildPage();
@ -26,7 +26,7 @@ private:
std::string LayoutKey;
std::string LayoutPath;
std::string Collection;
Configuration *Config;
Configuration &Config;
float ScaleX;
float ScaleY;
int ScreenHeight;

View File

@ -50,7 +50,7 @@ int main(int argc, char *argv[])
return -1;
}
RetroFE p(cdb, &config);
RetroFE p(*cdb, config);
if(p.Initialize())
{

View File

@ -25,7 +25,7 @@
Page *page = NULL;
RetroFE::RetroFE(CollectionDatabase *db, Configuration *c)
RetroFE::RetroFE(CollectionDatabase &db, Configuration &c)
: Config(c)
, CollectionDB(db)
, Input(Config)
@ -70,8 +70,8 @@ bool RetroFE::Initialize()
bool videoEnable = true;
int videoLoop = 0;
Config->GetProperty("videoEnable", videoEnable);
Config->GetProperty("videoLoop", videoLoop);
Config.GetProperty("videoEnable", videoEnable);
Config.GetProperty("videoLoop", videoLoop);
VideoFactory::SetEnabled(videoEnable);
VideoFactory::SetNumLoops(videoLoop);
@ -155,20 +155,14 @@ bool RetroFE::DeInitialize()
return retVal;
}
Configuration *RetroFE::GetConfiguration()
{
return Config;
}
void RetroFE::Run()
{
int attractModeTime = 0;
bool attractMode = false;
std::string firstCollection = "Main";
Config->GetProperty("attractModeTime", attractModeTime);
Config->GetProperty("firstCollection", firstCollection);
Config.GetProperty("attractModeTime", attractModeTime);
Config.GetProperty("firstCollection", firstCollection);
bool running = true;
Item *nextPageItem = NULL;
@ -190,7 +184,7 @@ void RetroFE::Run()
float lastTime = 0;
float deltaTime = 0;
page = PageChain.back();
Launcher l(this);
Launcher l(*this, Config);
if(!page)
{
@ -289,7 +283,7 @@ void RetroFE::Run()
{
// don't print the first framerate, it's likely inaccurate
bool logFps = false;
Config->GetProperty("debug.logfps", logFps);
Config.GetProperty("debug.logfps", logFps);
if(fpsStartTime != 0 && logFps)
{
@ -337,7 +331,7 @@ bool RetroFE::ItemSelected()
if(item->IsLeaf())
{
Launcher l(this);
Launcher l(*this, Config);
l.Run(page->GetCollectionName(), item);
}
@ -356,7 +350,7 @@ bool RetroFE::Back(bool &exit)
bool canGoBack = false;
bool exitOnBack = false;
Config->GetProperty("exitOnFirstPageBack", exitOnBack);
Config.GetProperty("exitOnFirstPageBack", exitOnBack);
exit = false;
if(PageChain.size() > 1)
@ -455,8 +449,8 @@ Page *RetroFE::LoadPage(std::string collectionName)
std::vector<Item *> *collection = new std::vector<Item *>(); // the page will deallocate this once its done
MenuParser mp;
mp.GetMenuItems(CollectionDB, collectionName, *collection);
CollectionDB->GetCollection(collectionName, *collection);
mp.GetMenuItems(&CollectionDB, collectionName, *collection);
CollectionDB.GetCollection(collectionName, *collection);
//todo: handle this in a more esthetically pleasing way instead of crashing
if(collection->size() == 0)
@ -468,9 +462,9 @@ Page *RetroFE::LoadPage(std::string collectionName)
std::string layoutKeyName = "collections." + collectionName + ".layout";
std::string layoutName = "Default 16x9";
if(!Config->GetProperty(layoutKeyName, layoutName))
if(!Config.GetProperty(layoutKeyName, layoutName))
{
Config->GetProperty("layout", layoutName);
Config.GetProperty("layout", layoutName);
}

View File

@ -17,12 +17,11 @@ class Page;
class RetroFE
{
public:
RetroFE(CollectionDatabase *db, Configuration *c);
RetroFE(CollectionDatabase &db, Configuration &c);
virtual ~RetroFE();
bool Initialize();
bool DeInitialize();
void Run();
Configuration *GetConfiguration();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter();
@ -50,8 +49,8 @@ private:
void Update(float dt, bool scrollActive);
Configuration *Config;
CollectionDatabase *CollectionDB;
Configuration &Config;
CollectionDatabase &CollectionDB;
UserInput Input;
std::list<Page *> PageChain;
float KeyInputDisable;

View File

@ -16,7 +16,7 @@ int SDL::WindowHeight = 0;
bool SDL::Fullscreen = false;
bool SDL::Initialize(Configuration *config)
bool SDL::Initialize(Configuration &config)
{
bool retVal = true;
std::string hString;
@ -36,7 +36,7 @@ bool SDL::Initialize(Configuration *config)
retVal = false;
}
if(retVal && config->GetProperty("hideMouse", hideMouse))
if(retVal && config.GetProperty("hideMouse", hideMouse))
{
if(hideMouse)
{
@ -64,7 +64,7 @@ bool SDL::Initialize(Configuration *config)
}
if(!config->GetProperty("horizontal", hString))
if(!config.GetProperty("horizontal", hString))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Missing property \"horizontal\"");
retVal = false;
@ -82,7 +82,7 @@ bool SDL::Initialize(Configuration *config)
}
}
}
else if(!config->GetProperty("horizontal", WindowWidth))
else if(!config.GetProperty("horizontal", WindowWidth))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Invalid property value for \"horizontal\"");
}
@ -91,7 +91,7 @@ bool SDL::Initialize(Configuration *config)
// check for a few other necessary Configurations
if(retVal)
{
if(!config->GetProperty("vertical", hString))
if(!config.GetProperty("vertical", hString))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Missing property \"vertical\"");
retVal = false;
@ -109,13 +109,13 @@ bool SDL::Initialize(Configuration *config)
}
}
}
else if(!config->GetProperty("vertical", WindowHeight))
else if(!config.GetProperty("vertical", WindowHeight))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Invalid property value for \"vertical\"");
}
}
if(retVal && !config->GetProperty("fullscreen", Fullscreen))
if(retVal && !config.GetProperty("fullscreen", Fullscreen))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Missing property: \"fullscreen\"");
retVal = false;

View File

@ -10,7 +10,7 @@ class Configuration;
class SDL
{
public:
static bool Initialize(Configuration *config);
static bool Initialize(Configuration &config);
static bool DeInitialize();
static SDL_Renderer *GetRenderer();
static SDL_mutex *GetMutex();