aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/Component.cpp3
-rw-r--r--src/crepe/api/Script.cpp21
-rw-r--r--src/crepe/api/Script.h18
-rw-r--r--src/crepe/manager/ReplayManager.h5
-rw-r--r--src/crepe/system/ReplaySystem.h2
-rw-r--r--src/example/replay.cpp35
6 files changed, 54 insertions, 30 deletions
diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp
index 8086492..1aed507 100644
--- a/src/crepe/Component.cpp
+++ b/src/crepe/Component.cpp
@@ -5,7 +5,8 @@ using namespace std;
Component::Component(game_object_id_t id) : game_object_id(id) {}
-Component & Component::operator=(const Component &) {
+Component & Component::operator=(const Component & other) {
+ this->active = other.active;
return *this;
}
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
index 753a9e3..8b95cc9 100644
--- a/src/crepe/api/Script.cpp
+++ b/src/crepe/api/Script.cpp
@@ -25,3 +25,24 @@ void Script::set_next_scene(const string & name) {
}
SaveManager & Script::get_save_manager() const { return this->mediator->save_manager; }
+
+void Script::replay::record_start() {
+ ReplayManager & mgr = this->mediator->replay_manager;
+ return mgr.record_start();
+}
+
+recording_t Script::replay::record_end() {
+ ReplayManager & mgr = this->mediator->replay_manager;
+ return mgr.record_end();
+}
+
+void Script::replay::play(recording_t recording) {
+ ReplayManager & mgr = this->mediator->replay_manager;
+ return mgr.play(recording);
+}
+
+void Script::replay::release(recording_t recording) {
+ ReplayManager & mgr = this->mediator->replay_manager;
+ return mgr.release(recording);
+}
+
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 668e5d1..c797db0 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -2,6 +2,7 @@
#include <vector>
+#include "../manager/ReplayManager.h"
#include "../manager/EventManager.h"
#include "../manager/Mediator.h"
#include "../system/CollisionSystem.h"
@@ -135,6 +136,23 @@ protected:
//! Retrieve SaveManager reference
SaveManager & get_save_manager() const;
+ //! Replay management functions
+ struct replay { // NOLINT
+ //! \copydoc ReplayManager::record_start
+ void record_start();
+ //! \copydoc ReplayManager::record_end
+ recording_t record_end();
+ //! \copydoc ReplayManager::play
+ void play(recording_t);
+ //! \copydoc ReplayManager::release
+ void release(recording_t);
+
+ private:
+ OptionalRef<Mediator> & mediator;
+ replay(OptionalRef<Mediator> & mediator) : mediator(mediator) {}
+ friend class Script;
+ } replay{mediator};
+
//! \}
private:
diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h
index 5794761..7be18f3 100644
--- a/src/crepe/manager/ReplayManager.h
+++ b/src/crepe/manager/ReplayManager.h
@@ -12,7 +12,12 @@ class ReplaySystem;
typedef size_t recording_t;
+/**
+ * \brief Replay manager
+ *
+ */
class ReplayManager : public Manager {
+ // TODO: Delete recordings at end of scene
public:
ReplayManager(Mediator & mediator);
diff --git a/src/crepe/system/ReplaySystem.h b/src/crepe/system/ReplaySystem.h
index 6f6fce4..919c554 100644
--- a/src/crepe/system/ReplaySystem.h
+++ b/src/crepe/system/ReplaySystem.h
@@ -15,8 +15,6 @@ public:
private:
ReplayManager::State last_state = ReplayManager::IDLE;
- void update_recording();
- void update_playing();
struct Snapshot {
ComponentManager::Snapshot components;
diff --git a/src/example/replay.cpp b/src/example/replay.cpp
index e7f4e6d..4c606d7 100644
--- a/src/example/replay.cpp
+++ b/src/example/replay.cpp
@@ -1,19 +1,6 @@
-#include <crepe/util/OptionalRef.h>
-#include <crepe/api/BoxCollider.h>
-#include <crepe/api/Camera.h>
-#include <crepe/api/Color.h>
-#include <crepe/api/Config.h>
-#include <crepe/api/Event.h>
-#include <crepe/api/GameObject.h>
#include <crepe/api/Engine.h>
-#include <crepe/api/Rigidbody.h>
-#include <crepe/api/Scene.h>
#include <crepe/api/Script.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/api/Transform.h>
-#include <crepe/manager/ComponentManager.h>
-#include <crepe/manager/Mediator.h>
-#include <crepe/manager/ReplayManager.h>
+#include <crepe/api/Config.h>
using namespace crepe;
using namespace std;
@@ -34,27 +21,20 @@ class AnimationScript : public Script {
class Timeline : public Script {
unsigned i = 0;
- ReplayManager & mgr;
recording_t recording;
-public:
- Timeline(ReplayManager & mgr)
- : mgr(mgr) {}
-
void update() {
switch (i++) {
default: break;
case 10:
- mgr.record_start();
+ replay.record_start();
break;
case 60:
- this->recording = mgr.record_end();
- break;
- case 70:
- mgr.play(this->recording);
+ this->recording = replay.record_end();
+ replay.play(this->recording);
break;
- case 71:
- mgr.release(this->recording);
+ case 61:
+ replay.release(this->recording);
break;
case 72:
throw;
@@ -86,7 +66,7 @@ public:
square.add_component<BehaviorScript>().set_script<AnimationScript>();
GameObject scapegoat = mgr.new_object("");
- scapegoat.add_component<BehaviorScript>().set_script<Timeline>(mediator.replay_manager);
+ scapegoat.add_component<BehaviorScript>().set_script<Timeline>();
}
string get_name() const { return "scene1"; }
@@ -100,5 +80,6 @@ int main(int argc, char * argv[]) {
engine.add_scene<TestScene>();
engine.start();
+
return 0;
}