aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/manager')
-rw-r--r--src/crepe/manager/ComponentManager.h24
-rw-r--r--src/crepe/manager/ReplayManager.cpp7
-rw-r--r--src/crepe/manager/ReplayManager.h52
-rw-r--r--src/crepe/manager/SystemManager.h24
4 files changed, 99 insertions, 8 deletions
diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h
index 457a196..c3a5b4a 100644
--- a/src/crepe/manager/ComponentManager.h
+++ b/src/crepe/manager/ComponentManager.h
@@ -142,19 +142,39 @@ public:
template <typename T>
RefVector<T> get_components_by_tag(const std::string & tag) const;
+ //! Snapshot of single component (including path in \c components)
struct SnapshotComponent {
+ //! \c components path
std::type_index type;
+ //! \c components path
game_object_id_t id;
+ //! \c components path
size_t index;
+ //! Actual component snapshot
std::unique_ptr<Component> component;
};
+ //! Snapshot of the entire component manager state
struct Snapshot {
+ //! All components
+ std::vector<SnapshotComponent> components;
// TODO: some kind of hash code that ensures components exist in all the same places as
// this snapshot
- std::vector<SnapshotComponent> components;
};
+ /**
+ * \name ReplayManager (Memento) functions
+ * \{
+ */
+ /**
+ * \brief Save a snapshot of the component manager state
+ * \returns Deep copy of the component manager's internal state
+ */
Snapshot save();
- void restore(const Snapshot &);
+ /**
+ * \brief Restore component manager from a snapshot
+ * \param snapshot Snapshot to restore from (as returned by \c save())
+ */
+ void restore(const Snapshot & snapshot);
+ //! \}
private:
/**
diff --git a/src/crepe/manager/ReplayManager.cpp b/src/crepe/manager/ReplayManager.cpp
index ab8a5a0..db6acb0 100644
--- a/src/crepe/manager/ReplayManager.cpp
+++ b/src/crepe/manager/ReplayManager.cpp
@@ -38,6 +38,9 @@ void ReplayManager::release(recording_t handle) {
}
void ReplayManager::frame_record() {
+ if (this->state != RECORDING)
+ throw runtime_error("ReplayManager: frame_step called while not playing");
+
ComponentManager & components = this->mediator.component_manager;
Recording & recording = this->recording;
@@ -46,6 +49,9 @@ void ReplayManager::frame_record() {
}
bool ReplayManager::frame_step() {
+ if (this->state != PLAYING)
+ throw runtime_error("ReplayManager: frame_step called while not playing");
+
ComponentManager & components = this->mediator.component_manager;
Recording & recording = this->recording;
@@ -58,6 +64,7 @@ bool ReplayManager::frame_step() {
// end of recording
recording.frame = 0;
this->state = IDLE;
+ this->recording.clear();
return true;
}
diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h
index 7be18f3..d3af879 100644
--- a/src/crepe/manager/ReplayManager.h
+++ b/src/crepe/manager/ReplayManager.h
@@ -8,13 +8,14 @@
namespace crepe {
-class ReplaySystem;
-
typedef size_t recording_t;
/**
* \brief Replay manager
*
+ * The replay manager is responsible for creating, storing and restoring ComponentManager
+ * snapshots. Sequential snapshots can be recorded and replayed in combination with
+ * ReplaySystem.
*/
class ReplayManager : public Manager {
// TODO: Delete recordings at end of scene
@@ -22,31 +23,70 @@ public:
ReplayManager(Mediator & mediator);
public:
+ //! Start a new recording
void record_start();
+ /**
+ * \brief End the latest recording started by \c record_start()
+ * \returns Handle to recording
+ */
recording_t record_end();
+ /**
+ * \brief Play a recording
+ * \param handle Handle to recording (as returned by \c record_end())
+ */
void play(recording_t handle);
+ /**
+ * \brief Delete a recording from memory
+ * \param handle Handle to recording (as returned by \c record_end())
+ */
void release(recording_t handle);
public:
+ //! Internal state
enum State {
- IDLE,
- RECORDING,
- PLAYING,
+ IDLE, //!< Not doing anything
+ RECORDING, //!< Currently recording
+ PLAYING, //!< Currently playing back a recording
};
+ //! Get current internal state
State get_state() const;
public:
+ /**
+ * \brief Record a single frame to the current recording
+ *
+ * This function is called by ReplaySystem after the game programmer has called \c
+ * record_start()
+ */
void frame_record();
+ /**
+ * \brief Play the next frame of the current recording
+ *
+ * \returns `true` if the recording is finished playing
+ * \returns `false` if there are more frames
+ *
+ * This function also automatically resets the internal state from PLAYING to IDLE at the end
+ * of a recording.
+ */
bool frame_step();
private:
+ /**
+ * \brief Recording data
+ */
struct Recording {
+ //! Current frame being shown
size_t frame = 0;
+ //! All frames in recording
std::vector<ComponentManager::Snapshot> frames;
};
+ //! Internal state
State state = IDLE;
- OptionalRef<Recording> recording;
+ //! Current recording handle
recording_t id = -1;
+ //! Current recording data
+ OptionalRef<Recording> recording;
+ //! Recording storage
std::unordered_map<recording_t, std::unique_ptr<Recording>> memory;
};
diff --git a/src/crepe/manager/SystemManager.h b/src/crepe/manager/SystemManager.h
index 6cf7f2b..a47961b 100644
--- a/src/crepe/manager/SystemManager.h
+++ b/src/crepe/manager/SystemManager.h
@@ -1,11 +1,21 @@
#pragma once
+#include <typeindex>
+#include <unordered_map>
+#include <memory>
+
#include "../system/System.h"
#include "Manager.h"
namespace crepe {
+/**
+ * \brief Collection of all systems
+ *
+ * This manager aggregates all systems and provides utility functions to retrieve references to
+ * and update systems.
+ */
class SystemManager : public Manager {
public:
SystemManager(Mediator &);
@@ -50,9 +60,23 @@ public:
T & get_system();
public:
+ /**
+ * \brief SystemManager snapshot
+ *
+ * The SystemManager snapshot only stores which systems are active
+ */
typedef std::unordered_map<std::type_index, bool> Snapshot;
+ /**
+ * \brief Save a snapshot of the systems' state
+ * \returns Copy of each system's active property
+ */
Snapshot save();
+ /**
+ * \brief Restore system active state from a snapshot
+ * \param snapshot Snapshot to restore from (as returned by \c save())
+ */
void restore(const Snapshot & snapshot);
+ //! Disable all systems
void disable_all();
};