mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-28 17:15:38 +00:00
Moved externs for command-line args into a Settings singleton.
This commit is contained in:
parent
19eb1c412f
commit
e8465baaba
|
@ -125,6 +125,7 @@ set(ES_HEADERS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/MathExp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Settings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Vector2.h
|
||||
|
@ -161,6 +162,7 @@ set(ES_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_init.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Settings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Sound.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/VolumeControl.cpp
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
#include "ImageIO.h"
|
||||
#include "../data/Resources.h"
|
||||
#include "EmulationStation.h"
|
||||
|
||||
extern bool WINDOWED;
|
||||
#include "Settings.h"
|
||||
|
||||
namespace Renderer
|
||||
{
|
||||
|
@ -72,7 +71,7 @@ namespace Renderer
|
|||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
//SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); //vsync
|
||||
sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | (WINDOWED ? 0 : SDL_FULLSCREEN));
|
||||
sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | (Settings::getInstance()->getBool("WINDOWED") ? 0 : SDL_FULLSCREEN));
|
||||
|
||||
if(sdlScreen == NULL)
|
||||
{
|
||||
|
|
48
src/Settings.cpp
Normal file
48
src/Settings.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "Settings.h"
|
||||
#include "Log.h"
|
||||
|
||||
Settings* Settings::sInstance = NULL;
|
||||
|
||||
Settings::Settings()
|
||||
{
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
Settings* Settings::getInstance()
|
||||
{
|
||||
if(sInstance == NULL)
|
||||
sInstance = new Settings();
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
void Settings::setDefaults()
|
||||
{
|
||||
mBoolMap.clear();
|
||||
mIntMap.clear();
|
||||
|
||||
mBoolMap["PARSEGAMELISTONLY"] = false;
|
||||
mBoolMap["IGNOREGAMELIST"] = false;
|
||||
mBoolMap["DRAWFRAMERATE"] = false;
|
||||
mBoolMap["DONTSHOWEXIT"] = false;
|
||||
mBoolMap["DEBUG"] = false;
|
||||
mBoolMap["WINDOWED"] = false;
|
||||
|
||||
mIntMap["DIMTIME"] = 30*1000;
|
||||
}
|
||||
|
||||
//Print a warning message if the setting we're trying to get doesn't already exist in the map, then return the value in the map.
|
||||
#define SETTINGS_GET(type, mapName, methodName) type Settings::##methodName##(const std::string& name) \
|
||||
{ \
|
||||
if(mapName.find(name) == mapName.end()) \
|
||||
{ \
|
||||
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
|
||||
} \
|
||||
return mapName[name]; \
|
||||
}
|
||||
|
||||
SETTINGS_GET(bool, mBoolMap, getBool);
|
||||
SETTINGS_GET(int, mIntMap, getInt);
|
||||
|
||||
void Settings::setBool(const std::string& name, bool value) { mBoolMap[name] = value; }
|
||||
void Settings::setInt(const std::string& name, int value) { mIntMap[name] = value; }
|
35
src/Settings.h
Normal file
35
src/Settings.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef _SETTINGS_H_
|
||||
#define _SETTINGS_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
//This is a singleton for storing settings.
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
static Settings* getInstance();
|
||||
|
||||
void loadFile(const std::string& path);
|
||||
void saveFile(const std::string& path);
|
||||
|
||||
//You will get a warning if you try a get on a key that is not already present.
|
||||
bool getBool(const std::string& name);
|
||||
int getInt(const std::string& name);
|
||||
|
||||
void setBool(const std::string& name, bool value);
|
||||
void setInt(const std::string& name, int value);
|
||||
|
||||
private:
|
||||
static Settings* sInstance;
|
||||
|
||||
Settings();
|
||||
|
||||
//Clear everything and load default values.
|
||||
void setDefaults();
|
||||
|
||||
std::map<std::string, bool> mBoolMap;
|
||||
std::map<std::string, int> mIntMap;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -11,14 +11,12 @@
|
|||
#include "Log.h"
|
||||
#include "InputManager.h"
|
||||
#include <iostream>
|
||||
#include "Settings.h"
|
||||
|
||||
std::vector<SystemData*> SystemData::sSystemVector;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
extern bool PARSEGAMELISTONLY;
|
||||
extern bool IGNOREGAMELIST;
|
||||
|
||||
std::string SystemData::getStartPath() { return mStartPath; }
|
||||
std::string SystemData::getExtension() { return mSearchExtension; }
|
||||
|
||||
|
@ -41,10 +39,10 @@ SystemData::SystemData(std::string name, std::string descName, std::string start
|
|||
|
||||
mRootFolder = new FolderData(this, mStartPath, "Search Root");
|
||||
|
||||
if(!PARSEGAMELISTONLY)
|
||||
if(!Settings::getInstance()->getBool("PARSEGAMELISTONLY"))
|
||||
populateFolder(mRootFolder);
|
||||
|
||||
if(!IGNOREGAMELIST)
|
||||
if(!Settings::getInstance()->getBool("IGNOREGAMELIST"))
|
||||
parseGamelist(this);
|
||||
|
||||
mRootFolder->sort();
|
||||
|
@ -322,8 +320,8 @@ FolderData* SystemData::getRootFolder()
|
|||
return mRootFolder;
|
||||
}
|
||||
|
||||
std::string SystemData::getGamelistPath(){
|
||||
|
||||
std::string SystemData::getGamelistPath()
|
||||
{
|
||||
std::string filePath;
|
||||
|
||||
filePath = mRootFolder->getPath() + "/gamelist.xml";
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "GuiFastSelect.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "../Log.h"
|
||||
#include "../Settings.h"
|
||||
|
||||
Vector2i GuiGameList::getImagePos()
|
||||
{
|
||||
|
@ -344,12 +345,11 @@ void GuiGameList::init()
|
|||
}
|
||||
}
|
||||
|
||||
extern bool IGNOREGAMELIST; //defined in main.cpp (as a command line argument)
|
||||
GuiGameList* GuiGameList::create(Window* window)
|
||||
{
|
||||
bool detailed = false;
|
||||
|
||||
if(!IGNOREGAMELIST)
|
||||
if(!Settings::getInstance()->getBool("IGNOREGAMELIST"))
|
||||
{
|
||||
for(unsigned int i = 0; i < SystemData::sSystemVector.size(); i++)
|
||||
{
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
#include "../Log.h"
|
||||
#include "../SystemData.h"
|
||||
#include "GuiGameList.h"
|
||||
|
||||
//defined in main.cpp
|
||||
extern bool DONTSHOWEXIT;
|
||||
#include "../Settings.h"
|
||||
|
||||
GuiMenu::GuiMenu(Window* window, GuiGameList* parent) : GuiComponent(window)
|
||||
{
|
||||
|
@ -76,7 +74,7 @@ void GuiMenu::populateList()
|
|||
|
||||
mList->addObject("Reload", "es_reload", 0x0000FFFF);
|
||||
|
||||
if(!DONTSHOWEXIT)
|
||||
if(!Settings::getInstance()->getBool("DONTSHOWEXIT"))
|
||||
mList->addObject("Exit", "exit", 0xFF0000FF); //a special case; pushes an SDL quit event to the event stack instead of being called by system()
|
||||
}
|
||||
|
||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -14,6 +14,7 @@
|
|||
#include "Log.h"
|
||||
#include "Window.h"
|
||||
#include "EmulationStation.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#ifdef _RPI_
|
||||
#include <bcm_host.h>
|
||||
|
@ -21,15 +22,6 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
//these can be set by command-line arguments
|
||||
bool PARSEGAMELISTONLY = false;
|
||||
bool IGNOREGAMELIST = false;
|
||||
bool DRAWFRAMERATE = false;
|
||||
bool DONTSHOWEXIT = false;
|
||||
bool DEBUG = false;
|
||||
bool WINDOWED = false;
|
||||
unsigned int DIMTIME = 30*1000;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -50,27 +42,27 @@ int main(int argc, char* argv[])
|
|||
i++; //skip the argument value
|
||||
}else if(strcmp(argv[i], "--gamelist-only") == 0)
|
||||
{
|
||||
PARSEGAMELISTONLY = true;
|
||||
Settings::getInstance()->setBool("PARSEGAMELISTONLY", true);
|
||||
}else if(strcmp(argv[i], "--ignore-gamelist") == 0)
|
||||
{
|
||||
IGNOREGAMELIST = true;
|
||||
Settings::getInstance()->setBool("IGNOREGAMELIST", true);
|
||||
}else if(strcmp(argv[i], "--draw-framerate") == 0)
|
||||
{
|
||||
DRAWFRAMERATE = true;
|
||||
Settings::getInstance()->setBool("DRAWFRAMERATE", true);
|
||||
}else if(strcmp(argv[i], "--no-exit") == 0)
|
||||
{
|
||||
DONTSHOWEXIT = true;
|
||||
Settings::getInstance()->setBool("DONTSHOWEXIT", true);
|
||||
}else if(strcmp(argv[i], "--debug") == 0)
|
||||
{
|
||||
DEBUG = true;
|
||||
Settings::getInstance()->setBool("DEBUG", true);
|
||||
Log::setReportingLevel(LogDebug);
|
||||
}else if(strcmp(argv[i], "--dimtime") == 0)
|
||||
{
|
||||
DIMTIME = atoi(argv[i + 1]) * 1000;
|
||||
Settings::getInstance()->setInt("DIMTIME", atoi(argv[i + 1]) * 1000);
|
||||
i++; //skip the argument value
|
||||
}else if(strcmp(argv[i], "--windowed") == 0)
|
||||
{
|
||||
WINDOWED = true;
|
||||
Settings::getInstance()->setBool("WINDOWED", true);
|
||||
}else if(strcmp(argv[i], "--help") == 0)
|
||||
{
|
||||
std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n";
|
||||
|
@ -200,7 +192,7 @@ int main(int argc, char* argv[])
|
|||
window.update(deltaTime);
|
||||
window.render();
|
||||
|
||||
if(DRAWFRAMERATE)
|
||||
if(Settings::getInstance()->getBool("DRAWFRAMERATE"))
|
||||
{
|
||||
static int timeElapsed = 0;
|
||||
static int nrOfFrames = 0;
|
||||
|
@ -224,7 +216,7 @@ int main(int argc, char* argv[])
|
|||
//sleeping entails setting a flag to start skipping frames
|
||||
//and initially drawing a black semi-transparent rect to dim the screen
|
||||
timeSinceLastEvent += deltaTime;
|
||||
if(timeSinceLastEvent >= DIMTIME && DIMTIME != 0)
|
||||
if(timeSinceLastEvent >= (unsigned int)Settings::getInstance()->getInt("DIMTIME") && Settings::getInstance()->getInt("DIMTIME") != 0)
|
||||
{
|
||||
sleeping = true;
|
||||
timeSinceLastEvent = 0;
|
||||
|
|
Loading…
Reference in a new issue