diff options
Diffstat (limited to 'src/crepe/manager')
-rw-r--r-- | src/crepe/manager/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/manager/ComponentManager.cpp | 2 | ||||
-rw-r--r-- | src/crepe/manager/ComponentManager.h | 23 | ||||
-rw-r--r-- | src/crepe/manager/ReplayManager.cpp | 8 | ||||
-rw-r--r-- | src/crepe/manager/ReplayManager.h | 37 |
5 files changed, 58 insertions, 14 deletions
diff --git a/src/crepe/manager/CMakeLists.txt b/src/crepe/manager/CMakeLists.txt index 480c8ee..459bbfa 100644 --- a/src/crepe/manager/CMakeLists.txt +++ b/src/crepe/manager/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(crepe PUBLIC SaveManager.cpp SceneManager.cpp ResourceManager.cpp + ReplayManager.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -19,5 +20,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES SceneManager.hpp ResourceManager.h ResourceManager.hpp + ReplayManager.h ) diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index df30d27..24ba0d7 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -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; diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h index 19a8e81..dd7c154 100644 --- a/src/crepe/manager/ComponentManager.h +++ b/src/crepe/manager/ComponentManager.h @@ -21,13 +21,6 @@ class GameObject; * This class manages all components. It provides methods to add, delete and get components. */ class ComponentManager : public Manager { - // TODO: This relation should be removed! I (loek) believe that the scene manager should - // create/destroy components because the GameObject's are stored in concrete Scene classes, - // which will in turn call GameObject's destructor, which will in turn call - // ComponentManager::delete_components_by_id or something. This is a pretty major change, so - // here is a comment and temporary fix instead :tada: - friend class SceneManager; - public: ComponentManager(Mediator & mediator); ~ComponentManager(); // dbg_trace @@ -49,12 +42,7 @@ public: const vec2 & position = {0, 0}, double rotation = 0, double scale = 1); -protected: - /** - * GameObject is used as an interface to add/remove components, and the game programmer is - * supposed to use it instead of interfacing with the component manager directly. - */ - friend class GameObject; +public: /** * \brief Add a component to the ComponentManager * @@ -154,6 +142,15 @@ public: template <typename T> RefVector<T> get_components_by_tag(const std::string & tag) const; + struct SnapshotComponent { + Component component; + }; + struct Snapshot { + + }; + Snapshot save(); + void restore(const Snapshot &); + private: /** * \brief Get object IDs by predicate function diff --git a/src/crepe/manager/ReplayManager.cpp b/src/crepe/manager/ReplayManager.cpp new file mode 100644 index 0000000..3643a8e --- /dev/null +++ b/src/crepe/manager/ReplayManager.cpp @@ -0,0 +1,8 @@ +#include "ReplayManager.h" +#include "manager/Manager.h" + +using namespace crepe; + +ReplayManager::ReplayManager(Mediator & mediator) : Manager(mediator) { +} + diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h new file mode 100644 index 0000000..c50196c --- /dev/null +++ b/src/crepe/manager/ReplayManager.h @@ -0,0 +1,37 @@ +#pragma once + +#include "Manager.h" +#include "ComponentManager.h" +#include <unordered_map> + +namespace crepe { + +class ReplaySystem; +class Memento; + +typedef size_t recording_t; + +class ReplayManager : public Manager { +public: + ReplayManager(Mediator & mediator); + friend class ReplaySystem; + +protected: + void record_frame(); + +private: + typedef std::vector<ComponentManager::Snapshot> Recording; + + bool recording = false; + recording_t current_recording = -1; + + + std::unordered_map<recording_t, std::unique_ptr<Recording>> memory; +public: + void record_start(); + recording_t record_end(); + void play(recording_t handle); + void release(recording_t handle); +}; + +} // namespace crepe |