Allowing the execution of pre-decoded inputs
This commit is contained in:
parent
998a01febc
commit
67c93e664e
|
@ -26,7 +26,7 @@ public:
|
||||||
port_t port2 = 0;
|
port_t port2 = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool parseInputString(const std::string& input)
|
inline bool parseInputString(const std::string& input, input_t* decoded) const
|
||||||
{
|
{
|
||||||
// Parse valid flag
|
// Parse valid flag
|
||||||
bool isValid = true;
|
bool isValid = true;
|
||||||
|
@ -38,13 +38,13 @@ public:
|
||||||
if (ss.get() != '|') isValid = false;
|
if (ss.get() != '|') isValid = false;
|
||||||
|
|
||||||
// Parsing console inputs
|
// Parsing console inputs
|
||||||
isValid &= parseConsoleInputs(_input.reset, _input.power, ss);
|
isValid &= parseConsoleInputs(decoded->reset, decoded->power, ss);
|
||||||
|
|
||||||
// Parsing controller 1 inputs
|
// Parsing controller 1 inputs
|
||||||
isValid &= parseControllerInputs(_controller1Type, _input.port1, ss);
|
isValid &= parseControllerInputs(_controller1Type, decoded->port1, ss);
|
||||||
|
|
||||||
// Parsing controller 1 inputs
|
// Parsing controller 1 inputs
|
||||||
isValid &= parseControllerInputs(_controller2Type, _input.port2, ss);
|
isValid &= parseControllerInputs(_controller2Type, decoded->port2, ss);
|
||||||
|
|
||||||
// End separator
|
// End separator
|
||||||
if (ss.get() != '|') isValid = false;
|
if (ss.get() != '|') isValid = false;
|
||||||
|
@ -60,11 +60,6 @@ public:
|
||||||
inline void setController1Type(const controller_t type) { _controller1Type = type; }
|
inline void setController1Type(const controller_t type) { _controller1Type = type; }
|
||||||
inline void setController2Type(const controller_t type) { _controller2Type = type; }
|
inline void setController2Type(const controller_t type) { _controller2Type = type; }
|
||||||
|
|
||||||
inline bool getPowerButtonState() { return _input.power; }
|
|
||||||
inline bool getResetButtonState() { return _input.reset; }
|
|
||||||
inline port_t getController1Code() { return _input.port1; }
|
|
||||||
inline port_t getController2Code() { return _input.port2; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static bool parseJoyPadInput(uint8_t& code, std::istringstream& ss)
|
static bool parseJoyPadInput(uint8_t& code, std::istringstream& ss)
|
||||||
|
@ -204,7 +199,6 @@ public:
|
||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_t _input;
|
|
||||||
controller_t _controller1Type;
|
controller_t _controller1Type;
|
||||||
controller_t _controller2Type;
|
controller_t _controller2Type;
|
||||||
|
|
||||||
|
|
|
@ -16,22 +16,43 @@ class NESInstanceBase
|
||||||
NESInstanceBase() = default;
|
NESInstanceBase() = default;
|
||||||
virtual ~NESInstanceBase() = default;
|
virtual ~NESInstanceBase() = default;
|
||||||
|
|
||||||
inline void advanceState(const std::string &move)
|
inline void advanceState(const std::string &input)
|
||||||
{
|
{
|
||||||
bool isInputValid = _controller.parseInputString(move);
|
// Storage for the decoded input
|
||||||
if (isInputValid == false) JAFFAR_THROW_LOGIC("Move provided cannot be parsed: '%s'\n", move.c_str());
|
quickNES::Controller::input_t decodedInput;
|
||||||
|
|
||||||
|
// Getting decoded input from the input string
|
||||||
|
decodeInput(input, &decodedInput);
|
||||||
|
|
||||||
|
// Calling advance state with the decoded input
|
||||||
|
advanceState(&decodedInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void advanceState(const void* decodedInputBuffer)
|
||||||
|
{
|
||||||
|
// Casting decoded input to the right type
|
||||||
|
const auto decodedInput = (quickNES::Controller::input_t*) decodedInputBuffer;
|
||||||
|
|
||||||
// Parsing power
|
// Parsing power
|
||||||
if (_controller.getPowerButtonState() == true) JAFFAR_THROW_LOGIC("Power button pressed, but not supported: '%s'\n", move.c_str());
|
if (decodedInput->power == true) JAFFAR_THROW_LOGIC("Power button pressed, but not supported.");
|
||||||
|
|
||||||
// Parsing reset
|
// Parsing reset
|
||||||
if (_controller.getResetButtonState() == true) doSoftReset();
|
if (decodedInput->reset == true) doSoftReset();
|
||||||
|
|
||||||
// Parsing Controllers
|
// Running specified inputs
|
||||||
const auto controller1 = _controller.getController1Code();
|
advanceStateImpl(decodedInput->port1, decodedInput->port2);
|
||||||
const auto controller2 = _controller.getController2Code();
|
}
|
||||||
|
|
||||||
advanceStateImpl(controller1, controller2);
|
inline size_t getDecodedInputSize() const
|
||||||
|
{
|
||||||
|
return sizeof(quickNES::Controller::input_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void decodeInput(const std::string &input, void* decodedInputBuffer) const
|
||||||
|
{
|
||||||
|
const auto decodedInput = (quickNES::Controller::input_t*) decodedInputBuffer;
|
||||||
|
bool isInputValid = _controller.parseInputString(input, decodedInput);
|
||||||
|
if (isInputValid == false) JAFFAR_THROW_LOGIC("Move provided cannot be parsed: '%s'\n", input.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setController1Type(const std::string& type)
|
inline void setController1Type(const std::string& type)
|
||||||
|
|
Loading…
Reference in New Issue