![]() |
JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
|
Abstract base for an emulation core. More...
#include <emulator.hpp>
Classes | |
| struct | inputEntry_t |
| Pairs an input's string form with its decoded, emulator-specific input data. More... | |
Public Member Functions | |
| Emulator (const nlohmann::json &config) | |
| Constructs the emulator, performing only configuration parsing (for dry runs). | |
| void | initialize () |
| Initializes the emulator instance. | |
| InputSet::inputIndex_t | registerInput (const std::string inputString) |
| Registers an input string, avoiding repeated decoding of the same input. | |
| const inputEntry_t & | getRegisteredInput (const InputSet::inputIndex_t inputIdx) const |
| Returns the information about a previously registered input. | |
| void | advanceState (const InputSet::inputIndex_t input) |
| Advances the emulator state by applying a registered input. | |
| size_t | getStateSize () const |
| Computes the serialized size of the emulator state. | |
| bool | isInitialized () const |
| Returns whether the emulator instance has been initialized. | |
| std::string | getName () const |
| Returns the emulator's configured name. | |
| virtual void | initializeImpl ()=0 |
| Core-specific initialization, invoked by initialize. | |
| virtual void | serializeState (jaffarCommon::serializer::Base &serializer) const =0 |
| Serializes the emulator state into the given serializer. | |
| virtual void | deserializeState (jaffarCommon::deserializer::Base &deserializer)=0 |
| Deserializes the emulator state from the given deserializer. | |
| virtual jaffar::InputParser * | getInputParser () const =0 |
| Returns a reference to the emulator's input parser. | |
| virtual void | printInfo () const =0 |
| Prints core-specific debug information. | |
| virtual property_t | getProperty (const std::string &propertyName) const =0 |
| Returns a memory property by name. | |
| virtual void | initializeVideoOutput ()=0 |
| Opens the video output (e.g., window). | |
| virtual void | finalizeVideoOutput ()=0 |
| Closes the video output (e.g., window). | |
| virtual void | enableRendering ()=0 |
| Enables rendering within the emulation core (does not output it to screen). | |
| virtual void | disableRendering ()=0 |
| Disables rendering within the emulation core (typically enables faster emulation). | |
| virtual void | updateRendererState (const size_t stepIdx, const std::string input)=0 |
| Updates the internal state of the renderer with the current game state. | |
| virtual void | serializeRendererState (jaffarCommon::serializer::Base &serializer) const =0 |
| Gathers the data needed to render a given state/frame into the serializer. | |
| virtual void | deserializeRendererState (jaffarCommon::deserializer::Base &deserializer)=0 |
| Loads the renderer state for a given state/frame from the deserializer. | |
| virtual size_t | getRendererStateSize () const =0 |
| Returns the size of the renderer state. | |
| virtual void | showRender ()=0 |
| Shows the contents of the emulator's renderer in the window. | |
| virtual void | saveScreenshot (const std::string &) |
| Saves the currently-rendered frame to an image file at the given destination path. | |
Static Public Member Functions | |
| static std::unique_ptr< Emulator > | getEmulator (const nlohmann::json &emulatorConfig) |
| Constructs the emulator core selected by the configuration. | |
Protected Member Functions | |
| virtual void | advanceStateImpl (const jaffar::input_t &input)=0 |
| Core-specific state advancement, invoked by advanceState. | |
| void | finalizeEmulatorConfig () |
| Asserts that every key in the emulator configuration has been recognized. | |
Protected Attributes | |
| std::string | _emulatorName |
| Emulator name (for runtime use). | |
| nlohmann::json | _emulatorConfigRemaining |
| Mutable working copy of the emulator config; recognized keys are popped, leftovers are unrecognized. See finalizeEmulatorConfig(). | |
| bool | _isInitialized = false |
| Whether the emulator has been initialized. | |
Private Attributes | |
| std::vector< inputEntry_t > | _inputMap |
| Maps an input id to its input data. | |
Abstract base for an emulation core.
Defines the interface JaffarPlus uses to drive a guest system: initializing the core, registering and advancing inputs, serializing/deserializing emulator state, exposing guest memory as named property_t segments, and (optionally) rendering frames and saving screenshots. Concrete cores implement the pure-virtual *Impl and rendering hooks; getEmulator constructs the appropriate core from configuration.
Definition at line 39 of file emulator.hpp.
|
inline |
Constructs the emulator, performing only configuration parsing (for dry runs).
| config | Emulator configuration object; must contain the "Emulator Name" field. |
Keeps a mutable working copy of config in _emulatorConfigRemaining and consumes (pops) the common keys it reads from it, so that a derived core can pop ITS own keys from the same copy and then call finalizeEmulatorConfig() to reject any leftover (unrecognized) key. Strict checking is opt-in: a core that does not call finalizeEmulatorConfig() is never checked, so unconverted cores keep working unchanged.
Definition at line 64 of file emulator.hpp.
|
inline |
Advances the emulator state by applying a registered input.
| input | The index of the registered input to apply. |
Definition at line 122 of file emulator.hpp.
|
protectedpure virtual |
Core-specific state advancement, invoked by advanceState.
| input | The decoded, emulator-specific input data to apply. |
|
pure virtual |
Loads the renderer state for a given state/frame from the deserializer.
| deserializer | The deserializer to read the renderer state from. |
|
pure virtual |
Deserializes the emulator state from the given deserializer.
| deserializer | The deserializer to read the emulator state from. |
|
inlineprotected |
Asserts that every key in the emulator configuration has been recognized.
Call this at the END of a derived core's constructor, after it has consumed all of its own configuration keys (via the jaffarCommon::json::pop* helpers) from _emulatorConfigRemaining. The base ctor has already popped the common keys, so anything still present is an unrecognized key (a typo or unsupported option) and is reported by name. Cores that do not call this remain lenient (opt-in strict validation).
Definition at line 244 of file emulator.hpp.
|
static |
Constructs the emulator core selected by the configuration.
| emulatorConfig | Emulator configuration object. |
|
pure virtual |
Returns a reference to the emulator's input parser.
|
inline |
Returns the emulator's configured name.
Definition at line 139 of file emulator.hpp.
|
pure virtual |
Returns a memory property by name.
| propertyName | The name of the property to look up. |
|
inline |
Returns the information about a previously registered input.
| inputIdx | The index of the registered input. |
Definition at line 116 of file emulator.hpp.
|
pure virtual |
Returns the size of the renderer state.
|
inline |
Computes the serialized size of the emulator state.
Definition at line 128 of file emulator.hpp.
|
inline |
Initializes the emulator instance.
Calls the core-specific initializeImpl and marks the instance as initialized.
| A | logic error if the instance was already initialized. |
Definition at line 77 of file emulator.hpp.
|
inline |
Returns whether the emulator instance has been initialized.
Definition at line 136 of file emulator.hpp.
|
inline |
Registers an input string, avoiding repeated decoding of the same input.
If the input is already registered, returns its existing id; otherwise decodes it via the input parser and stores a new entry. Registration is linear O(n) to keep read access O(1).
| inputString | The input string to register. |
Definition at line 95 of file emulator.hpp.
|
inlinevirtual |
Saves the currently-rendered frame to an image file at the given destination path.
Default: no-op (emulators without a screenshot backend simply ignore the request), so the player can request a screenshot emulator-agnostically. Overrides take the destination file path as their sole argument.
Definition at line 226 of file emulator.hpp.
|
pure virtual |
Gathers the data needed to render a given state/frame into the serializer.
| serializer | The serializer to write the renderer state into. |
|
pure virtual |
Serializes the emulator state into the given serializer.
| serializer | The serializer to write the emulator state into. |
|
pure virtual |
Updates the internal state of the renderer with the current game state.
| stepIdx | The index of the step/frame being rendered. |
| input | The input string associated with the step/frame. |
|
protected |
Mutable working copy of the emulator config; recognized keys are popped, leftovers are unrecognized. See finalizeEmulatorConfig().
Definition at line 250 of file emulator.hpp.
|
protected |
Emulator name (for runtime use).
Definition at line 247 of file emulator.hpp.
|
private |
Maps an input id to its input data.
Definition at line 257 of file emulator.hpp.
|
protected |
Whether the emulator has been initialized.
Definition at line 253 of file emulator.hpp.