8#include "zpp/zpp_bits.h"
70 const u64 recorded_frames =
_replay.inputs.size() / block;
71 size_t kept =
_replay.checksums.size();
72 while (kept > 0 && (
u64)
_replay.checksums[kept - 1].frame >= recorded_frames) {
75 std::vector<ReplayChecksum> later(
_replay.checksums.begin() + kept,
_replay.checksums.end());
78 std::vector<u8> packed;
84 const bool use_packed = !packed.empty() && packed.size() <
_replay.inputs.size();
92 const bool bad = failure(out(
109 _replay.checksums.insert(
_replay.checksums.end(), later.begin(), later.end());
112 printf(
"failed to serialize replay data\n");
133 std::unique_ptr<u8[]> inputs;
150 if (size == 0)
return;
155 const u64 needed = (index + 1) * size;
156 if (
_replay.inputs.size() < needed) {
160 std::memcpy(
_replay.inputs.data() + index * size, input, size);
167 if (length >
_replay.config.state_size)
return;
169 _replay.initial_state.assign(state, state + length);
184 _replay.checksum_interval = interval;
197 _replay.user_data.assign(data, data + length);
218 auto state = storage.
GetState(frame);
219 if (state->frame == frame) {
263 if (!replay_data || length == 0)
return false;
265 _bin_buffer.assign(replay_data, replay_data + length);
299 printf(
"failed to deserialize replay data\n");
305 printf(
"invalid replay header\n");
312 printf(
"unsupported replay version %u\n",
_replay.version);
318 printf(
"invalid replay config\n");
323 if (!
_replay.initial_state.empty() &&
325 printf(
"invalid replay state size\n");
331 if (
_replay.inputs.size() % 2 != 0) {
332 printf(
"invalid replay input data\n");
343 printf(
"invalid replay checksums\n");
357 if (
_replay.initial_state.empty())
return nullptr;
359 return _replay.initial_state.data();
367 if (size == 0)
return false;
370 if (offset + size >
_replay.inputs.size())
return false;
372 std::memcpy(input,
_replay.inputs.data() + offset, size);
382 const auto& checksums =
_replay.checksums;
404 return _replay.user_data.data();
449 if (
_replay.checksums.empty())
return true;
451 if (
_replay.checksum_interval == 0)
return false;
457 for (
auto& entry :
_replay.checksums) {
458 if (entry.frame <= previous || (
u64)entry.frame >= frames) {
461 previous = entry.frame;
StateEntry * GetState(Frame frame)
bool GetSpectatorInputs(std::unique_ptr< u8[]> &inputs, Frame frame)
Frame GetMinIncorrectFrame()
Frame GetMinReceivedFrame()
static std::vector< uint8_t > DeltaDecode(const uint8_t *data, u32 length, u32 stride)
static std::vector< uint8_t > RLEEncode(const uint8_t *data, u32 length)
static std::vector< uint8_t > DeltaEncode(const uint8_t *data, u32 length, u32 stride)
static std::vector< uint8_t > RLEDecode(const uint8_t *data, u32 length)
static constexpr u32 MAGIC
static constexpr u32 FORMAT_VERSION_1
static constexpr u32 FORMAT_VERSION
bool NextReplayInput(u8 *input)
std::vector< u8 > _bin_buffer
void RecordState(const u8 *state, u32 length, Frame frame)
Frame _last_checksum_frame
const u8 * UserData(u32 &length) const
bool SetUserData(const u8 *data, u32 length)
StateEntry * PendingState()
bool WantsChecksum(Frame frame) const
bool RecordedChecksum(Frame frame, u32 &checksum)
const u8 * Serialize(u32 &length)
bool ValidChecksums() const
void RecordInputs(SyncSystem &sync)
void RecordPendingState()
Frame _last_recorded_frame
enum Gekko::ReplaySystem::Mode _mode
void RecordChecksum(Frame frame, u32 checksum)
bool SetChecksumInterval(u32 interval)
bool StartRecording(GekkoConfig config, Frame frame, bool save_state, bool disable_compression)
bool LoadReplay(const u8 *replay_data, u32 length)
const u8 * PeekRecording(u32 &length)
const u8 * StopRecording(u32 &length)
void RecordInput(Frame frame, const u8 *input)
void RecordChecksums(StateStorage &storage, Frame up_to)