First pass at infrastructure for polling platform-specific hardware.

This is needed particularly for the GP2X joystick direction handling,
where directions are (incorrectly) implemented as button events
instead of more intuitive HAT events.  When this is complete, it will
also remove the EventHandler 'kJDirXXX' enums, which I always thought
was dirty code anyway.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@991 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-01-30 01:01:44 +00:00
parent 31c0d39ecf
commit 801f4a1bf9
6 changed files with 57 additions and 72 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.149 2006-01-25 01:42:46 stephena Exp $ // $Id: EventHandler.cxx,v 1.150 2006-01-30 01:01:44 stephena Exp $
//============================================================================ //============================================================================
#include <sstream> #include <sstream>
@ -349,6 +349,9 @@ void EventHandler::poll(uInt32 time)
// while(myEventStreamer->pollEvent(type, value)) // while(myEventStreamer->pollEvent(type, value))
// myEvent->set((Event::Type)type, value); // myEvent->set((Event::Type)type, value);
// Synthesize events for platform-specific hardware
myOSystem->pollEvent();
// Check for an event // Check for an event
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&event)) while(SDL_PollEvent(&event))

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.58 2006-01-19 00:45:12 stephena Exp $ // $Id: OSystem.cxx,v 1.59 2006-01-30 01:01:44 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -487,6 +487,11 @@ void OSystem::setDefaultJoyHatMap()
{ {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::pollEvent()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::OSystem(const OSystem& osystem) OSystem::OSystem(const OSystem& osystem)
{ {

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.hxx,v 1.36 2006-01-09 16:50:01 stephena Exp $ // $Id: OSystem.hxx,v 1.37 2006-01-30 01:01:44 stephena Exp $
//============================================================================ //============================================================================
#ifndef OSYSTEM_HXX #ifndef OSYSTEM_HXX
@ -44,7 +44,7 @@ class CheatManager;
other objects belong. other objects belong.
@author Stephen Anthony @author Stephen Anthony
@version $Id: OSystem.hxx,v 1.36 2006-01-09 16:50:01 stephena Exp $ @version $Id: OSystem.hxx,v 1.37 2006-01-30 01:01:44 stephena Exp $
*/ */
class OSystem class OSystem
{ {
@ -345,6 +345,11 @@ class OSystem
*/ */
virtual void setDefaultJoyHatMap(); virtual void setDefaultJoyHatMap();
/**
This method creates events from platform-specific hardware.
*/
virtual void pollEvent();
protected: protected:
/** /**
Set the base directory for all Stella files Set the base directory for all Stella files

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: OSystemGP2X.cxx,v 1.1 2006-01-08 02:28:03 stephena Exp $ // $Id: OSystemGP2X.cxx,v 1.2 2006-01-30 01:01:44 stephena Exp $
// Modified on 2006/01/06 by Alex Zaballa for use on GP2X // Modified on 2006/01/06 by Alex Zaballa for use on GP2X
//============================================================================ //============================================================================
@ -76,8 +76,6 @@ OSystemGP2X::OSystemGP2X()
string cacheFile = basedir + "/stella.cache"; string cacheFile = basedir + "/stella.cache";
setCacheFile(cacheFile); setCacheFile(cacheFile);
// No drivers are specified for Unix
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -92,40 +90,6 @@ void OSystemGP2X::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 accurate timing stuff
uInt32 startTime, delta;
// Set the base for the timers
frameTime = 0;
// Main game loop
for(;;)
{
// 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 // Set up less accurate timing stuff
uInt32 startTime, virtualTime, currentTime; uInt32 startTime, virtualTime, currentTime;
@ -147,15 +111,12 @@ void OSystemGP2X::mainLoop()
currentTime = getTicks(); currentTime = getTicks();
virtualTime += myTimePerFrame; virtualTime += myTimePerFrame;
if(currentTime < virtualTime) if(currentTime < virtualTime)
{
SDL_Delay((virtualTime - currentTime)/1000); SDL_Delay((virtualTime - currentTime)/1000);
}
currentTime = getTicks() - startTime; currentTime = getTicks() - startTime;
frameTime += currentTime; frameTime += currentTime;
++numberOfFrames; ++numberOfFrames;
} }
}
// Only print console information if a console was actually created // Only print console information if a console was actually created
if(mySettings->getBool("showinfo") && myConsole) if(mySettings->getBool("showinfo") && myConsole)
@ -218,3 +179,10 @@ void OSystemGP2X::setDefaultJoymap()
void OSystemGP2X::setDefaultJoyAxisMap() void OSystemGP2X::setDefaultJoyAxisMap()
{ {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystemGP2X::pollEvent()
{
// TODO - add code to translate joystick directions into proper SDL HAT
// events, so that the core code will 'just work'
}

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: OSystemGP2X.hxx,v 1.1 2006-01-08 02:28:03 stephena Exp $ // $Id: OSystemGP2X.hxx,v 1.2 2006-01-30 01:01:44 stephena Exp $
// Modified by Alex Zaballa on 2006/01/04 for use on GP2X // Modified by Alex Zaballa on 2006/01/04 for use on GP2X
//============================================================================ //============================================================================
@ -45,19 +45,19 @@ class OSystemGP2X : public OSystem
may use different timing methods and/or algorithms, this method has may use different timing methods and/or algorithms, this method has
been abstracted to each platform. been abstracted to each platform.
*/ */
virtual void mainLoop(); void mainLoop();
/** /**
This method returns number of ticks in microseconds. This method returns number of ticks in microseconds.
@return Current time in microseconds. @return Current time in microseconds.
*/ */
virtual uInt32 getTicks(); uInt32 getTicks();
/** /**
This method queries the dimensions of the screen for this hardware. This method queries the dimensions of the screen for this hardware.
*/ */
virtual void getScreenDimensions(int& width, int& height); void getScreenDimensions(int& width, int& height);
/** /**
This method determines the default mapping of joystick buttons to This method determines the default mapping of joystick buttons to
@ -70,6 +70,11 @@ class OSystemGP2X : public OSystem
Stella events for for the PSP device. Stella events for for the PSP device.
*/ */
void setDefaultJoyAxisMap(); void setDefaultJoyAxisMap();
/**
This method creates events from platform-specific hardware.
*/
void pollEvent();
}; };
#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: SettingsGP2X.cxx,v 1.3 2006-01-25 01:42:47 stephena Exp $ // $Id: SettingsGP2X.cxx,v 1.4 2006-01-30 01:01:44 stephena Exp $
// Modified on 2006/01/04 by Alex Zaballa for use on GP2X // Modified on 2006/01/04 by Alex Zaballa for use on GP2X
//============================================================================ //============================================================================
@ -28,7 +28,6 @@ SettingsGP2X::SettingsGP2X(OSystem* osystem)
{ {
// Some of these settings might be redundant, but are crucial for GP2X // Some of these settings might be redundant, but are crucial for GP2X
set("center", "true"); set("center", "true");
set("accurate", "false");
set("volume", "50"); set("volume", "50");
set("sound", "true"); set("sound", "true");
set("zoom", "1"); set("zoom", "1");