synced with scummvm to 2011-Apr-13

This commit is contained in:
Pawel Kolodziejski 2011-04-14 12:41:26 +02:00
parent f0a4299aef
commit 0640dcf2c7
347 changed files with 53648 additions and 8521 deletions

View file

@ -23,239 +23,101 @@
*
*/
#ifndef SDL_COMMON_H
#define SDL_COMMON_H
#ifndef PLATFORM_SDL_H
#define PLATFORM_SDL_H
#if defined(__SYMBIAN32__)
#include <esdl\SDL.h>
#else
#include <SDL.h>
#include "backends/platform/sdl/sdl-sys.h"
#ifdef USE_OPENGL
#include <SDL_opengl.h>
#endif
#endif
#include "backends/base-backend.h"
#include "graphics/scaler.h"
#include "backends/modular-backend.h"
#include "backends/mixer/sdl/sdl-mixer.h"
#include "backends/events/sdl/sdl-events.h"
#include "backends/log/log.h"
namespace Audio {
class MixerImpl;
}
#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
class OSystem_SDL : public BaseBackend {
/**
* Base OSystem class for all SDL ports.
*/
class OSystem_SDL : public ModularBackend {
public:
OSystem_SDL();
virtual ~OSystem_SDL();
/**
* Pre-initialize backend. It should be called after
* instantiating the backend. Early needed managers are
* created here.
*/
virtual void init();
/**
* Get the Mixer Manager instance. Not to confuse with getMixer(),
* that returns Audio::Mixer. The Mixer Manager is a SDL wrapper class
* for the Audio::Mixer. Used by other managers.
*/
virtual SdlMixerManager *getMixerManager();
// Override functions from ModularBackend and OSystem
virtual void initBackend();
// Set the size of the video bitmap.
// Typically, 320x200
virtual void launcherInitSize(uint w, uint h);
virtual byte *setupScreen(int screenW, int screenH, bool fullscreen, bool accel3d);
// 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)
// Get the number of milliseconds since the program was started.
uint32 getMillis();
// Delay for a specified amount of milliseconds
void delayMillis(uint msecs);
// 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 quit();
virtual void fatalError();
// Set function that generates samples
virtual void setupMixer();
static void mixCallback(void *s, byte *samples, int len);
// Logging
virtual void logMessage(LogMessageType::Type type, const char *message);
virtual void closeMixer();
virtual Audio::Mixer *getMixer();
// 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();
// 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 { return _overlayFormat; }
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; }
virtual Common::String getSystemLanguage() const;
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);
virtual void preprocessEvents(SDL_Event *event) {}
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 uint32 getMillis();
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(TimeDate &td) const;
virtual Audio::Mixer *getMixer();
// HACK: Special SDL events types
enum SdlEvent {
kSdlEventExpose = 100,
kSdlEventResize = 101
};
protected:
bool _inited;
SDL_AudioSpec _obtainedRate;
bool _initedSDL;
/**
* Mixer manager that configures and setups SDL for
* the wrapped Audio::Mixer, the true mixer.
*/
SdlMixerManager *_mixerManager;
#ifdef USE_OPENGL
bool _opengl;
#endif
bool _fullscreen;
SDL_Surface *_screen;
/**
* The event source we use for obtaining SDL events.
*/
SdlEventSource *_eventSource;
// overlay
SDL_Surface *_overlayscreen;
bool _overlayVisible;
Graphics::PixelFormat _overlayFormat;
int _overlayWidth, _overlayHeight;
bool _overlayDirty;
int _overlayNumTex;
#ifdef USE_OPENGL
GLuint *_overlayTexIds;
#endif
/**
* Initialze the SDL library.
*/
virtual void initSDL();
void closeOverlay();
/**
* Setup the window icon.
*/
virtual void setupIcon();
// CD Audio
SDL_CD *_cdrom;
int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration;
uint32 _cdEndTime, _cdStopTime;
/**
* Get the file path where the user configuration
* of ScummVM will be saved.
*/
virtual Common::String getDefaultConfigFileName();
// 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;
// Scroll lock state - since SDL doesn't track it
bool _scrollLock;
// joystick
SDL_Joystick *_joystick;
#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;
Common::SaveFileManager *_savefile;
Audio::MixerImpl *_mixer;
SDL_TimerID _timerID;
Common::TimerManager *_timer;
protected:
/** 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();
void setupIcon();
void handleKbdMouse();
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
bool handleScalerHotkeys(const SDL_KeyboardEvent &key);
// Logging
virtual Common::WriteStream *createLogFile() { return 0; }
Backends::Log::Log *_logger;
};
#endif