From 359ad8db97305856f4cfdade1cd1dada78a7a635 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 11 Dec 2024 21:04:30 +0100 Subject: more replay system WIP --- src/crepe/manager/ComponentManager.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/crepe/manager/ComponentManager.cpp') diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index 24ba0d7..5f5c050 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -72,3 +72,29 @@ set ComponentManager::get_objects_by_tag(const string & tag) c return this->get_objects_by_predicate( [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); + } +} + -- cgit v1.2.3 From 297d621987c224db26eadfb9bde9235741387496 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 12 Dec 2024 19:46:15 +0100 Subject: more cleanup + script utilities --- src/crepe/api/Animator.cpp | 2 +- src/crepe/api/BehaviorScript.hpp | 3 -- src/crepe/api/Camera.cpp | 2 +- src/crepe/api/Script.h | 78 +++++++++++++++++----------------- src/crepe/api/Script.hpp | 23 ++++++++-- src/crepe/api/Sprite.cpp | 2 +- src/crepe/api/Transform.cpp | 2 +- src/crepe/facade/DB.cpp | 2 +- src/crepe/facade/SDLContext.cpp | 2 +- src/crepe/facade/Sound.cpp | 2 +- src/crepe/facade/SoundContext.cpp | 2 +- src/crepe/facade/Texture.cpp | 2 +- src/crepe/manager/ComponentManager.cpp | 2 +- src/crepe/manager/LoopTimerManager.cpp | 2 +- src/crepe/manager/ResourceManager.cpp | 2 +- src/crepe/system/ScriptSystem.cpp | 1 + src/crepe/util/Log.cpp | 1 + src/crepe/util/Log.h | 21 --------- src/crepe/util/dbg.h | 19 +++++++++ src/example/replay.cpp | 6 ++- 20 files changed, 98 insertions(+), 78 deletions(-) create mode 100644 src/crepe/util/dbg.h (limited to 'src/crepe/manager/ComponentManager.cpp') diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 4ce4bf0..203cef3 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,5 +1,5 @@ -#include "util/Log.h" +#include "util/dbg.h" #include "Animator.h" #include "Component.h" diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp index b9bb1e2..353d5e2 100644 --- a/src/crepe/api/BehaviorScript.hpp +++ b/src/crepe/api/BehaviorScript.hpp @@ -2,8 +2,6 @@ #include -#include "../util/Log.h" - #include "BehaviorScript.h" #include "Script.h" @@ -11,7 +9,6 @@ namespace crepe { template BehaviorScript & BehaviorScript::set_script(Args &&... args) { - dbg_trace(); static_assert(std::is_base_of::value); this->script = std::unique_ptr