Replay: deterministic record & playback (#4)
Add deterministic record/playback for a run. Recording captures `(seed, config hash, ordered tick-tagged commands)` and re-simulates on playback — no state snapshots. `DotaFactory.exe --replay <file>` re-plays a recorded run view-only with manual speed/pause. Reviewed-on: #4 Co-authored-by: Malte Langkabel <malte.langkabel@gmail.com> Co-committed-by: Malte Langkabel <malte.langkabel@gmail.com>
This commit was merged in pull request #4.
This commit is contained in:
41
src/lib/sim/ReplayReader.h
Normal file
41
src/lib/sim/ReplayReader.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Tick.h"
|
||||
|
||||
struct Command;
|
||||
|
||||
struct ReplayHeader
|
||||
{
|
||||
int version = 0;
|
||||
std::string build;
|
||||
unsigned int seed = 0;
|
||||
std::string configHash;
|
||||
std::string timestamp;
|
||||
};
|
||||
|
||||
// One entry of the replay stream: either a command (applied at its tick) or an
|
||||
// RNG checksum (verified at its tick). Entries are kept in file order, which is
|
||||
// the canonical order the playback driver reproduces.
|
||||
struct ReplayEntry
|
||||
{
|
||||
Tick tick = 0;
|
||||
bool isCommand = false;
|
||||
std::shared_ptr<const Command> command; // set iff isCommand
|
||||
std::uint64_t fingerprint = 0; // set iff !isCommand
|
||||
};
|
||||
|
||||
struct ParsedReplay
|
||||
{
|
||||
ReplayHeader header;
|
||||
std::vector<ReplayEntry> entries;
|
||||
};
|
||||
|
||||
// Parses a replay file (header + command/checksum stream). Returns nullopt on an
|
||||
// I/O failure or malformed content (e.g. an unparseable command line).
|
||||
std::optional<ParsedReplay> readReplayFile(const std::string& path);
|
||||
Reference in New Issue
Block a user