Removed all reference to analog vs. digital joysticks, since we really

don't care what type they are (this is good, since the detection code
was crap anyway).  Events are now designated as being digital or analog.
If an event is analog and the stick also happens to be analog, then it
will get analog values; otherwise it won't.  Hopefully this will speed
up analog processing in Win32 (which I swear is the bane of my existence,
since every time I boot into Windows I feel my blood pressure rising :( )

Fixed typo which caused the joymap to be saved incorrectly.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@943 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-01-09 00:42:12 +00:00
parent e545c973c5
commit f8e51876b5
2 changed files with 35 additions and 66 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.cxx,v 1.141 2006-01-08 02:28:03 stephena Exp $ // $Id: EventHandler.cxx,v 1.142 2006-01-09 00:42:11 stephena Exp $
//============================================================================ //============================================================================
#include <sstream> #include <sstream>
@ -94,15 +94,10 @@ EventHandler::EventHandler(OSystem* osystem)
for(j = 0; j < kNumJoyButtons; ++j) for(j = 0; j < kNumJoyButtons; ++j)
myJoyTable[i][j] = Event::NoType; myJoyTable[i][j] = Event::NoType;
// Erase the joystick axis mapping and type arrays // Erase the joystick axis mapping array
for(i = 0; i < kNumJoysticks; ++i) for(i = 0; i < kNumJoysticks; ++i)
{
for(j = 0; j < kNumJoyAxis; ++j) for(j = 0; j < kNumJoyAxis; ++j)
{
myJoyAxisTable[i][j][0] = myJoyAxisTable[i][j][1] = Event::NoType; myJoyAxisTable[i][j][0] = myJoyAxisTable[i][j][1] = Event::NoType;
myJoyAxisType[i][j] = JA_NONE;
}
}
// Erase the Message array // Erase the Message array
for(i = 0; i < Event::LastType; ++i) for(i = 0; i < Event::LastType; ++i)
@ -893,55 +888,38 @@ void EventHandler::handleJoyAxisEvent(int stick, int axis, int value)
Event::Type eventAxisNeg = myJoyAxisTable[stick][axis][0]; Event::Type eventAxisNeg = myJoyAxisTable[stick][axis][0];
Event::Type eventAxisPos = myJoyAxisTable[stick][axis][1]; Event::Type eventAxisPos = myJoyAxisTable[stick][axis][1];
// Determine what type of axis we're dealing with // Check for analog events, which are handled differently
// Figure out the actual type if it's undefined switch((int)eventAxisNeg)
JoyAxisType type = myJoyAxisType[stick][axis];
if(type == JA_NONE)
{ {
// TODO - will this always work?? case Event::PaddleZeroAnalog:
if(value > 32767 - JOY_DEADZONE || value < -32767 + JOY_DEADZONE) myEvent->set(Event::PaddleZeroResistance,
type = myJoyAxisType[stick][axis] = JA_DIGITAL; (int)(1000000.0 * (32767 - value) / 65534));
else break;
type = myJoyAxisType[stick][axis] = JA_ANALOG; case Event::PaddleOneAnalog:
myEvent->set(Event::PaddleOneResistance,
(int)(1000000.0 * (32767 - value) / 65534));
break;
case Event::PaddleTwoAnalog:
myEvent->set(Event::PaddleTwoResistance,
(int)(1000000.0 * (32767 - value) / 65534));
break;
case Event::PaddleThreeAnalog:
myEvent->set(Event::PaddleThreeResistance,
(int)(1000000.0 * (32767 - value) / 65534));
break;
default:
// Otherwise, we know the event is digital
if(value > -JOY_DEADZONE && value < JOY_DEADZONE)
{
// Turn off both events, since we don't know exactly which one
// was previously activated.
handleEvent(eventAxisNeg, 0);
handleEvent(eventAxisPos, 0);
}
else
handleEvent(value < 0 ? eventAxisNeg : eventAxisPos, 1);
break;
} }
// Paddle emulation *REALLY* complicates this method
if(type == JA_ANALOG)
{
int idx = -1;
switch((int)eventAxisNeg)
{
case Event::PaddleZeroAnalog:
idx = 0;
break;
case Event::PaddleOneAnalog:
idx = 1;
break;
case Event::PaddleTwoAnalog:
idx = 2;
break;
case Event::PaddleThreeAnalog:
idx = 3;
break;
}
if(idx >= 0)
{
int resistance = (int)(1000000.0 * (32767 - value) / 65534);
myEvent->set(Paddle_Resistance[idx], resistance);
return;
}
}
// Otherwise, we know the event is digital
if(value == 0)
{
// Turn off both events, since we don't know exactly which one
// was previously activated.
handleEvent(eventAxisNeg, 0);
handleEvent(eventAxisPos, 0);
}
else
handleEvent(value < 0 ? eventAxisNeg : eventAxisPos, 1);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1344,7 +1322,7 @@ void EventHandler::setJoymap()
// Fill the joymap table with events // Fill the joymap table with events
int idx = 0; int idx = 0;
for(int i = 0; i < kNumJoysticks; ++i) for(int i = 0; i < kNumJoysticks; ++i)
for(int j = 0; j < kNumJoyAxis; ++j) for(int j = 0; j < kNumJoyButtons; ++j)
myJoyTable[i][j] = (Event::Type) map[idx++]; myJoyTable[i][j] = (Event::Type) map[idx++];
} }
else else

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.hxx,v 1.72 2006-01-08 02:28:03 stephena Exp $ // $Id: EventHandler.hxx,v 1.73 2006-01-09 00:42:12 stephena Exp $
//============================================================================ //============================================================================
#ifndef EVENTHANDLER_HXX #ifndef EVENTHANDLER_HXX
@ -94,12 +94,6 @@ enum JoyType {
JT_STELLADAPTOR_RIGHT JT_STELLADAPTOR_RIGHT
}; };
enum JoyAxisType {
JA_NONE,
JA_DIGITAL,
JA_ANALOG
};
struct Stella_Joystick { struct Stella_Joystick {
SDL_Joystick* stick; SDL_Joystick* stick;
JoyType type; JoyType type;
@ -128,7 +122,7 @@ struct JoyMouse {
mapping can take place. mapping can take place.
@author Stephen Anthony @author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.72 2006-01-08 02:28:03 stephena Exp $ @version $Id: EventHandler.hxx,v 1.73 2006-01-09 00:42:12 stephena Exp $
*/ */
class EventHandler class EventHandler
{ {
@ -465,9 +459,6 @@ class EventHandler
// Array of joystick axis events // Array of joystick axis events
Event::Type myJoyAxisTable[kNumJoysticks][kNumJoyAxis][2]; Event::Type myJoyAxisTable[kNumJoysticks][kNumJoyAxis][2];
// Array of joystick axis types (analog or digital)
JoyAxisType myJoyAxisType[kNumJoysticks][kNumJoyAxis];
// Array of messages for each Event // Array of messages for each Event
string ourMessageTable[Event::LastType]; string ourMessageTable[Event::LastType];