aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-22 12:32:22 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-22 12:32:22 +0100
commit61148c757a1f742ff09e40e5347e74e638c7371c (patch)
treea2e40998981fa6f12430d2a1254250219f30d44f /src/crepe/manager
parente2162171c7ab72f450f73a0908946aa4a4dee5ee (diff)
update clang-format options
Diffstat (limited to 'src/crepe/manager')
-rw-r--r--src/crepe/manager/ComponentManager.cpp22
-rw-r--r--src/crepe/manager/ComponentManager.h7
-rw-r--r--src/crepe/manager/ComponentManager.hpp20
-rw-r--r--src/crepe/manager/EventManager.h4
-rw-r--r--src/crepe/manager/EventManager.hpp14
-rw-r--r--src/crepe/manager/LoopTimerManager.cpp6
-rw-r--r--src/crepe/manager/LoopTimerManager.h12
-rw-r--r--src/crepe/manager/ResourceManager.hpp13
-rw-r--r--src/crepe/manager/SceneManager.cpp10
-rw-r--r--src/crepe/manager/SystemManager.hpp10
10 files changed, 68 insertions, 50 deletions
diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp
index 745ddae..245419d 100644
--- a/src/crepe/manager/ComponentManager.cpp
+++ b/src/crepe/manager/ComponentManager.cpp
@@ -46,14 +46,16 @@ void ComponentManager::delete_all_components() {
this->next_id = 0;
}
-GameObject ComponentManager::new_object(const string & name, const string & tag,
- const vec2 & position, double rotation, double scale) {
+GameObject ComponentManager::new_object(
+ const string & name, const string & tag, const vec2 & position, double rotation,
+ double scale
+) {
// Find the first available id (taking persistent objects into account)
while (this->persistent[this->next_id]) {
this->next_id++;
}
- GameObject object{this->mediator, this->next_id, name, tag, position, rotation, scale};
+ GameObject object {this->mediator, this->next_id, name, tag, position, rotation, scale};
this->next_id++;
return object;
@@ -64,23 +66,25 @@ void ComponentManager::set_persistent(game_object_id_t id, bool persistent) {
}
set<game_object_id_t> ComponentManager::get_objects_by_name(const string & name) const {
- return this->get_objects_by_predicate<Metadata>(
- [name](const Metadata & data) { return data.name == name; });
+ return this->get_objects_by_predicate<Metadata>([name](const Metadata & data) {
+ return data.name == name;
+ });
}
set<game_object_id_t> ComponentManager::get_objects_by_tag(const string & tag) const {
- return this->get_objects_by_predicate<Metadata>(
- [tag](const Metadata & data) { return data.tag == tag; });
+ return this->get_objects_by_predicate<Metadata>([tag](const Metadata & data) {
+ return data.tag == tag;
+ });
}
ComponentManager::Snapshot ComponentManager::save() {
- Snapshot snapshot{};
+ Snapshot snapshot {};
for (const auto & [type, by_id_index] : this->components) {
for (game_object_id_t id = 0; id < by_id_index.size(); id++) {
const auto & components = by_id_index[id];
for (size_t index = 0; index < components.size(); index++) {
const Component & component = *components[index];
- snapshot.components.push_back(SnapshotComponent{
+ snapshot.components.push_back(SnapshotComponent {
.type = type,
.id = id,
.index = index,
diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h
index c3a5b4a..2eb1f7e 100644
--- a/src/crepe/manager/ComponentManager.h
+++ b/src/crepe/manager/ComponentManager.h
@@ -38,9 +38,10 @@ public:
*
* \note This method automatically assigns a new entity ID
*/
- GameObject new_object(const std::string & name, const std::string & tag = "",
- const vec2 & position = {0, 0}, double rotation = 0,
- double scale = 1);
+ GameObject new_object(
+ const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0},
+ double rotation = 0, double scale = 1
+ );
public:
/**
diff --git a/src/crepe/manager/ComponentManager.hpp b/src/crepe/manager/ComponentManager.hpp
index 9e70865..6d32edb 100644
--- a/src/crepe/manager/ComponentManager.hpp
+++ b/src/crepe/manager/ComponentManager.hpp
@@ -11,8 +11,10 @@ template <class T, typename... Args>
T & ComponentManager::add_component(game_object_id_t id, Args &&... args) {
using namespace std;
- static_assert(is_base_of<Component, T>::value,
- "add_component must recieve a derivative class of Component");
+ static_assert(
+ is_base_of<Component, T>::value,
+ "add_component must recieve a derivative class of Component"
+ );
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
@@ -40,8 +42,8 @@ T & ComponentManager::add_component(game_object_id_t id, Args &&... args) {
// Check if the vector size is not greater than get_instances_max
int max_instances = instance->get_instances_max();
if (max_instances != -1 && components[type][id].size() >= max_instances) {
- throw std::runtime_error(
- "Exceeded maximum number of instances for this component type");
+ throw std::runtime_error("Exceeded maximum number of instances for this component type"
+ );
}
// store its unique_ptr in the vector<>
@@ -95,8 +97,10 @@ template <typename T>
RefVector<T> ComponentManager::get_components_by_id(game_object_id_t id) const {
using namespace std;
- static_assert(is_base_of<Component, T>::value,
- "get_components_by_id must recieve a derivative class of Component");
+ static_assert(
+ is_base_of<Component, T>::value,
+ "get_components_by_id must recieve a derivative class of Component"
+ );
type_index type = typeid(T);
if (!this->components.contains(type)) return {};
@@ -170,8 +174,8 @@ ComponentManager::get_objects_by_predicate(const std::function<bool(const T &)>
}
template <typename T>
-RefVector<T>
-ComponentManager::get_components_by_ids(const std::set<game_object_id_t> & ids) const {
+RefVector<T> ComponentManager::get_components_by_ids(const std::set<game_object_id_t> & ids
+) const {
using namespace std;
RefVector<T> out = {};
diff --git a/src/crepe/manager/EventManager.h b/src/crepe/manager/EventManager.h
index 0a57fb1..5766a0c 100644
--- a/src/crepe/manager/EventManager.h
+++ b/src/crepe/manager/EventManager.h
@@ -49,8 +49,8 @@ public:
* \return A unique subscription ID associated with the registered callback.
*/
template <typename EventType>
- subscription_t subscribe(const EventHandler<EventType> & callback,
- event_channel_t channel = CHANNEL_ALL);
+ subscription_t
+ subscribe(const EventHandler<EventType> & callback, event_channel_t channel = CHANNEL_ALL);
/**
* \brief Unsubscribe a previously registered callback.
diff --git a/src/crepe/manager/EventManager.hpp b/src/crepe/manager/EventManager.hpp
index b2090d0..1f44943 100644
--- a/src/crepe/manager/EventManager.hpp
+++ b/src/crepe/manager/EventManager.hpp
@@ -5,22 +5,24 @@
namespace crepe {
template <typename EventType>
-subscription_t EventManager::subscribe(const EventHandler<EventType> & callback,
- event_channel_t channel) {
+subscription_t
+EventManager::subscribe(const EventHandler<EventType> & callback, event_channel_t channel) {
subscription_counter++;
std::type_index event_type = typeid(EventType);
std::unique_ptr<EventHandlerWrapper<EventType>> handler
= std::make_unique<EventHandlerWrapper<EventType>>(callback);
std::vector<CallbackEntry> & handlers = this->subscribers[event_type];
- handlers.emplace_back(CallbackEntry{
- .callback = std::move(handler), .channel = channel, .id = subscription_counter});
+ handlers.emplace_back(CallbackEntry {
+ .callback = std::move(handler), .channel = channel, .id = subscription_counter
+ });
return subscription_counter;
}
template <typename EventType>
void EventManager::queue_event(const EventType & event, event_channel_t channel) {
- static_assert(std::is_base_of<Event, EventType>::value,
- "EventType must derive from Event");
+ static_assert(
+ std::is_base_of<Event, EventType>::value, "EventType must derive from Event"
+ );
this->events_queue.push_back(QueueEntry{
// unique_ptr w/ custom destructor implementation is used because the base Event interface
// can't be polymorphic (= have default virtual destructor)
diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp
index e78f92f..b4cd07f 100644
--- a/src/crepe/manager/LoopTimerManager.cpp
+++ b/src/crepe/manager/LoopTimerManager.cpp
@@ -17,9 +17,9 @@ LoopTimerManager::LoopTimerManager(Mediator & mediator) : Manager(mediator) {
void LoopTimerManager::start() {
this->last_frame_time = std::chrono::steady_clock::now();
- this->elapsed_time = elapsed_time_t{0};
- this->elapsed_fixed_time = elapsed_time_t{0};
- this->delta_time = duration_t{0};
+ this->elapsed_time = elapsed_time_t {0};
+ this->elapsed_fixed_time = elapsed_time_t {0};
+ this->delta_time = duration_t {0};
}
void LoopTimerManager::update() {
diff --git a/src/crepe/manager/LoopTimerManager.h b/src/crepe/manager/LoopTimerManager.h
index 2f1e6b6..279d6b2 100644
--- a/src/crepe/manager/LoopTimerManager.h
+++ b/src/crepe/manager/LoopTimerManager.h
@@ -157,17 +157,17 @@ private:
//! Time scale for speeding up or slowing down the game (0 = pause, < 1 = slow down, 1 = normal speed, > 1 = speed up).
float time_scale = 1;
//! Maximum delta time in seconds to avoid large jumps.
- duration_t maximum_delta_time{0.25};
+ duration_t maximum_delta_time {0.25};
//! Delta time for the current frame in seconds.
- duration_t delta_time{0.0};
+ duration_t delta_time {0.0};
//! Target time per frame in seconds
- duration_t frame_target_time{1.0 / target_fps};
+ duration_t frame_target_time {1.0 / target_fps};
//! Fixed delta time for fixed updates in seconds.
- duration_t fixed_delta_time{1.0 / 50.0};
+ duration_t fixed_delta_time {1.0 / 50.0};
//! Total elapsed game time in microseconds.
- elapsed_time_t elapsed_time{0};
+ elapsed_time_t elapsed_time {0};
//! Total elapsed time for fixed updates in microseconds.
- elapsed_time_t elapsed_fixed_time{0};
+ elapsed_time_t elapsed_fixed_time {0};
typedef std::chrono::steady_clock::time_point time_point_t;
//! Time of the last frame.
diff --git a/src/crepe/manager/ResourceManager.hpp b/src/crepe/manager/ResourceManager.hpp
index cf5c949..4ca6be0 100644
--- a/src/crepe/manager/ResourceManager.hpp
+++ b/src/crepe/manager/ResourceManager.hpp
@@ -9,17 +9,20 @@ 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, this->mediator);
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;
}
diff --git a/src/crepe/manager/SceneManager.cpp b/src/crepe/manager/SceneManager.cpp
index d4ca90b..e6f92db 100644
--- a/src/crepe/manager/SceneManager.cpp
+++ b/src/crepe/manager/SceneManager.cpp
@@ -17,10 +17,12 @@ void SceneManager::load_next_scene() {
// next scene not set
if (this->next_scene.empty()) return;
- auto it = find_if(this->scenes.begin(), this->scenes.end(),
- [&next_scene = this->next_scene](unique_ptr<Scene> & scene) {
- return scene.get()->get_name() == next_scene;
- });
+ auto it = find_if(
+ this->scenes.begin(), this->scenes.end(),
+ [&next_scene = this->next_scene](unique_ptr<Scene> & scene) {
+ return scene.get()->get_name() == next_scene;
+ }
+ );
// next scene not found
if (it == this->scenes.end()) return;
diff --git a/src/crepe/manager/SystemManager.hpp b/src/crepe/manager/SystemManager.hpp
index 8d06eb1..addd274 100644
--- a/src/crepe/manager/SystemManager.hpp
+++ b/src/crepe/manager/SystemManager.hpp
@@ -11,8 +11,9 @@ 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,8 +29,9 @@ T & SystemManager::get_system() {
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");
+ static_assert(
+ is_base_of<System, T>::value, "load_system must recieve a derivative class of System"
+ );
const type_info & type = typeid(T);
if (this->systems.contains(type))