2007-05-30 21:56:52 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
2002-08-24 10:41:32 +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 .
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2005-10-18 01:30:26 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2002-08-24 10:41:32 +00:00
*
2006-02-11 12:47:47 +00:00
* $ URL $
* $ Id $
2002-08-24 10:41:32 +00:00
*
*/
# ifndef SDL_COMMON_H
# define SDL_COMMON_H
2007-11-24 11:41:54 +00:00
# if defined(__SYMBIAN32__)
# include <esdl\SDL.h>
# else
2006-05-23 16:49:46 +00:00
# include <SDL.h>
2007-11-24 11:41:54 +00:00
# endif
2006-05-23 16:49:46 +00:00
2009-01-30 03:35:47 +00:00
# include "backends/base-backend.h"
2010-06-07 03:19:18 +00:00
# include "backends/mutex/sdl/sdl-mutex.h"
# include "backends/graphics/sdl/sdl-graphics.h"
2006-02-20 20:29:02 +00:00
# include "graphics/scaler.h"
2002-08-24 10:41:32 +00:00
2006-10-22 15:42:29 +00:00
namespace Audio {
2008-06-28 15:28:29 +00:00
class MixerImpl ;
2006-10-22 15:42:29 +00:00
}
2005-06-21 20:39:09 +00:00
# if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
2004-03-13 14:19:15 +00:00
// Uncomment this to enable the 'on screen display' code.
# define USE_OSD 1
2004-05-09 14:30:29 +00:00
# endif
2004-03-13 14:19:15 +00:00
2008-07-15 17:13:06 +00:00
# if defined(MACOSX)
// 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.
# define MIXER_DOUBLE_BUFFERING 1
# endif
2009-01-30 03:35:47 +00:00
class OSystem_SDL : public BaseBackend {
2002-08-24 10:41:32 +00:00
public :
2004-02-29 00:49:40 +00:00
OSystem_SDL ( ) ;
virtual ~ OSystem_SDL ( ) ;
2005-04-19 20:22:50 +00:00
virtual void initBackend ( ) ;
2010-06-07 03:19:18 +00:00
protected :
SdlMutexManager * _mutexManager ;
SdlGraphicsManager * _graphicsManager ;
public :
2009-11-02 21:54:57 +00:00
void beginGFXTransaction ( ) ;
TransactionError endGFXTransaction ( ) ;
2004-11-23 21:30:38 +00:00
2009-08-21 18:16:37 +00:00
# ifdef USE_RGB_COLOR
2009-06-10 05:35:18 +00:00
// Game screen
2010-06-07 03:19:18 +00:00
virtual Graphics : : PixelFormat getScreenFormat ( ) const ;
2009-06-16 09:04:37 +00:00
// Highest supported
2009-07-10 06:46:50 +00:00
virtual Common : : List < Graphics : : PixelFormat > getSupportedFormats ( ) ;
2009-06-10 05:35:18 +00:00
# endif
2009-06-23 02:02:51 +00:00
// Set the size and format of the video bitmap.
// Typically, 320x200 CLUT8
2009-06-30 07:30:57 +00:00
virtual void initSize ( uint w , uint h , const Graphics : : PixelFormat * format ) ; // overloaded by CE backend
2002-08-24 10:41:32 +00:00
2010-06-07 03:19:18 +00:00
virtual int getScreenChangeID ( ) const ;
2006-08-04 13:10:28 +00:00
2003-07-02 15:08:46 +00:00
// Set colors of the palette
2004-02-28 12:58:13 +00:00
void setPalette ( const byte * colors , uint start , uint num ) ;
2005-07-30 21:11:48 +00:00
2005-05-08 21:39:05 +00:00
// Get colors of the palette
void grabPalette ( byte * colors , uint start , uint num ) ;
2003-07-02 15:08:46 +00:00
2002-08-24 10:41:32 +00:00
// Draw a bitmap to screen.
// The screen will not be updated to reflect the new bitmap
2005-10-16 22:32:46 +00:00
virtual void copyRectToScreen ( const byte * src , int pitch , int x , int y , int w , int h ) ; // overloaded by CE backend (FIXME)
2002-08-24 10:41:32 +00:00
2007-06-19 22:39:59 +00:00
virtual Graphics : : Surface * lockScreen ( ) ;
virtual void unlockScreen ( ) ;
2004-11-13 04:33:33 +00:00
2002-08-24 10:41:32 +00:00
// Update the dirty areas of the screen
2004-02-28 12:58:13 +00:00
void updateScreen ( ) ;
2002-08-24 10:41:32 +00:00
// Either show or hide the mouse cursor
2004-03-28 16:30:50 +00:00
bool showMouse ( bool visible ) ;
2005-07-30 21:11:48 +00:00
2003-01-09 08:07:13 +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.
2005-10-16 22:32:46 +00:00
virtual void warpMouse ( int x , int y ) ; // overloaded by CE backend (FIXME)
2003-03-06 18:30:44 +00:00
2002-08-24 10:41:32 +00:00
// Set the bitmap that's used when drawing the cursor.
2009-06-30 07:30:57 +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)
2005-02-17 23:01:00 +00:00
// Set colors of cursor palette
void setCursorPalette ( const byte * colors , uint start , uint num ) ;
2003-03-06 18:30:44 +00:00
2005-02-20 02:04:45 +00:00
// Disables or enables cursor palette
2010-06-07 03:19:18 +00:00
void disableCursorPalette ( bool disable ) ;
2005-02-20 02:04:45 +00:00
2002-08-24 10:41:32 +00:00
// Shaking is used in SCUMM. Set current shake position.
2004-09-28 20:19:37 +00:00
void setShakePos ( int shake_pos ) ;
2003-03-06 18:30:44 +00:00
2002-08-24 10:41:32 +00:00
// Get the number of milliseconds since the program was started.
2004-09-28 20:19:37 +00:00
uint32 getMillis ( ) ;
2003-03-06 18:30:44 +00:00
2002-08-24 10:41:32 +00:00
// Delay for a specified amount of milliseconds
2004-09-28 20:19:37 +00:00
void delayMillis ( uint msecs ) ;
2003-03-06 18:30:44 +00:00
2002-08-24 10:41:32 +00:00
// Get the next event.
2005-07-30 21:11:48 +00:00
// Returns true if an event was retrieved.
2007-03-17 19:02:05 +00:00
virtual bool pollEvent ( Common : : Event & event ) ; // overloaded by CE backend
2003-03-06 18:30:44 +00:00
2009-11-09 23:31:46 +00:00
protected :
2009-11-10 00:01:43 +00:00
virtual bool dispatchSDLEvent ( SDL_Event & ev , Common : : Event & event ) ;
2009-11-09 23:31:46 +00:00
// 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.
2009-11-10 00:01:43 +00:00
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 ) ;
2009-11-09 23:31:46 +00:00
public :
2009-05-11 09:01:54 +00:00
// Define all hardware keys for keymapper
virtual Common : : HardwareKeySet * getHardwareKeySet ( ) ;
2008-08-06 14:21:05 +00:00
2005-07-30 21:11:48 +00:00
// Set function that generates samples
2008-06-28 15:28:29 +00:00
virtual void setupMixer ( ) ;
static void mixCallback ( void * s , byte * samples , int len ) ;
2008-07-15 17:13:06 +00:00
virtual void closeMixer ( ) ;
2006-10-22 15:42:29 +00:00
virtual Audio : : Mixer * getMixer ( ) ;
2003-03-06 18:30:44 +00:00
2002-09-28 16:19:28 +00:00
// Poll CD status
2002-08-24 10:41:32 +00:00
// Returns true if cd audio is playing
2004-09-28 20:19:37 +00:00
bool pollCD ( ) ;
2002-08-24 10:41:32 +00:00
2002-09-28 16:19:28 +00:00
// Play CD audio track
2004-09-28 20:19:37 +00:00
void playCD ( int track , int num_loops , int start_frame , int duration ) ;
2002-08-24 10:41:32 +00:00
2002-09-28 16:19:28 +00:00
// Stop CD audio track
2004-09-28 20:19:37 +00:00
void stopCD ( ) ;
2002-08-24 10:41:32 +00:00
2002-09-28 16:19:28 +00:00
// Update CD audio status
2004-09-28 20:19:37 +00:00
void updateCD ( ) ;
2002-08-24 10:41:32 +00:00
// Quit
2004-12-11 15:17:47 +00:00
virtual void quit ( ) ; // overloaded by CE backend
2002-08-24 10:41:32 +00:00
2010-05-21 18:22:11 +00:00
void deinit ( ) ;
2009-10-08 19:41:38 +00:00
virtual void getTimeAndDate ( TimeDate & t ) const ;
2006-10-22 15:42:29 +00:00
virtual Common : : TimerManager * getTimerManager ( ) ;
2002-08-24 10:41:32 +00:00
// Mutex handling
2004-02-28 12:58:13 +00:00
MutexRef createMutex ( ) ;
void lockMutex ( MutexRef mutex ) ;
void unlockMutex ( MutexRef mutex ) ;
void deleteMutex ( MutexRef mutex ) ;
2002-08-24 10:41:32 +00:00
2002-12-13 17:27:28 +00:00
// Overlay
2010-06-07 03:19:18 +00:00
virtual Graphics : : PixelFormat getOverlayFormat ( ) const ;
2009-06-09 07:55:43 +00:00
2007-09-11 09:20:39 +00:00
virtual void showOverlay ( ) ;
virtual void hideOverlay ( ) ;
2004-03-28 16:30:50 +00:00
virtual void clearOverlay ( ) ;
virtual void grabOverlay ( OverlayColor * buf , int pitch ) ;
2007-09-11 09:20:39 +00:00
virtual void copyRectToOverlay ( const OverlayColor * buf , int pitch , int x , int y , int w , int h ) ;
2004-03-15 00:45:45 +00:00
virtual int16 getHeight ( ) ;
virtual int16 getWidth ( ) ;
2010-06-07 03:19:18 +00:00
virtual int16 getOverlayHeight ( ) ;
virtual int16 getOverlayWidth ( ) ;
2002-12-13 17:27:28 +00:00
2004-02-24 22:39:42 +00:00
virtual const GraphicsMode * getSupportedGraphicsModes ( ) const ;
2004-03-15 00:45:45 +00:00
virtual int getDefaultGraphicsMode ( ) const ;
2004-02-24 22:39:42 +00:00
virtual bool setGraphicsMode ( int mode ) ;
virtual int getGraphicsMode ( ) const ;
2005-07-30 21:11:48 +00:00
2004-02-24 22:39:42 +00:00
virtual void setWindowCaption ( const char * caption ) ;
virtual bool openCD ( int drive ) ;
virtual bool hasFeature ( Feature f ) ;
virtual void setFeatureState ( Feature f , bool enable ) ;
virtual bool getFeatureState ( Feature f ) ;
2010-03-22 20:28:08 +00:00
virtual void preprocessEvents ( SDL_Event * event ) { }
2004-02-24 22:39:42 +00:00
2004-03-28 20:31:18 +00:00
# ifdef USE_OSD
void displayMessageOnOSD ( const char * msg ) ;
# endif
2006-10-22 15:42:29 +00:00
virtual Common : : SaveFileManager * getSavefileManager ( ) ;
2008-03-11 17:24:34 +00:00
virtual FilesystemFactory * getFilesystemFactory ( ) ;
2008-09-27 18:32:01 +00:00
virtual void addSysArchivesToSearchSet ( Common : : SearchSet & s , int priority = 0 ) ;
2006-10-22 15:42:29 +00:00
2009-01-23 03:30:40 +00:00
virtual Common : : SeekableReadStream * createConfigReadStream ( ) ;
virtual Common : : WriteStream * createConfigWriteStream ( ) ;
2008-08-03 17:05:01 +00:00
2002-08-24 10:41:32 +00:00
protected :
2005-04-19 20:22:50 +00:00
bool _inited ;
2009-08-22 13:18:26 +00:00
SDL_AudioSpec _obtainedRate ;
2003-05-14 19:44:41 +00:00
2002-09-28 16:19:28 +00:00
// CD Audio
SDL_CD * _cdrom ;
2004-12-01 21:16:55 +00:00
int _cdTrack , _cdNumLoops , _cdStartFrame , _cdDuration ;
uint32 _cdEndTime , _cdStopTime ;
2002-08-24 10:41:32 +00:00
2004-12-30 14:48:21 +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.
2005-07-30 21:11:48 +00:00
struct KbdMouse {
2002-08-24 10:41:32 +00:00
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 ;
2004-12-01 21:16:55 +00:00
} ;
2002-08-24 10:41:32 +00:00
2004-12-01 21:16:55 +00:00
KbdMouse _km ;
2002-08-24 10:41:32 +00:00
2010-02-21 04:04:13 +00:00
// Scroll lock state - since SDL doesn't track it
bool _scrollLock ;
2003-09-14 12:52:38 +00:00
// joystick
SDL_Joystick * _joystick ;
2008-07-15 17:13:06 +00:00
# ifdef MIXER_DOUBLE_BUFFERING
SDL_mutex * _soundMutex ;
SDL_cond * _soundCond ;
SDL_Thread * _soundThread ;
bool _soundThreadIsRunning ;
bool _soundThreadShouldQuit ;
2009-01-01 15:06:43 +00:00
2008-07-15 17:13:06 +00:00
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
2008-08-22 11:36:47 +00:00
FilesystemFactory * _fsFactory ;
2006-10-22 15:42:29 +00:00
Common : : SaveFileManager * _savefile ;
2008-06-28 15:28:29 +00:00
Audio : : MixerImpl * _mixer ;
2007-09-19 08:40:12 +00:00
2006-10-22 16:05:07 +00:00
SDL_TimerID _timerID ;
2006-10-22 15:42:29 +00:00
Common : : TimerManager * _timer ;
2008-07-15 17:13:06 +00:00
protected :
2007-03-17 19:02:05 +00:00
virtual void fillMouseEvent ( Common : : Event & event , int x , int y ) ; // overloaded by CE backend
2004-02-24 22:39:42 +00:00
void toggleMouseGrab ( ) ;
2003-09-11 23:53:38 +00:00
2010-06-07 03:19:18 +00:00
void handleKbdMouse ( ) ;
2003-08-22 07:40:40 +00:00
2004-12-01 21:16:55 +00:00
void setupIcon ( ) ;
2005-07-11 10:54:53 +00:00
2009-11-09 23:58:12 +00:00
virtual bool remapKey ( SDL_Event & ev , Common : : Event & event ) ;
2002-08-24 10:41:32 +00:00
} ;
# endif