prevent simultaneous mapping of analog and digital events on the same axis (until we find a way to how to detect analog or digital input)

remove joystick events from Paddles, these can now be mapped separately
This commit is contained in:
Thomas Jentzsch 2019-08-18 22:09:48 +02:00
parent feb4a07bb2
commit 17f5180682
4 changed files with 76 additions and 105 deletions

View File

@ -569,18 +569,27 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i
// but analog events only affect one of the axis. // but analog events only affect one of the axis.
if (Event::isAnalog(event)) if (Event::isAnalog(event))
{ {
// Turn off the digital event(s) for this axis, because we cannot have both
if(j->joyMap.get(evMode, button, axis, JoyDir::NEG) != Event::NoType)
j->joyMap.erase(evMode, button, axis, JoyDir::NEG);
if(j->joyMap.get(evMode, button, axis, JoyDir::POS) != Event::NoType)
j->joyMap.erase(evMode, button, axis, JoyDir::POS);
j->joyMap.add(event, evMode, button, axis, JoyDir::ANALOG); j->joyMap.add(event, evMode, button, axis, JoyDir::ANALOG);
// update running emulation mapping too // update running emulation mapping too
if(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::NEG) != Event::NoType)
j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::NEG);
if(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::POS) != Event::NoType)
j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::POS);
j->joyMap.add(event, EventMode::kEmulationMode, button, axis, JoyDir::ANALOG); j->joyMap.add(event, EventMode::kEmulationMode, button, axis, JoyDir::ANALOG);
} }
else else
{ {
// Otherwise, turn off the analog event(s) for this axis // Otherwise, turn off the analog event(s) for this axis, because we cannot have both
if (Event::isAnalog(j->joyMap.get(evMode, button, axis, JoyDir::ANALOG))) if (j->joyMap.get(evMode, button, axis, JoyDir::ANALOG) != Event::NoType)
j->joyMap.erase(evMode, button, axis, JoyDir::ANALOG); j->joyMap.erase(evMode, button, axis, JoyDir::ANALOG);
j->joyMap.add(event, evMode, button, axis, adir); j->joyMap.add(event, evMode, button, axis, adir);
// update running emulation mapping too // update running emulation mapping too
if(Event::isAnalog(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG))) if(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG) != Event::NoType)
j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG); j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG);
j->joyMap.add(event, EventMode::kEmulationMode, button, axis, adir); j->joyMap.add(event, EventMode::kEmulationMode, button, axis, adir);
} }
@ -618,10 +627,10 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
if (myHandler.state() == EventHandlerState::EMULATION) if (myHandler.state() == EventHandlerState::EMULATION)
{ {
// Check for analog events, which are handled differently
Event::Type eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG); Event::Type eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG);
// Check for analog events, which are handled differently if (eventAxisAnalog != Event::NoType)
if (Event::isAnalog(eventAxisAnalog))
{ {
myHandler.handleEvent(eventAxisAnalog, value); myHandler.handleEvent(eventAxisAnalog, value);
} }
@ -817,24 +826,28 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRight
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftPaddlesMapping = { PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftPaddlesMapping = {
{Event::PaddleZeroAnalog, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG}, {Event::PaddleZeroAnalog, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG},
{Event::PaddleZeroDecrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS}, // Current code does NOT allow digital and anlog events on the same axis at the same time
{Event::PaddleZeroIncrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::NEG}, //{Event::PaddleZeroDecrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS},
//{Event::PaddleZeroIncrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::NEG},
{Event::PaddleZeroFire, 0}, {Event::PaddleZeroFire, 0},
{Event::PaddleOneAnalog, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG}, {Event::PaddleOneAnalog, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG},
{Event::PaddleOneDecrease, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS}, // Current code does NOT allow digital and anlog events on the same axis at the same
{Event::PaddleOneIncrease, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG}, //{Event::PaddleOneDecrease, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::POS},
//{Event::PaddleOneIncrease, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::NEG},
{Event::PaddleOneFire, 1}, {Event::PaddleOneFire, 1},
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRightPaddlesMapping = { PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRightPaddlesMapping = {
{Event::PaddleTwoAnalog, JOY_CTRL_NONE, JoyAxis::Z, JoyDir::ANALOG}, {Event::PaddleTwoAnalog, JOY_CTRL_NONE, JoyAxis::Z, JoyDir::ANALOG},
{Event::PaddleTwoDecrease, JOY_CTRL_NONE, JoyAxis::Z, JoyDir::POS}, // Current code does NOT allow digital and anlog events on the same axis at the same
{Event::PaddleTwoIncrease, JOY_CTRL_NONE, JoyAxis::Z, JoyDir::NEG}, //{Event::PaddleTwoDecrease, JOY_CTRL_NONE, JoyAxis::Z, JoyDir::POS},
//{Event::PaddleTwoIncrease, JOY_CTRL_NONE, JoyAxis::Z, JoyDir::NEG},
{Event::PaddleTwoFire, 2}, {Event::PaddleTwoFire, 2},
{Event::PaddleThreeAnalog, JOY_CTRL_NONE, JoyAxis(3), JoyDir::ANALOG}, {Event::PaddleThreeAnalog, JOY_CTRL_NONE, JoyAxis(3), JoyDir::ANALOG},
{Event::PaddleThreeDecrease,JOY_CTRL_NONE, JoyAxis(3), JoyDir::POS}, // Current code does NOT allow digital and anlog events on the same axis at the same
{Event::PaddleThreeIncrease,JOY_CTRL_NONE, JoyAxis(3), JoyDir::NEG}, //{Event::PaddleThreeDecrease,JOY_CTRL_NONE, JoyAxis(3), JoyDir::POS},
//{Event::PaddleThreeIncrease,JOY_CTRL_NONE, JoyAxis(3), JoyDir::NEG},
{Event::PaddleThreeFire, 3}, {Event::PaddleThreeFire, 3},
}; };

View File

@ -322,7 +322,7 @@ void PhysicalKeyboardHandler::saveMapping()
bool PhysicalKeyboardHandler::addMapping(Event::Type event, EventMode mode, bool PhysicalKeyboardHandler::addMapping(Event::Type event, EventMode mode,
StellaKey key, StellaMod mod) StellaKey key, StellaMod mod)
{ {
// These keys cannot be remapped // These events cannot be remapped to keys
if(Event::isAnalog(event)) if(Event::isAnalog(event))
return false; return false;
else else

View File

@ -55,35 +55,25 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
// These aren't affected by changes in axis orientation // These aren't affected by changes in axis orientation
myP0AxisValue = Event::PaddleZeroAnalog; myP0AxisValue = Event::PaddleZeroAnalog;
myP1AxisValue = Event::PaddleOneAnalog; myP1AxisValue = Event::PaddleOneAnalog;
myP0FireEvent1 = Event::PaddleZeroFire; myP0FireEvent = Event::PaddleZeroFire;
myP0FireEvent2 = Event::JoystickZeroFire; myP1FireEvent = Event::PaddleOneFire;
myP1FireEvent1 = Event::PaddleOneFire;
myP1FireEvent2 = Event::JoystickZeroFire9;
// Direction of movement is swapped // Direction of movement is swapped
// That is, moving in a certain direction on an axis can // That is, moving in a certain direction on an axis can
// result in either increasing or decreasing paddle movement // result in either increasing or decreasing paddle movement
if(!swapdir) if(!swapdir)
{ {
myP0DecEvent1 = Event::PaddleZeroDecrease; myP0DecEvent = Event::PaddleZeroDecrease;
myP0DecEvent2 = Event::JoystickZeroRight; myP0IncEvent = Event::PaddleZeroIncrease;
myP0IncEvent1 = Event::PaddleZeroIncrease; myP1DecEvent = Event::PaddleOneDecrease;
myP0IncEvent2 = Event::JoystickZeroLeft; myP1IncEvent = Event::PaddleOneIncrease;
myP1DecEvent1 = Event::PaddleOneDecrease;
myP1DecEvent2 = Event::JoystickZeroDown;
myP1IncEvent1 = Event::PaddleOneIncrease;
myP1IncEvent2 = Event::JoystickZeroUp;
} }
else else
{ {
myP0DecEvent1 = Event::PaddleZeroIncrease; myP0DecEvent = Event::PaddleZeroIncrease;
myP0DecEvent2 = Event::JoystickZeroLeft; myP0IncEvent = Event::PaddleZeroDecrease;
myP0IncEvent1 = Event::PaddleZeroDecrease; myP1DecEvent = Event::PaddleOneIncrease;
myP0IncEvent2 = Event::JoystickZeroRight; myP1IncEvent = Event::PaddleOneDecrease;
myP1DecEvent1 = Event::PaddleOneIncrease;
myP1DecEvent2 = Event::JoystickZeroUp;
myP1IncEvent1 = Event::PaddleOneDecrease;
myP1IncEvent2 = Event::JoystickZeroDown;
} }
} }
else // First paddle is 1, second is 0 else // First paddle is 1, second is 0
@ -91,35 +81,25 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
// These aren't affected by changes in axis orientation // These aren't affected by changes in axis orientation
myP0AxisValue = Event::PaddleOneAnalog; myP0AxisValue = Event::PaddleOneAnalog;
myP1AxisValue = Event::PaddleZeroAnalog; myP1AxisValue = Event::PaddleZeroAnalog;
myP0FireEvent1 = Event::PaddleOneFire; myP0FireEvent = Event::PaddleOneFire;
myP0FireEvent2 = Event::JoystickZeroFire9; myP1FireEvent = Event::PaddleZeroFire;
myP1FireEvent1 = Event::PaddleZeroFire;
myP1FireEvent2 = Event::JoystickZeroFire;
// Direction of movement is swapped // Direction of movement is swapped
// That is, moving in a certain direction on an axis can // That is, moving in a certain direction on an axis can
// result in either increasing or decreasing paddle movement // result in either increasing or decreasing paddle movement
if(!swapdir) if(!swapdir)
{ {
myP0DecEvent1 = Event::PaddleOneDecrease; myP0DecEvent = Event::PaddleOneDecrease;
myP0DecEvent2 = Event::JoystickZeroDown; myP0IncEvent = Event::PaddleOneIncrease;
myP0IncEvent1 = Event::PaddleOneIncrease; myP1DecEvent = Event::PaddleZeroDecrease;
myP0IncEvent2 = Event::JoystickZeroUp; myP1IncEvent = Event::PaddleZeroIncrease;
myP1DecEvent1 = Event::PaddleZeroDecrease;
myP1DecEvent2 = Event::JoystickZeroRight;
myP1IncEvent1 = Event::PaddleZeroIncrease;
myP1IncEvent2 = Event::JoystickZeroLeft;
} }
else else
{ {
myP0DecEvent1 = Event::PaddleOneIncrease; myP0DecEvent = Event::PaddleOneIncrease;
myP0DecEvent2 = Event::JoystickZeroUp; myP0IncEvent = Event::PaddleOneDecrease;
myP0IncEvent1 = Event::PaddleOneDecrease; myP1DecEvent = Event::PaddleZeroIncrease;
myP0IncEvent2 = Event::JoystickZeroDown; myP1IncEvent = Event::PaddleZeroDecrease;
myP1DecEvent1 = Event::PaddleZeroIncrease;
myP1DecEvent2 = Event::JoystickZeroLeft;
myP1IncEvent1 = Event::PaddleZeroDecrease;
myP1IncEvent2 = Event::JoystickZeroRight;
} }
} }
} }
@ -130,35 +110,25 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
// These aren't affected by changes in axis orientation // These aren't affected by changes in axis orientation
myP0AxisValue = Event::PaddleTwoAnalog; myP0AxisValue = Event::PaddleTwoAnalog;
myP1AxisValue = Event::PaddleThreeAnalog; myP1AxisValue = Event::PaddleThreeAnalog;
myP0FireEvent1 = Event::PaddleTwoFire; myP0FireEvent = Event::PaddleTwoFire;
myP0FireEvent2 = Event::JoystickOneFire; myP1FireEvent = Event::PaddleThreeFire;
myP1FireEvent1 = Event::PaddleThreeFire;
myP1FireEvent2 = Event::JoystickOneFire9;
// Direction of movement is swapped // Direction of movement is swapped
// That is, moving in a certain direction on an axis can // That is, moving in a certain direction on an axis can
// result in either increasing or decreasing paddle movement // result in either increasing or decreasing paddle movement
if(!swapdir) if(!swapdir)
{ {
myP0DecEvent1 = Event::PaddleTwoDecrease; myP0DecEvent = Event::PaddleTwoDecrease;
myP0DecEvent2 = Event::JoystickOneRight; myP0IncEvent = Event::PaddleTwoIncrease;
myP0IncEvent1 = Event::PaddleTwoIncrease; myP1DecEvent = Event::PaddleThreeDecrease;
myP0IncEvent2 = Event::JoystickOneLeft; myP1IncEvent = Event::PaddleThreeIncrease;
myP1DecEvent1 = Event::PaddleThreeDecrease;
myP1DecEvent2 = Event::JoystickOneDown;
myP1IncEvent1 = Event::PaddleThreeIncrease;
myP1IncEvent2 = Event::JoystickOneUp;
} }
else else
{ {
myP0DecEvent1 = Event::PaddleTwoIncrease; myP0DecEvent = Event::PaddleTwoIncrease;
myP0DecEvent2 = Event::JoystickOneLeft; myP0IncEvent = Event::PaddleTwoDecrease;
myP0IncEvent1 = Event::PaddleTwoDecrease; myP1DecEvent = Event::PaddleThreeIncrease;
myP0IncEvent2 = Event::JoystickOneRight; myP1IncEvent = Event::PaddleThreeDecrease;
myP1DecEvent1 = Event::PaddleThreeIncrease;
myP1DecEvent2 = Event::JoystickOneUp;
myP1IncEvent1 = Event::PaddleThreeDecrease;
myP1IncEvent2 = Event::JoystickOneDown;
} }
} }
else // First paddle is 3, second is 2 else // First paddle is 3, second is 2
@ -166,35 +136,25 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
// These aren't affected by changes in axis orientation // These aren't affected by changes in axis orientation
myP0AxisValue = Event::PaddleThreeAnalog; myP0AxisValue = Event::PaddleThreeAnalog;
myP1AxisValue = Event::PaddleTwoAnalog; myP1AxisValue = Event::PaddleTwoAnalog;
myP0FireEvent1 = Event::PaddleThreeFire; myP0FireEvent = Event::PaddleThreeFire;
myP0FireEvent2 = Event::JoystickOneFire9; myP1FireEvent = Event::PaddleTwoFire;
myP1FireEvent1 = Event::PaddleTwoFire;
myP1FireEvent2 = Event::JoystickOneFire;
// Direction of movement is swapped // Direction of movement is swapped
// That is, moving in a certain direction on an axis can // That is, moving in a certain direction on an axis can
// result in either increasing or decreasing paddle movement // result in either increasing or decreasing paddle movement
if(!swapdir) if(!swapdir)
{ {
myP0DecEvent1 = Event::PaddleThreeDecrease; myP0DecEvent = Event::PaddleThreeDecrease;
myP0DecEvent2 = Event::JoystickOneDown; myP0IncEvent = Event::PaddleThreeIncrease;
myP0IncEvent1 = Event::PaddleThreeIncrease; myP1DecEvent = Event::PaddleTwoDecrease;
myP0IncEvent2 = Event::JoystickOneUp; myP1IncEvent = Event::PaddleTwoIncrease;
myP1DecEvent1 = Event::PaddleTwoDecrease;
myP1DecEvent2 = Event::JoystickOneRight;
myP1IncEvent1 = Event::PaddleTwoIncrease;
myP1IncEvent2 = Event::JoystickOneLeft;
} }
else else
{ {
myP0DecEvent1 = Event::PaddleThreeIncrease; myP0DecEvent = Event::PaddleThreeIncrease;
myP0DecEvent2 = Event::JoystickOneUp; myP0IncEvent = Event::PaddleThreeDecrease;
myP0IncEvent1 = Event::PaddleThreeDecrease; myP1DecEvent = Event::PaddleTwoIncrease;
myP0IncEvent2 = Event::JoystickOneDown; myP1IncEvent = Event::PaddleTwoDecrease;
myP1DecEvent1 = Event::PaddleTwoIncrease;
myP1DecEvent2 = Event::JoystickOneLeft;
myP1IncEvent1 = Event::PaddleTwoDecrease;
myP1IncEvent2 = Event::JoystickOneRight;
} }
} }
} }
@ -236,10 +196,8 @@ void Paddles::update()
setPin(DigitalPin::Four, true); setPin(DigitalPin::Four, true);
// Digital events (from keyboard or joystick hats & buttons) // Digital events (from keyboard or joystick hats & buttons)
setPin(DigitalPin::Three, setPin(DigitalPin::Three, myEvent.get(myP1FireEvent) == 0);
myEvent.get(myP1FireEvent1) == 0 && myEvent.get(myP1FireEvent2) == 0); setPin(DigitalPin::Four, myEvent.get(myP0FireEvent) == 0);
setPin(DigitalPin::Four,
myEvent.get(myP0FireEvent1) == 0 && myEvent.get(myP0FireEvent2) == 0);
// Paddle movement is a very difficult thing to accurately emulate, // Paddle movement is a very difficult thing to accurately emulate,
// since it originally came from an analog device that had very // since it originally came from an analog device that had very
@ -362,25 +320,25 @@ void Paddles::update()
myKeyRepeat0 = false; myKeyRepeat0 = false;
myKeyRepeat1 = false; myKeyRepeat1 = false;
if(myEvent.get(myP0DecEvent1) || myEvent.get(myP0DecEvent2)) if(myEvent.get(myP0DecEvent))
{ {
myKeyRepeat0 = true; myKeyRepeat0 = true;
if(myCharge[myAxisDigitalZero] > myPaddleRepeat0) if(myCharge[myAxisDigitalZero] > myPaddleRepeat0)
myCharge[myAxisDigitalZero] -= myPaddleRepeat0; myCharge[myAxisDigitalZero] -= myPaddleRepeat0;
} }
if(myEvent.get(myP0IncEvent1) || myEvent.get(myP0IncEvent2)) if(myEvent.get(myP0IncEvent))
{ {
myKeyRepeat0 = true; myKeyRepeat0 = true;
if((myCharge[myAxisDigitalZero] + myPaddleRepeat0) < TRIGRANGE) if((myCharge[myAxisDigitalZero] + myPaddleRepeat0) < TRIGRANGE)
myCharge[myAxisDigitalZero] += myPaddleRepeat0; myCharge[myAxisDigitalZero] += myPaddleRepeat0;
} }
if(myEvent.get(myP1DecEvent1) || myEvent.get(myP1DecEvent2)) if(myEvent.get(myP1DecEvent))
{ {
myKeyRepeat1 = true; myKeyRepeat1 = true;
if(myCharge[myAxisDigitalOne] > myPaddleRepeat1) if(myCharge[myAxisDigitalOne] > myPaddleRepeat1)
myCharge[myAxisDigitalOne] -= myPaddleRepeat1; myCharge[myAxisDigitalOne] -= myPaddleRepeat1;
} }
if(myEvent.get(myP1IncEvent1) || myEvent.get(myP1IncEvent2)) if(myEvent.get(myP1IncEvent))
{ {
myKeyRepeat1 = true; myKeyRepeat1 = true;
if((myCharge[myAxisDigitalOne] + myPaddleRepeat1) < TRIGRANGE) if((myCharge[myAxisDigitalOne] + myPaddleRepeat1) < TRIGRANGE)

View File

@ -136,9 +136,9 @@ class Paddles : public Controller
// Pre-compute the events we care about based on given port // Pre-compute the events we care about based on given port
// This will eliminate test for left or right port in update() // This will eliminate test for left or right port in update()
Event::Type myP0AxisValue, myP1AxisValue, Event::Type myP0AxisValue, myP1AxisValue,
myP0DecEvent1, myP0DecEvent2, myP0IncEvent1, myP0IncEvent2, myP0DecEvent, myP0IncEvent,
myP1DecEvent1, myP1DecEvent2, myP1IncEvent1, myP1IncEvent2, myP1DecEvent, myP1IncEvent,
myP0FireEvent1, myP0FireEvent2, myP1FireEvent1, myP1FireEvent2, myP0FireEvent, myP1FireEvent,
myAxisMouseMotion; myAxisMouseMotion;
// The following are used for the various mouse-axis modes // The following are used for the various mouse-axis modes