aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/ReplayManager.h
blob: 5794761afd6d4f4662c781fd26bad0e1bdf8d84b (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
#pragma once

#include <unordered_map>

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

namespace crepe {

class ReplaySystem;

typedef size_t recording_t;

class ReplayManager : public Manager {
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