aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/ReplayManager.h
blob: 672d093f123385af95aaa7ac451e78852ffd16d8 (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
#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);
	friend class ReplaySystem;

protected:
	void record_frame();

private:
	struct Recording {
		size_t frame = 0;
		std::vector<ComponentManager::Snapshot> frames;
	};

	enum State {
		IDLE,
		RECORDING,
		PLAYING,
	};

	State state = IDLE;
	OptionalRef<Recording> recording;
	recording_t id = -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