Added joystick to mouse movement emulation. Currently it moves the

cursor much slower than a real mouse, since directional pads/joysticks
tend to be not as precise as a real mouse.

Still TODO is have joystick buttons create mouse button events.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@750 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-08-30 01:10:54 +00:00
parent f4590830d4
commit 1cf03b53ed
6 changed files with 218 additions and 121 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.89 2005-08-29 18:36:41 stephena Exp $ // $Id: EventHandler.cxx,v 1.90 2005-08-30 01:10:54 stephena Exp $
//============================================================================ //============================================================================
#include <algorithm> #include <algorithm>
@ -48,21 +48,19 @@ void handleMacOSXKeypress(int key);
} }
#endif #endif
#define JOY_DEADZONE 3200
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::EventHandler(OSystem* osystem) EventHandler::EventHandler(OSystem* osystem)
: myOSystem(osystem), : myOSystem(osystem),
myState(S_NONE), myState(S_NONE),
myLSState(0), myLSState(0),
myPauseFlag(false), myPauseFlag(false),
myQuitFlag(false), myQuitFlag(false),
myGrabMouseFlag(false), myGrabMouseFlag(false),
myUseLauncherFlag(false), myUseLauncherFlag(false),
myPaddleMode(0), myPaddleMode(0),
myMouseX(0), myMouseMove(3)
myMouseY(0),
myLastMouseMoveX(0),
myLastMouseMoveY(0)
{ {
// Add this eventhandler object to the OSystem // Add this eventhandler object to the OSystem
myOSystem->attach(this); myOSystem->attach(this);
@ -103,6 +101,9 @@ EventHandler::EventHandler(OSystem* osystem)
myGrabMouseFlag = myOSystem->settings().getBool("grabmouse"); myGrabMouseFlag = myOSystem->settings().getBool("grabmouse");
myFryingFlag = false; myFryingFlag = false;
memset(&myJoyMouse, 0, sizeof(myJoyMouse));
myJoyMouse.delay_time = 25;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -156,6 +157,11 @@ void EventHandler::reset(State state)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::refreshDisplay() void EventHandler::refreshDisplay()
{ {
// These are reset each time the display changes size
myJoyMouse.x_max = myOSystem->frameBuffer().imageWidth();
myJoyMouse.y_max = myOSystem->frameBuffer().imageHeight();
myMouseMove = myOSystem->frameBuffer().zoomLevel() * 3;
switch(myState) switch(myState)
{ {
case S_EMULATE: case S_EMULATE:
@ -269,6 +275,9 @@ void EventHandler::poll(uInt32 time)
{ {
SDL_Event event; SDL_Event event;
// Handle joystick to mouse emulation
handleJoyMouse(time);
// Check for an event // Check for an event
while(SDL_PollEvent(&event)) while(SDL_PollEvent(&event))
{ {
@ -474,7 +483,6 @@ void EventHandler::poll(uInt32 time)
break; // SDL_KEYUP, SDL_KEYDOWN break; // SDL_KEYUP, SDL_KEYDOWN
} }
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
handleMouseMotionEvent(event); handleMouseMotionEvent(event);
break; // SDL_MOUSEMOTION break; // SDL_MOUSEMOTION
@ -506,7 +514,7 @@ void EventHandler::poll(uInt32 time)
// Read joystick events and modify event states // Read joystick events and modify event states
uInt8 stick; uInt8 stick;
uInt32 code; uInt32 code;
uInt8 state; uInt8 state = 0;
Uint8 axis; Uint8 axis;
Uint8 button; Uint8 button;
Int32 resistance; Int32 resistance;
@ -536,19 +544,19 @@ void EventHandler::poll(uInt32 time)
code = event.jbutton.button; code = event.jbutton.button;
state = event.jbutton.state == SDL_PRESSED ? 1 : 0; state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
#ifdef PSP //#ifdef PSP
handleWarpMouseButton(code,state); handleWarpMouseButton(code,state);
#endif //#endif
handleJoyEvent(stick, code, state); handleJoyEvent(stick, code, state);
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
axis = event.jaxis.axis; axis = event.jaxis.axis;
value = event.jaxis.value; value = event.jaxis.value;
#ifdef PSP //#ifdef PSP
if (state!=S_EMULATE) // if(state != S_EMULATE)
handleMouseWarp(stick,axis,value); handleMouseWarp(stick, axis, value);
#endif //#endif
if(axis == 0) // x-axis if(axis == 0) // x-axis
{ {
handleJoyEvent(stick, kJAxisLeft, (value < -16384) ? 1 : 0); handleJoyEvent(stick, kJAxisLeft, (value < -16384) ? 1 : 0);
@ -735,6 +743,9 @@ void EventHandler::handleMouseMotionEvent(SDL_Event& event)
{ {
// Take window zooming into account // Take window zooming into account
int x = event.motion.x, y = event.motion.y; int x = event.motion.x, y = event.motion.y;
myJoyMouse.x = x;
myJoyMouse.y = y;
myOSystem->frameBuffer().translateCoords(&x, &y); myOSystem->frameBuffer().translateCoords(&x, &y);
// Determine which mode we're in, then send the event to the appropriate place // Determine which mode we're in, then send the event to the appropriate place
@ -840,10 +851,101 @@ void EventHandler::handleMouseButtonEvent(SDL_Event& event, uInt8 state)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleJoyMouse(uInt32 time)
{
bool mouseAccel = false; // FIXME - make this a commandline option
if (time >= myJoyMouse.last_time + myJoyMouse.delay_time)
{
myJoyMouse.last_time = time;
if (myJoyMouse.x_down_count == 1)
{
myJoyMouse.x_down_time = time;
myJoyMouse.x_down_count = 2;
}
if (myJoyMouse.y_down_count == 1)
{
myJoyMouse.y_down_time = time;
myJoyMouse.y_down_count = 2;
}
if (myJoyMouse.x_vel || myJoyMouse.y_vel)
{
if (myJoyMouse.x_down_count)
{
if (mouseAccel && time > myJoyMouse.x_down_time + myJoyMouse.delay_time * 12)
{
if (myJoyMouse.x_vel > 0)
myJoyMouse.x_vel++;
else
myJoyMouse.x_vel--;
}
else if (time > myJoyMouse.x_down_time + myJoyMouse.delay_time * 8)
{
if (myJoyMouse.x_vel > 0)
myJoyMouse.x_vel = myMouseMove;
else
myJoyMouse.x_vel = -myMouseMove;
}
}
if (myJoyMouse.y_down_count)
{
if (mouseAccel && time > myJoyMouse.y_down_time + myJoyMouse.delay_time * 12)
{
if (myJoyMouse.y_vel > 0)
myJoyMouse.y_vel++;
else
myJoyMouse.y_vel--;
}
else if (time > myJoyMouse.y_down_time + myJoyMouse.delay_time * 8)
{
if (myJoyMouse.y_vel > 0)
myJoyMouse.y_vel = myMouseMove;
else
myJoyMouse.y_vel = -myMouseMove;
}
}
myJoyMouse.x += myJoyMouse.x_vel;
myJoyMouse.y += myJoyMouse.y_vel;
if (myJoyMouse.x < 0)
{
myJoyMouse.x = 0;
myJoyMouse.x_vel = -1;
myJoyMouse.x_down_count = 1;
}
else if (myJoyMouse.x > myJoyMouse.x_max)
{
myJoyMouse.x = myJoyMouse.x_max;
myJoyMouse.x_vel = 1;
myJoyMouse.x_down_count = 1;
}
if (myJoyMouse.y < 0)
{
myJoyMouse.y = 0;
myJoyMouse.y_vel = -1;
myJoyMouse.y_down_count = 1;
}
else if (myJoyMouse.y > myJoyMouse.y_max)
{
myJoyMouse.y = myJoyMouse.y_max;
myJoyMouse.y_vel = 1;
myJoyMouse.y_down_count = 1;
}
SDL_WarpMouse(myJoyMouse.x, myJoyMouse.y);
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleWarpMouseButton(uInt8 event_button, uInt8 state) void EventHandler::handleWarpMouseButton(uInt8 event_button, uInt8 state)
{ {
#ifdef PSP // FIXME - this will disappear, and be integrated directly into handleJoyEvent()
#if 0
// Determine which mode we're in, then send the event to the appropriate place // Determine which mode we're in, then send the event to the appropriate place
switch(myState) switch(myState)
{ {
@ -936,29 +1038,43 @@ void EventHandler::handleWarpMouseButton(uInt8 event_button, uInt8 state)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::handleMouseWarp(uInt8 stick,uInt8 axis,Int16 value) void EventHandler::handleMouseWarp(uInt8 stick, uInt8 axis, Int16 value)
{ {
#ifdef PSP if(value > JOY_DEADZONE)
Int32 new_x = myMouseX; value -= JOY_DEADZONE;
Int32 new_y = myMouseY; else if(value < -JOY_DEADZONE )
value = value / 4000; value += JOY_DEADZONE;
if (axis == 0) else
{ value = 0;
myLastMouseMoveX = value;
}
else if (axis == 1)
{
myLastMouseMoveY = value;
}
new_x += myLastMouseMoveX;
new_y += myLastMouseMoveY;
if (new_x >=0 and new_x <= PSP_SCREEN_WIDTH) if(axis == 0) // X axis
myMouseX = new_x; {
if (new_y >=0 and new_y <= PSP_SCREEN_HEIGHT) if (value != 0)
myMouseY = new_y; {
SDL_WarpMouse(myMouseX,myMouseY); myJoyMouse.x_vel = (value > 0) ? 1 : -1;
#endif myJoyMouse.x_down_count = 1;
}
else
{
myJoyMouse.x_vel = 0;
myJoyMouse.x_down_count = 0;
}
}
else if(axis == 1) // Y axis
{
value = -value;
if (value != 0)
{
myJoyMouse.y_vel = (-value > 0) ? 1 : -1;
myJoyMouse.y_down_count = 1;
}
else
{
myJoyMouse.y_vel = 0;
myJoyMouse.y_down_count = 0;
}
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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.47 2005-08-29 18:36:41 stephena Exp $ // $Id: EventHandler.hxx,v 1.48 2005-08-30 01:10:54 stephena Exp $
//============================================================================ //============================================================================
#ifndef EVENTHANDLER_HXX #ifndef EVENTHANDLER_HXX
@ -74,7 +74,7 @@ struct Stella_Joystick {
mapping can take place. mapping can take place.
@author Stephen Anthony @author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.47 2005-08-29 18:36:41 stephena Exp $ @version $Id: EventHandler.hxx,v 1.48 2005-08-30 01:10:54 stephena Exp $
*/ */
class EventHandler class EventHandler
{ {
@ -284,6 +284,13 @@ class EventHandler
void handleMouseWarp(uInt8 stick, uInt8 axis, Int16 value); void handleMouseWarp(uInt8 stick, uInt8 axis, Int16 value);
void handleWarpMouseButton(uInt8 event_button, uInt8 state); void handleWarpMouseButton(uInt8 event_button, uInt8 state);
/**
Handle joystick movement emulating mouse motion
@param time Current millisecond count
*/
void handleJoyMouse(uInt32 time);
/** /**
The following methods take care of assigning action mappings. The following methods take care of assigning action mappings.
*/ */
@ -355,10 +362,16 @@ class EventHandler
// The current joymap in string form // The current joymap in string form
string myJoymapString; string myJoymapString;
Int32 myMouseX; // Used for joystick to mouse emulation
Int32 myMouseY; struct JoyMouse {
Int32 myLastMouseMoveX; int x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
Int32 myLastMouseMoveY; unsigned int last_time, delay_time, x_down_time, y_down_time;
};
JoyMouse myJoyMouse;
// How far the joystick will move the mouse on each frame tick
int myMouseMove;
}; };
#endif #endif

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: FrameBuffer.hxx,v 1.55 2005-08-29 18:36:41 stephena Exp $ // $Id: FrameBuffer.hxx,v 1.56 2005-08-30 01:10:54 stephena Exp $
//============================================================================ //============================================================================
#ifndef FRAMEBUFFER_HXX #ifndef FRAMEBUFFER_HXX
@ -52,7 +52,7 @@ enum FrameStyle {
All GUI elements (ala ScummVM) are drawn here as well. All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony @author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.55 2005-08-29 18:36:41 stephena Exp $ @version $Id: FrameBuffer.hxx,v 1.56 2005-08-30 01:10:54 stephena Exp $
*/ */
class FrameBuffer class FrameBuffer
{ {
@ -196,6 +196,11 @@ class FrameBuffer
*/ */
uInt32 maxWindowSizeForScreen(); uInt32 maxWindowSizeForScreen();
/**
Returns current zoomlevel of the framebuffer.
*/
uInt32 zoomLevel() { return theZoomLevel; }
/** /**
Set the title for the main SDL window. Set the title for the main SDL window.
*/ */

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: OSystem.cxx,v 1.34 2005-08-29 18:36:41 stephena Exp $ // $Id: OSystem.cxx,v 1.35 2005-08-30 01:10:54 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -348,7 +348,7 @@ bool OSystem::createConsole(const string& romfile)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::createLauncher() void OSystem::createLauncher()
{ {
setFramerate(20); // We don't need a large framerate for the launcher setFramerate(60);
myEventHandler->reset(EventHandler::S_LAUNCHER); myEventHandler->reset(EventHandler::S_LAUNCHER);
// Create the window // Create the window

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: LauncherDialog.cxx,v 1.29 2005-08-22 18:17:10 stephena Exp $ // $Id: LauncherDialog.cxx,v 1.30 2005-08-30 01:10:54 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
@ -53,9 +53,7 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
myProgressBar(NULL) myProgressBar(NULL)
{ {
const GUI::Font& font = instance()->font(); const GUI::Font& font = instance()->font();
const int fontWidth = font.getMaxCharWidth(), const int fontHeight = font.getFontHeight();
fontHeight = font.getFontHeight(),
lineHeight = font.getLineHeight();
// Show game name // Show game name
new StaticTextWidget(this, 10, 8, 200, fontHeight, new StaticTextWidget(this, 10, 8, 200, fontHeight,

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: OSystemPSP.cxx,v 1.1 2005-08-25 15:19:17 stephena Exp $ // $Id: OSystemPSP.cxx,v 1.2 2005-08-30 01:10:54 stephena Exp $
//============================================================================ //============================================================================
#include <cstdlib> #include <cstdlib>
@ -24,6 +24,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <pspkernel.h>
#include <psppower.h>
#include "bspf.hxx" #include "bspf.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "OSystemPSP.hxx" #include "OSystemPSP.hxx"
@ -72,7 +75,8 @@ OSystemPSP::OSystemPSP()
string cacheFile = basedir + "/stella.cache"; string cacheFile = basedir + "/stella.cache";
setCacheFile(cacheFile); setCacheFile(cacheFile);
// No drivers are specified for Unix // Overclock CPU to 333MHz
scePowerSetClockFrequency(333,333,166);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -87,71 +91,32 @@ void OSystemPSP::mainLoop()
// and are needed to calculate the overall frames per second. // and are needed to calculate the overall frames per second.
uInt32 frameTime = 0, numberOfFrames = 0; uInt32 frameTime = 0, numberOfFrames = 0;
if(mySettings->getBool("accurate")) // normal, CPU-intensive timing // Set up less accurate timing stuff
uInt32 startTime, virtualTime, currentTime;
// Set the base for the timers
virtualTime = getTicks();
frameTime = 0;
// Main game loop
for(;;)
{ {
// Set up accurate timing stuff // Exit if the user wants to quit
uInt32 startTime, delta; if(myEventHandler->doQuit())
break;
// Set the base for the timers startTime = getTicks();
frameTime = 0; myEventHandler->poll(startTime);
myFrameBuffer->update();
currentTime = getTicks();
virtualTime += myTimePerFrame;
if(currentTime < virtualTime)
SDL_Delay((virtualTime - currentTime)/1000);
// Main game loop currentTime = getTicks() - startTime;
for(;;) frameTime += currentTime;
{ ++numberOfFrames;
// Exit if the user wants to quit
if(myEventHandler->doQuit()){
break;
}
startTime = getTicks();
myEventHandler->poll(startTime);
myFrameBuffer->update();
// Now, waste time if we need to so that we are at the desired frame rate
for(;;)
{
delta = getTicks() - startTime;
if(delta >= myTimePerFrame)
break;
}
frameTime += getTicks() - startTime;
++numberOfFrames;
}
} }
else // less accurate, less CPU-intensive timing
{
// Set up less accurate timing stuff
uInt32 startTime, virtualTime, currentTime;
// Set the base for the timers
virtualTime = getTicks();
frameTime = 0;
// Main game loop
for(;;)
{
// Exit if the user wants to quit
if(myEventHandler->doQuit()){
break;
}
startTime = getTicks();
myEventHandler->poll(startTime);
myFrameBuffer->update();
currentTime = getTicks();
virtualTime += myTimePerFrame;
if(currentTime < virtualTime)
{
SDL_Delay((virtualTime - currentTime)/1000);
}
currentTime = getTicks() - startTime;
frameTime += currentTime;
++numberOfFrames;
}
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -