Started support for remapping joystick axis other than 0/1 to any event

in the emulator, including paddle events.  Analog and digital sticks will
be supported.  Currently, axis handling is completely broken.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@900 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-12-07 02:33:56 +00:00
parent b52198aeaa
commit 76a74c0577
6 changed files with 109 additions and 30 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.118 2005-11-21 13:47:34 stephena Exp $ // $Id: EventHandler.cxx,v 1.119 2005-12-07 02:33:56 stephena Exp $
//============================================================================ //============================================================================
#include <algorithm> #include <algorithm>
@ -75,7 +75,7 @@ EventHandler::EventHandler(OSystem* osystem)
myPaddleMode(0), myPaddleMode(0),
myMouseMove(3) myMouseMove(3)
{ {
uInt32 i; int i, j;
// Add this eventhandler object to the OSystem // Add this eventhandler object to the OSystem
myOSystem->attach(this); myOSystem->attach(this);
@ -83,17 +83,22 @@ EventHandler::EventHandler(OSystem* osystem)
// Create the event object which will be used for this handler // Create the event object which will be used for this handler
myEvent = new Event(); myEvent = new Event();
// Erase the KeyEvent arrays // Erase the key mapping array
for(i = 0; i < SDLK_LAST; ++i) for(i = 0; i < SDLK_LAST; ++i)
{ {
myKeyTable[i] = Event::NoType; myKeyTable[i] = Event::NoType;
ourSDLMapping[i] = ""; ourSDLMapping[i] = "";
} }
// Erase the JoyEvent array // Erase the joystick button mapping array
for(i = 0; i < kNumJoysticks * kNumJoyButtons; ++i) for(i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
myJoyTable[i] = Event::NoType; myJoyTable[i] = Event::NoType;
// Erase the joystick axis mapping array
for(i = 0; i < kNumJoysticks; ++i)
for(j = 0; j < kNumJoyAxis; ++j)
myJoyAxisTable[i][j][0] = myJoyAxisTable[i][j][1] = Event::NoType;
// Erase the Message array // Erase the Message array
for(i = 0; i < Event::LastType; ++i) for(i = 0; i < Event::LastType; ++i)
ourMessageTable[i] = ""; ourMessageTable[i] = "";
@ -657,20 +662,12 @@ void EventHandler::poll(uInt32 time)
// Handle emulation of mouse using the joystick // Handle emulation of mouse using the joystick
if(myState == S_EMULATE) if(myState == S_EMULATE)
handleJoyAxisEvent(stick, axis, value);
else if(myOverlay != NULL)
{ {
if(axis == 0) // x-axis
{
handleJoyEvent(stick, kJAxisLeft, (value < -16384) ? 1 : 0);
handleJoyEvent(stick, kJAxisRight, (value > 16384) ? 1 : 0);
}
else if(axis == 1) // y-axis
{
handleJoyEvent(stick, kJAxisUp, (value < -16384) ? 1 : 0);
handleJoyEvent(stick, kJAxisDown, (value > 16384) ? 1 : 0);
}
}
else
handleMouseWarp(stick, axis, value); handleMouseWarp(stick, axis, value);
myOverlay->handleJoyAxisEvent(stick, axis, value);
}
break; // Regular joystick axis break; // Regular joystick axis
} }
@ -987,6 +984,60 @@ void EventHandler::handleJoyEvent(uInt8 stick, uInt32 code, uInt8 state)
myOverlay->handleJoyEvent(stick, code, state); myOverlay->handleJoyEvent(stick, code, state);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleJoyAxisEvent(int stick, int axis, int value)
{
// Every axis event has two associated values, negative and positive
Event::Type eventAxisNeg = myJoyAxisTable[stick][axis][0];
Event::Type eventAxisPos = myJoyAxisTable[stick][axis][1];
// Determine if the events should be treated as discrete/digital
// or continuous/analog values
bool analog = false;
switch((int)eventAxisNeg)
{
case Event::PaddleZeroResistance:
case Event::PaddleOneResistance:
case Event::PaddleTwoResistance:
case Event::PaddleThreeResistance:
analog = true;
break;
}
switch((int)eventAxisPos)
{
case Event::PaddleZeroResistance:
case Event::PaddleOneResistance:
case Event::PaddleTwoResistance:
case Event::PaddleThreeResistance:
analog = true;
break;
}
// Analog vs. digital events treat the input values differently
// A value of zero might mean that an action should be turned off
// (this is the case for all events that are togglable).
// On the other hand, if the event represents a continuous analog
// value, then a zero is just another valid number in the range.
if(!analog)
{
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 if(value < 0)
handleEvent(eventAxisNeg, 1);
else
handleEvent(eventAxisPos, 1);
}
else
{
cerr << "do paddle event for " << value << endl;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleEvent(Event::Type event, Int32 state) void EventHandler::handleEvent(Event::Type event, Int32 state)
{ {
@ -1168,6 +1219,7 @@ void EventHandler::setActionMappings()
switch(button) switch(button)
{ {
/*
case kJAxisUp: case kJAxisUp:
joyevent << "J" << stick << " UP"; joyevent << "J" << stick << " UP";
break; break;
@ -1183,7 +1235,7 @@ void EventHandler::setActionMappings()
case kJAxisRight: case kJAxisRight:
joyevent << "J" << stick << " RIGHT"; joyevent << "J" << stick << " RIGHT";
break; break;
*/
default: default:
joyevent << "J" << stick << " B" << button; joyevent << "J" << stick << " B" << button;
break; break;
@ -1389,10 +1441,12 @@ void EventHandler::setDefaultJoymap()
// Left joystick // Left joystick
i = 0 * kNumJoyButtons; i = 0 * kNumJoyButtons;
/*
myJoyTable[i + kJAxisUp] = Event::JoystickZeroUp; myJoyTable[i + kJAxisUp] = Event::JoystickZeroUp;
myJoyTable[i + kJAxisDown] = Event::JoystickZeroDown; myJoyTable[i + kJAxisDown] = Event::JoystickZeroDown;
myJoyTable[i + kJAxisLeft] = Event::JoystickZeroLeft; myJoyTable[i + kJAxisLeft] = Event::JoystickZeroLeft;
myJoyTable[i + kJAxisRight] = Event::JoystickZeroRight; myJoyTable[i + kJAxisRight] = Event::JoystickZeroRight;
*/
myJoyTable[i + 0] = Event::JoystickZeroFire; myJoyTable[i + 0] = Event::JoystickZeroFire;
#ifdef PSP #ifdef PSP
@ -1414,10 +1468,12 @@ void EventHandler::setDefaultJoymap()
// Right joystick // Right joystick
i = 1 * kNumJoyButtons; i = 1 * kNumJoyButtons;
/*
myJoyTable[i + kJAxisUp] = Event::JoystickOneUp; myJoyTable[i + kJAxisUp] = Event::JoystickOneUp;
myJoyTable[i + kJAxisDown] = Event::JoystickOneDown; myJoyTable[i + kJAxisDown] = Event::JoystickOneDown;
myJoyTable[i + kJAxisLeft] = Event::JoystickOneLeft; myJoyTable[i + kJAxisLeft] = Event::JoystickOneLeft;
myJoyTable[i + kJAxisRight] = Event::JoystickOneRight; myJoyTable[i + kJAxisRight] = Event::JoystickOneRight;
*/
myJoyTable[i + 0] = Event::JoystickOneFire; myJoyTable[i + 0] = Event::JoystickOneFire;
saveJoyMapping(); saveJoyMapping();

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.58 2005-11-19 22:26:13 stephena Exp $ // $Id: EventHandler.hxx,v 1.59 2005-12-07 02:33:56 stephena Exp $
//============================================================================ //============================================================================
#ifndef EVENTHANDLER_HXX #ifndef EVENTHANDLER_HXX
@ -55,10 +55,7 @@ enum {
enum { enum {
kNumJoysticks = 8, kNumJoysticks = 8,
kNumJoyButtons = 24, kNumJoyButtons = 24,
kJAxisUp = kNumJoyButtons - 4, // Upper 4 buttons are actually kNumJoyAxis = 16
kJAxisDown = kNumJoyButtons - 3, // directions
kJAxisLeft = kNumJoyButtons - 2,
kJAxisRight = kNumJoyButtons - 1
}; };
enum JoyType { enum JoyType {
@ -87,7 +84,7 @@ struct Stella_Joystick {
mapping can take place. mapping can take place.
@author Stephen Anthony @author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.58 2005-11-19 22:26:13 stephena Exp $ @version $Id: EventHandler.hxx,v 1.59 2005-12-07 02:33:56 stephena Exp $
*/ */
class EventHandler class EventHandler
{ {
@ -296,6 +293,9 @@ class EventHandler
*/ */
void handleJoyEvent(uInt8 stick, uInt32 code, uInt8 state); void handleJoyEvent(uInt8 stick, uInt32 code, uInt8 state);
// FIXME - comment
void handleJoyAxisEvent(int stick, int axis, int value);
/** /**
Convert joystick motion events to simulated mouse motion events Convert joystick motion events to simulated mouse motion events
@ -356,9 +356,12 @@ class EventHandler
// Array of key events, indexed by SDLKey // Array of key events, indexed by SDLKey
Event::Type myKeyTable[SDLK_LAST]; Event::Type myKeyTable[SDLK_LAST];
// Array of joystick events // Array of joystick button events
Event::Type myJoyTable[kNumJoysticks * kNumJoyButtons]; Event::Type myJoyTable[kNumJoysticks * kNumJoyButtons];
// Array of joystick axis events
Event::Type myJoyAxisTable[kNumJoysticks][kNumJoyAxis][2];
// Array of messages for each Event // Array of messages for each Event
string ourMessageTable[Event::LastType]; string ourMessageTable[Event::LastType];

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: DialogContainer.cxx,v 1.18 2005-08-31 19:15:10 stephena Exp $ // $Id: DialogContainer.cxx,v 1.19 2005-12-07 02:33:56 stephena Exp $
//============================================================================ //============================================================================
#include "OSystem.hxx" #include "OSystem.hxx"
@ -253,3 +253,11 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
else else
activeDialog->handleJoyUp(stick, button); activeDialog->handleJoyUp(stick, button);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
{
cerr << "DialogContainer::handleJoyAxisEvent\n"
<< " stick = " << stick << ", axis = " << axis << ", value = " << value
<< endl;
}

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: DialogContainer.hxx,v 1.8 2005-08-11 19:12:39 stephena Exp $ // $Id: DialogContainer.hxx,v 1.9 2005-12-07 02:33:56 stephena Exp $
//============================================================================ //============================================================================
#ifndef DIALOG_CONTAINER_HXX #ifndef DIALOG_CONTAINER_HXX
@ -37,7 +37,7 @@ typedef FixedStack<Dialog *> DialogStack;
a stack, and handles their events. a stack, and handles their events.
@author Stephen Anthony @author Stephen Anthony
@version $Id: DialogContainer.hxx,v 1.8 2005-08-11 19:12:39 stephena Exp $ @version $Id: DialogContainer.hxx,v 1.9 2005-12-07 02:33:56 stephena Exp $
*/ */
class DialogContainer class DialogContainer
{ {
@ -99,6 +99,15 @@ class DialogContainer
*/ */
void handleJoyEvent(int stick, int button, uInt8 state); void handleJoyEvent(int stick, int button, uInt8 state);
/**
Handle a joystick axis event.
@param stick The joystick number
@param axis The joystick axis
@param value Value associated with given axis
*/
void handleJoyAxisEvent(int stick, int axis, int value);
/** /**
Draw the stack of menus. Draw the stack of menus.
*/ */

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: InputDialog.cxx,v 1.3 2005-11-19 22:26:14 stephena Exp $ // $Id: InputDialog.cxx,v 1.4 2005-12-07 02:33:56 stephena Exp $
//============================================================================ //============================================================================
#include "OSystem.hxx" #include "OSystem.hxx"
@ -181,6 +181,7 @@ void InputDialog::saveConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputDialog::handleKeyDown(int ascii, int keycode, int modifiers) void InputDialog::handleKeyDown(int ascii, int keycode, int modifiers)
{ {
cerr << "InputDialog::handleKeyDown: " << ascii << endl;
// Remap key events in remap mode, otherwise pass to listwidget // Remap key events in remap mode, otherwise pass to listwidget
if(myEventMapper->remapMode()) if(myEventMapper->remapMode())
myEventMapper->handleKeyDown(ascii, keycode, modifiers); myEventMapper->handleKeyDown(ascii, keycode, modifiers);
@ -191,6 +192,7 @@ void InputDialog::handleKeyDown(int ascii, int keycode, int modifiers)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputDialog::handleJoyDown(int stick, int button) void InputDialog::handleJoyDown(int stick, int button)
{ {
cerr << "InputDialog::handleJoyDown: stick = " << stick << ", button = " << button << endl;
// Remap joystick buttons in remap mode, otherwise pass to listwidget // Remap joystick buttons in remap mode, otherwise pass to listwidget
if(myEventMapper->remapMode()) if(myEventMapper->remapMode())
myEventMapper->handleJoyDown(stick, button); myEventMapper->handleJoyDown(stick, button);

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: Widget.hxx,v 1.39 2005-09-30 00:53:30 stephena Exp $ // $Id: Widget.hxx,v 1.40 2005-12-07 02:33:56 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -72,7 +72,7 @@ enum {
This is the base class for all widgets. This is the base class for all widgets.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Widget.hxx,v 1.39 2005-09-30 00:53:30 stephena Exp $ @version $Id: Widget.hxx,v 1.40 2005-12-07 02:33:56 stephena Exp $
*/ */
class Widget : public GuiObject class Widget : public GuiObject
{ {
@ -95,6 +95,7 @@ class Widget : public GuiObject
virtual bool handleKeyUp(int ascii, int keycode, int modifiers) { return false; } virtual bool handleKeyUp(int ascii, int keycode, int modifiers) { return false; }
virtual void handleJoyDown(int stick, int button) {} virtual void handleJoyDown(int stick, int button) {}
virtual void handleJoyUp(int stick, int button) {} virtual void handleJoyUp(int stick, int button) {}
virtual void handleJoyAxis(int stick, int axis, int value) {}
void draw(); void draw();
void receivedFocus(); void receivedFocus();