mirror of https://github.com/stella-emu/stella.git
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:
parent
b52198aeaa
commit
76a74c0577
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// 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>
|
||||
|
@ -75,7 +75,7 @@ EventHandler::EventHandler(OSystem* osystem)
|
|||
myPaddleMode(0),
|
||||
myMouseMove(3)
|
||||
{
|
||||
uInt32 i;
|
||||
int i, j;
|
||||
|
||||
// Add this eventhandler object to the OSystem
|
||||
myOSystem->attach(this);
|
||||
|
@ -83,17 +83,22 @@ EventHandler::EventHandler(OSystem* osystem)
|
|||
// Create the event object which will be used for this handler
|
||||
myEvent = new Event();
|
||||
|
||||
// Erase the KeyEvent arrays
|
||||
// Erase the key mapping array
|
||||
for(i = 0; i < SDLK_LAST; ++i)
|
||||
{
|
||||
myKeyTable[i] = Event::NoType;
|
||||
ourSDLMapping[i] = "";
|
||||
}
|
||||
|
||||
// Erase the JoyEvent array
|
||||
// Erase the joystick button mapping array
|
||||
for(i = 0; i < kNumJoysticks * kNumJoyButtons; ++i)
|
||||
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
|
||||
for(i = 0; i < Event::LastType; ++i)
|
||||
ourMessageTable[i] = "";
|
||||
|
@ -657,20 +662,12 @@ void EventHandler::poll(uInt32 time)
|
|||
|
||||
// Handle emulation of mouse using the joystick
|
||||
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);
|
||||
myOverlay->handleJoyAxisEvent(stick, axis, value);
|
||||
}
|
||||
break; // Regular joystick axis
|
||||
}
|
||||
|
||||
|
@ -987,6 +984,60 @@ void EventHandler::handleJoyEvent(uInt8 stick, uInt32 code, uInt8 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)
|
||||
{
|
||||
|
@ -1168,6 +1219,7 @@ void EventHandler::setActionMappings()
|
|||
|
||||
switch(button)
|
||||
{
|
||||
/*
|
||||
case kJAxisUp:
|
||||
joyevent << "J" << stick << " UP";
|
||||
break;
|
||||
|
@ -1183,7 +1235,7 @@ void EventHandler::setActionMappings()
|
|||
case kJAxisRight:
|
||||
joyevent << "J" << stick << " RIGHT";
|
||||
break;
|
||||
|
||||
*/
|
||||
default:
|
||||
joyevent << "J" << stick << " B" << button;
|
||||
break;
|
||||
|
@ -1389,10 +1441,12 @@ void EventHandler::setDefaultJoymap()
|
|||
|
||||
// Left joystick
|
||||
i = 0 * kNumJoyButtons;
|
||||
/*
|
||||
myJoyTable[i + kJAxisUp] = Event::JoystickZeroUp;
|
||||
myJoyTable[i + kJAxisDown] = Event::JoystickZeroDown;
|
||||
myJoyTable[i + kJAxisLeft] = Event::JoystickZeroLeft;
|
||||
myJoyTable[i + kJAxisRight] = Event::JoystickZeroRight;
|
||||
*/
|
||||
myJoyTable[i + 0] = Event::JoystickZeroFire;
|
||||
|
||||
#ifdef PSP
|
||||
|
@ -1414,10 +1468,12 @@ void EventHandler::setDefaultJoymap()
|
|||
|
||||
// Right joystick
|
||||
i = 1 * kNumJoyButtons;
|
||||
/*
|
||||
myJoyTable[i + kJAxisUp] = Event::JoystickOneUp;
|
||||
myJoyTable[i + kJAxisDown] = Event::JoystickOneDown;
|
||||
myJoyTable[i + kJAxisLeft] = Event::JoystickOneLeft;
|
||||
myJoyTable[i + kJAxisRight] = Event::JoystickOneRight;
|
||||
*/
|
||||
myJoyTable[i + 0] = Event::JoystickOneFire;
|
||||
|
||||
saveJoyMapping();
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// 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
|
||||
|
@ -55,10 +55,7 @@ enum {
|
|||
enum {
|
||||
kNumJoysticks = 8,
|
||||
kNumJoyButtons = 24,
|
||||
kJAxisUp = kNumJoyButtons - 4, // Upper 4 buttons are actually
|
||||
kJAxisDown = kNumJoyButtons - 3, // directions
|
||||
kJAxisLeft = kNumJoyButtons - 2,
|
||||
kJAxisRight = kNumJoyButtons - 1
|
||||
kNumJoyAxis = 16
|
||||
};
|
||||
|
||||
enum JoyType {
|
||||
|
@ -87,7 +84,7 @@ struct Stella_Joystick {
|
|||
mapping can take place.
|
||||
|
||||
@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
|
||||
{
|
||||
|
@ -296,6 +293,9 @@ class EventHandler
|
|||
*/
|
||||
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
|
||||
|
||||
|
@ -356,9 +356,12 @@ class EventHandler
|
|||
// Array of key events, indexed by SDLKey
|
||||
Event::Type myKeyTable[SDLK_LAST];
|
||||
|
||||
// Array of joystick events
|
||||
// Array of joystick button events
|
||||
Event::Type myJoyTable[kNumJoysticks * kNumJoyButtons];
|
||||
|
||||
// Array of joystick axis events
|
||||
Event::Type myJoyAxisTable[kNumJoysticks][kNumJoyAxis][2];
|
||||
|
||||
// Array of messages for each Event
|
||||
string ourMessageTable[Event::LastType];
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// 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"
|
||||
|
@ -253,3 +253,11 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
|
|||
else
|
||||
activeDialog->handleJoyUp(stick, button);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value)
|
||||
{
|
||||
cerr << "DialogContainer::handleJoyAxisEvent\n"
|
||||
<< " stick = " << stick << ", axis = " << axis << ", value = " << value
|
||||
<< endl;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// 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
|
||||
|
@ -37,7 +37,7 @@ typedef FixedStack<Dialog *> DialogStack;
|
|||
a stack, and handles their events.
|
||||
|
||||
@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
|
||||
{
|
||||
|
@ -99,6 +99,15 @@ class DialogContainer
|
|||
*/
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// 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"
|
||||
|
@ -181,6 +181,7 @@ void InputDialog::saveConfig()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void InputDialog::handleKeyDown(int ascii, int keycode, int modifiers)
|
||||
{
|
||||
cerr << "InputDialog::handleKeyDown: " << ascii << endl;
|
||||
// Remap key events in remap mode, otherwise pass to listwidget
|
||||
if(myEventMapper->remapMode())
|
||||
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)
|
||||
{
|
||||
cerr << "InputDialog::handleJoyDown: stick = " << stick << ", button = " << button << endl;
|
||||
// Remap joystick buttons in remap mode, otherwise pass to listwidget
|
||||
if(myEventMapper->remapMode())
|
||||
myEventMapper->handleJoyDown(stick, button);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// 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
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -72,7 +72,7 @@ enum {
|
|||
This is the base class for all widgets.
|
||||
|
||||
@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
|
||||
{
|
||||
|
@ -95,6 +95,7 @@ class Widget : public GuiObject
|
|||
virtual bool handleKeyUp(int ascii, int keycode, int modifiers) { return false; }
|
||||
virtual void handleJoyDown(int stick, int button) {}
|
||||
virtual void handleJoyUp(int stick, int button) {}
|
||||
virtual void handleJoyAxis(int stick, int axis, int value) {}
|
||||
|
||||
void draw();
|
||||
void receivedFocus();
|
||||
|
|
Loading…
Reference in New Issue