diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-12 22:45:30 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-12 22:45:30 +0100 |
commit | 1d1c256eea43a3d0685919ed2997e10990ef639f (patch) | |
tree | 99f85ea9d8852ba3e33a05df699f028f29d3f9d1 /src | |
parent | 23196be83778973d9688cc5d465e4e4a16476568 (diff) |
`make format`
Diffstat (limited to 'src')
26 files changed, 68 insertions, 78 deletions
diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index 1aed507..ae76e65 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -14,7 +14,4 @@ unique_ptr<Component> Component::save() const { return unique_ptr<Component>(new Component(*this)); } -void Component::restore(const Component & snapshot) { - *this = snapshot; -} - +void Component::restore(const Component & snapshot) { *this = snapshot; } diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp index e8b7fd6..bbb4494 100644 --- a/src/crepe/api/Engine.cpp +++ b/src/crepe/api/Engine.cpp @@ -46,7 +46,8 @@ void Engine::loop() { try { systems.fixed_update(); } catch (const exception & e) { - Log::logf(Log::Level::WARNING, "Uncaught exception in fixed update function: {}\n", e.what()); + Log::logf(Log::Level::WARNING, + "Uncaught exception in fixed update function: {}\n", e.what()); } timer.advance_fixed_elapsed_time(); } @@ -54,9 +55,9 @@ void Engine::loop() { try { systems.frame_update(); } catch (const exception & e) { - Log::logf(Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", e.what()); + Log::logf(Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", + e.what()); } timer.enforce_frame_rate(); } } - diff --git a/src/crepe/api/Engine.h b/src/crepe/api/Engine.h index efe7853..3145723 100644 --- a/src/crepe/api/Engine.h +++ b/src/crepe/api/Engine.h @@ -2,14 +2,13 @@ #include "../facade/SDLContext.h" #include "../manager/ComponentManager.h" +#include "../manager/EventManager.h" +#include "../manager/LoopTimerManager.h" #include "../manager/ReplayManager.h" #include "../manager/ResourceManager.h" -#include "../manager/ResourceManager.h" #include "../manager/SaveManager.h" #include "../manager/SceneManager.h" #include "../manager/SystemManager.h" -#include "../manager/LoopTimerManager.h" -#include "../manager/EventManager.h" namespace crepe { diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 68b074e..9b94cad 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -7,13 +7,14 @@ using namespace crepe; using namespace std; -GameObject::GameObject(Mediator & mediator, game_object_id_t id, - const std::string & name, const std::string & tag, - const vec2 & position, double rotation, double scale) +GameObject::GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, + const std::string & tag, const vec2 & position, double rotation, + double scale) : id(id), mediator(mediator), - transform(mediator.component_manager->add_component<Transform>(this->id, position, rotation, scale)), - metadata(mediator.component_manager->add_component<Metadata>(this->id, name, tag)) { } + transform(mediator.component_manager->add_component<Transform>(this->id, position, + rotation, scale)), + metadata(mediator.component_manager->add_component<Metadata>(this->id, name, tag)) {} void GameObject::set_parent(const GameObject & parent) { ComponentManager & mgr = this->mediator.component_manager; diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 0dabed1..572ce3a 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -30,9 +30,8 @@ private: * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - GameObject(Mediator & mediator, game_object_id_t id, - const std::string & name, const std::string & tag, const vec2 & position, - double rotation, double scale); + GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, + const std::string & tag, const vec2 & position, double rotation, double scale); //! ComponentManager instances GameObject friend class ComponentManager; diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index fd69e26..a9c5cf6 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -23,4 +23,3 @@ ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter & other) { data.particles = other.data.particles; return *this; } - diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 8b95cc9..34e7908 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -45,4 +45,3 @@ void Script::replay::release(recording_t recording) { ReplayManager & mgr = this->mediator->replay_manager; return mgr.release(recording); } - diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 18a029b..6536fa4 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -2,13 +2,13 @@ #include <vector> -#include "../manager/ReplayManager.h" #include "../manager/EventManager.h" #include "../manager/Mediator.h" +#include "../manager/ReplayManager.h" #include "../system/CollisionSystem.h" #include "../types.h" -#include "../util/OptionalRef.h" #include "../util/Log.h" +#include "../util/OptionalRef.h" namespace crepe { @@ -115,10 +115,12 @@ protected: void subscribe(const EventHandler<EventType> & callback); //! \copydoc EventManager::trigger_event template <typename EventType> - void trigger_event(const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL); + void trigger_event(const EventType & event = {}, + event_channel_t channel = EventManager::CHANNEL_ALL); //! \copydoc EventManager::queue_event template <typename EventType> - void queue_event(const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL); + void queue_event(const EventType & event = {}, + event_channel_t channel = EventManager::CHANNEL_ALL); //! \} /** diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index b42a6df..4462a41 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -48,7 +48,8 @@ void Script::subscribe_internal(const EventHandler<EventType> & callback, try { ReplayManager & replay = this->mediator->replay_manager; if (replay.get_state() == ReplayManager::PLAYING) return false; - } catch (const std::runtime_error &) {} + } catch (const std::runtime_error &) { + } // call user-provided callback return callback(data); diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index 32b44e1..fcfce14 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -20,4 +20,3 @@ unique_ptr<Component> Transform::save() const { void Transform::restore(const Component & snapshot) { *this = static_cast<const Transform &>(snapshot); } - diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index bc104d3..745ddae 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -97,4 +97,3 @@ void ComponentManager::restore(const Snapshot & snapshot) { this->components[info.type][info.id][info.index]->restore(*info.component); } } - diff --git a/src/crepe/manager/ReplayManager.cpp b/src/crepe/manager/ReplayManager.cpp index db6acb0..090a94e 100644 --- a/src/crepe/manager/ReplayManager.cpp +++ b/src/crepe/manager/ReplayManager.cpp @@ -1,7 +1,7 @@ #include <format> -#include "ReplayManager.h" #include "Manager.h" +#include "ReplayManager.h" using namespace crepe; using namespace std; @@ -32,8 +32,7 @@ void ReplayManager::play(recording_t handle) { } void ReplayManager::release(recording_t handle) { - if (!this->memory.contains(handle)) - return; + if (!this->memory.contains(handle)) return; this->memory.erase(handle); } @@ -68,7 +67,4 @@ bool ReplayManager::frame_step() { return true; } -ReplayManager::State ReplayManager::get_state() const { - return this->state; -} - +ReplayManager::State ReplayManager::get_state() const { return this->state; } diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h index d3af879..ab15b27 100644 --- a/src/crepe/manager/ReplayManager.h +++ b/src/crepe/manager/ReplayManager.h @@ -2,8 +2,8 @@ #include <unordered_map> -#include "Manager.h" #include "ComponentManager.h" +#include "Manager.h" #include "util/OptionalRef.h" namespace crepe { @@ -19,6 +19,7 @@ typedef size_t recording_t; */ class ReplayManager : public Manager { // TODO: Delete recordings at end of scene + public: ReplayManager(Mediator & mediator); @@ -40,7 +41,7 @@ public: * \param handle Handle to recording (as returned by \c record_end()) */ void release(recording_t handle); - + public: //! Internal state enum State { diff --git a/src/crepe/manager/SystemManager.cpp b/src/crepe/manager/SystemManager.cpp index f67e786..5ada30f 100644 --- a/src/crepe/manager/SystemManager.cpp +++ b/src/crepe/manager/SystemManager.cpp @@ -2,13 +2,13 @@ #include "../system/AnimatorSystem.h" #include "../system/AudioSystem.h" #include "../system/CollisionSystem.h" +#include "../system/EventSystem.h" #include "../system/InputSystem.h" #include "../system/ParticleSystem.h" #include "../system/PhysicsSystem.h" #include "../system/RenderSystem.h" -#include "../system/ScriptSystem.h" -#include "../system/EventSystem.h" #include "../system/ReplaySystem.h" +#include "../system/ScriptSystem.h" #include "SystemManager.h" @@ -64,4 +64,3 @@ void SystemManager::disable_all() { system->active = false; } } - diff --git a/src/crepe/manager/SystemManager.h b/src/crepe/manager/SystemManager.h index a47961b..50acf77 100644 --- a/src/crepe/manager/SystemManager.h +++ b/src/crepe/manager/SystemManager.h @@ -1,8 +1,8 @@ #pragma once +#include <memory> #include <typeindex> #include <unordered_map> -#include <memory> #include "../system/System.h" diff --git a/src/crepe/manager/SystemManager.hpp b/src/crepe/manager/SystemManager.hpp index 46ada5f..3d26e4c 100644 --- a/src/crepe/manager/SystemManager.hpp +++ b/src/crepe/manager/SystemManager.hpp @@ -1,8 +1,8 @@ #pragma once -#include <memory> #include <cassert> #include <format> +#include <memory> #include "SystemManager.h" @@ -11,7 +11,8 @@ namespace crepe { template <class T> T & SystemManager::get_system() { using namespace std; - static_assert(is_base_of<System, T>::value, "get_system must recieve a derivative class of System"); + static_assert(is_base_of<System, T>::value, + "get_system must recieve a derivative class of System"); const type_info & type = typeid(T); if (!this->systems.contains(type)) @@ -28,7 +29,7 @@ template <class T> void SystemManager::load_system() { using namespace std; static_assert(is_base_of<System, T>::value, - "load_system must recieve a derivative class of System"); + "load_system must recieve a derivative class of System"); const type_info & type = typeid(T); if (this->systems.contains(type)) diff --git a/src/crepe/system/EventSystem.cpp b/src/crepe/system/EventSystem.cpp index 5475798..7e168ab 100644 --- a/src/crepe/system/EventSystem.cpp +++ b/src/crepe/system/EventSystem.cpp @@ -1,5 +1,5 @@ -#include "../manager/EventManager.h" #include "EventSystem.h" +#include "../manager/EventManager.h" using namespace crepe; @@ -7,4 +7,3 @@ void EventSystem::fixed_update() { EventManager & ev = this->mediator.event_manager; ev.dispatch_events(); } - diff --git a/src/crepe/system/EventSystem.h b/src/crepe/system/EventSystem.h index ff3ca4e..0ae48d2 100644 --- a/src/crepe/system/EventSystem.h +++ b/src/crepe/system/EventSystem.h @@ -18,5 +18,4 @@ public: void fixed_update() override; }; -} - +} // namespace crepe diff --git a/src/crepe/system/ReplaySystem.cpp b/src/crepe/system/ReplaySystem.cpp index 2b2e4ab..efc3be4 100644 --- a/src/crepe/system/ReplaySystem.cpp +++ b/src/crepe/system/ReplaySystem.cpp @@ -1,9 +1,9 @@ #include "../manager/ReplayManager.h" #include "../manager/SystemManager.h" +#include "EventSystem.h" #include "RenderSystem.h" #include "ReplaySystem.h" -#include "EventSystem.h" using namespace crepe; using namespace std; @@ -15,7 +15,8 @@ void ReplaySystem::fixed_update() { this->last_state = state; switch (state) { - case ReplayManager::IDLE: break; + case ReplayManager::IDLE: + break; case ReplayManager::RECORDING: { replay.frame_record(); break; @@ -51,4 +52,3 @@ void ReplaySystem::playback_end() { components.restore(this->playback.components); systems.restore(this->playback.systems); } - diff --git a/src/crepe/system/ReplaySystem.h b/src/crepe/system/ReplaySystem.h index 8ba60d5..bbc8d76 100644 --- a/src/crepe/system/ReplaySystem.h +++ b/src/crepe/system/ReplaySystem.h @@ -41,5 +41,4 @@ private: void playback_end(); }; -} - +} // namespace crepe diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 11da618..0d10011 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -1,7 +1,7 @@ -#include "../util/dbg.h" #include "../api/BehaviorScript.h" #include "../api/Script.h" #include "../manager/ComponentManager.h" +#include "../util/dbg.h" #include "ScriptSystem.h" diff --git a/src/crepe/util/Log.cpp b/src/crepe/util/Log.cpp index e11a8d9..ce25a1d 100644 --- a/src/crepe/util/Log.cpp +++ b/src/crepe/util/Log.cpp @@ -3,8 +3,8 @@ #include "../api/Config.h" -#include "LogColor.h" #include "Log.h" +#include "LogColor.h" using namespace crepe; using namespace std; diff --git a/src/crepe/util/dbg.h b/src/crepe/util/dbg.h index 500e959..c7283ee 100644 --- a/src/crepe/util/dbg.h +++ b/src/crepe/util/dbg.h @@ -16,4 +16,3 @@ #define dbg_log(str) _crepe_logf_here(crepe::Log::Level::DEBUG, ": {}", str) #define dbg_trace() _crepe_logf_here(crepe::Log::Level::TRACE, "", "") // NOLINTEND - diff --git a/src/example/replay.cpp b/src/example/replay.cpp index 130c0d3..82fd478 100644 --- a/src/example/replay.cpp +++ b/src/example/replay.cpp @@ -1,6 +1,6 @@ +#include <crepe/api/Config.h> #include <crepe/api/Engine.h> #include <crepe/api/Script.h> -#include <crepe/api/Config.h> using namespace crepe; using namespace std; @@ -9,13 +9,11 @@ class AnimationScript : public Script { Transform * transform; float t = 0; - void init() { - transform = &get_component<Transform>(); - } + void init() { transform = &get_component<Transform>(); } void update() { t += 0.05; - transform->position = { sin(t), cos(t) }; + transform->position = {sin(t), cos(t)}; } }; @@ -25,7 +23,8 @@ class Timeline : public Script { void update() { switch (i++) { - default: break; + default: + break; case 10: logf("record start"); replay.record_start(); @@ -56,17 +55,15 @@ public: ComponentManager & mgr = mediator.component_manager; GameObject cam = mgr.new_object("cam"); - cam.add_component<Camera>(ivec2{640,480},vec2{3,3}, Camera::Data{ - .bg_color = Color::WHITE, - }); + cam.add_component<Camera>(ivec2{640, 480}, vec2{3, 3}, + Camera::Data{ + .bg_color = Color::WHITE, + }); GameObject square = mgr.new_object("square"); - square.add_component<Sprite>( - Asset{"asset/texture/square.png"}, - Sprite::Data{ - .size = { 0.5, 0.5 }, - } - ); + square.add_component<Sprite>(Asset{"asset/texture/square.png"}, Sprite::Data{ + .size = {0.5, 0.5}, + }); square.add_component<BehaviorScript>().set_script<AnimationScript>(); GameObject scapegoat = mgr.new_object(""); diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index eccfd89..f5ae4b1 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -102,12 +102,14 @@ public: // Run and profile all systems, return the total time in milliseconds std::chrono::microseconds run_all_systems() { std::chrono::microseconds total_microseconds = 0us; - total_microseconds += time_function("PhysicsSystem", [&]() { physics_sys.fixed_update(); }); + total_microseconds + += time_function("PhysicsSystem", [&]() { physics_sys.fixed_update(); }); total_microseconds += time_function("CollisionSystem", [&]() { collision_sys.fixed_update(); }); total_microseconds += time_function("ParticleSystem", [&]() { particle_sys.fixed_update(); }); - total_microseconds += time_function("RenderSystem", [&]() { render_sys.frame_update(); }); + total_microseconds + += time_function("RenderSystem", [&]() { render_sys.frame_update(); }); return total_microseconds; } diff --git a/src/test/ReplayManagerTest.cpp b/src/test/ReplayManagerTest.cpp index aa5a766..5ee4b40 100644 --- a/src/test/ReplayManagerTest.cpp +++ b/src/test/ReplayManagerTest.cpp @@ -1,10 +1,10 @@ #include <gtest/gtest.h> -#include <crepe/manager/ReplayManager.h> -#include <crepe/system/ReplaySystem.h> +#include <crepe/api/BehaviorScript.h> #include <crepe/api/Scene.h> #include <crepe/api/Script.h> -#include <crepe/api/BehaviorScript.h> +#include <crepe/manager/ReplayManager.h> +#include <crepe/system/ReplaySystem.h> using namespace std; using namespace crepe; @@ -12,14 +12,17 @@ using namespace testing; class ReplayManagerTest : public Test { Mediator mediator; + public: ComponentManager component_manager{mediator}; ReplayManager replay_manager{mediator}; ReplaySystem replay_system{mediator}; GameObject entity = component_manager.new_object("foo"); - Transform & entity_transform = component_manager.get_components_by_id<Transform>(entity.id).back(); - Metadata & entity_metadata = component_manager.get_components_by_id<Metadata>(entity.id).back(); + Transform & entity_transform + = component_manager.get_components_by_id<Transform>(entity.id).back(); + Metadata & entity_metadata + = component_manager.get_components_by_id<Metadata>(entity.id).back(); }; TEST_F(ReplayManagerTest, Default) { @@ -33,4 +36,3 @@ TEST_F(ReplayManagerTest, Default) { // recording_t recording = replay_manager.record_end(); } - |