aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorAlejandro Marzini2010-06-09 20:09:57 +0000
committerAlejandro Marzini2010-06-09 20:09:57 +0000
commite991cd8c53ad21af037df1e0a16816aeea2d0fe2 (patch)
treef647f636fc3898c150db61de50c3522056a65d17 /backends
parent4177a1e16df7712c081e41a8eabf0b7d4694230b (diff)
downloadscummvm-rg350-e991cd8c53ad21af037df1e0a16816aeea2d0fe2.tar.gz
scummvm-rg350-e991cd8c53ad21af037df1e0a16816aeea2d0fe2.tar.bz2
scummvm-rg350-e991cd8c53ad21af037df1e0a16816aeea2d0fe2.zip
- Revised abstract AudioCDManager.
- Removed AudioCDManager Singleton, and changed code for using AudioCDManager in OSystem. - Added initialization code for new AudioCDManager in BaseBackend and OSystem_SDL. svn-id: r49548
Diffstat (limited to 'backends')
-rw-r--r--backends/audiocd/abstract-audiocd.h8
-rw-r--r--backends/audiocd/default/default-audiocd.h5
-rw-r--r--backends/base-backend.cpp8
-rw-r--r--backends/base-backend.h3
-rw-r--r--backends/platform/sdl/sdl.cpp112
-rw-r--r--backends/platform/sdl/sdl.h24
6 files changed, 39 insertions, 121 deletions
diff --git a/backends/audiocd/abstract-audiocd.h b/backends/audiocd/abstract-audiocd.h
index 7d61c0092b..07d428fce6 100644
--- a/backends/audiocd/abstract-audiocd.h
+++ b/backends/audiocd/abstract-audiocd.h
@@ -40,11 +40,19 @@ public:
int numLoops;
};
+ // Emulated CD functions, engines should call these functions
virtual void play(int track, int numLoops, int startFrame, int duration, bool only_emulate = false) = 0;
virtual void stop() = 0;
virtual bool isPlaying() const = 0;
virtual void update() = 0;
virtual Status getStatus() const = 0;
+
+ // Real CD functions. Let Subclasses implement the real code
+ virtual bool openCD(int drive) { return false; }
+ virtual void updateCD() {}
+ virtual bool pollCD() const { return false; }
+ virtual void playCD(int track, int num_loops, int start_frame, int duration) {}
+ virtual void stopCD() {}
};
#endif
diff --git a/backends/audiocd/default/default-audiocd.h b/backends/audiocd/default/default-audiocd.h
index 5125f4e4e8..af75572788 100644
--- a/backends/audiocd/default/default-audiocd.h
+++ b/backends/audiocd/default/default-audiocd.h
@@ -34,22 +34,19 @@ public:
DefaultAudioCDManager();
virtual ~DefaultAudioCDManager() {}
- // Emulated CD functions, engines should call this functions
void play(int track, int numLoops, int startFrame, int duration, bool only_emulate = false);
void stop();
bool isPlaying() const;
void update();
virtual Status getStatus() const; // Subclasses should override for better status results
-protected:
-
- // Real CD functions. Let Subclasses implement the real code
virtual bool openCD(int drive) { return false; }
virtual void updateCD() {}
virtual bool pollCD() const { return false; }
virtual void playCD(int track, int num_loops, int start_frame, int duration) {}
virtual void stopCD() {}
+protected:
Audio::SoundHandle _handle;
bool _emulating;
diff --git a/backends/base-backend.cpp b/backends/base-backend.cpp
index c06695a727..e5df465fc5 100644
--- a/backends/base-backend.cpp
+++ b/backends/base-backend.cpp
@@ -84,3 +84,11 @@ Common::WriteStream *BaseBackend::createConfigWriteStream() {
return file.createWriteStream();
#endif
}
+
+static DefaultAudioCDManager *s_audiocdManager = 0;
+
+AudioCDManager *BaseBackend::getAudioCD() {
+ if (!s_audiocdManager)
+ s_audiocdManager = new DefaultAudioCDManager();
+ return (AudioCDManager *)s_audiocdManager;
+}
diff --git a/backends/base-backend.h b/backends/base-backend.h
index 3fcca9c3b7..3511226bb9 100644
--- a/backends/base-backend.h
+++ b/backends/base-backend.h
@@ -28,6 +28,7 @@
#include "common/system.h"
#include "backends/events/default/default-events.h"
+#include "backends/audiocd/default/default-audiocd.h"
class BaseBackend : public OSystem, Common::EventSource {
public:
@@ -37,6 +38,8 @@ public:
virtual Common::SeekableReadStream *createConfigReadStream();
virtual Common::WriteStream *createConfigWriteStream();
+
+ virtual AudioCDManager *getAudioCD();
};
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 6f82ede114..c662fed2bf 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -157,6 +157,10 @@ void OSystem_SDL::initBackend() {
_graphicsManager = new SdlGraphicsManager();
}
+ if (_audiocdManager == 0) {
+ _audiocdManager = new SdlAudioCDManager();
+ }
+
#if !defined(MACOSX) && !defined(__SYMBIAN32__)
// Setup a custom program icon.
// Don't set icon on OS X, as we use a nicer external icon there.
@@ -172,7 +176,6 @@ void OSystem_SDL::initBackend() {
OSystem_SDL::OSystem_SDL()
:
- _cdrom(0),
_scrollLock(false),
_joystick(0),
#if MIXER_DOUBLE_BUFFERING
@@ -184,7 +187,8 @@ OSystem_SDL::OSystem_SDL()
_mixer(0),
_timer(0),
_mutexManager(0),
- _graphicsManager(0) {
+ _graphicsManager(0),
+ _audiocdManager(0) {
// reset mouse state
memset(&_km, 0, sizeof(_km));
@@ -384,11 +388,6 @@ bool OSystem_SDL::getFeatureState(Feature f) {
}
void OSystem_SDL::deinit() {
- if (_cdrom) {
- SDL_CDStop(_cdrom);
- SDL_CDClose(_cdrom);
- }
-
if (_joystick)
SDL_JoystickClose(_joystick);
@@ -669,96 +668,6 @@ Audio::Mixer *OSystem_SDL::getMixer() {
}
#pragma mark -
-#pragma mark --- CD Audio ---
-#pragma mark -
-
-bool OSystem_SDL::openCD(int drive) {
- if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
- _cdrom = NULL;
- else {
- _cdrom = SDL_CDOpen(drive);
- // Did it open? Check if _cdrom is NULL
- if (!_cdrom) {
- warning("Couldn't open drive: %s", SDL_GetError());
- } else {
- _cdNumLoops = 0;
- _cdStopTime = 0;
- _cdEndTime = 0;
- }
- }
-
- return (_cdrom != NULL);
-}
-
-void OSystem_SDL::stopCD() { /* Stop CD Audio in 1/10th of a second */
- _cdStopTime = SDL_GetTicks() + 100;
- _cdNumLoops = 0;
-}
-
-void OSystem_SDL::playCD(int track, int num_loops, int start_frame, int duration) {
- if (!num_loops && !start_frame)
- return;
-
- if (!_cdrom)
- return;
-
- if (duration > 0)
- duration += 5;
-
- _cdTrack = track;
- _cdNumLoops = num_loops;
- _cdStartFrame = start_frame;
-
- SDL_CDStatus(_cdrom);
- if (start_frame == 0 && duration == 0)
- SDL_CDPlayTracks(_cdrom, track, 0, 1, 0);
- else
- SDL_CDPlayTracks(_cdrom, track, start_frame, 0, duration);
- _cdDuration = duration;
- _cdStopTime = 0;
- _cdEndTime = SDL_GetTicks() + _cdrom->track[track].length * 1000 / CD_FPS;
-}
-
-bool OSystem_SDL::pollCD() {
- if (!_cdrom)
- return false;
-
- return (_cdNumLoops != 0 && (SDL_GetTicks() < _cdEndTime || SDL_CDStatus(_cdrom) == CD_PLAYING));
-}
-
-void OSystem_SDL::updateCD() {
- if (!_cdrom)
- return;
-
- if (_cdStopTime != 0 && SDL_GetTicks() >= _cdStopTime) {
- SDL_CDStop(_cdrom);
- _cdNumLoops = 0;
- _cdStopTime = 0;
- return;
- }
-
- if (_cdNumLoops == 0 || SDL_GetTicks() < _cdEndTime)
- return;
-
- if (_cdNumLoops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
- // Wait another second for it to be done
- _cdEndTime += 1000;
- return;
- }
-
- if (_cdNumLoops > 0)
- _cdNumLoops--;
-
- if (_cdNumLoops != 0) {
- if (_cdStartFrame == 0 && _cdDuration == 0)
- SDL_CDPlayTracks(_cdrom, _cdTrack, 0, 1, 0);
- else
- SDL_CDPlayTracks(_cdrom, _cdTrack, _cdStartFrame, 0, _cdDuration);
- _cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
- }
-}
-
-#pragma mark -
#pragma mark --- Graphics ---
#pragma mark -
@@ -900,4 +809,13 @@ int OSystem_SDL::getScreenChangeID() const {
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 214a8a988c..ebe8728f51 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -36,6 +36,7 @@
#include "backends/mutex/sdl/sdl-mutex.h"
#include "backends/graphics/sdl/sdl-graphics.h"
+#include "backends/audiocd/sdl/sdl-audiocd.h"
#include "graphics/scaler.h"
@@ -69,6 +70,7 @@ public:
protected:
SdlMutexManager *_mutexManager;
SdlGraphicsManager *_graphicsManager;
+ SdlAudioCDManager *_audiocdManager;
public:
void beginGFXTransaction();
@@ -164,19 +166,6 @@ public:
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
@@ -210,7 +199,6 @@ public:
virtual int getGraphicsMode() const;
virtual void setWindowCaption(const char *caption);
- virtual bool openCD(int drive);
virtual bool hasFeature(Feature f);
virtual void setFeatureState(Feature f, bool enable);
@@ -228,15 +216,12 @@ public:
virtual Common::SeekableReadStream *createConfigReadStream();
virtual Common::WriteStream *createConfigWriteStream();
+ virtual AudioCDManager *getAudioCD();
+
protected:
bool _inited;
SDL_AudioSpec _obtainedRate;
- // CD Audio
- SDL_CD *_cdrom;
- int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration;
- uint32 _cdEndTime, _cdStopTime;
-
// 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.
@@ -277,7 +262,6 @@ protected:
SDL_TimerID _timerID;
Common::TimerManager *_timer;
-protected:
virtual void fillMouseEvent(Common::Event &event, int x, int y); // overloaded by CE backend
void toggleMouseGrab();