mirror of https://github.com/stella-emu/stella.git
Modified joystick axis event handling, so that digital output is always used
when sending axis events to the DialogContainer (ie, all UI-related stuff). The UI code was originally written with this in mind, and wasn't designed for analog input. For normal digital sticks, nothing changes. For analog sticks, values are clamped to 3 points (max, min, off), and repeated consecutive events are ignored. This (partially) fixes bugs in the UI, where pressing an analog stick would cause the current selector to move very fast. Added repeat mode for joystick hats, similar to joystick axes (so holding down a hat will cause continuous events to occur. More testing is required for this, as I don't actually have access to hats right now. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2058 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
88e6b69195
commit
78fd3c0c7d
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <cstdlib>
|
||||
|
||||
#define STELLA_VERSION "3.2_svn"
|
||||
#define STELLA_VERSION "3.2_test1"
|
||||
#define STELLA_BUILD atoi("$Rev$"+6)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -85,11 +85,14 @@ EventHandler::EventHandler(OSystem* osystem)
|
|||
for(int j = 0; j < kNumJoyButtons; ++j)
|
||||
myJoyTable[i][j][m] = Event::NoType;
|
||||
|
||||
// Erase the joystick axis mapping array
|
||||
for(int m = 0; m < kNumModes; ++m)
|
||||
// Erase the joystick axis mapping array and last axis value
|
||||
for(int i = 0; i < kNumJoysticks; ++i)
|
||||
for(int j = 0; j < kNumJoyAxis; ++j)
|
||||
{
|
||||
myAxisLastValue[i][j] = 0;
|
||||
for(int m = 0; m < kNumModes; ++m)
|
||||
myJoyAxisTable[i][j][0][m] = myJoyAxisTable[i][j][1][m] = Event::NoType;
|
||||
}
|
||||
|
||||
// Erase the joystick hat mapping array
|
||||
for(int m = 0; m < kNumModes; ++m)
|
||||
|
@ -696,7 +699,25 @@ void EventHandler::poll(uInt64 time)
|
|||
if(myState == S_EMULATE)
|
||||
handleJoyAxisEvent(stick, axis, value);
|
||||
else if(myOverlay != NULL)
|
||||
{
|
||||
// First, clamp the values to simulate digital input
|
||||
// (the only thing that the underlying code understands)
|
||||
if(value > Joystick::deadzone())
|
||||
value = 32000;
|
||||
else if(value < -Joystick::deadzone())
|
||||
value = -32000;
|
||||
else
|
||||
value = 0;
|
||||
|
||||
// Now filter out consecutive, similar values
|
||||
// (only pass on the event if the state has changed)
|
||||
if(value != myAxisLastValue[stick][axis])
|
||||
{
|
||||
// cerr << value << " @ " << COUNTER++ << "(" << stick << "/" << axis << ")" << endl;
|
||||
myOverlay->handleJoyAxisEvent(stick, axis, value);
|
||||
myAxisLastValue[stick][axis] = value;
|
||||
}
|
||||
}
|
||||
break; // Regular joystick axis
|
||||
|
||||
case JT_STELLADAPTOR_LEFT:
|
||||
|
|
|
@ -506,6 +506,10 @@ class EventHandler
|
|||
// Indicates which paddle the mouse currently emulates
|
||||
Int8 myPaddleMode;
|
||||
|
||||
// Keeps track of last axis values (used to emulate digital state
|
||||
// for analog sticks)
|
||||
int myAxisLastValue[kNumJoysticks][kNumJoyAxis];
|
||||
|
||||
// Holds static strings for the remap menu (emulation and menu events)
|
||||
static ActionList ourEmulActionList[kEmulActionListSize];
|
||||
static ActionList ourMenuActionList[kMenuActionListSize];
|
||||
|
|
|
@ -68,7 +68,6 @@ class Joystick : public Controller
|
|||
Event::Type myUpEvent, myDownEvent, myLeftEvent, myRightEvent,
|
||||
myXAxisValue, myYAxisValue, myFireEvent;
|
||||
|
||||
|
||||
static int _DEAD_ZONE;
|
||||
};
|
||||
|
||||
|
|
|
@ -896,7 +896,14 @@ void OSystem::setDefaultJoyAxisMap()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void OSystem::setDefaultJoyHatMap()
|
||||
{
|
||||
// FIXME - add emul and UI events
|
||||
// FIXME - add emulation events
|
||||
EventMode mode;
|
||||
|
||||
mode = kMenuMode; // Default menu/UI events
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UILeft, mode, 0, 0, 2);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIRight, mode, 0, 0, 3);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIUp, mode, 0, 0, 0);
|
||||
myEventHandler->setDefaultJoyHatMapping(Event::UIDown, mode, 0, 0, 1);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -84,6 +84,14 @@ void DialogContainer::updateTime(uInt64 time)
|
|||
myCurrentAxisDown.value);
|
||||
myAxisRepeatTime = myTime + kRepeatSustainDelay;
|
||||
}
|
||||
|
||||
// Joystick hat still pressed
|
||||
if(myCurrentHatDown.stick != -1 && myHatRepeatTime < myTime)
|
||||
{
|
||||
activeDialog->handleJoyHat(myCurrentHatDown.stick, myCurrentHatDown.hat,
|
||||
myCurrentHatDown.value);
|
||||
myHatRepeatTime = myTime + kRepeatSustainDelay;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -282,22 +290,9 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
|
||||
{
|
||||
// FIXME - analog axis events cause autofire to inadvertently come on and not go off
|
||||
|
||||
if(myDialogStack.empty())
|
||||
return;
|
||||
|
||||
// Send the event to the dialog box on the top of the stack
|
||||
Dialog* activeDialog = myDialogStack.top();
|
||||
|
||||
int deadzone = Joystick::deadzone();
|
||||
if(value > deadzone)
|
||||
value -= deadzone;
|
||||
else if(value < -deadzone )
|
||||
value += deadzone;
|
||||
else
|
||||
value = 0;
|
||||
|
||||
// Only stop firing events if it's the current stick
|
||||
if(myCurrentAxisDown.stick == stick && value == 0)
|
||||
{
|
||||
|
@ -311,7 +306,7 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
|
|||
myCurrentAxisDown.value = value;
|
||||
myAxisRepeatTime = myTime + kRepeatInitialDelay;
|
||||
}
|
||||
activeDialog->handleJoyAxis(stick, axis, value);
|
||||
myDialogStack.top()->handleJoyAxis(stick, axis, value);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -320,11 +315,20 @@ void DialogContainer::handleJoyHatEvent(int stick, int hat, int value)
|
|||
if(myDialogStack.empty())
|
||||
return;
|
||||
|
||||
// Send the event to the dialog box on the top of the stack
|
||||
Dialog* activeDialog = myDialogStack.top();
|
||||
|
||||
// FIXME - add repeat processing, similar to axis/button events
|
||||
activeDialog->handleJoyHat(stick, hat, value);
|
||||
// Only stop firing events if it's the current stick
|
||||
if(myCurrentHatDown.stick == stick && value == 0)
|
||||
{
|
||||
myCurrentHatDown.stick = myCurrentHatDown.hat = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now account for repeated hat events (press and hold)
|
||||
myCurrentHatDown.stick = stick;
|
||||
myCurrentHatDown.hat = hat;
|
||||
myCurrentHatDown.value = value;
|
||||
myHatRepeatTime = myTime + kRepeatInitialDelay;
|
||||
}
|
||||
myDialogStack.top()->handleJoyHat(stick, hat, value);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
Loading…
Reference in New Issue