diff options
author | Alejandro Marzini | 2010-06-11 02:50:25 +0000 |
---|---|---|
committer | Alejandro Marzini | 2010-06-11 02:50:25 +0000 |
commit | e81fb60d34029c761c8b935ceaad3322f7b8bdee (patch) | |
tree | 9a1b0fded7153ce6efe31b75c7deb600912152f0 /backends/platform | |
parent | 11e8ac61d1d446e9e5517ff9b39c701170f245bd (diff) | |
download | scummvm-rg350-e81fb60d34029c761c8b935ceaad3322f7b8bdee.tar.gz scummvm-rg350-e81fb60d34029c761c8b935ceaad3322f7b8bdee.tar.bz2 scummvm-rg350-e81fb60d34029c761c8b935ceaad3322f7b8bdee.zip |
Add Common::EventSource inheritance for ModularBackend. OSystem_SDL now subclass from ModularBackend insteand of BaseBackend. Added forceFullRedraw() to SdlGraphicsManager and removed _modeChanged.
svn-id: r49590
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/sdl/events.cpp | 12 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 256 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 151 |
3 files changed, 52 insertions, 367 deletions
diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp index 9f80557c0c..fc5332adb5 100644 --- a/backends/platform/sdl/events.cpp +++ b/backends/platform/sdl/events.cpp @@ -184,11 +184,11 @@ bool OSystem_SDL::pollEvent(Common::Event &event) { handleKbdMouse(); // If the screen mode changed, send an Common::EVENT_SCREEN_CHANGED - if (_graphicsManager->_modeChanged) { + /*if (_graphicsManager->_modeChanged) { // TODO: use getScreenChangeID _graphicsManager->_modeChanged = false; event.type = Common::EVENT_SCREEN_CHANGED; return true; - } + }*/ while (SDL_PollEvent(&ev)) { preprocessEvents(&ev); @@ -218,7 +218,7 @@ bool OSystem_SDL::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { return handleJoyAxisMotion(ev, event); case SDL_VIDEOEXPOSE: - _graphicsManager->_forceFull = true; + ((SdlGraphicsManager *)_graphicsManager)->forceFullRedraw(); break; case SDL_QUIT: @@ -312,7 +312,7 @@ bool OSystem_SDL::handleKeyDown(SDL_Event &ev, Common::Event &event) { // Ctrl-Alt-<key> will change the GFX mode if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { - if (_graphicsManager->handleScalerHotkeys(ev.key)) + if (((SdlGraphicsManager *)_graphicsManager)->handleScalerHotkeys(ev.key)) return false; } @@ -341,7 +341,7 @@ bool OSystem_SDL::handleKeyUp(SDL_Event &ev, Common::Event &event) { if (_scrollLock) event.kbd.flags |= Common::KBD_SCRL; - if (_graphicsManager->isScalerHotkey(event)) + if (((SdlGraphicsManager *)_graphicsManager)->isScalerHotkey(event)) // Swallow these key up events return false; @@ -352,7 +352,7 @@ bool OSystem_SDL::handleMouseMotion(SDL_Event &ev, Common::Event &event) { event.type = Common::EVENT_MOUSEMOVE; fillMouseEvent(event, ev.motion.x, ev.motion.y); - _graphicsManager->setMousePos(event.mouse.x, event.mouse.y); + ((SdlGraphicsManager *)_graphicsManager)->setMousePos(event.mouse.x, event.mouse.y); return true; } diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 684befa623..8ace81c0a6 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -118,13 +118,19 @@ void OSystem_SDL::initBackend() { _joystick = SDL_JoystickOpen(joystick_num); } + // Create and hook up the event manager, if none exists yet (we check for + // this to allow subclasses to provide their own). + if (_eventManager == 0) { + _eventManager = new DefaultEventManager(this); + } + // Create the savefile manager, if none exists yet (we check for this to // allow subclasses to provide their own). - if (_savefile == 0) { + if (_savefileManager == 0) { #ifdef UNIX - _savefile = new POSIXSaveFileManager(); + _savefileManager = new POSIXSaveFileManager(); #else - _savefile = new DefaultSaveFileManager(); + _savefileManager = new DefaultSaveFileManager(); #endif } @@ -141,14 +147,14 @@ void OSystem_SDL::initBackend() { // Create and hook up the timer manager, if none exists yet (we check for // this to allow subclasses to provide their own). - if (_timer == 0) { + if (_timerManager == 0) { // TODO: Implement SdlTimerManager if (SDL_InitSubSystem(SDL_INIT_TIMER) == -1) { error("Could not initialize SDL: %s", SDL_GetError()); } - _timer = new DefaultTimerManager(); - _timerID = SDL_AddTimer(10, &timer_handler, _timer); + _timerManager = new DefaultTimerManager(); + _timerID = SDL_AddTimer(10, &timer_handler, _timerManager); } // Create and hook up the graphics manager, if none exists yet (we check for @@ -158,7 +164,7 @@ void OSystem_SDL::initBackend() { } if (_audiocdManager == 0) { - _audiocdManager = new SdlAudioCDManager(); + _audiocdManager = (AudioCDManager *)new SdlAudioCDManager(); } #if !defined(MACOSX) && !defined(__SYMBIAN32__) @@ -176,19 +182,12 @@ void OSystem_SDL::initBackend() { OSystem_SDL::OSystem_SDL() : - _scrollLock(false), - _joystick(0), #if MIXER_DOUBLE_BUFFERING _soundMutex(0), _soundCond(0), _soundThread(0), _soundThreadIsRunning(false), _soundThreadShouldQuit(false), #endif - _fsFactory(0), - _savefile(0), - _mixer(0), - _timer(0), - _mutexManager(0), - _graphicsManager(0), - _audiocdManager(0) { + _scrollLock(false), + _joystick(0) { // reset mouse state memset(&_km, 0, sizeof(_km)); @@ -212,8 +211,8 @@ OSystem_SDL::~OSystem_SDL() { SDL_RemoveTimer(_timerID); closeMixer(); - delete _savefile; - delete _timer; + delete _savefileManager; + delete _timerManager; } uint32 OSystem_SDL::getMillis() { @@ -237,21 +236,6 @@ void OSystem_SDL::getTimeAndDate(TimeDate &td) const { td.tm_year = t.tm_year; } -Common::TimerManager *OSystem_SDL::getTimerManager() { - assert(_timer); - return _timer; -} - -Common::SaveFileManager *OSystem_SDL::getSavefileManager() { - assert(_savefile); - return _savefile; -} - -FilesystemFactory *OSystem_SDL::getFilesystemFactory() { - assert(_fsFactory); - return _fsFactory; -} - void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { #ifdef DATA_PATH @@ -375,18 +359,6 @@ void OSystem_SDL::setWindowCaption(const char *caption) { SDL_WM_SetCaption(cap.c_str(), cap.c_str()); } -bool OSystem_SDL::hasFeature(Feature f) { - return _graphicsManager->hasFeature(f); -} - -void OSystem_SDL::setFeatureState(Feature f, bool enable) { - _graphicsManager->setFeatureState(f, enable); -} - -bool OSystem_SDL::getFeatureState(Feature f) { - return _graphicsManager->getFeatureState(f); -} - void OSystem_SDL::deinit() { if (_joystick) SDL_JoystickClose(_joystick); @@ -396,14 +368,14 @@ void OSystem_SDL::deinit() { SDL_RemoveTimer(_timerID); closeMixer(); - delete _timer; + delete _timerManager; SDL_Quit(); // Event Manager requires save manager for storing // recorded events delete getEventManager(); - delete _savefile; + delete _savefileManager; } void OSystem_SDL::quit() { @@ -467,26 +439,6 @@ void OSystem_SDL::setupIcon() { } #pragma mark - -#pragma mark --- Mutex --- -#pragma mark - - -OSystem::MutexRef OSystem_SDL::createMutex() { - return _mutexManager->createMutex(); -} - -void OSystem_SDL::lockMutex(MutexRef mutex) { - _mutexManager->lockMutex(mutex); -} - -void OSystem_SDL::unlockMutex(MutexRef mutex) { - _mutexManager->unlockMutex(mutex); -} - -void OSystem_SDL::deleteMutex(MutexRef mutex) { - _mutexManager->deleteMutex(mutex); -} - -#pragma mark - #pragma mark --- Audio --- #pragma mark - @@ -585,11 +537,11 @@ void OSystem_SDL::mixCallback(void *arg, byte *samples, int len) { #else void OSystem_SDL::mixCallback(void *sys, byte *samples, int len) { - OSystem_SDL *this_ = (OSystem_SDL *)sys; + ModularBackend *this_ = (ModularBackend *)sys; assert(this_); - assert(this_->_mixer); + assert(this_->getMixer()); - this_->_mixer->mixCallback(samples, len); + ((Audio::MixerImpl *)this_->getMixer())->mixCallback(samples, len); } #endif @@ -625,7 +577,7 @@ void OSystem_SDL::setupMixer() { warning("Could not open audio device: %s", SDL_GetError()); _mixer = new Audio::MixerImpl(this, samplesPerSec); assert(_mixer); - _mixer->setReady(false); + ((Audio::MixerImpl *)_mixer)->setReady(false); } else { // Note: This should be the obtained output rate, but it seems that at // least on some platforms SDL will lie and claim it did get the rate @@ -636,7 +588,7 @@ void OSystem_SDL::setupMixer() { // Create the mixer instance and start the sound processing _mixer = new Audio::MixerImpl(this, samplesPerSec); assert(_mixer); - _mixer->setReady(true); + ((Audio::MixerImpl *)_mixer)->setReady(true); #if MIXER_DOUBLE_BUFFERING initThreadedMixer(_mixer, _obtainedRate.samples * 4); @@ -649,7 +601,7 @@ void OSystem_SDL::setupMixer() { void OSystem_SDL::closeMixer() { if (_mixer) - _mixer->setReady(false); + ((Audio::MixerImpl *)_mixer)->setReady(false); SDL_CloseAudio(); @@ -661,161 +613,3 @@ void OSystem_SDL::closeMixer() { #endif } - -Audio::Mixer *OSystem_SDL::getMixer() { - assert(_mixer); - return _mixer; -} - -#pragma mark - -#pragma mark --- Graphics --- -#pragma mark - - -const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const { - return _graphicsManager->getSupportedGraphicsModes(); -} - -int OSystem_SDL::getDefaultGraphicsMode() const { - return _graphicsManager->getDefaultGraphicsMode(); -} - -bool OSystem_SDL::setGraphicsMode(int mode) { - return _graphicsManager->setGraphicsMode(mode); -} - -int OSystem_SDL::getGraphicsMode() const { - return _graphicsManager->getGraphicsMode(); -} - -#ifdef USE_RGB_COLOR -Graphics::PixelFormat OSystem_SDL::getScreenFormat() const { - return _graphicsManager->getScreenFormat(); -} - -Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() { - return _graphicsManager->getSupportedFormats(); -} -#endif - -void OSystem_SDL::beginGFXTransaction() { - _graphicsManager->beginGFXTransaction(); -} - -OSystem::TransactionError OSystem_SDL::endGFXTransaction() { - return _graphicsManager->endGFXTransaction(); -} - -void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format ) { - _graphicsManager->initSize(w, h, format); -} - -int16 OSystem_SDL::getHeight() { - return _graphicsManager->getHeight(); -} - -int16 OSystem_SDL::getWidth() { - return _graphicsManager->getWidth(); -} - -void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { - _graphicsManager->setPalette(colors, start, num); -} - -void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { - _graphicsManager->grabPalette(colors, start, num); -} - -void OSystem_SDL::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { - _graphicsManager->copyRectToScreen(buf, pitch, x, y, w, h); -} - -Graphics::Surface *OSystem_SDL::lockScreen() { - return _graphicsManager->lockScreen(); -} - -void OSystem_SDL::unlockScreen() { - _graphicsManager->unlockScreen(); -} - -/*void OSystem_SDL::fillScreen(uint32 col) { - _graphicsManager->fillScreen(col); -}*/ - -void OSystem_SDL::updateScreen() { - _graphicsManager->updateScreen(); -} - -void OSystem_SDL::setShakePos(int shakeOffset) { - _graphicsManager->setShakePos(shakeOffset); -} - -void OSystem_SDL::showOverlay() { - _graphicsManager->showOverlay(); -} - -void OSystem_SDL::hideOverlay() { - _graphicsManager->hideOverlay(); -} - -Graphics::PixelFormat OSystem_SDL::getOverlayFormat() const { - return _graphicsManager->getOverlayFormat(); -} - -void OSystem_SDL::clearOverlay() { - _graphicsManager->clearOverlay(); -} - -void OSystem_SDL::grabOverlay(OverlayColor *buf, int pitch) { - _graphicsManager->grabOverlay(buf, pitch); -} - -void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { - _graphicsManager->copyRectToOverlay(buf, pitch, x, y, w, h); -} - -int16 OSystem_SDL::getOverlayHeight() { - return _graphicsManager->getOverlayHeight(); -} - -int16 OSystem_SDL::getOverlayWidth() { - return _graphicsManager->getOverlayWidth(); -} - -bool OSystem_SDL::showMouse(bool visible) { - return _graphicsManager->showMouse(visible); -} - -void OSystem_SDL::warpMouse(int x, int y) { - _graphicsManager->warpMouse(x, y); -} - -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { - _graphicsManager->setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, cursorTargetScale, format); -} - -void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { - _graphicsManager->setCursorPalette(colors, start, num); -} - -void OSystem_SDL::disableCursorPalette(bool disable) { - _graphicsManager->disableCursorPalette(disable); -} - -int OSystem_SDL::getScreenChangeID() const { - return _graphicsManager->getScreenChangeID(); -} - -#ifdef USE_OSD -void OSystem_SDL::displayMessageOnOSD(const char *msg) { - _graphicsManager->displayMessageOnOSD(msg); -} - -#pragma mark - -#pragma mark --- AudioCD --- -#pragma mark - - -AudioCDManager *OSystem_SDL::getAudioCD() { - return (AudioCDManager *)_audiocdManager; -} - -#endif diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index ebe8728f51..67ad339da7 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -32,7 +32,7 @@ #include <SDL.h> #endif -#include "backends/base-backend.h" +#include "backends/modular-backend.h" #include "backends/mutex/sdl/sdl-mutex.h" #include "backends/graphics/sdl/sdl-graphics.h" @@ -59,165 +59,46 @@ namespace Audio { #define MIXER_DOUBLE_BUFFERING 1 #endif -class OSystem_SDL : public BaseBackend { +class OSystem_SDL : public ModularBackend { public: OSystem_SDL(); virtual ~OSystem_SDL(); virtual void initBackend(); - -protected: - SdlMutexManager *_mutexManager; - SdlGraphicsManager *_graphicsManager; - SdlAudioCDManager *_audiocdManager; - -public: - void beginGFXTransaction(); - TransactionError endGFXTransaction(); - -#ifdef USE_RGB_COLOR - // Game screen - virtual Graphics::PixelFormat getScreenFormat() const; - - // Highest supported - virtual Common::List<Graphics::PixelFormat> getSupportedFormats(); -#endif - - // Set the size and format of the video bitmap. - // Typically, 320x200 CLUT8 - virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format); // overloaded by CE backend - - virtual int getScreenChangeID() const; - - // Set colors of the palette - void setPalette(const byte *colors, uint start, uint num); - - // Get colors of the palette - void grabPalette(byte *colors, uint start, uint num); - - // Draw a bitmap to screen. - // The screen will not be updated to reflect the new bitmap - virtual void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h); // overloaded by CE backend (FIXME) - - virtual Graphics::Surface *lockScreen(); - virtual void unlockScreen(); - - // Update the dirty areas of the screen - void updateScreen(); - - // Either show or hide the mouse cursor - bool showMouse(bool visible); - - // 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. - virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) - - // Set the bitmap that's used when drawing the cursor. - 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) - - // Set colors of cursor palette - void setCursorPalette(const byte *colors, uint start, uint num); - - // Disables or enables cursor palette - void disableCursorPalette(bool disable); - - // Shaking is used in SCUMM. Set current shake position. - void setShakePos(int shake_pos); - // Get the number of milliseconds since the program was started. uint32 getMillis(); // Delay for a specified amount of milliseconds void delayMillis(uint msecs); + virtual void getTimeAndDate(TimeDate &t) const; + // Get the next event. // Returns true if an event was retrieved. virtual bool pollEvent(Common::Event &event); // overloaded by CE backend -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: - - // Define all hardware keys for keymapper virtual Common::HardwareKeySet *getHardwareKeySet(); + virtual void preprocessEvents(SDL_Event *event) {} + // Set function that generates samples virtual void setupMixer(); static void mixCallback(void *s, byte *samples, int len); - virtual void closeMixer(); - virtual Audio::Mixer *getMixer(); - // Quit virtual void quit(); // overloaded by CE backend void deinit(); - virtual void getTimeAndDate(TimeDate &t) const; - virtual Common::TimerManager *getTimerManager(); - - // Mutex handling - MutexRef createMutex(); - void lockMutex(MutexRef mutex); - void unlockMutex(MutexRef mutex); - void deleteMutex(MutexRef mutex); - - // Overlay - virtual Graphics::PixelFormat getOverlayFormat() const; - - 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(); - virtual int16 getOverlayWidth(); - - virtual const GraphicsMode *getSupportedGraphicsModes() const; - virtual int getDefaultGraphicsMode() const; - virtual bool setGraphicsMode(int mode); - virtual int getGraphicsMode() const; - virtual void setWindowCaption(const char *caption); - virtual bool hasFeature(Feature f); - virtual void setFeatureState(Feature f, bool enable); - virtual bool getFeatureState(Feature f); - virtual void preprocessEvents(SDL_Event *event) {} - -#ifdef USE_OSD - void displayMessageOnOSD(const char *msg); -#endif - - virtual Common::SaveFileManager *getSavefileManager(); - virtual FilesystemFactory *getFilesystemFactory(); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); - virtual Common::SeekableReadStream *createConfigReadStream(); virtual Common::WriteStream *createConfigWriteStream(); - virtual AudioCDManager *getAudioCD(); - protected: bool _inited; SDL_AudioSpec _obtainedRate; @@ -238,6 +119,21 @@ protected: // joystick SDL_Joystick *_joystick; + 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); + #ifdef MIXER_DOUBLE_BUFFERING SDL_mutex *_soundMutex; SDL_cond *_soundCond; @@ -255,12 +151,7 @@ protected: void deinitThreadedMixer(); #endif - FilesystemFactory *_fsFactory; - Common::SaveFileManager *_savefile; - Audio::MixerImpl *_mixer; - SDL_TimerID _timerID; - Common::TimerManager *_timer; virtual void fillMouseEvent(Common::Event &event, int x, int y); // overloaded by CE backend void toggleMouseGrab(); |