GekkoNet 1.0
C/C++ Peer to Peer Game Networking SDK
Loading...
Searching...
No Matches
replay.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "gekko_types.h"
6#include "gekkonet.h"
7#include "storage.h"
8#include "sync.h"
9
10namespace Gekko {
12 // frame relative to the first recorded input.
15 };
16
17 struct ReplayBlob {
18 static constexpr u32 MAGIC = 0x474B5250; // GKRP
19 static constexpr u32 FORMAT_VERSION = 2;
20 // version 1 replays end after the initial state.
21 static constexpr u32 FORMAT_VERSION_1 = 1;
22
25 bool compressed = false;
26
28
29 std::vector<u8> inputs;
30 std::vector<u8> initial_state;
31
32 // added in version 2
34 std::vector<ReplayChecksum> checksums;
35 std::vector<u8> user_data;
36 };
37
38 struct ReplaySystem {
39 bool StartRecording(GekkoConfig config, Frame frame, bool save_state, bool disable_compression);
40 const u8* StopRecording(u32& length);
41 const u8* PeekRecording(u32& length);
42 void RecordInputs(SyncSystem& sync);
43 void RecordState(const u8* state, u32 length, Frame frame);
44
45 bool SetChecksumInterval(u32 interval);
46 bool SetUserData(const u8* data, u32 length);
47 // records the checksums of the frames up to and including up_to the storage still holds.
48 void RecordChecksums(StateStorage& storage, Frame up_to);
49 // records the checksum of a single confirmed frame.
50 void RecordChecksum(Frame frame, u32 checksum);
51 bool WantsChecksum(Frame frame) const;
52
53 bool NeedsState();
55
56 bool LoadReplay(const u8* replay_data, u32 length);
57 const u8* ReplayState();
58 bool NextReplayInput(u8* input);
59 // the recorded checksum of a playback frame, frames have to be asked in order.
60 bool RecordedChecksum(Frame frame, u32& checksum);
61 const u8* UserData(u32& length) const;
62
64
65 bool IsRecording() const;
66 bool IsReplaying() const;
67
68 void Reset();
69
70 private:
71
72 void RecordInput(Frame frame, const u8* input);
73
74 void RecordPendingState();
75
76 const u8* Serialize(u32& length);
77
78 u32 InputSize() const;
79
80 bool ValidChecksums() const;
81
87
88 bool _needs_state = false;
89 bool _pending_state = false;
90 bool _no_compression = false;
91
96
98
99 std::vector<u8> _bin_buffer;
100
102
104 };
105}
int32_t Frame
Definition gekko_types.h:18
uint8_t u8
Definition gekko_types.h:5
uint32_t u32
Definition gekko_types.h:7
static const i32 NULL_FRAME
Definition input.h:21
static constexpr u32 MAGIC
Definition replay.h:18
std::vector< u8 > user_data
Definition replay.h:35
u32 checksum_interval
Definition replay.h:33
static constexpr u32 FORMAT_VERSION_1
Definition replay.h:21
static constexpr u32 FORMAT_VERSION
Definition replay.h:19
GekkoConfig config
Definition replay.h:27
std::vector< u8 > inputs
Definition replay.h:29
std::vector< u8 > initial_state
Definition replay.h:30
std::vector< ReplayChecksum > checksums
Definition replay.h:34
bool NextReplayInput(u8 *input)
Definition replay.cpp:362
std::vector< u8 > _bin_buffer
Definition replay.h:99
void RecordState(const u8 *state, u32 length, Frame frame)
Definition replay.cpp:163
Frame _last_checksum_frame
Definition replay.h:95
const u8 * UserData(u32 &length) const
Definition replay.cpp:396
bool IsReplaying() const
Definition replay.cpp:417
bool SetUserData(const u8 *data, u32 length)
Definition replay.cpp:189
GekkoConfig Config()
Definition replay.cpp:407
StateEntry * PendingState()
Definition replay.cpp:243
bool WantsChecksum(Frame frame) const
Definition replay.cpp:203
bool RecordedChecksum(Frame frame, u32 &checksum)
Definition replay.cpp:378
const u8 * Serialize(u32 &length)
Definition replay.cpp:60
StateEntry _state
Definition replay.h:101
bool ValidChecksums() const
Definition replay.cpp:447
void RecordInputs(SyncSystem &sync)
Definition replay.cpp:121
ReplayBlob _replay
Definition replay.h:103
void RecordPendingState()
Definition replay.cpp:250
Frame _last_recorded_frame
Definition replay.h:94
const u8 * ReplayState()
Definition replay.cpp:355
enum Gekko::ReplaySystem::Mode _mode
void RecordChecksum(Frame frame, u32 checksum)
Definition replay.cpp:227
bool SetChecksumInterval(u32 interval)
Definition replay.cpp:180
bool StartRecording(GekkoConfig config, Frame frame, bool save_state, bool disable_compression)
Definition replay.cpp:10
bool IsRecording() const
Definition replay.cpp:412
bool LoadReplay(const u8 *replay_data, u32 length)
Definition replay.cpp:259
const u8 * PeekRecording(u32 &length)
Definition replay.cpp:51
const u8 * StopRecording(u32 &length)
Definition replay.cpp:38
u32 InputSize() const
Definition replay.cpp:442
void RecordInput(Frame frame, const u8 *input)
Definition replay.cpp:145
Frame _current_frame
Definition replay.h:93
void RecordChecksums(StateStorage &storage, Frame up_to)
Definition replay.cpp:212