10#include <inputParser.hpp>
12#include <jaffarCommon/deserializers/contiguous.hpp>
13#include <jaffarCommon/file.hpp>
14#include <jaffarCommon/json.hpp>
15#include <jaffarCommon/serializers/contiguous.hpp>
79 if (
_isInitialized ==
true) JAFFAR_THROW_LOGIC(
"This emulator instance was already initialized");
98 for (
size_t i = 0; i <
_inputMap.size(); i++)
99 if (inputString ==
_inputMap[i].inputString)
return i;
105 _inputMap.push_back({inputString, inputData});
130 jaffarCommon::serializer::Contiguous s;
132 return s.getOutputSize();
148 virtual void serializeState(jaffarCommon::serializer::Base& serializer)
const = 0;
176 static std::unique_ptr<Emulator>
getEmulator(
const nlohmann::json& emulatorConfig);
Abstract base for an emulation core.
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.
virtual void serializeState(jaffarCommon::serializer::Base &serializer) const =0
Serializes the emulator state into the given serializer.
Emulator(const nlohmann::json &config)
Constructs the emulator, performing only configuration parsing (for dry runs).
void finalizeEmulatorConfig()
Asserts that every key in the emulator configuration has been recognized.
virtual size_t getRendererStateSize() const =0
Returns the size of the renderer state.
virtual void saveScreenshot(const std::string &)
Saves the currently-rendered frame to an image file at the given destination path.
bool isInitialized() const
Returns whether the emulator instance has been initialized.
virtual void printInfo() const =0
Prints core-specific debug information.
void initialize()
Initializes the emulator instance.
std::string getName() const
Returns the emulator's configured name.
static std::unique_ptr< Emulator > getEmulator(const nlohmann::json &emulatorConfig)
Constructs the emulator core selected by the configuration.
void advanceState(const InputSet::inputIndex_t input)
Advances the emulator state by applying a registered input.
virtual void deserializeRendererState(jaffarCommon::deserializer::Base &deserializer)=0
Loads the renderer state for a given state/frame from the deserializer.
virtual void disableRendering()=0
Disables rendering within the emulation core (typically enables faster emulation).
nlohmann::json _emulatorConfigRemaining
Mutable working copy of the emulator config; recognized keys are popped, leftovers are unrecognized....
virtual void enableRendering()=0
Enables rendering within the emulation core (does not output it to screen).
std::string _emulatorName
Emulator name (for runtime use).
virtual void showRender()=0
Shows the contents of the emulator's renderer in the window.
virtual void serializeRendererState(jaffarCommon::serializer::Base &serializer) const =0
Gathers the data needed to render a given state/frame into the serializer.
bool _isInitialized
Whether the emulator has been initialized.
virtual void deserializeState(jaffarCommon::deserializer::Base &deserializer)=0
Deserializes the emulator state from the given deserializer.
virtual void finalizeVideoOutput()=0
Closes the video output (e.g., window).
size_t getStateSize() const
Computes the serialized size of the emulator state.
virtual property_t getProperty(const std::string &propertyName) const =0
Returns a memory property by name.
virtual void initializeImpl()=0
Core-specific initialization, invoked by initialize.
virtual void advanceStateImpl(const jaffar::input_t &input)=0
Core-specific state advancement, invoked by advanceState.
virtual void initializeVideoOutput()=0
Opens the video output (e.g., window).
virtual void updateRendererState(const size_t stepIdx, const std::string input)=0
Updates the internal state of the renderer with the current game state.
std::vector< inputEntry_t > _inputMap
Maps an input id to its input data.
virtual jaffar::InputParser * getInputParser() const =0
Returns a reference to the emulator's input parser.
Pairs an input's string form with its decoded, emulator-specific input data.
std::string inputString
Input string.
jaffar::input_t inputData
Emulator-specific input data.
A property: a contiguous segment of memory with a size, identifiable by name.
uint8_t * pointer
Pointer to the start of the property's memory segment.
size_t size
Size of the property's memory segment, in bytes.