JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
Loading...
Searching...
No Matches
jaffarPlus::Playback Class Referencefinal

Replays a solution's input sequence and caches per-step state for navigation. More...

#include <playback.hpp>

Classes

struct  hashHasher_t
 Hash functor for 128-bit state hashes (std::pair<uint64_t, uint64_t>). More...
 
struct  step_t
 A single recorded playback step. More...
 

Public Member Functions

 Playback (Runner &runner)
 Constructs the playback over a runner and caches state sizes.
 
void initialize (const std::vector< std::string > &inputSequence)
 Replays the input sequence, recording one cached step per input (plus a trailing end-of-sequence step).
 
 ~Playback ()
 Frees the game and renderer state memory allocated during initialization.
 
std::string getStateInputString (const size_t currentStep) const
 Returns the input string of the given step.
 
jaffarPlus::InputSet::inputIndex_t getStateInputIndex (const size_t currentStep) const
 Returns the input index of the given step.
 
void * getStateData (const size_t currentStep) const
 Returns the serialized game state data of the given step.
 
const std::vector< size_t > getStateRepeatedHashSteps (const size_t currentStep) const
 Returns the earlier steps (ascending) sharing the given step's hash.
 
jaffarCommon::hash::hash_t getStateHash (const size_t currentStep) const
 Returns the state hash of the given step.
 
bool isInputAllowed (const size_t currentStep) const
 Returns whether the input of the given step is allowed by the current move set.
 
ssize_t getFirstWinStep () const
 Returns the first step (number of inputs applied) at which the solution reaches a win state, or -1 if it never does.
 
ssize_t getFirstFailStep () const
 Returns the first step (number of inputs applied) at which the solution reaches a fail state, or -1 if it never does.
 
void renderFrame (const size_t currentStep)
 Renders the cached frame for the given step into the emulator window.
 
void loadStepData (const size_t stepId)
 Loads the cached game state of the given step back into the runner.
 
void printInfo () const
 Prints runner, game, and emulator information.
 

Private Member Functions

step_t getStep (const size_t stepId) const
 Returns the cached step with the given id.
 

Private Attributes

Runner_runner
 Pointer to the runner used for playback.
 
size_t _gameStateSize
 Size, in bytes, of a serialized game state.
 
size_t _rendererStateSize
 Size, in bytes, of a serialized renderer state.
 
std::vector< step_t_sequence
 The recorded sequence of playback steps.
 
std::unordered_map< jaffarCommon::hash::hash_t, std::vector< size_t >, hashHasher_t_hashOccurrences
 Maps each state hash to the steps (ascending) at which it occurred, used to detect the repeated states the engine would have deduplicated.
 
ssize_t _firstWinStep = -1
 First step (inputs applied) reaching a win state; -1 until/unless one is seen.
 
ssize_t _firstFailStep = -1
 First step (inputs applied) reaching a fail state; -1 until/unless one is seen.
 

Detailed Description

Replays a solution's input sequence and caches per-step state for navigation.

Built from a Runner, initialize applies each input in order, recording for every step its input, allowance, serialized game and renderer state, state hash, and any earlier steps sharing that hash, as well as the first win/fail step. Cached steps can then be queried and re-loaded/rendered out of order by the player tool.

Definition at line 29 of file playback.hpp.

Constructor & Destructor Documentation

◆ Playback()

jaffarPlus::Playback::Playback ( Runner runner)
inline

Constructs the playback over a runner and caches state sizes.

Parameters
runnerThe runner used to advance and serialize the solution.

Definition at line 63 of file playback.hpp.

◆ ~Playback()

jaffarPlus::Playback::~Playback ( )
inline

Frees the game and renderer state memory allocated during initialization.

Definition at line 171 of file playback.hpp.

Member Function Documentation

◆ getFirstFailStep()

ssize_t jaffarPlus::Playback::getFirstFailStep ( ) const
inline

Returns the first step (number of inputs applied) at which the solution reaches a fail state, or -1 if it never does.

Computed once during initialize.

Definition at line 205 of file playback.hpp.

◆ getFirstWinStep()

ssize_t jaffarPlus::Playback::getFirstWinStep ( ) const
inline

Returns the first step (number of inputs applied) at which the solution reaches a win state, or -1 if it never does.

Computed once during initialize.

Definition at line 199 of file playback.hpp.

◆ getStateData()

void * jaffarPlus::Playback::getStateData ( const size_t  currentStep) const
inline

