diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-30 16:42:21 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-30 16:42:21 +0100 |
commit | 9eff2e24fa4cf0ffad2b47cc922a6558bc1a9fa1 (patch) | |
tree | e673cba5f221523d37f51b67a155abfc0c415eb3 /src/crepe | |
parent | f7d70abf3fee5933034d93f594f898849c5273ad (diff) |
`make format`
Diffstat (limited to 'src/crepe')
25 files changed, 60 insertions, 87 deletions
diff --git a/src/crepe/Resource.cpp b/src/crepe/Resource.cpp index e254695..27b4c4b 100644 --- a/src/crepe/Resource.cpp +++ b/src/crepe/Resource.cpp @@ -2,5 +2,4 @@ using namespace crepe; -Resource::Resource(const Asset & asset) { } - +Resource::Resource(const Asset & asset) {} diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index cc70801..7b05cb1 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -3,17 +3,13 @@ using namespace crepe; using namespace std; -AudioSource::AudioSource(game_object_id_t id, const Asset & src) : - Component(id), - source(src) -{ } +AudioSource::AudioSource(game_object_id_t id, const Asset & src) + : Component(id), + source(src) {} void AudioSource::play(bool looping) { this->loop = looping; this->oneshot_play = true; } -void AudioSource::stop() { - this->oneshot_stop = true; -} - +void AudioSource::stop() { this->oneshot_stop = true; } diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 1899c22..63b4bc4 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -4,8 +4,8 @@ #include "../types.h" #include "../util/Private.h" -#include "GameObject.h" #include "Asset.h" +#include "GameObject.h" namespace crepe { @@ -20,6 +20,7 @@ protected: AudioSource(game_object_id_t id, const Asset & source); //! Only ComponentManager can create components friend class ComponentManager; + public: // But std::unique_ptr needs to be able to destoy this component again virtual ~AudioSource() = default; @@ -62,4 +63,3 @@ private: }; } // namespace crepe - diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index b277185..731cfb7 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -22,9 +22,7 @@ LoopManager::LoopManager() { this->load_system<ScriptSystem>(); } -void LoopManager::process_input() { - this->sdl_context.handle_events(this->game_running); -} +void LoopManager::process_input() { this->sdl_context.handle_events(this->game_running); } void LoopManager::start() { this->setup(); @@ -69,4 +67,3 @@ void LoopManager::render() { } void LoopManager::update() {} - diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index 6ea5ccc..d8910a0 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -2,10 +2,10 @@ #include <memory> +#include "../facade/SDLContext.h" #include "../manager/ComponentManager.h" #include "../manager/SceneManager.h" #include "../system/System.h" -#include "../facade/SDLContext.h" #include "LoopTimer.h" diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 66dad17..9f1e8ce 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -2,8 +2,8 @@ #include <string> -#include "../util/OptionalRef.h" #include "../manager/Mediator.h" +#include "../util/OptionalRef.h" namespace crepe { @@ -37,6 +37,7 @@ public: // TODO: Late references should ALWAYS be private! This is currently kept as-is so unit tests // keep passing, but this reference should not be directly accessible by the user!!! + protected: /** * \name Late references diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index a27838e..4091fd4 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -25,4 +25,3 @@ void Script::set_next_scene(const string & name) { SceneManager & mgr = mediator.scene_manager; mgr.set_next_scene(name); } - diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index e1f86b2..1b339b0 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -2,10 +2,10 @@ #include <vector> +#include "../manager/EventManager.h" +#include "../manager/Mediator.h" #include "../types.h" #include "../util/OptionalRef.h" -#include "../manager/Mediator.h" -#include "../manager/EventManager.h" namespace crepe { diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp index 0df1f48..33a0c47 100644 --- a/src/crepe/facade/Sound.cpp +++ b/src/crepe/facade/Sound.cpp @@ -23,26 +23,25 @@ Sound::~Sound() { dbg_trace(); } // ctx.engine.setLooping(this->handle, this->looping); // } // } -// +// // void Sound::pause(SoundContext & ctx) { // if (ctx.engine.getPause(this->handle)) return; // ctx.engine.setPause(this->handle, true); // } -// +// // void Sound::rewind(SoundContext & ctx) { // if (!ctx.engine.isValidVoiceHandle(this->handle)) return; // ctx.engine.seek(this->handle, 0); // } -// +// // void Sound::set_volume(SoundContext & ctx, float volume) { // this->volume = volume; // if (!ctx.engine.isValidVoiceHandle(this->handle)) return; // ctx.engine.setVolume(this->handle, this->volume); // } -// +// // void Sound::set_looping(SoundContext & ctx, bool looping) { // this->looping = looping; // if (!ctx.engine.isValidVoiceHandle(this->handle)) return; // ctx.engine.setLooping(this->handle, this->looping); // } - diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp index 3ae5956..470b3cc 100644 --- a/src/crepe/facade/SoundContext.cpp +++ b/src/crepe/facade/SoundContext.cpp @@ -21,9 +21,7 @@ Sound::Handle SoundContext::play(Sound & resource) { }; } -void SoundContext::stop(Sound::Handle & handle) { - this->engine.stop(handle.handle); -} +void SoundContext::stop(Sound::Handle & handle) { this->engine.stop(handle.handle); } void SoundContext::set_volume(Sound & resource, Sound::Handle & handle, float volume) { this->engine.setVolume(handle.handle, volume); @@ -33,4 +31,3 @@ void SoundContext::set_volume(Sound & resource, Sound::Handle & handle, float vo void SoundContext::set_loop(Sound & resource, Sound::Handle & handle, bool loop) { this->engine.setLooping(handle.handle, loop); } - diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index 5a96158..80cf8b4 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -1,6 +1,6 @@ #include "../api/GameObject.h" -#include "../util/Log.h" #include "../types.h" +#include "../util/Log.h" #include "ComponentManager.h" diff --git a/src/crepe/manager/Manager.cpp b/src/crepe/manager/Manager.cpp index fe7c936..1182785 100644 --- a/src/crepe/manager/Manager.cpp +++ b/src/crepe/manager/Manager.cpp @@ -2,5 +2,4 @@ using namespace crepe; -Manager::Manager(Mediator & mediator) : mediator(mediator) { } - +Manager::Manager(Mediator & mediator) : mediator(mediator) {} diff --git a/src/crepe/manager/Manager.h b/src/crepe/manager/Manager.h index 9adfd0b..4f21ef4 100644 --- a/src/crepe/manager/Manager.h +++ b/src/crepe/manager/Manager.h @@ -13,5 +13,4 @@ protected: Mediator & mediator; }; -} - +} // namespace crepe diff --git a/src/crepe/manager/Mediator.h b/src/crepe/manager/Mediator.h index 475aed9..e9c10b1 100644 --- a/src/crepe/manager/Mediator.h +++ b/src/crepe/manager/Mediator.h @@ -3,8 +3,8 @@ #include "../util/OptionalRef.h" // TODO: remove these singletons: -#include "SaveManager.h" #include "EventManager.h" +#include "SaveManager.h" namespace crepe { @@ -32,4 +32,4 @@ struct Mediator { OptionalRef<ResourceManager> resource_manager; }; -} +} // namespace crepe diff --git a/src/crepe/manager/ResourceManager.cpp b/src/crepe/manager/ResourceManager.cpp index 87585ad..7c01808 100644 --- a/src/crepe/manager/ResourceManager.cpp +++ b/src/crepe/manager/ResourceManager.cpp @@ -18,17 +18,13 @@ void ResourceManager::clear() { }); } -void ResourceManager::clear_all() { - this->resources.clear(); -} +void ResourceManager::clear_all() { this->resources.clear(); } void ResourceManager::set_persistent(const Asset & asset, bool persistent) { this->get_entry(asset).persistent = persistent; } ResourceManager::CacheEntry & ResourceManager::get_entry(const Asset & asset) { - if (!this->resources.contains(asset)) - this->resources[asset] = {}; + if (!this->resources.contains(asset)) this->resources[asset] = {}; return this->resources.at(asset); } - diff --git a/src/crepe/manager/ResourceManager.hpp b/src/crepe/manager/ResourceManager.hpp index 8270bc5..5167d71 100644 --- a/src/crepe/manager/ResourceManager.hpp +++ b/src/crepe/manager/ResourceManager.hpp @@ -9,18 +9,19 @@ namespace crepe { template <typename T> T & ResourceManager::get(const Asset & asset) { using namespace std; - static_assert(is_base_of<Resource, T>::value, "cache must recieve a derivative class of Resource"); + static_assert(is_base_of<Resource, T>::value, + "cache must recieve a derivative class of Resource"); CacheEntry & entry = this->get_entry(asset); - if (entry.resource == nullptr) - entry.resource = make_unique<T>(asset); + if (entry.resource == nullptr) entry.resource = make_unique<T>(asset); T * concrete_resource = dynamic_cast<T *>(entry.resource.get()); if (concrete_resource == nullptr) - throw runtime_error(format("ResourceManager: mismatch between requested type and actual type of resource ({})", asset.get_path())); + throw runtime_error(format("ResourceManager: mismatch between requested type and " + "actual type of resource ({})", + asset.get_path())); return *concrete_resource; } -} - +} // namespace crepe diff --git a/src/crepe/manager/SaveManager.cpp b/src/crepe/manager/SaveManager.cpp index 121d017..d4ed1c1 100644 --- a/src/crepe/manager/SaveManager.cpp +++ b/src/crepe/manager/SaveManager.cpp @@ -1,7 +1,7 @@ +#include "../ValueBroker.h" +#include "../api/Config.h" #include "../facade/DB.h" #include "../util/Log.h" -#include "../api/Config.h" -#include "../ValueBroker.h" #include "SaveManager.h" diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index 84a101a..0696b34 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -10,7 +10,8 @@ using namespace std; void AudioSystem::update() { ComponentManager & component_manager = this->mediator.component_manager; ResourceManager & resource_manager = this->mediator.resource_manager; - RefVector<AudioSource> components = component_manager.get_components_by_type<AudioSource>(); + RefVector<AudioSource> components + = component_manager.get_components_by_type<AudioSource>(); for (AudioSource & component : components) { Sound & resource = resource_manager.get<Sound>(component.source); @@ -28,7 +29,8 @@ void AudioSystem::update() { } } -void AudioSystem::diff_update(AudioSource & component, ComponentPrivate & data, Sound & resource) { +void AudioSystem::diff_update(AudioSource & component, ComponentPrivate & data, + Sound & resource) { SoundContext & context = this->get_context(); if (component.active != data.last_active) { @@ -64,8 +66,6 @@ void AudioSystem::update_last(const AudioSource & component, ComponentPrivate & } SoundContext & AudioSystem::get_context() { - if (this->context.empty()) - this->context.set<SoundContext>(); + if (this->context.empty()) this->context.set<SoundContext>(); return this->context.get<SoundContext>(); } - diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h index a004c60..c941470 100644 --- a/src/crepe/system/AudioSystem.h +++ b/src/crepe/system/AudioSystem.h @@ -1,8 +1,8 @@ #pragma once -#include "../facade/SoundContext.h" -#include "../facade/Sound.h" #include "../api/AudioSource.h" +#include "../facade/Sound.h" +#include "../facade/SoundContext.h" #include "System.h" @@ -37,9 +37,9 @@ private: protected: virtual SoundContext & get_context(); + private: Private context; }; } // namespace crepe - diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index eba9dfa..bebcf3d 100644 --- a/src/crepe/system/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -1,10 +1,10 @@ #include <cmath> -#include "../manager/ComponentManager.h" #include "../api/Config.h" #include "../api/Rigidbody.h" #include "../api/Transform.h" #include "../api/Vector2.h" +#include "../manager/ComponentManager.h" #include "PhysicsSystem.h" diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 4e97b3e..0ad685c 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -5,12 +5,12 @@ #include <stdexcept> #include <vector> -#include "../manager/ComponentManager.h" #include "../api/Camera.h" #include "../api/ParticleEmitter.h" #include "../api/Sprite.h" #include "../api/Transform.h" #include "../facade/SDLContext.h" +#include "../manager/ComponentManager.h" #include "RenderSystem.h" diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 2e16eb0..d6b2ca1 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -1,6 +1,6 @@ -#include "../manager/ComponentManager.h" #include "../api/BehaviorScript.h" #include "../api/Script.h" +#include "../manager/ComponentManager.h" #include "ScriptSystem.h" diff --git a/src/crepe/util/Private.cpp b/src/crepe/util/Private.cpp index cb4cb5b..262620d 100644 --- a/src/crepe/util/Private.cpp +++ b/src/crepe/util/Private.cpp @@ -2,18 +2,14 @@ using namespace crepe; -bool Private::empty() const noexcept { - return this->instance == nullptr; -} +bool Private::empty() const noexcept { return this->instance == nullptr; } Private::~Private() { if (this->instance == nullptr) return; this->destructor(this->instance); } -Private::Private(Private && other) { - *this = std::move(other); -} +Private::Private(Private && other) { *this = std::move(other); } Private & Private::operator=(Private && other) { // TODO: ideally this function checks for self-assignment @@ -22,13 +18,10 @@ Private & Private::operator=(Private && other) { this->type = other.type; other.instance = nullptr; - other.destructor = [](void*){}; - - return *this; -} + other.destructor = [](void *) {}; -Private::Private(const Private & other) { } -Private & Private::operator=(const Private & other) { return *this; } +Private::Private(const Private & other) {} +Private & Private::operator=(const Private & other) { return *this; } diff --git a/src/crepe/util/Private.h b/src/crepe/util/Private.h index 6dd28bb..62a2e1a 100644 --- a/src/crepe/util/Private.h +++ b/src/crepe/util/Private.h @@ -1,7 +1,7 @@ #pragma once -#include <typeindex> #include <functional> +#include <typeindex> namespace crepe { @@ -28,7 +28,6 @@ private: void * instance = nullptr; }; -} +} // namespace crepe #include "Private.hpp" - diff --git a/src/crepe/util/Private.hpp b/src/crepe/util/Private.hpp index d6ab23f..3a87a9f 100644 --- a/src/crepe/util/Private.hpp +++ b/src/crepe/util/Private.hpp @@ -1,7 +1,7 @@ #pragma once -#include <stdexcept> #include <format> +#include <stdexcept> #include "Private.h" @@ -11,10 +11,8 @@ template <typename T, typename... Args> T & Private::set(Args &&... args) { if (!this->empty()) this->destructor(this->instance); T * instance = new T(std::forward<Args>(args)...); - this->instance = static_cast<void*>(instance); - this->destructor = [](void * instance) { - delete static_cast<T*>(instance); - }; + this->instance = static_cast<void *>(instance); + this->destructor = [](void * instance) { delete static_cast<T *>(instance); }; this->type = typeid(T); return *instance; } @@ -22,12 +20,12 @@ T & Private::set(Args &&... args) { template <typename T> T & Private::get() { using namespace std; - if (this->empty()) - throw out_of_range("Private: get() called on empty object"); + if (this->empty()) throw out_of_range("Private: get() called on empty object"); type_index requested_type = typeid(T); if (this->type != requested_type) - throw logic_error(format("Private: get() called with [T = {}] (actual is [T = {}])", requested_type.name(), this->type.name())); - return *static_cast<T*>(this->instance); + throw logic_error(format("Private: get() called with [T = {}] (actual is [T = {}])", + requested_type.name(), this->type.name())); + return *static_cast<T *>(this->instance); } -} +} // namespace crepe |