mirror of https://github.com/stella-emu/stella.git
Added paddle threshold/non-jitter code to Stelladaptor paddle handling.
This code basically comes from z26, and is used to eliminate rapid left/right movements which result in visual jitter. Added 'pthresh' commandline option to set this threshold, which defaults to 600. I haven't decided if I should add a GUI option for this yet. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1069 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
11f3395f2d
commit
46a44d93e9
|
@ -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.158 2006-03-27 12:52:19 stephena Exp $
|
||||
// $Id: EventHandler.cxx,v 1.159 2006-03-27 21:06:44 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <sstream>
|
||||
|
@ -69,7 +69,8 @@ EventHandler::EventHandler(OSystem* osystem)
|
|||
myQuitFlag(false),
|
||||
myGrabMouseFlag(false),
|
||||
myUseLauncherFlag(false),
|
||||
myPaddleMode(0)
|
||||
myPaddleMode(0),
|
||||
myPaddleThreshold(0)
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
|
@ -133,6 +134,8 @@ EventHandler::EventHandler(OSystem* osystem)
|
|||
setPaddleMode(myOSystem->settings().getInt("paddle"), false);
|
||||
|
||||
myFryingFlag = false;
|
||||
|
||||
myPaddleThreshold = myOSystem->settings().getInt("pthresh");
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -757,6 +760,11 @@ void EventHandler::poll(uInt32 time)
|
|||
// Send axis events for the paddles
|
||||
case Controller::Paddles:
|
||||
{
|
||||
// Determine which paddle we're emulating and see if
|
||||
// we're getting rapid movement (aka jittering)
|
||||
if(isJitter(((type-2) << 1) + axis, value))
|
||||
break;
|
||||
|
||||
int resistance = (Int32) (1000000.0 * (32767 - value) / 65534);
|
||||
myEvent->set(SA_Axis[type-2][axis][2], resistance);
|
||||
break;
|
||||
|
@ -1849,6 +1857,25 @@ inline bool EventHandler::eventIsAnalog(Event::Type event)
|
|||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
inline bool EventHandler::isJitter(int paddle, int value)
|
||||
{
|
||||
bool jitter = false;
|
||||
bool leftMotion = myPaddle[paddle].joy_val - myPaddle[paddle].old_joy_val > 0;
|
||||
int distance = value - myPaddle[paddle].joy_val;
|
||||
|
||||
// Filter out jitter by not allowing rapid direction changes
|
||||
if(distance > 0 && !leftMotion) // movement switched from left to right
|
||||
jitter = distance < myPaddleThreshold;
|
||||
else if(distance < 0 && leftMotion) // movement switched from right to left
|
||||
jitter = distance > -myPaddleThreshold;
|
||||
|
||||
myPaddle[paddle].old_joy_val = myPaddle[paddle].joy_val;
|
||||
myPaddle[paddle].joy_val = value;
|
||||
|
||||
return jitter;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::saveState()
|
||||
{
|
||||
|
|
|
@ -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.83 2006-03-25 00:34:17 stephena Exp $
|
||||
// $Id: EventHandler.hxx,v 1.84 2006-03-27 21:06:44 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef EVENTHANDLER_HXX
|
||||
|
@ -91,9 +91,9 @@ struct JoyMouse {
|
|||
int x, y, x_vel, y_vel, x_max, y_max, x_amt, y_amt, amt,
|
||||
x_down_count, y_down_count;
|
||||
unsigned int last_time, delay_time, x_down_time, y_down_time;
|
||||
int joy_val, old_joy_val;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This class takes care of event remapping and dispatching for the
|
||||
Stella core, as well as keeping track of the current 'mode'.
|
||||
|
@ -107,7 +107,7 @@ struct JoyMouse {
|
|||
mapping can take place.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: EventHandler.hxx,v 1.83 2006-03-25 00:34:17 stephena Exp $
|
||||
@version $Id: EventHandler.hxx,v 1.84 2006-03-27 21:06:44 stephena Exp $
|
||||
*/
|
||||
class EventHandler
|
||||
{
|
||||
|
@ -458,6 +458,16 @@ class EventHandler
|
|||
*/
|
||||
inline bool eventIsAnalog(Event::Type event);
|
||||
|
||||
/**
|
||||
Tests if the given paddle value is displaying a rapid left/right
|
||||
motion, which is also known as jitter.
|
||||
|
||||
@param paddle The paddle to test
|
||||
@param value The value assigned to the paddle
|
||||
@return True if jittering, else false
|
||||
*/
|
||||
inline bool isJitter(int paddle, int value);
|
||||
|
||||
void saveState();
|
||||
void changeState();
|
||||
void loadState();
|
||||
|
@ -525,6 +535,9 @@ class EventHandler
|
|||
// Indicates which paddle the mouse currently emulates
|
||||
Int8 myPaddleMode;
|
||||
|
||||
// Indicates the amount by which we consider a paddle to be jittering
|
||||
int myPaddleThreshold;
|
||||
|
||||
// Used for paddle emulation by keyboard or joystick
|
||||
JoyMouse myPaddle[4];
|
||||
|
||||
|
|
|
@ -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: Settings.cxx,v 1.82 2006-03-19 00:46:04 stephena Exp $
|
||||
// $Id: Settings.cxx,v 1.83 2006-03-27 21:06:44 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <cassert>
|
||||
|
@ -68,6 +68,7 @@ Settings::Settings(OSystem* osystem)
|
|||
setInternal("p2speed", "50");
|
||||
setInternal("p3speed", "50");
|
||||
setInternal("p4speed", "50");
|
||||
setInternal("pthresh", "600");
|
||||
|
||||
setInternal("showinfo", "false");
|
||||
|
||||
|
@ -314,6 +315,7 @@ void Settings::usage()
|
|||
<< " -p2speed <number> Speed of emulated mouse movement for paddle 2 (0-100)\n"
|
||||
<< " -p3speed <number> Speed of emulated mouse movement for paddle 3 (0-100)\n"
|
||||
<< " -p4speed <number> Speed of emulated mouse movement for paddle 4 (0-100)\n"
|
||||
<< " -pthresh <number> Set threshold for eliminating paddle jitter\n"
|
||||
<< " -tiadefaults <1|0> Use TIA positioning defaults instead of enhanced values\n"
|
||||
#ifdef UNIX
|
||||
<< " -accurate <1|0> Accurate game timing (uses more CPU)\n"
|
||||
|
|
Loading…
Reference in New Issue