diff --git a/src/framework/configmanager.cpp b/src/framework/configmanager.cpp index eca1c6cd..2bcc1ee4 100644 --- a/src/framework/configmanager.cpp +++ b/src/framework/configmanager.cpp @@ -93,12 +93,12 @@ void ConfigManager::setValue(const std::string &key, const char *value) void ConfigManager::setValue(const std::string &key, int value) { - setValue(key, boost::lexical_cast(value)); + setValue(key, convertType(value)); } void ConfigManager::setValue(const std::string &key, float value) { - setValue(key, boost::lexical_cast(value)); + setValue(key, convertType(value)); } void ConfigManager::setValue(const std::string &key, bool value) @@ -127,7 +127,7 @@ float ConfigManager::getFloat(const std::string &key) warning("Config value %s not found", key.c_str()); return 0; } - return boost::lexical_cast(iter->second); + return convertType(iter->second); } bool ConfigManager::getBoolean(const std::string &key) @@ -147,5 +147,5 @@ int ConfigManager::getInteger(const std::string &key) warning("Config value %s not found", key.c_str()); return 0; } - return boost::lexical_cast(iter->second); + return convertType(iter->second); } diff --git a/src/framework/resourcemanager.cpp b/src/framework/resourcemanager.cpp index 011abd6e..c239adbb 100644 --- a/src/framework/resourcemanager.cpp +++ b/src/framework/resourcemanager.cpp @@ -57,7 +57,7 @@ bool ResourceManager::setWriteDir(const std::string& path) return ret; } -bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront) +bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront /*= true*/) { if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) { error("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError()); diff --git a/src/framework/util.h b/src/framework/util.h index 1e82ff77..b0fffdf7 100644 --- a/src/framework/util.h +++ b/src/framework/util.h @@ -33,4 +33,21 @@ std::string vformat(const char *format, va_list args); /// Formatting like printf for std::string std::string format(const char *format, ...); +/// Convert any data type through boost::lexical_cast +//TODO: move declatation to util.cpp +template +R convertType(T t) +{ + R r = R(); + + try{ + r = boost::lexical_cast(t); + } + catch(boost::bad_lexical_cast bad){ + //TODO: add an error message + } + + return r; +} + #endif \ No newline at end of file diff --git a/src/framework/win32platform.cpp b/src/framework/win32platform.cpp index a01bed24..79ae6808 100644 --- a/src/framework/win32platform.cpp +++ b/src/framework/win32platform.cpp @@ -288,7 +288,7 @@ void Platform::showMouseCursor() ShowCursor(true); } -void Platform::setVsync(bool enable) +void Platform::setVsync(bool enable /*= true*/) { typedef GLint (*glSwapIntervalProc)(GLint); glSwapIntervalProc glSwapInterval = NULL; diff --git a/src/main.cpp b/src/main.cpp index a62b63e9..9109a701 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -108,7 +108,7 @@ int main(int argc, const char *argv[]) // state scope { - std::unique_ptr menuState(new MenuState); + std::unique_ptr menuState(new MenuState()); g_engine.changeState(menuState.get()); Platform::showWindow(); diff --git a/src/menustate.h b/src/menustate.h index 1f488421..7923fffd 100644 --- a/src/menustate.h +++ b/src/menustate.h @@ -35,14 +35,14 @@ public: MenuState(); virtual ~MenuState(); - void onEnter(); - void onLeave(); + virtual void onEnter(); + virtual void onLeave(); - void onClose(); - void onInputEvent(InputEvent *event); + virtual void onClose(); + virtual void onInputEvent(InputEvent *event); - void render(); - void update(int ticks, int elapsedTicks); + virtual void render(); + virtual void update(int ticks, int elapsedTicks); private: TexturePtr m_background;