aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules8
m---------lib/SDL_ttf0
m---------lib/libdb0
m---------lib/sdl_image0
m---------lib/sdl_ttf0
m---------lib/soloud0
-rw-r--r--readme.md39
-rw-r--r--src/crepe/Exception.cpp5
-rw-r--r--src/crepe/Exception.h3
-rw-r--r--src/crepe/ValueBroker.h7
-rw-r--r--src/crepe/ValueBroker.hpp10
-rw-r--r--src/crepe/api/Config.cpp1
-rw-r--r--src/crepe/api/Config.h6
-rw-r--r--src/crepe/api/SaveManager.cpp53
-rw-r--r--src/crepe/api/SaveManager.h7
-rw-r--r--src/crepe/facade/DB.cpp20
-rw-r--r--src/crepe/facade/DB.h7
-rw-r--r--src/crepe/util/Proxy.h7
-rw-r--r--src/crepe/util/Proxy.hpp9
-rw-r--r--src/example/db.cpp4
-rw-r--r--src/example/proxy.cpp20
-rw-r--r--src/example/savemgr.cpp13
22 files changed, 125 insertions, 94 deletions
diff --git a/.gitmodules b/.gitmodules
index 481519b..2f64601 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -14,3 +14,11 @@
path = lib/sdl_image
url = https://github.com/libsdl-org/SDL_image
shallow = true
+[submodule "lib/sdl_ttf"]
+ path = lib/sdl_ttf
+ url = https://github.com/libsdl-org/SDL_ttf.git
+ shallow = true
+[submodule "lib/libdb"]
+ path = lib/libdb
+ url = https://github.com/berkeleydb/libdb
+ shallow = true
diff --git a/lib/SDL_ttf b/lib/SDL_ttf
deleted file mode 160000
-Subproject a3d0895c1b60c41ff9e85d9203ddd7485c014da
diff --git a/lib/libdb b/lib/libdb
new file mode 160000
+Subproject 5b7b02ae052442626af54c176335b67ecc613a3
diff --git a/lib/sdl_image b/lib/sdl_image
-Subproject c6c7278b86b5de1232b10de8f612ed05cf2d11f
+Subproject abcf63aa71b4e3ac32120fa9870a6500ddcdcc8
diff --git a/lib/sdl_ttf b/lib/sdl_ttf
new file mode 160000
+Subproject 4a318f8dfaa1bb6f10e0c5e54052e25d3c7f344
diff --git a/lib/soloud b/lib/soloud
-Subproject e82fd32c1f62183922f08c14c814a02b58db187
+Subproject c8e339fdce5c7107bdb3e64bbf707c8fd3449be
diff --git a/readme.md b/readme.md
index 7cf044f..f699c27 100644
--- a/readme.md
+++ b/readme.md
@@ -16,12 +16,32 @@ This repository uses CMake (the makefile in the root of this repository is for
running auxiliary tasks only). See [src/readme.md](src/readme.md) for detailed
building instructions.
-## Installing libraries
+## Code style
+
+Please read [contributing.md](./contributing.md).
+
+## Libraries
+
+This project uses the following libraries
+
+|Name|Version|
+|-|-:|
+|`SDL2`|2.30.9|
+|`SDL2_image`|2.8.2|
+|`SDL_ttf`|2.22.0|
+|`SoLoud`|20200207|
+|Google Test (`GTest`)|1.15.2|
+|Berkeley DB (`libdb`)|5.3.21|
+
+> [!NOTE]
+> Most of these libraries are likely available from your package manager if you
+> are using Linux or MinGW. Make sure your entire distribution is up-to-date if
+> you are not using a rolling release distribution.
-The expected library (source) versions are included in this repository as git
-submodules, which may be used if your distro's package manager does not provide
-(recent enough versions of) them. To build any of the dependencies, make sure
-the submodules are initialized by running:
+The sources for all of the above libraries are also included in this repository
+as git submodules, which may be used if your distro's package manager does not
+provide (recent enough versions of) them. To build any of the libraries
+manually, make sure the submodules are initialized by running:
```
$ git submodule update --init --recursive --depth 1
@@ -35,6 +55,7 @@ Then, follow these steps for each library you want to install:
$ cd lib/sdl2
$ cd lib/soloud/contrib
$ cd lib/sdl_image
+ $ cd lib/sdl_ttf
```
2. Use CMake to configure the build, run the build and install (run **all** of
these):
@@ -44,6 +65,10 @@ Then, follow these steps for each library you want to install:
# cmake --install build
```
+## Tooling
+
+- TODO
+
## Documentation
API documentation is done using Doxygen. To generate the docs, run
@@ -51,7 +76,3 @@ API documentation is done using Doxygen. To generate the docs, run
$ make doxygen
```
-## Code style
-
-Please read [contributing.md](./contributing.md).
-
diff --git a/src/crepe/Exception.cpp b/src/crepe/Exception.cpp
index f27d5a8..dab8f2e 100644
--- a/src/crepe/Exception.cpp
+++ b/src/crepe/Exception.cpp
@@ -6,9 +6,7 @@
using namespace std;
using namespace crepe;
-const char * Exception::what() {
- return error.c_str();
-}
+const char * Exception::what() { return error.c_str(); }
Exception::Exception(const char * fmt, ...) {
va_list args;
@@ -16,4 +14,3 @@ Exception::Exception(const char * fmt, ...) {
this->error = va_stringf(args, fmt);
va_end(args);
}
-
diff --git a/src/crepe/Exception.h b/src/crepe/Exception.h
index e4a7bb8..6473043 100644
--- a/src/crepe/Exception.h
+++ b/src/crepe/Exception.h
@@ -17,7 +17,6 @@ protected:
Exception() = default;
//! Formatted error message
std::string error;
-
};
-}
+} // namespace crepe
diff --git a/src/crepe/ValueBroker.h b/src/crepe/ValueBroker.h
index 88988b4..d844d6a 100644
--- a/src/crepe/ValueBroker.h
+++ b/src/crepe/ValueBroker.h
@@ -23,10 +23,12 @@ public:
virtual const T & get();
typedef std::function<void(const T & target)> setter_t;
- typedef std::function<const T & ()> getter_t;
+ typedef std::function<const T &()> getter_t;
+
private:
setter_t setter;
getter_t getter;
+
public:
/**
* \param setter Function that sets the variable
@@ -35,7 +37,6 @@ public:
ValueBroker(const setter_t & setter, const getter_t & getter);
};
-}
+} // namespace crepe
#include "ValueBroker.hpp"
-
diff --git a/src/crepe/ValueBroker.hpp b/src/crepe/ValueBroker.hpp
index 0d08333..927142f 100644
--- a/src/crepe/ValueBroker.hpp
+++ b/src/crepe/ValueBroker.hpp
@@ -5,11 +5,8 @@
namespace crepe {
template <typename T>
-ValueBroker<T>::ValueBroker(const setter_t & setter, const getter_t & getter) :
- setter(setter),
- getter(getter)
- {
-}
+ValueBroker<T>::ValueBroker(const setter_t & setter, const getter_t & getter)
+ : setter(setter), getter(getter) {}
template <typename T>
const T & ValueBroker<T>::get() {
@@ -21,5 +18,4 @@ void ValueBroker<T>::set(const T & value) {
this->setter(value);
}
-}
-
+} // namespace crepe
diff --git a/src/crepe/api/Config.cpp b/src/crepe/api/Config.cpp
index d6206da..0100bcc 100644
--- a/src/crepe/api/Config.cpp
+++ b/src/crepe/api/Config.cpp
@@ -6,4 +6,3 @@ Config & Config::get_instance() {
static Config instance;
return instance;
}
-
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 56e3af5..8c9e643 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -7,6 +7,7 @@ namespace crepe {
class Config {
private:
Config() = default;
+
public:
~Config() = default;
@@ -16,8 +17,8 @@ public:
// singleton
Config(const Config &) = delete;
Config(Config &&) = delete;
- Config & operator = (const Config &) = delete;
- Config & operator = (Config &&) = delete;
+ Config & operator=(const Config &) = delete;
+ Config & operator=(Config &&) = delete;
public:
//! Logging-related settings
@@ -60,4 +61,3 @@ public:
};
} // namespace crepe
-
diff --git a/src/crepe/api/SaveManager.cpp b/src/crepe/api/SaveManager.cpp
index 23587e4..43276c5 100644
--- a/src/crepe/api/SaveManager.cpp
+++ b/src/crepe/api/SaveManager.cpp
@@ -2,8 +2,8 @@
#include "../util/log.h"
#include "Config.h"
-#include "ValueBroker.h"
#include "SaveManager.h"
+#include "ValueBroker.h"
using namespace std;
using namespace crepe;
@@ -65,17 +65,33 @@ string SaveManager::deserialize(const string & value) const noexcept {
return value;
}
-template <> uint8_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<uint64_t>(value); }
-template <> int8_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<int64_t>(value); }
-template <> uint16_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<uint64_t>(value); }
-template <> int16_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<int64_t>(value); }
-template <> uint32_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<uint64_t>(value); }
-template <> int32_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<int64_t>(value); }
-
-SaveManager::SaveManager() {
- dbg_trace();
+template <>
+uint8_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<uint64_t>(value);
+}
+template <>
+int8_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<int64_t>(value);
+}
+template <>
+uint16_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<uint64_t>(value);
+}
+template <>
+int16_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<int64_t>(value);
+}
+template <>
+uint32_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<uint64_t>(value);
+}
+template <>
+int32_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<int64_t>(value);
}
+SaveManager::SaveManager() { dbg_trace(); }
+
SaveManager & SaveManager::get_instance() {
dbg_trace();
static SaveManager instance;
@@ -118,17 +134,19 @@ template void SaveManager::set(const string &, const double &);
template <typename T>
ValueBroker<T> SaveManager::get(const string & key, const T & default_value) {
- if (!this->has(key))
- this->set<T>(key, default_value);
+ if (!this->has(key)) this->set<T>(key, default_value);
return this->get<T>(key);
}
template ValueBroker<uint8_t> SaveManager::get(const string &, const uint8_t &);
template ValueBroker<int8_t> SaveManager::get(const string &, const int8_t &);
-template ValueBroker<uint16_t> SaveManager::get(const string &, const uint16_t &);
+template ValueBroker<uint16_t> SaveManager::get(const string &,
+ const uint16_t &);
template ValueBroker<int16_t> SaveManager::get(const string &, const int16_t &);
-template ValueBroker<uint32_t> SaveManager::get(const string &, const uint32_t &);
+template ValueBroker<uint32_t> SaveManager::get(const string &,
+ const uint32_t &);
template ValueBroker<int32_t> SaveManager::get(const string &, const int32_t &);
-template ValueBroker<uint64_t> SaveManager::get(const string &, const uint64_t &);
+template ValueBroker<uint64_t> SaveManager::get(const string &,
+ const uint64_t &);
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 &);
@@ -138,8 +156,8 @@ 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 & {
+ [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;
},
@@ -156,4 +174,3 @@ 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/api/SaveManager.h b/src/crepe/api/SaveManager.h
index 3073656..4be85fb 100644
--- a/src/crepe/api/SaveManager.h
+++ b/src/crepe/api/SaveManager.h
@@ -93,8 +93,8 @@ public:
static SaveManager & get_instance();
SaveManager(const SaveManager &) = delete;
SaveManager(SaveManager &&) = delete;
- SaveManager & operator = (const SaveManager &) = delete;
- SaveManager & operator = (SaveManager &&) = delete;
+ SaveManager & operator=(const SaveManager &) = delete;
+ SaveManager & operator=(SaveManager &&) = delete;
private:
/**
@@ -110,5 +110,4 @@ private:
static DB & get_db();
};
-}
-
+} // namespace crepe
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp
index c885560..0a2f455 100644
--- a/src/crepe/facade/DB.cpp
+++ b/src/crepe/facade/DB.cpp
@@ -1,7 +1,7 @@
#include <cstring>
-#include "util/log.h"
#include "Exception.h"
+#include "util/log.h"
#include "DB.h"
@@ -16,20 +16,21 @@ DB::DB(const string & path) {
libdb::DB * db;
if ((ret = libdb::db_create(&db, NULL, 0)) != 0)
throw Exception("db_create: %s", libdb::db_strerror(ret));
- this->db = { db, [] (libdb::DB * db) { db->close(db, 0); } };
+ this->db = {db, [](libdb::DB * db) { db->close(db, 0); }};
// load or create database file
- if ((ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, libdb::DB_BTREE, DB_CREATE, 0)) != 0)
+ if ((ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL,
+ libdb::DB_BTREE, DB_CREATE, 0))
+ != 0)
throw Exception("db->open: %s", libdb::db_strerror(ret));
// create cursor
libdb::DBC * cursor;
if ((ret = this->db->cursor(this->db.get(), NULL, &cursor, 0)) != 0)
throw Exception("db->cursor: %s", libdb::db_strerror(ret));
- this->cursor = { cursor, [] (libdb::DBC * cursor) { cursor->close(cursor); } };
+ this->cursor = {cursor, [](libdb::DBC * cursor) { cursor->close(cursor); }};
}
-
libdb::DBT DB::to_thing(const string & thing) const noexcept {
libdb::DBT thang;
memset(&thang, 0, sizeof(libdb::DBT));
@@ -44,17 +45,15 @@ string DB::get(const string & key) {
memset(&db_val, 0, sizeof(libdb::DBT));
int ret = this->cursor->get(this->cursor.get(), &db_key, &db_val, DB_FIRST);
- if (ret != 0)
- throw Exception("cursor->get: %s", libdb::db_strerror(ret));
- return { static_cast<char *>(db_val.data), db_val.size };
+ if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret));
+ return {static_cast<char *>(db_val.data), db_val.size};
}
void DB::set(const string & key, const string & value) {
libdb::DBT db_key = this->to_thing(key);
libdb::DBT db_val = this->to_thing(value);
int ret = this->db->put(this->db.get(), NULL, &db_key, &db_val, 0);
- if (ret != 0)
- throw Exception("cursor->get: %s", libdb::db_strerror(ret));
+ if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret));
}
bool DB::has(const std::string & key) noexcept {
@@ -65,4 +64,3 @@ bool DB::has(const std::string & key) noexcept {
}
return true;
}
-
diff --git a/src/crepe/facade/DB.h b/src/crepe/facade/DB.h
index b62a974..7c757a2 100644
--- a/src/crepe/facade/DB.h
+++ b/src/crepe/facade/DB.h
@@ -1,14 +1,14 @@
#pragma once
-#include <string>
#include <functional>
#include <memory>
+#include <string>
namespace libdb {
extern "C" {
#include <db.h>
}
-}
+} // namespace libdb
namespace crepe {
@@ -71,5 +71,4 @@ private:
libdb::DBT to_thing(const std::string & thing) const noexcept;
};
-}
-
+} // namespace crepe
diff --git a/src/crepe/util/Proxy.h b/src/crepe/util/Proxy.h
index fbfed0c..f84e462 100644
--- a/src/crepe/util/Proxy.h
+++ b/src/crepe/util/Proxy.h
@@ -16,9 +16,9 @@ template <typename T>
class Proxy {
public:
//! Set operator
- Proxy & operator = (const T &);
+ Proxy & operator=(const T &);
//! Get operator
- operator const T & ();
+ operator const T &();
public:
Proxy(ValueBroker<T>);
@@ -27,7 +27,6 @@ private:
ValueBroker<T> broker;
};
-}
+} // namespace crepe
#include "Proxy.hpp"
-
diff --git a/src/crepe/util/Proxy.hpp b/src/crepe/util/Proxy.hpp
index 4aec9e9..b9923db 100644
--- a/src/crepe/util/Proxy.hpp
+++ b/src/crepe/util/Proxy.hpp
@@ -5,18 +5,17 @@
namespace crepe {
template <typename T>
-Proxy<T>::Proxy(ValueBroker<T> broker) : broker(broker) { }
+Proxy<T>::Proxy(ValueBroker<T> broker) : broker(broker) {}
template <typename T>
-Proxy<T> & Proxy<T>::operator = (const T & val) {
+Proxy<T> & Proxy<T>::operator=(const T & val) {
this->broker.set(val);
return *this;
}
template <typename T>
-Proxy<T>::operator const T & () {
+Proxy<T>::operator const T &() {
return this->broker.get();
}
-}
-
+} // namespace crepe
diff --git a/src/example/db.cpp b/src/example/db.cpp
index c046421..8c06a84 100644
--- a/src/example/db.cpp
+++ b/src/example/db.cpp
@@ -1,12 +1,12 @@
-#include <crepe/facade/DB.h>
#include <crepe/api/Config.h>
+#include <crepe/facade/DB.h>
#include <crepe/util/log.h>
using namespace crepe;
using namespace std;
// run before main
-static auto _ = [] () {
+static auto _ = []() {
auto & cfg = Config::get_instance();
cfg.log.level = LogLevel::TRACE;
return 0;
diff --git a/src/example/proxy.cpp b/src/example/proxy.cpp
index 9f54f96..0afff41 100644
--- a/src/example/proxy.cpp
+++ b/src/example/proxy.cpp
@@ -5,15 +5,15 @@
#include <crepe/ValueBroker.h>
#include <crepe/api/Config.h>
-#include <crepe/util/log.h>
#include <crepe/util/Proxy.h>
+#include <crepe/util/log.h>
using namespace std;
using namespace crepe;
-void test_ro_ref(const int & val) { }
-void test_rw_ref(int & val) { }
-void test_ro_val(int val) { }
+void test_ro_ref(const int & val) {}
+void test_rw_ref(int & val) {}
+void test_ro_val(int val) {}
int main() {
auto & cfg = Config::get_instance();
@@ -21,18 +21,19 @@ int main() {
int real_value = 0;
- ValueBroker<int> broker {
- [&real_value] (const int & target) {
- dbg_logf("set %s to %s", to_string(real_value).c_str(), to_string(target).c_str());
+ ValueBroker<int> broker{
+ [&real_value](const int & target) {
+ dbg_logf("set %s to %s", to_string(real_value).c_str(),
+ to_string(target).c_str());
real_value = target;
},
- [&real_value] () -> const int & {
+ [&real_value]() -> const int & {
dbg_logf("get %s", to_string(real_value).c_str());
return real_value;
},
};
- Proxy<int> proxy { broker };
+ Proxy<int> proxy{broker};
broker.set(54);
proxy = 84;
@@ -43,4 +44,3 @@ int main() {
return 0;
}
-
diff --git a/src/example/savemgr.cpp b/src/example/savemgr.cpp
index c8dd2bc..436fb5a 100644
--- a/src/example/savemgr.cpp
+++ b/src/example/savemgr.cpp
@@ -4,21 +4,21 @@
*/
#include <cassert>
-#include <crepe/util/log.h>
-#include <crepe/util/Proxy.h>
-#include <crepe/api/SaveManager.h>
#include <crepe/api/Config.h>
+#include <crepe/api/SaveManager.h>
+#include <crepe/util/Proxy.h>
+#include <crepe/util/log.h>
using namespace crepe;
// unrelated setup code
-int _ = [] () {
+int _ = []() {
// make sure all log messages get printed
auto & cfg = Config::get_instance();
cfg.log.level = LogLevel::TRACE;
return 0; // satisfy compiler
-} ();
+}();
int main() {
const char * key = "mygame.test";
@@ -27,7 +27,7 @@ int main() {
dbg_logf("has key = %s", mgr.has(key) ? "true" : "false");
ValueBroker<int> prop = mgr.get<int>(key, 0);
- Proxy<int> val = mgr.get<int>(key, 0);
+ Proxy<int> val = mgr.get<int>(key, 0);
dbg_logf("val = %d", mgr.get<int>(key).get());
prop.set(1);
@@ -42,4 +42,3 @@ int main() {
return 0;
}
-