aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/ComponentManager.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-06 17:13:59 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-06 17:13:59 +0100
commitf4824f5e7e6cee12bec602f3240770945a73d043 (patch)
tree7d51652e5395ca70f995c0d059c36e1dd18bd8ae /src/crepe/manager/ComponentManager.h
parent0bed469e2ececfa240085a34252dd7ed23519de3 (diff)
add more fetching functions to ComponentManager
Diffstat (limited to 'src/crepe/manager/ComponentManager.h')
-rw-r--r--src/crepe/manager/ComponentManager.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h
index ad37586..5f2cf3c 100644
--- a/src/crepe/manager/ComponentManager.h
+++ b/src/crepe/manager/ComponentManager.h
@@ -4,6 +4,7 @@
#include <typeindex>
#include <unordered_map>
#include <vector>
+#include <set>
#include "../Component.h"
#include "../types.h"
@@ -136,6 +137,17 @@ public:
RefVector<T> get_components_by_type() const;
private:
+ template <typename T>
+ std::set<game_object_id_t> get_objects_by_predicate(const std::function<bool (const T &)> & pred) const;
+
+ std::set<game_object_id_t> get_objects_by_name(const std::string & name) const;
+ std::set<game_object_id_t> get_objects_by_tag(const std::string & tag) const;
+
+private:
+ template <typename T>
+ using by_type = std::unordered_map<std::type_index, T>;
+ template <typename T>
+ using by_id_index = std::vector<T>;
/**
* \brief The components
*
@@ -146,8 +158,7 @@ private:
* The first vector is for the ids of the GameObjects and the second vector is for the
* components (because a GameObject might have multiple components).
*/
- std::unordered_map<std::type_index, std::vector<std::vector<std::unique_ptr<Component>>>>
- components;
+ by_type<by_id_index<std::vector<std::unique_ptr<Component>>>> components;
//! Persistent flag for each GameObject
std::unordered_map<game_object_id_t, bool> persistent;
@@ -156,6 +167,9 @@ private:
game_object_id_t next_id = 0;
};
+// template <>
+// RefVector<Component> ComponentManager::get_components_by_id(game_object_id_t id) const;
+
} // namespace crepe
#include "ComponentManager.hpp"