aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/ReplayManager.h
blob: 7be18f3db0fa4107baae2e79e0bc99f75b9f4616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include <unordered_map>

#include "Manager.h"
#include "ComponentManager.h"
#include "util/OptionalRef.h"

namespace crepe {

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);

public:
	void record_start();
	recording_t record_end();
	void play(recording_t handle);
	void release(recording_t handle);
	
public:
	enum State {
		IDLE,
		RECORDING,
		PLAYING,
	};
	State get_state() const;

public:
	void frame_record();
	bool frame_step();

private:
	struct Recording {
		size_t frame = 0;
		std::vector<ComponentManager::Snapshot> frames;
	};
	State state = IDLE;
	OptionalRef<Recording> recording;
	recording_t id = -1;
	std::unordered_map<recording_t, std::unique_ptr<Recording>> memory;
};

} // namespace crepe