Returns the serialized game state data of the given step.

Definition at line 186 of file playback.hpp.

◆ getStateHash()

jaffarCommon::hash::hash_t jaffarPlus::Playback::getStateHash ( const size_t  currentStep) const
inline

Returns the state hash of the given step.

Definition at line 190 of file playback.hpp.

◆ getStateInputIndex()

jaffarPlus::InputSet::inputIndex_t jaffarPlus::Playback::getStateInputIndex ( const size_t  currentStep) const
inline

Returns the input index of the given step.

Definition at line 184 of file playback.hpp.

◆ getStateInputString()

std::string jaffarPlus::Playback::getStateInputString ( const size_t  currentStep) const
inline

Returns the input string of the given step.

Definition at line 182 of file playback.hpp.

◆ getStateRepeatedHashSteps()

const std::vector< size_t > jaffarPlus::Playback::getStateRepeatedHashSteps ( const size_t  currentStep) const
inline

Returns the earlier steps (ascending) sharing the given step's hash.

Definition at line 188 of file playback.hpp.

◆ getStep()

step_t jaffarPlus::Playback::getStep ( const size_t  stepId) const
inlineprivate

Returns the cached step with the given id.

Parameters
stepIdThe index of the step to retrieve.
Returns
A copy of the cached step.
Exceptions
Aruntime error if stepId exceeds the recorded sequence size.

Definition at line 251 of file playback.hpp.

◆ initialize()

void jaffarPlus::Playback::initialize ( const std::vector< std::string > &  inputSequence)
inline

Replays the input sequence, recording one cached step per input (plus a trailing end-of-sequence step).

For each step, registers/looks up the input, computes its allowance and state hash, records earlier steps sharing that hash, serializes the game and renderer state, advances the runner, evaluates rules, updates the game state type and reward, and records the first win/fail step.

Parameters
inputSequenceThe ordered list of input strings to replay.

Definition at line 81 of file playback.hpp.

◆ isInputAllowed()

bool jaffarPlus::Playback::isInputAllowed ( const size_t  currentStep) const
inline

Returns whether the input of the given step is allowed by the current move set.

Definition at line 192 of file playback.hpp.

◆ loadStepData()

void jaffarPlus::Playback::loadStepData ( const size_t  stepId)
inline

Loads the cached game state of the given step back into the runner.

Parameters
stepIdThe step whose game state to deserialize.

Definition at line 223 of file playback.hpp.

◆ printInfo()

void jaffarPlus::Playback::printInfo ( ) const
inline

Prints runner, game, and emulator information.

Definition at line 233 of file playback.hpp.

◆ renderFrame()

void jaffarPlus::Playback::renderFrame ( const size_t  currentStep)
inline

Renders the cached frame for the given step into the emulator window.

Parameters
currentStepThe step whose renderer state to display.

Definition at line 211 of file playback.hpp.

Member Data Documentation

◆ _firstFailStep

ssize_t jaffarPlus::Playback::_firstFailStep = -1
private

First step (inputs applied) reaching a fail state; -1 until/unless one is seen.

Definition at line 287 of file playback.hpp.

◆ _firstWinStep

ssize_t jaffarPlus::Playback::_firstWinStep = -1
private

First step (inputs applied) reaching a win state; -1 until/unless one is seen.

Definition at line 286 of file playback.hpp.

◆ _gameStateSize

size_t jaffarPlus::Playback::_gameStateSize
private

Size, in bytes, of a serialized game state.

Definition at line 275 of file playback.hpp.

◆ _hashOccurrences

std::unordered_map<jaffarCommon::hash::hash_t, std::vector<size_t>, hashHasher_t> jaffarPlus::Playback::_hashOccurrences
private

Maps each state hash to the steps (ascending) at which it occurred, used to detect the repeated states the engine would have deduplicated.

Definition at line 284 of file playback.hpp.

◆ _rendererStateSize

size_t jaffarPlus::Playback::_rendererStateSize
private

Size, in bytes, of a serialized renderer state.

Definition at line 278 of file playback.hpp.

◆ _runner

Runner* jaffarPlus::Playback::_runner
private

Pointer to the runner used for playback.

Definition at line 272 of file playback.hpp.

◆ _sequence

std::vector<step_t> jaffarPlus::Playback::_sequence
private

The recorded sequence of playback steps.

Definition at line 281 of file playback.hpp.


The documentation for this class was generated from the following file: