aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Asset.h4
-rw-r--r--src/crepe/api/Config.h38
-rw-r--r--src/crepe/facade/SDLContext.cpp6
-rw-r--r--src/crepe/manager/SaveManager.cpp48
-rw-r--r--src/crepe/manager/SaveManager.h6
5 files changed, 48 insertions, 54 deletions
diff --git a/src/crepe/api/Asset.h b/src/crepe/api/Asset.h
index bfd0ac7..d802e83 100644
--- a/src/crepe/api/Asset.h
+++ b/src/crepe/api/Asset.h
@@ -43,13 +43,13 @@ private:
/**
* \brief Locate asset path, or throw exception if it cannot be found
*
- * This function resolves asset locations relative to crepe::Config::root_pattern if it is
+ * This function resolves asset locations relative to Config::asset::root_pattern if it is
* set and \p src is a relative path. If \p src is an absolute path, it is canonicalized.
* This function only returns if the file can be found.
*
* \param src Arbitrary path to resource file
*
- * \returns \p src if crepe::Config::root_pattern is empty
+ * \returns \p src if Config::asset::root_pattern is empty
* \returns Canonical path to \p src
*
* \throws std::runtime_error if root_pattern cannot be found
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 6472270..fae31f4 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -3,24 +3,21 @@
#include <string>
#include "../util/Log.h"
-
-#include "types.h"
+#include "../types.h"
namespace crepe {
/**
* \brief Global configuration interface
*
- * This class stores engine default settings. Properties on this class are only supposed to be
- * modified *before* execution is handed over from the game programmer to the engine (i.e. the
- * main loop is started).
+ * This struct stores both engine default settings and global configuration parameters.
*/
struct Config final {
//! Retrieve handle to global Config instance
static Config & get_instance();
//! Logging-related settings
- struct {
+ struct log { // NOLINT
/**
* \brief Log level
*
@@ -28,7 +25,7 @@ struct Config final {
*/
Log::Level level = Log::Level::INFO;
/**
- * \brief Colored log output
+ * \brief Enable colored log output
*
* Enables log coloring using ANSI escape codes.
*/
@@ -36,7 +33,7 @@ struct Config final {
} log;
//! Save manager
- struct {
+ struct savemgr { // NOLINT
/**
* \brief Save file location
*
@@ -46,25 +43,22 @@ struct Config final {
std::string location = "save.crepe.db";
} savemgr;
- //! physics-related settings
- struct {
- /**
- * \brief gravity value of physics system
- *
- * Gravity value of game.
- */
+ //! Physics-related settings
+ struct physics { // NOLINT
+ //! Gravity value of physics system
double gravity = 1;
} physics;
- //! default window settings
- struct {
- //! default screen size in pixels
- ivec2 default_size = {1280, 720};
- std::string window_title = "Jetpack joyride clone";
- } window_settings;
+ //! Default window settings
+ struct window { // NOLINT
+ //! Default window size (in pixels)
+ ivec2 size = {1280, 720};
+ //! Default window title
+ std::string title = "Jetpack joyride clone";
+ } window;
//! Asset loading options
- struct {
+ struct asset { // NOLINT
/**
* \brief Pattern to match for Asset base directory
*
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 6becf60..52929e1 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -39,10 +39,10 @@ SDLContext::SDLContext() {
throw runtime_error(format("SDLContext: SDL_Init error: {}", SDL_GetError()));
}
- auto & cfg = Config::get_instance().window_settings;
+ auto & cfg = Config::get_instance().window;
SDL_Window * tmp_window
- = SDL_CreateWindow(cfg.window_title.c_str(), SDL_WINDOWPOS_CENTERED,
- SDL_WINDOWPOS_CENTERED, cfg.default_size.x, cfg.default_size.y, 0);
+ = SDL_CreateWindow(cfg.title.c_str(), SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED, cfg.size.x, cfg.size.y, 0);
if (!tmp_window) {
throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError()));
}
diff --git a/src/crepe/manager/SaveManager.cpp b/src/crepe/manager/SaveManager.cpp
index d4ed1c1..034a283 100644
--- a/src/crepe/manager/SaveManager.cpp
+++ b/src/crepe/manager/SaveManager.cpp
@@ -133,9 +133,32 @@ template void SaveManager::set(const string &, const float &);
template void SaveManager::set(const string &, const double &);
template <typename T>
+T SaveManager::get(const string & key) {
+ return this->deserialize<T>(this->get_db().get(key));
+}
+template uint8_t SaveManager::get(const string &);
+template int8_t SaveManager::get(const string &);
+template uint16_t SaveManager::get(const string &);
+template int16_t SaveManager::get(const string &);
+template uint32_t SaveManager::get(const string &);
+template int32_t SaveManager::get(const string &);
+template uint64_t SaveManager::get(const string &);
+template int64_t SaveManager::get(const string &);
+template float SaveManager::get(const string &);
+template double SaveManager::get(const string &);
+template string SaveManager::get(const string &);
+
+template <typename T>
ValueBroker<T> SaveManager::get(const string & key, const T & default_value) {
if (!this->has(key)) this->set<T>(key, default_value);
- return this->get<T>(key);
+ T value;
+ return {
+ [this, key](const T & target) { this->set<T>(key, target); },
+ [this, key, value]() mutable -> const T & {
+ value = this->get<T>(key);
+ return value;
+ },
+ };
}
template ValueBroker<uint8_t> SaveManager::get(const string &, const uint8_t &);
template ValueBroker<int8_t> SaveManager::get(const string &, const int8_t &);
@@ -148,26 +171,3 @@ template ValueBroker<int64_t> SaveManager::get(const string &, const int64_t &);
template ValueBroker<float> SaveManager::get(const string &, const float &);
template ValueBroker<double> SaveManager::get(const string &, const double &);
template ValueBroker<string> SaveManager::get(const string &, const string &);
-
-template <typename T>
-ValueBroker<T> SaveManager::get(const string & key) {
- T value;
- return {
- [this, key](const T & target) { this->set<T>(key, target); },
- [this, key, value]() mutable -> const T & {
- value = this->deserialize<T>(this->get_db().get(key));
- return value;
- },
- };
-}
-template ValueBroker<uint8_t> SaveManager::get(const string &);
-template ValueBroker<int8_t> SaveManager::get(const string &);
-template ValueBroker<uint16_t> SaveManager::get(const string &);
-template ValueBroker<int16_t> SaveManager::get(const string &);
-template ValueBroker<uint32_t> SaveManager::get(const string &);
-template ValueBroker<int32_t> SaveManager::get(const string &);
-template ValueBroker<uint64_t> SaveManager::get(const string &);
-template ValueBroker<int64_t> SaveManager::get(const string &);
-template ValueBroker<float> SaveManager::get(const string &);
-template ValueBroker<double> SaveManager::get(const string &);
-template ValueBroker<string> SaveManager::get(const string &);
diff --git a/src/crepe/manager/SaveManager.h b/src/crepe/manager/SaveManager.h
index 3d8c852..e2ef005 100644
--- a/src/crepe/manager/SaveManager.h
+++ b/src/crepe/manager/SaveManager.h
@@ -33,17 +33,17 @@ public:
ValueBroker<T> get(const std::string & key, const T & default_value);
/**
- * \brief Get a read/write reference to a value
+ * \brief Get a value directly
*
* \param key The value key
*
- * \return Read/write reference to the value
+ * \return The value
*
* \note Attempting to read this value before it is initialized (i.e. set) will result in an
* exception
*/
template <typename T>
- ValueBroker<T> get(const std::string & key);
+ T get(const std::string & key);
/**
* \brief Set a value directly