aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/ComponentManager.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/ComponentManager.hpp')
-rw-r--r--src/crepe/ComponentManager.hpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp
index be99cac..ffb38ec 100644
--- a/src/crepe/ComponentManager.hpp
+++ b/src/crepe/ComponentManager.hpp
@@ -54,6 +54,11 @@ template <typename T>
void ComponentManager::delete_components_by_id(game_object_id_t id) {
using namespace std;
+ // Do not delete persistent objects
+ if (this->persistent[id]) {
+ return;
+ }
+
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
@@ -77,19 +82,24 @@ void ComponentManager::delete_components() {
if (this->components.find(type) == this->components.end()) return;
- this->components[type].clear();
+ // Loop through the whole vector<> of this specific type
+ for (game_object_id_t i = 0; i < this->components[type].size(); ++i) {
+ // Do not delete persistent objects
+ if (!this->persistent[i]) {
+ this->components[type][i].clear();
+ }
+ }
}
template <typename T>
-std::vector<std::reference_wrapper<T>>
-ComponentManager::get_components_by_id(game_object_id_t id) const {
+RefVector<T> ComponentManager::get_components_by_id(game_object_id_t id) const {
using namespace std;
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
// Create an empty vector<>
- vector<reference_wrapper<T>> component_vector;
+ RefVector<T> component_vector;
if (this->components.find(type) == this->components.end()) return component_vector;
@@ -114,14 +124,14 @@ ComponentManager::get_components_by_id(game_object_id_t id) const {
}
template <typename T>
-std::vector<std::reference_wrapper<T>> ComponentManager::get_components_by_type() const {
+RefVector<T> ComponentManager::get_components_by_type() const {
using namespace std;
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
// Create an empty vector<>
- vector<reference_wrapper<T>> component_vector;
+ RefVector<T> component_vector;
// Find the type (in the unordered_map<>)
if (this->components.find(type) == this->components.end()) return component_vector;