Modularized Linuxmoto port.

svn-id: r50474
This commit is contained in:
Alejandro Marzini 2010-06-29 01:08:36 +00:00
parent 494755cc36
commit fd77e4b09c
13 changed files with 238 additions and 121 deletions

View file

@ -23,8 +23,46 @@
* *
*/ */
#if defined(LINUXMOTO)
#include "backends/events/linuxmotosdl/linuxmotosdl-events.h"
#include "backends/platform/linuxmoto/linuxmoto-sdl.h" #include "backends/platform/linuxmoto/linuxmoto-sdl.h"
#include "graphics/scaler/aspect.h" // for aspect2Real
enum {
GFX_HALF = 12
};
LinuxmotoSdlEventManager::LinuxmotoSdlEventManager(Common::EventSource *boss)
:
SdlEventManager(boss) {
}
LinuxmotoSdlEventManager::~LinuxmotoSdlEventManager() {
}
void LinuxmotoSdlEventManager::preprocessEvents(SDL_Event *event) {
if (event->type == SDL_ACTIVEEVENT) {
if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain) {
((OSystem_SDL* )g_system)->getMixerManager()->suspendAudio();
for (;;) {
if (!SDL_WaitEvent(event)) {
SDL_Delay(10);
continue;
}
if (event->type == SDL_QUIT)
return;
if (event->type != SDL_ACTIVEEVENT)
continue;
if (event->active.state == SDL_APPINPUTFOCUS && event->active.gain) {
((OSystem_SDL* )g_system)->getMixerManager()->resumeAudio();
return;
}
}
}
}
}
static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
if (key >= SDLK_F1 && key <= SDLK_F9) { if (key >= SDLK_F1 && key <= SDLK_F9) {
@ -43,29 +81,9 @@ static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
return key; return key;
} }
void OSystem_LINUXMOTO::fillMouseEvent(Common::Event &event, int x, int y) { bool LinuxmotoSdlEventManager::remapKey(SDL_Event &ev, Common::Event &event) {
if (_videoMode.mode == GFX_HALF && !_overlayVisible) { if (false) {}
event.mouse.x = x*2;
event.mouse.y = y*2;
} else {
event.mouse.x = x;
event.mouse.y = y;
}
// Update the "keyboard mouse" coords
_km.x = x;
_km.y = y;
// Adjust for the screen scaling
if (!_overlayVisible) {
event.mouse.x /= _videoMode.scaleFactor;
event.mouse.y /= _videoMode.scaleFactor;
if (_videoMode.aspectRatioCorrection)
event.mouse.y = aspect2Real(event.mouse.y);
}
}
bool OSystem_LINUXMOTO::remapKey(SDL_Event &ev, Common::Event &event) {
// Motorol A1200/E6/A1600 remapkey by Lubomyr // Motorol A1200/E6/A1600 remapkey by Lubomyr
#ifdef MOTOEZX #ifdef MOTOEZX
// Quit on MOD+Camera Key on A1200 // Quit on MOD+Camera Key on A1200
@ -226,3 +244,5 @@ bool OSystem_LINUXMOTO::remapKey(SDL_Event &ev, Common::Event &event) {
return false; return false;
} }
#endif

View file

@ -0,0 +1,41 @@
/* 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.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#if !defined(BACKEND_EVENTS_SDL_LINUXMOTO_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
#define BACKEND_EVENTS_SDL_LINUXMOTO_H
#include "backends/events/sdl/sdl-events.h"
class LinuxmotoSdlEventManager : public SdlEventManager {
public:
LinuxmotoSdlEventManager(Common::EventSource *boss);
virtual ~LinuxmotoSdlEventManager();
protected:
virtual void preprocessEvents(SDL_Event *event);
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
};
#endif

View file

@ -43,6 +43,8 @@ public:
virtual void resetKeyboadEmulation(int16 x_max, int16 y_max); virtual void resetKeyboadEmulation(int16 x_max, int16 y_max);
virtual void toggleMouseGrab();
protected: protected:
virtual void preprocessEvents(SDL_Event *event) {} virtual void preprocessEvents(SDL_Event *event) {}
@ -77,8 +79,7 @@ protected:
virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event); virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event); virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
virtual void fillMouseEvent(Common::Event &event, int x, int y); // overloaded by CE backend virtual void fillMouseEvent(Common::Event &event, int x, int y);
virtual void toggleMouseGrab();
virtual void handleKbdMouse(); virtual void handleKbdMouse();
virtual bool remapKey(SDL_Event &ev, Common::Event &event); virtual bool remapKey(SDL_Event &ev, Common::Event &event);

View file

@ -23,8 +23,10 @@
* *
*/ */
#include "backends/platform/linuxmoto/linuxmoto-sdl.h" #ifdef LINUXMOTO
#include "backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h"
#include "backends/events/linuxmotosdl/linuxmotosdl-events.h"
#include "common/mutex.h" #include "common/mutex.h"
#include "graphics/font.h" #include "graphics/font.h"
#include "graphics/fontman.h" #include "graphics/fontman.h"
@ -33,22 +35,33 @@
#include "graphics/scaler/downscaler.h" #include "graphics/scaler/downscaler.h"
#include "graphics/surface.h" #include "graphics/surface.h"
enum {
GFX_HALF = 12
};
static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{"1x", "Fullscreen", GFX_NORMAL}, {"1x", "Fullscreen", GFX_NORMAL},
{"½x", "Downscale", GFX_HALF}, {"½x", "Downscale", GFX_HALF},
{0, 0, 0} {0, 0, 0}
}; };
LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager() {
const OSystem::GraphicsMode *OSystem_LINUXMOTO::getSupportedGraphicsModes() const { }
LinuxmotoSdlGraphicsManager::~LinuxmotoSdlGraphicsManager() {
}
const OSystem::GraphicsMode *LinuxmotoSdlGraphicsManager::getSupportedGraphicsModes() const {
return s_supportedGraphicsModes; return s_supportedGraphicsModes;
} }
int OSystem_LINUXMOTO::getDefaultGraphicsMode() const { int LinuxmotoSdlGraphicsManager::getDefaultGraphicsMode() const {
return GFX_NORMAL; return GFX_NORMAL;
} }
bool OSystem_LINUXMOTO::setGraphicsMode(int mode) { bool LinuxmotoSdlGraphicsManager::setGraphicsMode(int mode) {
Common::StackLock lock(_graphicsMutex); Common::StackLock lock(_graphicsMutex);
assert(_transactionMode == kTransactionActive); assert(_transactionMode == kTransactionActive);
@ -82,7 +95,7 @@ bool OSystem_LINUXMOTO::setGraphicsMode(int mode) {
return true; return true;
} }
void OSystem_LINUXMOTO::setGraphicsModeIntern() { void LinuxmotoSdlGraphicsManager::setGraphicsModeIntern() {
Common::StackLock lock(_graphicsMutex); Common::StackLock lock(_graphicsMutex);
ScalerProc *newScalerProc = 0; ScalerProc *newScalerProc = 0;
@ -112,7 +125,7 @@ void OSystem_LINUXMOTO::setGraphicsModeIntern() {
} }
void OSystem_LINUXMOTO::initSize(uint w, uint h) { void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) {
assert(_transactionMode == kTransactionActive); assert(_transactionMode == kTransactionActive);
// Avoid redundant res changes // Avoid redundant res changes
@ -125,13 +138,13 @@ void OSystem_LINUXMOTO::initSize(uint w, uint h) {
if (w > 320 || h > 240) { if (w > 320 || h > 240) {
setGraphicsMode(GFX_HALF); setGraphicsMode(GFX_HALF);
setGraphicsModeIntern(); setGraphicsModeIntern();
toggleMouseGrab(); ((LinuxmotoSdlEventManager *)g_system->getEventManager())->toggleMouseGrab();
} }
_transactionDetails.sizeChanged = true; _transactionDetails.sizeChanged = true;
} }
bool OSystem_LINUXMOTO::loadGFXMode() { bool LinuxmotoSdlGraphicsManager::loadGFXMode() {
printf("Game ScreenMode = %d*%d\n",_videoMode.screenWidth, _videoMode.screenHeight); printf("Game ScreenMode = %d*%d\n",_videoMode.screenWidth, _videoMode.screenHeight);
if (_videoMode.screenWidth > 320 || _videoMode.screenHeight > 240) { if (_videoMode.screenWidth > 320 || _videoMode.screenHeight > 240) {
_videoMode.aspectRatioCorrection = false; _videoMode.aspectRatioCorrection = false;
@ -157,10 +170,10 @@ bool OSystem_LINUXMOTO::loadGFXMode() {
_videoMode.hardwareHeight = effectiveScreenHeight(); _videoMode.hardwareHeight = effectiveScreenHeight();
} }
return OSystem_SDL::loadGFXMode(); return SdlGraphicsManager::loadGFXMode();
} }
void OSystem_LINUXMOTO::drawMouse() { void LinuxmotoSdlGraphicsManager::drawMouse() {
if (!_mouseVisible || !_mouseSurface) { if (!_mouseVisible || !_mouseSurface) {
_mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
return; return;
@ -226,7 +239,7 @@ void OSystem_LINUXMOTO::drawMouse() {
addDirtyRect(dst.x, dst.y, dst.w, dst.h, true); addDirtyRect(dst.x, dst.y, dst.w, dst.h, true);
} }
void OSystem_LINUXMOTO::undrawMouse() { void LinuxmotoSdlGraphicsManager::undrawMouse() {
const int x = _mouseBackup.x; const int x = _mouseBackup.x;
const int y = _mouseBackup.y; const int y = _mouseBackup.y;
@ -244,13 +257,13 @@ void OSystem_LINUXMOTO::undrawMouse() {
} }
} }
void OSystem_LINUXMOTO::internUpdateScreen() { void LinuxmotoSdlGraphicsManager::internUpdateScreen() {
SDL_Surface *srcSurf, *origSurf; SDL_Surface *srcSurf, *origSurf;
int height, width; int height, width;
ScalerProc *scalerProc; ScalerProc *scalerProc;
int scale1; int scale1;
#if defined (DEBUG) && ! defined(_WIN32_WCE) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?) #if defined (DEBUG) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?)
assert(_hwscreen != NULL); assert(_hwscreen != NULL);
assert(_hwscreen->map->sw_data != NULL); assert(_hwscreen->map->sw_data != NULL);
#endif #endif
@ -443,28 +456,43 @@ void OSystem_LINUXMOTO::internUpdateScreen() {
_mouseNeedsRedraw = false; _mouseNeedsRedraw = false;
} }
void OSystem_LINUXMOTO::showOverlay() { void LinuxmotoSdlGraphicsManager::showOverlay() {
if (_videoMode.mode == GFX_HALF) { if (_videoMode.mode == GFX_HALF) {
_mouseCurState.x = _mouseCurState.x / 2; _mouseCurState.x = _mouseCurState.x / 2;
_mouseCurState.y = _mouseCurState.y / 2; _mouseCurState.y = _mouseCurState.y / 2;
} }
OSystem_SDL::showOverlay(); SdlGraphicsManager::showOverlay();
} }
void OSystem_LINUXMOTO::hideOverlay() { void LinuxmotoSdlGraphicsManager::hideOverlay() {
if (_videoMode.mode == GFX_HALF) { if (_videoMode.mode == GFX_HALF) {
_mouseCurState.x = _mouseCurState.x * 2; _mouseCurState.x = _mouseCurState.x * 2;
_mouseCurState.y = _mouseCurState.y * 2; _mouseCurState.y = _mouseCurState.y * 2;
} }
OSystem_SDL::hideOverlay(); SdlGraphicsManager::hideOverlay();
} }
void OSystem_LINUXMOTO::warpMouse(int x, int y) { void LinuxmotoSdlGraphicsManager::warpMouse(int x, int y) {
if (_mouseCurState.x != x || _mouseCurState.y != y) { if (_mouseCurState.x != x || _mouseCurState.y != y) {
if (_videoMode.mode == GFX_HALF && !_overlayVisible) { if (_videoMode.mode == GFX_HALF && !_overlayVisible) {
x = x / 2; x = x / 2;
y = y / 2; y = y / 2;
} }
} }
OSystem_SDL::warpMouse(x, y); SdlGraphicsManager::warpMouse(x, y);
} }
void LinuxmotoSdlGraphicsManager::adjustMouseEvent(Common::Event &event) {
if (!_overlayVisible) {
if (_videoMode.mode == GFX_HALF) {
event.mouse.x *= 2;
event.mouse.y *= 2;
}
event.mouse.x /= _videoMode.scaleFactor;
event.mouse.y /= _videoMode.scaleFactor;
if (_videoMode.aspectRatioCorrection)
event.mouse.y = aspect2Real(event.mouse.y);
}
}
#endif

View file

@ -0,0 +1,51 @@
/* 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.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef BACKENDS_GRAPHICS_SDL_LINUXMOTO_H
#define BACKENDS_GRAPHICS_SDL_LINUXMOTO_H
#include "backends/graphics/sdl/sdl-graphics.h"
class LinuxmotoSdlGraphicsManager : public SdlGraphicsManager {
public:
LinuxmotoSdlGraphicsManager();
virtual ~LinuxmotoSdlGraphicsManager();
virtual void initSize(uint w, uint h);
virtual void setGraphicsModeIntern();
virtual bool setGraphicsMode(int mode);
virtual void internUpdateScreen();
virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
virtual int getDefaultGraphicsMode() const;
virtual bool loadGFXMode();
virtual void drawMouse();
virtual void undrawMouse();
virtual void showOverlay();
virtual void hideOverlay();
virtual void warpMouse(int x, int y);
virtual void adjustMouseEvent(Common::Event &event);
};
#endif

View file

@ -35,7 +35,8 @@
SdlMixerManager::SdlMixerManager() SdlMixerManager::SdlMixerManager()
: :
_mixer(0) { _mixer(0),
_audioSuspended(false) {
} }
@ -120,4 +121,20 @@ void SdlMixerManager::sdlCallback(void *this_, byte *samples, int len) {
manager->callbackHandler(samples, len); manager->callbackHandler(samples, len);
} }
void SdlMixerManager::suspendAudio() {
SDL_CloseAudio();
_audioSuspended = true;
}
int SdlMixerManager::resumeAudio() {
if (!_audioSuspended)
return -2;
if (SDL_OpenAudio(&_obtainedRate, NULL) < 0){
return -1;
}
SDL_PauseAudio(0);
_audioSuspended = false;
return 0;
}
#endif #endif

View file

@ -43,9 +43,14 @@ public:
Audio::Mixer *getMixer() { return (Audio::Mixer *)_mixer; } Audio::Mixer *getMixer() { return (Audio::Mixer *)_mixer; }
// Used by LinuxMoto Port
virtual void suspendAudio();
virtual int resumeAudio();
protected: protected:
Audio::MixerImpl *_mixer; Audio::MixerImpl *_mixer;
SDL_AudioSpec _obtainedRate; SDL_AudioSpec _obtainedRate;
bool _audioSuspended;
virtual SDL_AudioSpec getAudioSpec(); virtual SDL_AudioSpec getAudioSpec();
virtual void startAudio(); virtual void startAudio();

View file

@ -26,19 +26,20 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/system.h" #include "common/system.h"
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include "backends/platform/linuxmoto/linuxmoto-sdl.h" #include "backends/platform/linuxmoto/linuxmoto-sdl.h"
#include "base/main.h" #include "base/main.h"
#include "base/internal_version.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Create our OSystem instance
g_system = new OSystem_LINUXMOTO(); g_system = new OSystem_LINUXMOTO();
assert(g_system); assert(g_system);
// Invoke the actual ScummVM main entry point: // Invoke the actual ScummVM main entry point:
int res = scummvm_main(argc, argv); int res = scummvm_main(argc, argv);
g_system->quit(); // TODO: Consider removing / replacing this!
// Free OSystem
delete (OSystem_LINUXMOTO *)g_system;
return res; return res;
} }

View file

@ -25,44 +25,17 @@
#include "backends/platform/linuxmoto/linuxmoto-sdl.h" #include "backends/platform/linuxmoto/linuxmoto-sdl.h"
void OSystem_LINUXMOTO::preprocessEvents(SDL_Event *event) { #include "backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h"
if (event->type == SDL_ACTIVEEVENT) { #include "backends/events/linuxmotosdl/linuxmotosdl-events.h"
if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain) {
suspendAudio();
for (;;) {
if (!SDL_WaitEvent(event)) {
SDL_Delay(10);
continue;
}
if (event->type == SDL_QUIT)
return;
if (event->type != SDL_ACTIVEEVENT)
continue;
if (event->active.state == SDL_APPINPUTFOCUS && event->active.gain) {
resumeAudio();
return;
}
}
}
}
}
void OSystem_LINUXMOTO::suspendAudio() { void OSystem_LINUXMOTO::initBackend() {
SDL_CloseAudio(); // Create the backend custom managers
_audioSuspended = true; if (_eventsManager == 0)
} _eventsManager = new LinuxmotoSdlEventManager();
int OSystem_LINUXMOTO::resumeAudio() { if (_graphicsManager == 0)
if (!_audioSuspended) _graphicsManager = new LinuxmotoSdlGraphicsManager();
return -2;
if (SDL_OpenAudio(&_obtainedRate, NULL) < 0){
return -1;
}
SDL_PauseAudio(0);
_audioSuspended = false;
return 0;
}
void OSystem_LINUXMOTO::setupMixer() { // Call parent implementation of this method
OSystem_SDL::setupMixer(); OSystem_POSIX::initBackend();
} }

View file

@ -23,43 +23,17 @@
* *
*/ */
#ifndef LINUXMOTO_SDL #ifndef PLATFORM_SDL_LINUXMOTO_H
#define LINUXMOTO_SDL #define PLATFORM_SDL_LINUXMOTO_H
#include "backends/platform/sdl/sdl.h" #include "backends/platform/sdl/posix/posix.h"
// FIXME: For now keep hacks in this header to save polluting the SDL backend. class OSystem_LINUXMOTO : public OSystem_POSIX {
enum {
GFX_HALF = 12
};
class OSystem_LINUXMOTO : public OSystem_SDL {
private:
bool _audioSuspended;
public: public:
/* Graphics */ virtual void initBackend();
void initSize(uint w, uint h);
void setGraphicsModeIntern();
bool setGraphicsMode(int mode);
void internUpdateScreen();
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
bool setGraphicsMode(const char *name);
int getDefaultGraphicsMode() const;
bool loadGFXMode();
void drawMouse();
void undrawMouse();
void showOverlay();
void hideOverlay();
/* Event Stuff */ // FIXME: This just calls parent methods, is it needed?
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
virtual void preprocessEvents(SDL_Event *event);
virtual void setupMixer();
virtual Common::HardwareKeySet *getHardwareKeySet(); virtual Common::HardwareKeySet *getHardwareKeySet();
void fillMouseEvent(Common::Event&, int, int);
void suspendAudio();
int resumeAudio();
void warpMouse(int, int);
}; };
#endif #endif

View file

@ -1,8 +1,6 @@
MODULE := backends/platform/linuxmoto MODULE := backends/platform/linuxmoto
MODULE_OBJS := \ MODULE_OBJS := \
linuxmoto-events.o \
linuxmoto-graphics.o \
linuxmoto-main.o \ linuxmoto-main.o \
linuxmoto-sdl.o \ linuxmoto-sdl.o \
hardwarekeys.o hardwarekeys.o

View file

@ -269,3 +269,8 @@ Audio::Mixer *OSystem_SDL::getMixer() {
assert(_mixerManager); assert(_mixerManager);
return _mixerManager->getMixer(); return _mixerManager->getMixer();
} }
SdlMixerManager *OSystem_SDL::getMixerManager() {
assert(_mixerManager);
return _mixerManager;
}

View file

@ -71,6 +71,9 @@ public:
// Get the Graphics Manager instance, used by other managers // Get the Graphics Manager instance, used by other managers
virtual SdlGraphicsManager *getGraphicsManager(); virtual SdlGraphicsManager *getGraphicsManager();
// Get the Sdl Mixer Manager instance (not the Audio::Mixer)
virtual SdlMixerManager *getMixerManager();
protected: protected:
bool _inited; bool _inited;
bool _initedSDL; bool _initedSDL;