2009-05-26 14:17:05 +00:00
/* Residual - A 3D game interpreter
2008-06-13 14:57:47 +00:00
*
* Residual is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the AUTHORS
* file distributed with this source distribution .
2006-04-02 14:20:45 +00:00
*
2009-10-04 14:40:09 +00:00
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
2006-04-02 14:20:45 +00:00
2009-10-04 14:40:09 +00:00
* This program is distributed in the hope that it will be useful ,
2006-04-02 14:20:45 +00:00
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2009-10-04 14:40:09 +00:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2006-04-02 14:20:45 +00:00
2009-10-04 14:40:09 +00:00
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2006-04-02 14:20:45 +00:00
*
* $ URL $
* $ Id $
*
*/
2006-02-05 17:19:44 +00:00
2009-10-04 16:33:49 +00:00
# ifndef SDL_COMMON_H
# define SDL_COMMON_H
2006-02-05 17:19:44 +00:00
2009-10-04 16:33:49 +00:00
# if defined(__SYMBIAN32__)
# include <esdl\SDL.h>
# else
2006-02-05 17:19:44 +00:00
# include <SDL.h>
2009-05-07 19:06:31 +00:00
# ifdef USE_OPENGL
# include <SDL_opengl.h>
# endif
2009-10-04 16:33:49 +00:00
# endif
# include "backends/base-backend.h"
# include "graphics/scaler.h"
2006-02-05 17:19:44 +00:00
2009-05-07 23:09:25 +00:00
2008-07-03 12:04:12 +00:00
namespace Audio {
class MixerImpl ;
}
2009-05-07 23:06:06 +00:00
# if defined(MACOSX)
2009-10-04 16:33:49 +00:00
// On Mac OS X, we need to double buffer the audio buffer, else anything
// which produces sampled data with high latency (like the MT-32 emulator)
// will sound terribly.
// This could be enabled for more / most ports in the future, but needs some
// testing.
2009-05-07 23:06:06 +00:00
# define MIXER_DOUBLE_BUFFERING 1
# endif
2009-05-07 19:06:31 +00:00
class OSystem_SDL : public BaseBackend {
2006-02-05 17:19:44 +00:00
public :
2009-05-07 19:06:31 +00:00
OSystem_SDL ( ) ;
virtual ~ OSystem_SDL ( ) ;
2008-07-03 12:04:12 +00:00
2009-05-07 19:06:31 +00:00
virtual void initBackend ( ) ;
2008-07-03 13:49:47 +00:00
2009-10-04 10:58:28 +00:00
// Set the size of the video bitmap.
2009-10-04 16:33:49 +00:00
// Typically, 320x200
2009-10-04 10:58:28 +00:00
virtual void launcherInitSize ( uint w , uint h ) ;
2009-05-07 19:06:31 +00:00
virtual byte * setupScreen ( int screenW , int screenH , bool fullscreen , bool accel3d ) ;
2006-02-05 17:19:44 +00:00
2009-05-07 19:06:31 +00:00
// Update the dirty areas of the screen
void updateScreen ( ) ;
2009-06-18 11:52:26 +00:00
// Either show or hide the mouse cursor
bool showMouse ( bool visible ) ;
2009-05-07 19:06:31 +00:00
// Warp the mouse cursor. Where set_mouse_pos() only informs the
// backend of the mouse cursor's current position, this function
// actually moves the cursor to the specified position.
2009-10-04 16:33:49 +00:00
virtual void warpMouse ( int x , int y ) ; // overloaded by CE backend (FIXME)
2009-05-07 19:06:31 +00:00
2009-10-04 10:58:28 +00:00
// Set the bitmap that's used when drawing the cursor.
2009-10-05 08:33:46 +00:00
virtual void setMouseCursor ( const byte * buf , uint w , uint h , int hotspot_x , int hotspot_y , uint32 keycolor , int cursorTargetScale , const Graphics : : PixelFormat * format ) ; // overloaded by CE backend (FIXME)
2009-10-04 10:58:28 +00:00
2009-05-07 19:06:31 +00:00
// Get the number of milliseconds since the program was started.
2006-02-05 17:19:44 +00:00
uint32 getMillis ( ) ;
2009-05-07 19:06:31 +00:00
// Delay for a specified amount of milliseconds
2006-02-05 17:19:44 +00:00
void delayMillis ( uint msecs ) ;
2009-05-07 19:06:31 +00:00
// Get the next event.
// Returns true if an event was retrieved.
2009-10-04 16:33:49 +00:00
virtual bool pollEvent ( Common : : Event & event ) ; // overloaded by CE backend
2006-02-05 17:48:19 +00:00
2010-01-21 19:25:03 +00:00
protected :
virtual bool dispatchSDLEvent ( SDL_Event & ev , Common : : Event & event ) ;
// Handlers for specific SDL events, called by pollEvent.
// This way, if a backend inherits fromt the SDL backend, it can
// change the behavior of only a single event, without having to override all
// of pollEvent.
virtual bool handleKeyDown ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleKeyUp ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleMouseMotion ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleMouseButtonDown ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleMouseButtonUp ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleJoyButtonDown ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleJoyButtonUp ( SDL_Event & ev , Common : : Event & event ) ;
virtual bool handleJoyAxisMotion ( SDL_Event & ev , Common : : Event & event ) ;
public :
2009-10-04 14:11:35 +00:00
// Define all hardware keys for keymapper
virtual Common : : HardwareKeySet * getHardwareKeySet ( ) ;
2009-04-05 14:48:54 +00:00
// Set function that generates samples
virtual void setupMixer ( ) ;
static void mixCallback ( void * s , byte * samples , int len ) ;
virtual void closeMixer ( ) ;
virtual Audio : : Mixer * getMixer ( ) ;
2009-06-18 11:52:26 +00:00
// Poll CD status
// Returns true if cd audio is playing
bool pollCD ( ) ;
// Play CD audio track
void playCD ( int track , int num_loops , int start_frame , int duration ) ;
// Stop CD audio track
void stopCD ( ) ;
// Update CD audio status
void updateCD ( ) ;
2009-05-07 19:06:31 +00:00
// Quit
2009-10-04 16:33:49 +00:00
virtual void quit ( ) ; // overloaded by CE backend
2009-04-05 14:48:54 +00:00
2010-01-21 19:25:03 +00:00
virtual void getTimeAndDate ( TimeDate & t ) const ;
2009-05-07 19:06:31 +00:00
virtual Common : : TimerManager * getTimerManager ( ) ;
// Mutex handling
2006-02-13 21:15:32 +00:00
MutexRef createMutex ( ) ;
void lockMutex ( MutexRef mutex ) ;
void unlockMutex ( MutexRef mutex ) ;
void deleteMutex ( MutexRef mutex ) ;
2009-08-23 10:51:20 +00:00
// Overlay
virtual Graphics : : PixelFormat getOverlayFormat ( ) const { return _overlayFormat ; }
2009-10-05 08:33:46 +00:00
2009-08-23 10:51:20 +00:00
virtual void showOverlay ( ) ;
virtual void hideOverlay ( ) ;
virtual void clearOverlay ( ) ;
virtual void grabOverlay ( OverlayColor * buf , int pitch ) ;
virtual void copyRectToOverlay ( const OverlayColor * buf , int pitch , int x , int y , int w , int h ) ;
virtual int16 getHeight ( ) ;
virtual int16 getWidth ( ) ;
virtual int16 getOverlayHeight ( ) { return _overlayHeight ; }
virtual int16 getOverlayWidth ( ) { return _overlayWidth ; }
2009-05-07 19:06:31 +00:00
virtual void setWindowCaption ( const char * caption ) ;
2009-06-18 11:52:26 +00:00
virtual bool openCD ( int drive ) ;
2009-05-07 19:06:31 +00:00
virtual bool hasFeature ( Feature f ) ;
virtual void setFeatureState ( Feature f , bool enable ) ;
virtual bool getFeatureState ( Feature f ) ;
2011-04-10 21:59:04 +02:00
virtual void preprocessEvents ( SDL_Event * event ) { }
2009-04-05 14:48:54 +00:00
virtual Common : : SaveFileManager * getSavefileManager ( ) ;
virtual FilesystemFactory * getFilesystemFactory ( ) ;
virtual void addSysArchivesToSearchSet ( Common : : SearchSet & s , int priority = 0 ) ;
2009-10-04 16:33:49 +00:00
2009-05-07 19:21:52 +00:00
virtual Common : : SeekableReadStream * createConfigReadStream ( ) ;
virtual Common : : WriteStream * createConfigWriteStream ( ) ;
2009-04-05 14:48:54 +00:00
2009-10-04 16:33:49 +00:00
protected :
bool _inited ;
2009-10-05 08:33:46 +00:00
SDL_AudioSpec _obtainedRate ;
2009-10-04 16:33:49 +00:00
2008-07-03 12:04:12 +00:00
2009-05-07 19:06:31 +00:00
# ifdef USE_OPENGL
bool _opengl ;
# endif
bool _fullscreen ;
SDL_Surface * _screen ;
2009-08-23 10:51:20 +00:00
// overlay
SDL_Surface * _overlayscreen ;
bool _overlayVisible ;
Graphics : : PixelFormat _overlayFormat ;
int _overlayWidth , _overlayHeight ;
bool _overlayDirty ;
int _overlayNumTex ;
2010-05-17 16:24:57 +00:00
# ifdef USE_OPENGL
2009-08-23 10:51:20 +00:00
GLuint * _overlayTexIds ;
2010-05-17 16:24:57 +00:00
# endif
2009-08-23 10:51:20 +00:00
2009-10-04 10:58:28 +00:00
void closeOverlay ( ) ;
2009-06-18 11:52:26 +00:00
// CD Audio
SDL_CD * _cdrom ;
int _cdTrack , _cdNumLoops , _cdStartFrame , _cdDuration ;
uint32 _cdEndTime , _cdStopTime ;
2009-10-04 16:33:49 +00:00
// Keyboard mouse emulation. Disabled by fingolfin 2004-12-18.
// I am keeping the rest of the code in for now, since the joystick
// code (or rather, "hack") uses it, too.
struct KbdMouse {
int16 x , y , x_vel , y_vel , x_max , y_max , x_down_count , y_down_count ;
uint32 last_time , delay_time , x_down_time , y_down_time ;
} ;
// mouse
KbdMouse _km ;
2011-04-10 21:59:04 +02:00
// Scroll lock state - since SDL doesn't track it
bool _scrollLock ;
2009-10-04 16:33:49 +00:00
// joystick
SDL_Joystick * _joystick ;
2009-04-05 14:48:54 +00:00
# ifdef MIXER_DOUBLE_BUFFERING
SDL_mutex * _soundMutex ;
SDL_cond * _soundCond ;
SDL_Thread * _soundThread ;
bool _soundThreadIsRunning ;
bool _soundThreadShouldQuit ;
byte _activeSoundBuf ;
uint _soundBufSize ;
byte * _soundBuffers [ 2 ] ;
void mixerProducerThread ( ) ;
static int SDLCALL mixerProducerThreadEntry ( void * arg ) ;
void initThreadedMixer ( Audio : : MixerImpl * mixer , uint bufSize ) ;
void deinitThreadedMixer ( ) ;
# endif
FilesystemFactory * _fsFactory ;
2008-07-20 15:00:50 +00:00
Common : : SaveFileManager * _savefile ;
2009-04-05 14:48:54 +00:00
Audio : : MixerImpl * _mixer ;
2008-07-03 12:04:12 +00:00
SDL_TimerID _timerID ;
2009-04-05 14:48:54 +00:00
Common : : TimerManager * _timer ;
2008-07-03 12:04:12 +00:00
2009-10-04 16:33:49 +00:00
protected :
2008-08-17 12:01:26 +00:00
2009-10-04 16:33:49 +00:00
/** Set the position of the virtual mouse cursor. */
void setMousePos ( int x , int y ) ;
virtual void fillMouseEvent ( Common : : Event & event , int x , int y ) ; // overloaded by CE backend
void toggleMouseGrab ( ) ;
2008-08-17 12:01:26 +00:00
2009-05-07 19:06:31 +00:00
2009-10-04 16:33:49 +00:00
void setupIcon ( ) ;
2008-08-17 12:01:26 +00:00
void handleKbdMouse ( ) ;
2009-10-04 16:33:49 +00:00
virtual bool remapKey ( SDL_Event & ev , Common : : Event & event ) ;
2010-01-21 19:25:03 +00:00
bool handleScalerHotkeys ( const SDL_KeyboardEvent & key ) ;
2006-02-05 17:19:44 +00:00
} ;
# endif