diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-12-20 12:01:36 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-12-20 12:01:36 +0100 |
commit | 79d3a9f4311e6684b6df83a15ca7844f58c1959c (patch) | |
tree | b2883e83f61cee9edf290a6a7228c7f0b1fbae8a /src/crepe/manager/ComponentManager.cpp | |
parent | 9140b73e4af7aa925b53e4fb4e6aa7f4ea2e3385 (diff) | |
parent | 03aea832aa0bc2edba2cc5ab4d9f8eba42d355be (diff) |
Merge remote-tracking branch 'origin/master' into max/game
Diffstat (limited to 'src/crepe/manager/ComponentManager.cpp')
-rw-r--r-- | src/crepe/manager/ComponentManager.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index df30d27..745ddae 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -1,7 +1,7 @@ #include "../api/GameObject.h" #include "../api/Metadata.h" #include "../types.h" -#include "../util/Log.h" +#include "../util/dbg.h" #include "ComponentManager.h" @@ -53,7 +53,7 @@ GameObject ComponentManager::new_object(const string & name, const string & tag, this->next_id++; } - GameObject object{*this, 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; @@ -72,3 +72,28 @@ set<game_object_id_t> ComponentManager::get_objects_by_tag(const string & tag) c return this->get_objects_by_predicate<Metadata>( [tag](const Metadata & data) { return data.tag == tag; }); } + +ComponentManager::Snapshot ComponentManager::save() { + 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{ + .type = type, + .id = id, + .index = index, + .component = component.save(), + }); + } + } + } + return snapshot; +} + +void ComponentManager::restore(const Snapshot & snapshot) { + for (const SnapshotComponent & info : snapshot.components) { + this->components[info.type][info.id][info.index]->restore(*info.component); + } +} |