From d121154932ee89189344a6cf22df71be385edcb6 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 21 Nov 2010 19:48:58 -0200 Subject: [PATCH] config manager using yaml logger improvements more documentation --- CMakeLists.txt | 46 ++++++++---- cmake/FindYamlCpp.cmake | 40 +++++++++++ src/configmanager.cpp | 153 ++++++++++++++++++++++++++++++++++++++++ src/configmanager.h | 61 ++++++++++++++++ src/const.h | 1 + src/engine.cpp | 11 ++- src/engine.h | 9 ++- src/graphics.cpp | 1 + src/graphics.h | 5 ++ src/input.h | 1 + src/logger.cpp | 21 +++--- src/logger.h | 34 ++++++--- src/main.cpp | 16 +++++ src/platform.h | 13 +++- src/resourcemanager.cpp | 37 ++++++++++ src/resourcemanager.h | 42 +++++++++++ src/util.cpp | 1 + src/util.h | 21 ++++++ src/x11platform.cpp | 11 +++ 19 files changed, 483 insertions(+), 41 deletions(-) create mode 100644 cmake/FindYamlCpp.cmake create mode 100644 src/configmanager.cpp create mode 100644 src/configmanager.h create mode 100644 src/resourcemanager.cpp create mode 100644 src/resourcemanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fd8b5d6e..12fa3abb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(otclient) +SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") + # find needed packages SET(Boost_USE_STATIC_LIBS ON) -FIND_PACKAGE(Boost COMPONENTS thread filesystem REQUIRED) +FIND_PACKAGE(Boost REQUIRED) FIND_PACKAGE(OpenGL REQUIRED) FIND_PACKAGE(Lua51 REQUIRED) +FIND_PACKAGE(YamlCpp REQUIRED) +FIND_PACKAGE(PhysFS REQUIRED) +FIND_PACKAGE(PNG REQUIRED) # choose a default build type if not specified IF(NOT CMAKE_BUILD_TYPE) @@ -15,19 +20,26 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE}) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wl,--as-needed") + SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wno-unused-parameter") SET(CMAKE_CXX_FLAGS_DEBUG "-O1 -g -ggdb -fno-inline") SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wl,-s") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") + SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--as-needed") ENDIF(CMAKE_COMPILER_IS_GNUCXX) INCLUDE_DIRECTORIES( -${LUA_INCLUDE_DIRS} -${Boost_INCLUDE_DIRS}) + ${Boost_INCLUDE_DIRS} + ${LUA_INCLUDE_DIRS} + ${YAMLCPP_INCLUDE_DIRS} + ${PHYSFS_INCLUDE_DIRS} + ${PNG_INCLUDE_DIRS}) LINK_DIRECTORIES( -${Boost_LIBRARY_DIRS} -${LUA_LIBRARY_DIRS}) + ${Boost_LIBRARY_DIRS} + ${LUA_LIBRARY_DIRS} + ${PHYSFS_LIBRARY_DIRS} + ${YAMLCPP_LIBRARY_DIRS} + ${PNG_LIBRARY_DIRS}) # setup definitions ADD_DEFINITIONS(-D_REENTRANT) @@ -38,11 +50,13 @@ ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") # find sources SET(SOURCES -src/main.cpp -src/engine.cpp -src/graphics.cpp -src/logger.cpp -src/util.cpp) + src/configmanager.cpp + src/resourcemanager.cpp + src/main.cpp + src/engine.cpp + src/graphics.cpp + src/logger.cpp + src/util.cpp) IF(WIN32) SET(SOURCES ${SOURCES} src/win32platform.cpp) @@ -55,7 +69,9 @@ ADD_EXECUTABLE(otclient ${SOURCES}) # target link libraries TARGET_LINK_LIBRARIES(otclient -${Boost_LIBRARIES} -${OPENGL_LIBRARY} -${LUA51_LIBRARY}) - + ${Boost_LIBRARIES} + ${OPENGL_LIBRARY} + ${LUA51_LIBRARY} + ${YAMLCPP_LIBRARY} + ${PHYSFS_LIBRARY} + ${PNG_LIBRARY}) diff --git a/cmake/FindYamlCpp.cmake b/cmake/FindYamlCpp.cmake new file mode 100644 index 00000000..bfa24711 --- /dev/null +++ b/cmake/FindYamlCpp.cmake @@ -0,0 +1,40 @@ +# - Try to find yaml-cpp +# Once done, this will define +# +# YAMLCPP_LIBRARY, link these to use yaml-cpp +# YAMLCPP_FOUND - system has yaml-cpp +# YAMLCPP_INCLUDE_DIR, the yaml-cpp include directories + +FIND_PATH(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h +HINTS +$ENV{PHYSFSDIR} +PATH_SUFFIXES include/yaml-cpp include +PATHS +~/Library/Frameworks +/Library/Frameworks +/usr/local +/usr +/sw # Fink +/opt/local # DarwinPorts +/opt/csw # Blastwave +/opt +) + +FIND_LIBRARY(YAMLCPP_LIBRARY +NAMES yaml-cpp +HINTS +$ENV{PHYSFSDIR} +PATH_SUFFIXES lib64 lib +PATHS +~/Library/Frameworks +/Library/Frameworks +/usr/local +/usr +/sw +/opt/local +/opt/csw +/opt +) + +INCLUDE("${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake") +FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG YAMLCPP_LIBRARY YAMLCPP_INCLUDE_DIR) \ No newline at end of file diff --git a/src/configmanager.cpp b/src/configmanager.cpp new file mode 100644 index 00000000..9cd683c3 --- /dev/null +++ b/src/configmanager.cpp @@ -0,0 +1,153 @@ +/* The MIT License + * + * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "configmanager.h" +#include "logger.h" +#include "util.h" + +#include +#include + +ConfigManager g_config; + +ConfigManager::ConfigManager() +{ + +} + +ConfigManager::~ConfigManager() +{ + +} + +bool ConfigManager::load(const std::string& fileName) +{ + std::ifstream fin(fileName.c_str()); + if(!fin.good()) + return false; + + m_fileName = fileName; + + try { + YAML::Parser parser(fin); + + YAML::Node doc; + parser.GetNextDocument(doc); + + for(YAML::Iterator it=doc.begin(); it != doc.end(); ++it) { + std::string key, value; + it.first() >> key; + it.second() >> value; + m_confsMap[key] = value; + } + } catch (YAML::ParserException& e) { + error("Malformed configuration file!"); + return false; + } + + return true; +} + +void ConfigManager::save() +{ + std::ofstream fout(m_fileName.c_str()); + if(!fout.good()) { + error("Failed to save configuration file %s", m_fileName.c_str()); + return; + } + + YAML::Emitter out; + out << m_confsMap; + + fout << out.c_str(); +} + +void ConfigManager::setValue(const std::string &key, const std::string &value) +{ + m_confsMap[key] = value; +} + +void ConfigManager::setValue(const std::string &key, const char *value) +{ + m_confsMap[key] = value; +} + +void ConfigManager::setValue(const std::string &key, int value) +{ + setValue(key, castToString(value)); +} + +void ConfigManager::setValue(const std::string &key, float value) +{ + setValue(key, castToString(value)); +} + +void ConfigManager::setValue(const std::string &key, bool value) +{ + if(value) + setValue(key,"true"); + else + setValue(key,"false"); +} + +const std::string &ConfigManager::getString(const std::string &key) +{ + std::map::iterator iter = m_confsMap.find(key); + if(iter == m_confsMap.end()) { + warning("Config value %s not found", key.c_str()); + static std::string emptystr; + return emptystr; + } + return iter->second; +} + +float ConfigManager::getFloat(const std::string &key) +{ + std::map::iterator iter = m_confsMap.find(key); + if(iter == m_confsMap.end()) { + warning("Config value %s not found", key.c_str()); + return 0; + } + return castFromString(iter->second); +} + +bool ConfigManager::getBoolean(const std::string &key) +{ + std::map::iterator iter = m_confsMap.find(key); + if(iter == m_confsMap.end()) { + warning("Config value %s not found", key.c_str()); + return 0; + } + return (iter->second == std::string("true")); +} + +int ConfigManager::getInteger(const std::string &key) +{ + std::map::iterator iter = m_confsMap.find(key); + if(iter == m_confsMap.end()) { + warning("Config value %s not found", key.c_str()); + return 0; + } + return castFromString(iter->second); +} diff --git a/src/configmanager.h b/src/configmanager.h new file mode 100644 index 00000000..d9dccd5c --- /dev/null +++ b/src/configmanager.h @@ -0,0 +1,61 @@ +/* The MIT License + * + * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef CONFIGMANAGER_H +#define CONFIGMANAGER_H + +#include +#include + +class ConfigManager +{ +public: + ConfigManager(); + ~ConfigManager(); + + /// Read configuration file and parse all settings to memory + bool load(const std::string& fileName); + + /// Dump all settings to configuration file + void save(); + + void setValue(const std::string &key, const std::string &value); + void setValue(const std::string &key, const char *value); + void setValue(const std::string &key, float value); + void setValue(const std::string &key, bool value); + void setValue(const std::string &key, int value); + + const std::string &getString(const std::string &key); + float getFloat(const std::string &key); + bool getBoolean(const std::string &key); + int getInteger(const std::string &key); + +private: + std::string m_fileName; + std::map m_confsMap; +}; + +extern ConfigManager g_config; + +#endif // CONFIGMANAGER_H diff --git a/src/const.h b/src/const.h index c3528e1d..7a30e759 100644 --- a/src/const.h +++ b/src/const.h @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #ifndef VERSION_H #define VERSION_H diff --git a/src/engine.cpp b/src/engine.cpp index 78b0090e..665c0534 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -21,11 +21,14 @@ * THE SOFTWARE. */ + #include "engine.h" #include "platform.h" #include "graphics.h" #include "const.h" #include "input.h" +#include "configmanager.h" +#include "logger.h" Engine g_engine; @@ -44,8 +47,8 @@ void Engine::init() { Platform::init(); - int width = 640; - int height = 480; + int width = g_config.getInteger("width"); + int height = g_config.getInteger("height"); // create the window Platform::createWindow(width, height, 550, 450); @@ -63,6 +66,10 @@ void Engine::init() void Engine::terminate() { + // save configs + g_config.setValue("width", Platform::getWindowWidth()); + g_config.setValue("height", Platform::getWindowHeight()); + Platform::showMouseCursor(); Platform::terminate(); g_graphics.terminate(); diff --git a/src/engine.h b/src/engine.h index 36b6afdb..8374b33d 100644 --- a/src/engine.h +++ b/src/engine.h @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #ifndef ENGINE_H #define ENGINE_H @@ -35,20 +36,24 @@ public: void init(); void terminate(); + /// Main loop void run(); void stop(); bool isRunning() const { return m_running; } bool isStopping() const { return m_stopping; } - unsigned long getLastFrameTicks() const { return m_lastFrameTicks; } - // events fired by platform + /// Fired by platform on window close void onClose(); + /// Fired by platform on window resize void onResize(int width, int height); + /// Fired by platform on mouse/keyboard input void onInputEvent(InputEvent *event); private: + /// Called to render every frame void render(); + /// Called between renders void update(int elapsedTicks); bool m_stopping; diff --git a/src/graphics.cpp b/src/graphics.cpp index 22312217..e9f08eb3 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #include "graphics.h" #include "logger.h" diff --git a/src/graphics.h b/src/graphics.h index fbab7997..aad36e5a 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #ifndef GRAPHICS_H #define GRAPHICS_H @@ -33,9 +34,13 @@ public: void init(); void terminate(); + ///Called after every window resize void resize(int width, int height); + ///Called before every render void beginRender(); + + ///Called after every render void endRender(); }; diff --git a/src/input.h b/src/input.h index 2c4a6af8..a6083273 100644 --- a/src/input.h +++ b/src/input.h @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #ifndef INPUT_H #define INPUT_H diff --git a/src/logger.cpp b/src/logger.cpp index e582f308..02179f1d 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -21,19 +21,17 @@ * THE SOFTWARE. */ + #include "logger.h" #include "util.h" -#include -#include #include #include #include -void _log(int level, const char *trace, const char *format, ...) +void Logger::log(int level, const char *trace, const char *format, ...) { va_list args; - std::stringstream out; std::string strace; va_start(args, format); @@ -51,25 +49,22 @@ void _log(int level, const char *trace, const char *format, ...) static char const *colors[] = { "\033[01;31m ", "\033[01;31m", "\033[01;33m", "\033[0;32m", "\033[01;34m" }; static bool colored = getenv("COLORED_OUTPUT"); if(colored) - out << colors[level]; + std::cout << colors[level]; #endif if(!strace.empty()) - out << "[" << strace << "] "; + std::cout << "[" << strace << "] "; static char const *prefixes[] = { "FATAL ERROR: ", "ERROR: ", "WARNING: ", "", "", "" }; - out << prefixes[level]; - out << text; + std::cout << prefixes[level]; + std::cout << text; #ifdef linux if(colored) - out << "\033[0m"; + std::cout << "\033[0m"; #endif - if(level <= LWARNING) - std::cerr << out.str() << std::endl; - else - std::cout << out.str() << std::endl; + std::cout << std::endl; if(level == LFATAL) exit(-1); diff --git a/src/logger.h b/src/logger.h index c40b2d15..59b1c45b 100644 --- a/src/logger.h +++ b/src/logger.h @@ -21,11 +21,16 @@ * THE SOFTWARE. */ + #ifndef LOGGER_H #define LOGGER_H +#include +#include #include +namespace Logger { + enum ELogLevel { LFATAL = 0, LERROR, @@ -34,15 +39,28 @@ enum ELogLevel { LDEBUG }; -void _log(int level, const char *trace, const char *format, ...); +void log(int level, const char *trace, const char *format, ...); + +} -#define fatal(...) _log(LFATAL, NULL, __VA_ARGS__) -#define error(...) _log(LERROR, NULL, __VA_ARGS__) -#define warning(...) _log(LWARNING, NULL, __VA_ARGS__) -#define debug(...) _log(LDEBUG, NULL, __VA_ARGS__) -#define notice(...) _log(LNOTICE, NULL, __VA_ARGS__) +#define fatal(...) Logger::log(Logger::LFATAL, NULL, __VA_ARGS__) +#define error(...) Logger::log(Logger::LERROR, NULL, __VA_ARGS__) +#define warning(...) Logger::log(Logger::LWARNING, NULL, __VA_ARGS__) +#define debug(...) Logger::log(Logger::LDEBUG, NULL, __VA_ARGS__) +#define notice(...) Logger::log(Logger::LNOTICE, NULL, __VA_ARGS__) + +#define trace() Logger::log(Logger::LDEBUG, __PRETTY_FUNCTION__, "") +#define tdebug(...) Logger::log(Logger::LDEBUG, __PRETTY_FUNCTION__, __VA_ARGS__) + +struct Dump { +public: + Dump() { } + ~Dump() { debug(m_buf.str().c_str()); } + template Dump &operator<<(const T &x) { m_buf << x << " "; return *this; } +private: + std::ostringstream m_buf; +}; -#define trace() _log(LDEBUG, __PRETTY_FUNCTION__, "") -#define tdebug(...) _log(LDEBUG, __PRETTY_FUNCTION__, __VA_ARGS__) +#define dump() Dump() #endif diff --git a/src/main.cpp b/src/main.cpp index 98034eb8..e5d43c7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,11 +21,14 @@ * THE SOFTWARE. */ + #include "engine.h" #include "const.h" #include "logger.h" #include +#include "configmanager.h" +#include "util.h" // catches terminate signals to exit nicely void signal_handler(int sig) @@ -45,6 +48,13 @@ void signal_handler(int sig) } } +/// Default otclient configurations +void setDefaultConfigs() +{ + g_config.setValue("width", 640); + g_config.setValue("height", 480); +} + int main(int argc, const char *argv[]) { // install our signal handler @@ -52,11 +62,17 @@ int main(int argc, const char *argv[]) signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); + setDefaultConfigs(); + if(!g_config.load("config.yml")) + notice("Could not read configuration file, default configurations will be used."); + notice(APP_LONGNAME); // setup the engine and run g_engine.init(); g_engine.run(); g_engine.terminate(); + + g_config.save(); return 0; } diff --git a/src/platform.h b/src/platform.h index 13d63d1b..73740f40 100644 --- a/src/platform.h +++ b/src/platform.h @@ -21,17 +21,22 @@ * THE SOFTWARE. */ + #ifndef PLATFORM_H #define PLATFORM_H +// namespace with platform specific stuff namespace Platform { void init(); void terminate(); + /// Poll platform input/window events void poll(); + /// Get current time in milliseconds since first frame render unsigned long getTicks(); + /// Sleep in current thread void sleep(unsigned long miliseconds); bool createWindow(int width, int height, int minWidth, int minHeight); @@ -40,8 +45,12 @@ namespace Platform void setWindowTitle(const char *title); bool isWindowFocused(); bool isWindowVisible(); + int getWindowWidth(); + int getWindowHeight(); + /// Get GL extension function address void *getExtensionProcAddress(const char *ext); + /// Check if GL extension is supported bool isExtensionSupported(const char *ext); const char *getTextFromClipboard(); @@ -50,8 +59,10 @@ namespace Platform void hideMouseCursor(); void showMouseCursor(); + /// Enable/disable vertical synchronization void setVsync(bool enable = true); + /// Swap GL buffers void swapBuffers(); -}; +} #endif // PLATFORM_H diff --git a/src/resourcemanager.cpp b/src/resourcemanager.cpp new file mode 100644 index 00000000..30006809 --- /dev/null +++ b/src/resourcemanager.cpp @@ -0,0 +1,37 @@ +/* The MIT License + * + * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "resourcemanager.h" + +ResourceManager g_resources; + +ResourceManager::ResourceManager() +{ + +} + +ResourceManager::~ResourceManager() +{ + +} diff --git a/src/resourcemanager.h b/src/resourcemanager.h new file mode 100644 index 00000000..fc84ebc8 --- /dev/null +++ b/src/resourcemanager.h @@ -0,0 +1,42 @@ +/* The MIT License + * + * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#ifndef RESOURCEMANAGER_H +#define RESOURCEMANAGER_H + +#include +#include + +class ResourceManager +{ +public: + ResourceManager(); + ~ResourceManager(); + +private: +}; + +extern ResourceManager g_resources; + +#endif // RESOURCEMANAGER_H diff --git a/src/util.cpp b/src/util.cpp index 501f1be9..6a597041 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #include "util.h" #include diff --git a/src/util.h b/src/util.h index 0a9a51d6..967ec7b0 100644 --- a/src/util.h +++ b/src/util.h @@ -21,13 +21,34 @@ * THE SOFTWARE. */ + #ifndef UTIL_H #define UTIL_H #include +#include #include +/// Formatting like printf for std::string, va_list input version std::string vformat(const char *format, va_list args); + +/// Formatting like printf for std::string std::string format(const char *format, ...); +/// Convert int/float like types to std::string +template +inline std::string castToString(const T& x) { + std::ostringstream ss; + ss << x; + return ss.str(); +} + +template +inline T castFromString(const std::string& s) { + std::istringstream ss(s); + T x = 0; + ss >> x; + return x; +} + #endif \ No newline at end of file diff --git a/src/x11platform.cpp b/src/x11platform.cpp index dabf6738..6c1c2252 100644 --- a/src/x11platform.cpp +++ b/src/x11platform.cpp @@ -21,6 +21,7 @@ * THE SOFTWARE. */ + #include "platform.h" #include "engine.h" #include "input.h" @@ -708,3 +709,13 @@ bool Platform::isWindowVisible() { return x11.visible; } + +int Platform::getWindowWidth() +{ + return x11.width; +} + +int Platform::getWindowHeight() +{ + return x11.height; +}