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
// 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>
@ -349,6 +349,9 @@ void EventHandler::poll(uInt32 time)
// while(myEventStreamer->pollEvent(type, value))
// myEvent->set((Event::Type)type, value);
// Synthesize events for platform-specific hardware
myOSystem->pollEvent();
// Check for an event
SDL_Event event;
while(SDL_PollEvent(&event))

View File

@ -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: 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>
@ -487,6 +487,11 @@ void OSystem::setDefaultJoyHatMap()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::pollEvent()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::OSystem(const OSystem& osystem)
{

View File

@ -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: 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
@ -44,7 +44,7 @@ class CheatManager;
other objects belong.
@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
{
@ -345,6 +345,11 @@ class OSystem
*/
virtual void setDefaultJoyHatMap();
/**
This method creates events from platform-specific hardware.
*/
virtual void pollEvent();
protected:
/**
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
// 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
//============================================================================
@ -76,8 +76,6 @@ OSystemGP2X::OSystemGP2X()
string cacheFile = basedir + "/stella.cache";
setCacheFile(cacheFile);
// No drivers are specified for Unix
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -92,69 +90,32 @@ void OSystemGP2X::mainLoop()
// and are needed to calculate the overall frames per second.
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
uInt32 startTime, delta;
// Exit if the user wants to quit
if(myEventHandler->doQuit())
break;
// Set the base for the timers
frameTime = 0;
startTime = getTicks();
myEventHandler->poll(startTime);
myFrameBuffer->update();
// Main game loop
for(;;)
{
// Exit if the user wants to quit
if(myEventHandler->doQuit())
break;
currentTime = getTicks();
virtualTime += myTimePerFrame;
if(currentTime < virtualTime)
SDL_Delay((virtualTime - currentTime)/1000);
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;
}
currentTime = getTicks() - startTime;
frameTime += currentTime;
++numberOfFrames;
}
// Only print console information if a console was actually created
@ -218,3 +179,10 @@ void OSystemGP2X::setDefaultJoymap()
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
// 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
//============================================================================
@ -45,19 +45,19 @@ class OSystemGP2X : public OSystem
may use different timing methods and/or algorithms, this method has
been abstracted to each platform.
*/
virtual void mainLoop();
void mainLoop();
/**
This method returns number of ticks in microseconds.
@return Current time in microseconds.
*/
virtual uInt32 getTicks();
uInt32 getTicks();
/**
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
@ -70,6 +70,11 @@ class OSystemGP2X : public OSystem
Stella events for for the PSP device.
*/
void setDefaultJoyAxisMap();
/**
This method creates events from platform-specific hardware.
*/
void pollEvent();
};
#endif

View File

@ -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: 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
//============================================================================
@ -28,7 +28,6 @@ SettingsGP2X::SettingsGP2X(OSystem* osystem)
{
// Some of these settings might be redundant, but are crucial for GP2X
set("center", "true");
set("accurate", "false");
set("volume", "50");
set("sound", "true");
set("zoom", "1");