From dc93b1e9b3e05dfd3e271aaccbee1210180a6906 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 7 Nov 2024 21:19:01 +0100 Subject: update clang-format and run `make format` over my (loek)s files --- .clang-format | 1 + mwe/ecs-homemade/src/Components.cpp | 4 +- mwe/ecs-homemade/src/GameObjectMax.cpp | 6 ++- .../inc/ContiguousContainer.hpp | 3 +- mwe/ecs-memory-efficient/src/Components.cpp | 4 +- mwe/ecs-memory-efficient/src/GameObjectMax.cpp | 6 ++- mwe/events/include/customTypes.h | 4 +- mwe/events/include/eventHandler.h | 3 +- mwe/events/src/event.cpp | 31 +++++++++---- mwe/events/src/main.cpp | 4 +- mwe/events/src/uiObject.cpp | 13 ++++-- mwe/gameloop/src/gameObject.cpp | 7 ++- src/crepe/Exception.cpp | 5 +- src/crepe/Exception.h | 3 +- src/crepe/ValueBroker.h | 7 +-- src/crepe/ValueBroker.hpp | 11 ++--- src/crepe/api/CircleCollider.h | 3 +- src/crepe/api/Config.cpp | 1 - src/crepe/api/Config.h | 6 +-- src/crepe/api/Metadata.cpp | 4 +- src/crepe/api/ParticleEmitter.cpp | 11 +++-- src/crepe/api/Rigidbody.cpp | 3 +- src/crepe/api/SaveManager.cpp | 53 ++++++++++++++-------- src/crepe/api/SaveManager.h | 7 ++- src/crepe/api/Sprite.cpp | 5 +- src/crepe/api/Transform.cpp | 5 +- src/crepe/facade/DB.cpp | 25 +++++----- src/crepe/facade/DB.h | 7 ++- src/crepe/util/Proxy.h | 7 ++- src/crepe/util/Proxy.hpp | 9 ++-- src/example/db.cpp | 4 +- src/example/proxy.cpp | 20 ++++---- src/example/savemgr.cpp | 13 +++--- src/makefile | 2 - 34 files changed, 179 insertions(+), 118 deletions(-) diff --git a/.clang-format b/.clang-format index 3ae6c28..8ce4033 100644 --- a/.clang-format +++ b/.clang-format @@ -23,6 +23,7 @@ ReflowComments: false AlignEscapedNewlines: DontAlign BreakBeforeBinaryOperators: All AlwaysBreakTemplateDeclarations: Yes +PackConstructorInitializers: CurrentLine ... # vim: ft=yaml diff --git a/mwe/ecs-homemade/src/Components.cpp b/mwe/ecs-homemade/src/Components.cpp index de8753e..0d62bd5 100644 --- a/mwe/ecs-homemade/src/Components.cpp +++ b/mwe/ecs-homemade/src/Components.cpp @@ -6,7 +6,9 @@ Component::Component() : mActive(true) {} Sprite::Sprite(std::string path) : mPath(path) {} Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mMass(mass), mGravityScale(gravityScale), mBodyType(bodyType) {} + : mMass(mass), + mGravityScale(gravityScale), + mBodyType(bodyType) {} Colider::Colider(int size) : mSize(size) {} diff --git a/mwe/ecs-homemade/src/GameObjectMax.cpp b/mwe/ecs-homemade/src/GameObjectMax.cpp index b0c5af7..753c8e2 100644 --- a/mwe/ecs-homemade/src/GameObjectMax.cpp +++ b/mwe/ecs-homemade/src/GameObjectMax.cpp @@ -4,4 +4,8 @@ GameObject::GameObject(std::uint32_t id, std::string name, std::string tag, int layer) - : mId(id), mName(name), mTag(tag), mActive(true), mLayer(layer) {} + : mId(id), + mName(name), + mTag(tag), + mActive(true), + mLayer(layer) {} diff --git a/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp b/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp index 408d5aa..ff8fde4 100644 --- a/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp +++ b/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp @@ -1,5 +1,6 @@ template -ContiguousContainer::ContiguousContainer() : mSize(0), mCapacity(10) { +ContiguousContainer::ContiguousContainer() : mSize(0), + mCapacity(10) { // Allocate memory for 10 objects initially mData = static_cast(malloc(mCapacity * sizeof(T))); if (!mData) { diff --git a/mwe/ecs-memory-efficient/src/Components.cpp b/mwe/ecs-memory-efficient/src/Components.cpp index c8347b3..2ec8609 100644 --- a/mwe/ecs-memory-efficient/src/Components.cpp +++ b/mwe/ecs-memory-efficient/src/Components.cpp @@ -6,6 +6,8 @@ Component::Component() : mActive(true) {} Sprite::Sprite(std::string path) : mPath(path) {} Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mMass(mass), mGravityScale(gravityScale), mBodyType(bodyType) {} + : mMass(mass), + mGravityScale(gravityScale), + mBodyType(bodyType) {} Colider::Colider(int size) : mSize(size) {} diff --git a/mwe/ecs-memory-efficient/src/GameObjectMax.cpp b/mwe/ecs-memory-efficient/src/GameObjectMax.cpp index b0c5af7..753c8e2 100644 --- a/mwe/ecs-memory-efficient/src/GameObjectMax.cpp +++ b/mwe/ecs-memory-efficient/src/GameObjectMax.cpp @@ -4,4 +4,8 @@ GameObject::GameObject(std::uint32_t id, std::string name, std::string tag, int layer) - : mId(id), mName(name), mTag(tag), mActive(true), mLayer(layer) {} + : mId(id), + mName(name), + mTag(tag), + mActive(true), + mLayer(layer) {} diff --git a/mwe/events/include/customTypes.h b/mwe/events/include/customTypes.h index a5d8dc9..415b989 100644 --- a/mwe/events/include/customTypes.h +++ b/mwe/events/include/customTypes.h @@ -33,6 +33,8 @@ struct Collision { // Constructor to initialize a Collision Collision(int idA, int idB, const Vector2 & point, const Vector2 & normal, float depth) - : objectIdA(idA), objectIdB(idB), contactPoint(point), + : objectIdA(idA), + objectIdB(idB), + contactPoint(point), contactNormal(normal) {} }; diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h index aa8f63b..3a83b15 100644 --- a/mwe/events/include/eventHandler.h +++ b/mwe/events/include/eventHandler.h @@ -24,7 +24,8 @@ class EventHandlerWrapper : public IEventHandlerWrapper { public: explicit EventHandlerWrapper(const EventHandler & handler, const bool destroyOnSuccess = false) - : m_handler(handler), m_handlerType(m_handler.target_type().name()), + : m_handler(handler), + m_handlerType(m_handler.target_type().name()), m_destroyOnSuccess(destroyOnSuccess) { // std::cout << m_handlerType << std::endl; } diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp index 0c9f3ed..8ffa0b1 100644 --- a/mwe/events/src/event.cpp +++ b/mwe/events/src/event.cpp @@ -23,7 +23,9 @@ void Event::markHandled() { isHandled = true; } // KeyPressedEvent class methods KeyPressedEvent::KeyPressedEvent(int keycode) - : Event("KeyPressedEvent"), key(keycode), repeatCount(0) {} + : Event("KeyPressedEvent"), + key(keycode), + repeatCount(0) {} Keycode KeyPressedEvent::getKeyCode() const { return key; } @@ -31,13 +33,16 @@ int KeyPressedEvent::getRepeatCount() const { return repeatCount; } // KeyReleasedEvent class methods KeyReleasedEvent::KeyReleasedEvent(int keycode) - : Event("KeyReleasedEvent"), key(keycode) {} + : Event("KeyReleasedEvent"), + key(keycode) {} Keycode KeyReleasedEvent::getKeyCode() const { return key; } // MousePressedEvent class methods MousePressedEvent::MousePressedEvent(int mouseX, int mouseY) - : Event("MousePressedEvent"), mouseX(mouseX), mouseY(mouseY) {} + : Event("MousePressedEvent"), + mouseX(mouseX), + mouseY(mouseY) {} std::pair MousePressedEvent::getMousePosition() const { return {mouseX, mouseY}; @@ -45,26 +50,36 @@ std::pair MousePressedEvent::getMousePosition() const { //Collision event CollisionEvent::CollisionEvent(Collision collision) - : collisionData(collision), Event("CollisionEvent") {} + : collisionData(collision), + Event("CollisionEvent") {} Collision CollisionEvent::getCollisionData() const { return this->collisionData; } TextSubmitEvent::TextSubmitEvent(std::string text) - : text(text), Event("TextSubmitEvent") {} + : text(text), + Event("TextSubmitEvent") {} std::string TextSubmitEvent::getText() const { return this->text; } MouseReleasedEvent::MouseReleasedEvent(int x, int y, MouseButton button) - : mouseX(x), mouseY(y), button(button), Event("MouseReleased") {} + : mouseX(x), + mouseY(y), + button(button), + Event("MouseReleased") {} std::pair MouseReleasedEvent::getMousePosition() const { return {mouseX, mouseY}; } MouseClickEvent::MouseClickEvent(int x, int y, MouseButton button) - : mouseX(x), mouseY(y), button(button), Event("MouseClickEvent") {} + : mouseX(x), + mouseY(y), + button(button), + Event("MouseClickEvent") {} MouseMovedEvent::MouseMovedEvent(int x, int y) - : mouseX(x), mouseY(y), Event("MouseMovedEvent") {} + : mouseX(x), + mouseY(y), + Event("MouseMovedEvent") {} std::pair MouseClickEvent::getMousePosition() const { return {mouseX, mouseY}; } diff --git a/mwe/events/src/main.cpp b/mwe/events/src/main.cpp index d49cf74..f4e7390 100644 --- a/mwe/events/src/main.cpp +++ b/mwe/events/src/main.cpp @@ -11,7 +11,9 @@ class PlayerDamagedEvent : public Event { public: PlayerDamagedEvent(int damage, int playerID) - : Event("PlayerDamaged"), damage(damage), playerID(playerID) {} + : Event("PlayerDamaged"), + damage(damage), + playerID(playerID) {} REGISTER_EVENT_TYPE(PlayerDamagedEvent); diff --git a/mwe/events/src/uiObject.cpp b/mwe/events/src/uiObject.cpp index 8405469..947d1a2 100644 --- a/mwe/events/src/uiObject.cpp +++ b/mwe/events/src/uiObject.cpp @@ -7,7 +7,9 @@ UIObject::UIObject(int width, int height) : width(width), height(height) {} Button::Button(int width, int height) : UIObject(width, height) {} Text::Text(int width, int height) - : UIObject(width, height), size(12), font(nullptr), + : UIObject(width, height), + size(12), + font(nullptr), color{255, 255, 255} { // Default size and color alignment.horizontal = Alignment::Horizontal::CENTER; alignment.vertical = Alignment::Vertical::MIDDLE; @@ -15,8 +17,13 @@ Text::Text(int width, int height) } TextInput::TextInput(int width, int height) - : UIObject(width, height), textBuffer(""), placeholder(""), isActive(false), - textColor{255, 255, 255}, backgroundColor{0, 0, 0}, maxLength(100), + : UIObject(width, height), + textBuffer(""), + placeholder(""), + isActive(false), + textColor{255, 255, 255}, + backgroundColor{0, 0, 0}, + maxLength(100), font(nullptr) { alignment.horizontal = Alignment::Horizontal::LEFT; alignment.vertical = Alignment::Vertical::TOP; diff --git a/mwe/gameloop/src/gameObject.cpp b/mwe/gameloop/src/gameObject.cpp index 78217c4..b33dc78 100644 --- a/mwe/gameloop/src/gameObject.cpp +++ b/mwe/gameloop/src/gameObject.cpp @@ -26,5 +26,10 @@ void GameObject::setVelY(float value) { velY = value; } GameObject::GameObject(std::string name, float x, float y, float width, float height, float velX, float velY) - : name(name), x(x), y(y), width(width), height(height), velX(velX), + : name(name), + x(x), + y(y), + width(width), + height(height), + velX(velX), velY(velY) {} 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 setter_t; - typedef std::function getter_t; + typedef std::function 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..5c3bed9 100644 --- a/src/crepe/ValueBroker.hpp +++ b/src/crepe/ValueBroker.hpp @@ -5,11 +5,9 @@ namespace crepe { template -ValueBroker::ValueBroker(const setter_t & setter, const getter_t & getter) : - setter(setter), - getter(getter) - { -} +ValueBroker::ValueBroker(const setter_t & setter, const getter_t & getter) + : setter(setter), + getter(getter) {} template const T & ValueBroker::get() { @@ -21,5 +19,4 @@ void ValueBroker::set(const T & value) { this->setter(value); } -} - +} // namespace crepe diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index caa7e43..e77a592 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -6,7 +6,8 @@ namespace crepe { class CircleCollider : public Collider { public: CircleCollider(game_object_id_t game_object_id, int radius) - : Collider(game_object_id), radius(radius) {} + : Collider(game_object_id), + radius(radius) {} int radius; }; 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/Metadata.cpp b/src/crepe/api/Metadata.cpp index 76f11d7..d421de5 100644 --- a/src/crepe/api/Metadata.cpp +++ b/src/crepe/api/Metadata.cpp @@ -4,4 +4,6 @@ using namespace crepe; using namespace std; Metadata::Metadata(game_object_id_t id, const string & name, const string & tag) - : Component(id), name(name), tag(tag) {} + : Component(id), + name(name), + tag(tag) {} diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 3b2e2f2..0bc2197 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -11,9 +11,14 @@ ParticleEmitter::ParticleEmitter(game_object_id_t id, uint32_t max_particles, uint32_t speed_offset, uint32_t angle, uint32_t angleOffset, float begin_lifespan, float end_lifespan) - : Component(id), max_particles(max_particles), emission_rate(emission_rate), - speed(speed), speed_offset(speed_offset), position{0, 0}, - begin_lifespan(begin_lifespan), end_lifespan(end_lifespan) { + : Component(id), + max_particles(max_particles), + emission_rate(emission_rate), + speed(speed), + speed_offset(speed_offset), + position{0, 0}, + begin_lifespan(begin_lifespan), + end_lifespan(end_lifespan) { std::srand( static_cast(std::time(nullptr))); // initialize random seed std::cout << "Create emitter" << std::endl; diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index cbf1325..3bf1c5b 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -3,7 +3,8 @@ using namespace crepe; crepe::Rigidbody::Rigidbody(uint32_t game_object_id, const Data & data) - : Component(game_object_id), data(data) {} + : Component(game_object_id), + data(data) {} void crepe::Rigidbody::add_force_linear(const Vector2 & force) { this->data.linear_velocity += force; 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(value); } -template <> int8_t SaveManager::deserialize(const string & value) const noexcept { return deserialize(value); } -template <> uint16_t SaveManager::deserialize(const string & value) const noexcept { return deserialize(value); } -template <> int16_t SaveManager::deserialize(const string & value) const noexcept { return deserialize(value); } -template <> uint32_t SaveManager::deserialize(const string & value) const noexcept { return deserialize(value); } -template <> int32_t SaveManager::deserialize(const string & value) const noexcept { return deserialize(value); } - -SaveManager::SaveManager() { - dbg_trace(); +template <> +uint8_t SaveManager::deserialize(const string & value) const noexcept { + return deserialize(value); +} +template <> +int8_t SaveManager::deserialize(const string & value) const noexcept { + return deserialize(value); +} +template <> +uint16_t SaveManager::deserialize(const string & value) const noexcept { + return deserialize(value); +} +template <> +int16_t SaveManager::deserialize(const string & value) const noexcept { + return deserialize(value); +} +template <> +uint32_t SaveManager::deserialize(const string & value) const noexcept { + return deserialize(value); +} +template <> +int32_t SaveManager::deserialize(const string & value) const noexcept { + return deserialize(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 ValueBroker SaveManager::get(const string & key, const T & default_value) { - if (!this->has(key)) - this->set(key, default_value); + if (!this->has(key)) this->set(key, default_value); return this->get(key); } template ValueBroker SaveManager::get(const string &, const uint8_t &); template ValueBroker SaveManager::get(const string &, const int8_t &); -template ValueBroker SaveManager::get(const string &, const uint16_t &); +template ValueBroker SaveManager::get(const string &, + const uint16_t &); template ValueBroker SaveManager::get(const string &, const int16_t &); -template ValueBroker SaveManager::get(const string &, const uint32_t &); +template ValueBroker SaveManager::get(const string &, + const uint32_t &); template ValueBroker SaveManager::get(const string &, const int32_t &); -template ValueBroker SaveManager::get(const string &, const uint64_t &); +template ValueBroker SaveManager::get(const string &, + const uint64_t &); template ValueBroker SaveManager::get(const string &, const int64_t &); template ValueBroker SaveManager::get(const string &, const float &); template ValueBroker SaveManager::get(const string &, const double &); @@ -138,8 +156,8 @@ template ValueBroker SaveManager::get(const string & key) { T value; return { - [this, key] (const T & target) { this->set(key, target); }, - [this, key, value] () mutable -> const T & { + [this, key](const T & target) { this->set(key, target); }, + [this, key, value]() mutable -> const T & { value = this->deserialize(this->get_db().get(key)); return value; }, @@ -156,4 +174,3 @@ template ValueBroker SaveManager::get(const string &); template ValueBroker SaveManager::get(const string &); template ValueBroker SaveManager::get(const string &); template ValueBroker 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/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index d3465c7..88a442b 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -12,7 +12,10 @@ using namespace crepe; Sprite::Sprite(game_object_id_t id, shared_ptr image, const Color & color, const FlipSettings & flip) - : Component(id), color(color), flip(flip), sprite_image(image) { + : Component(id), + color(color), + flip(flip), + sprite_image(image) { dbg_trace(); } diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index a244bc5..e401120 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -6,6 +6,9 @@ using namespace crepe; Transform::Transform(game_object_id_t id, const Vector2 & point, double rotation, double scale) - : Component(id), position(point), rotation(rotation), scale(scale) { + : Component(id), + position(point), + rotation(rotation), + scale(scale) { dbg_trace(); } diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp index c885560..405f7c4 100644 --- a/src/crepe/facade/DB.cpp +++ b/src/crepe/facade/DB.cpp @@ -1,7 +1,7 @@ #include -#include "util/log.h" #include "Exception.h" +#include "util/log.h" #include "DB.h" @@ -16,20 +16,20 @@ 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) - throw Exception("db->open: %s", libdb::db_strerror(ret)); + ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, + libdb::DB_BTREE, DB_CREATE, 0); + if (ret != 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); } }; + ret = this->db->cursor(this->db.get(), NULL, &cursor, 0); + if (ret != 0) throw Exception("db->cursor: %s", libdb::db_strerror(ret)); + 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 +44,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(db_val.data), db_val.size }; + if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret)); + return {static_cast(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 +63,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 #include #include +#include namespace libdb { extern "C" { #include } -} +} // 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 class Proxy { public: //! Set operator - Proxy & operator = (const T &); + Proxy & operator=(const T &); //! Get operator - operator const T & (); + operator const T &(); public: Proxy(ValueBroker); @@ -27,7 +27,6 @@ private: ValueBroker 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 -Proxy::Proxy(ValueBroker broker) : broker(broker) { } +Proxy::Proxy(ValueBroker broker) : broker(broker) {} template -Proxy & Proxy::operator = (const T & val) { +Proxy & Proxy::operator=(const T & val) { this->broker.set(val); return *this; } template -Proxy::operator const T & () { +Proxy::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 #include +#include #include 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 #include -#include #include +#include 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 broker { - [&real_value] (const int & target) { - dbg_logf("set %s to %s", to_string(real_value).c_str(), to_string(target).c_str()); + ValueBroker 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 proxy { broker }; + Proxy 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 -#include -#include -#include #include +#include +#include +#include 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 prop = mgr.get(key, 0); - Proxy val = mgr.get(key, 0); + Proxy val = mgr.get(key, 0); dbg_logf("val = %d", mgr.get(key).get()); prop.set(1); @@ -42,4 +42,3 @@ int main() { return 0; } - diff --git a/src/makefile b/src/makefile index ee189e3..d9c5a57 100644 --- a/src/makefile +++ b/src/makefile @@ -32,8 +32,6 @@ TODO += crepe/Position.h TODO += crepe/api/AssetManager.cpp TODO += crepe/api/AssetManager.h TODO += crepe/api/AssetManager.hpp -LOEK += crepe/api/AudioSource.cpp -LOEK += crepe/api/AudioSource.h LOEK += crepe/api/BehaviorScript.cpp LOEK += crepe/api/BehaviorScript.h LOEK += crepe/api/BehaviorScript.hpp -- cgit v1.2.3