aboutsummaryrefslogtreecommitdiff
path: root/engines/startrek
diff options
context:
space:
mode:
Diffstat (limited to 'engines/startrek')
-rw-r--r--engines/startrek/graphics.h2
-rw-r--r--engines/startrek/sound.cpp107
-rw-r--r--engines/startrek/sound.h20
-rw-r--r--engines/startrek/startrek.cpp26
-rw-r--r--engines/startrek/startrek.h4
-rw-r--r--engines/startrek/text.cpp24
6 files changed, 123 insertions, 60 deletions
diff --git a/engines/startrek/graphics.h b/engines/startrek/graphics.h
index b3c84930a7..efcf27d9f7 100644
--- a/engines/startrek/graphics.h
+++ b/engines/startrek/graphics.h
@@ -147,8 +147,6 @@ public:
void showOptionsMenu(int x, int y);
void showSaveMenu();
void showLoadMenu();
- void setMusicEnabled(bool enabled);
- void setSfxEnabled(bool enabled);
void showQuitGamePrompt(int x, int y);
void showTextConfigurationMenu(bool fromOptionMenu);
diff --git a/engines/startrek/sound.cpp b/engines/startrek/sound.cpp
index ac23cf620e..2871a88613 100644
--- a/engines/startrek/sound.cpp
+++ b/engines/startrek/sound.cpp
@@ -17,6 +17,7 @@
* 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.
+ *
*/
#include "startrek/sound.h"
@@ -59,7 +60,7 @@ Sound::Sound(StarTrekEngine *vm) : _vm(vm) {
loadedSoundData = nullptr;
for (int i=1; i<8; i++) {
- _sfxSlotList.push_back(&_midiSlots[i]);
+ _midiSlotList.push_back(&_midiSlots[i]);
}
if (!SearchMan.hasFile("voc/speech.mrk")) {
@@ -78,37 +79,50 @@ Sound::~Sound() {
}
+/**
+ * Plays a midi track as a sound effect (one of midi slots 1-7)
+ */
void Sound::playMidiTrack(int track) {
if (!_vm->_musicEnabled || !_vm->_musicWorking)
return;
- assert(loadedSoundData != NULL);
-
- debugC(6, kDebugSound, "Playing MIDI track %d", track);
+ assert(loadedSoundData != nullptr);
// Check if a midi slot for this track exists already
for (int i=1; i<8; i++) {
if (_midiSlots[i].track == track) {
+ debugC(6, kDebugSound, "Playing MIDI track %d (slot %d)", track, i);
_midiSlots[i].midiParser->loadMusic(loadedSoundData, sizeof(loadedSoundData));
_midiSlots[i].midiParser->setTrack(track);
// Shift this to the back (most recently used)
- _sfxSlotList.remove(&_midiSlots[i]);
- _sfxSlotList.push_back(&_midiSlots[i]);
+ _midiSlotList.remove(&_midiSlots[i]);
+ _midiSlotList.push_back(&_midiSlots[i]);
return;
}
}
// Take the least recently used slot and use that for the sound effect
- MidiPlaybackSlot *slot = _sfxSlotList.front();
- _sfxSlotList.pop_front();
- _sfxSlotList.push_back(slot);
- slot->track = track;
- slot->midiParser->loadMusic(loadedSoundData, sizeof(loadedSoundData));
- slot->midiParser->setTrack(track);
+ MidiPlaybackSlot *slot = _midiSlotList.front();
+ _midiSlotList.pop_front();
+ _midiSlotList.push_back(slot);
+ playMidiTrackInSlot(slot->slot, track);
}
-void Sound::loadMusicFile(const char *baseSoundName) {
+void Sound::playMidiTrackInSlot(int slot, int track) {
+ assert(loadedSoundData != nullptr);
+ debugC(6, kDebugSound, "Playing MIDI track %d (slot %d)", track, slot);
+
+ clearMidiSlot(slot);
+
+ if (track != -1) {
+ _midiSlots[slot].track = track;
+ _midiSlots[slot].midiParser->loadMusic(loadedSoundData, sizeof(loadedSoundData));
+ _midiSlots[slot].midiParser->setTrack(track);
+ }
+}
+
+void Sound::loadMusicFile(const Common::String &baseSoundName) {
clearAllMidiSlots();
/*
if (_vm->getPlatform() == Common::kPlatformAmiga)
@@ -122,7 +136,20 @@ void Sound::loadMusicFile(const char *baseSoundName) {
loadPCMusicFile(baseSoundName);
}
-void Sound::playSoundEffect(const char *baseSoundName) {
+void Sound::playMidiMusicTracks(int startTrack, int loopTrack) {
+ if (!_vm->_musicWorking || !_vm->_musicEnabled)
+ return;
+
+ if (loopTrack == -3)
+ _loopingMidiTrack = startTrack;
+ else if (loopTrack != -2)
+ _loopingMidiTrack = loopTrack;
+
+ if (startTrack != -2 && _vm->_musicEnabled)
+ playMidiTrackInSlot(0, startTrack);
+}
+
+void Sound::playVoc(const Common::String &baseSoundName) {
/*
if (_vm->getPlatform() == Common::kPlatformAmiga)
playAmigaSoundEffect(baseSoundName);
@@ -130,13 +157,14 @@ void Sound::playSoundEffect(const char *baseSoundName) {
playMacSoundEffect(baseSoundName);
else
*/
- if (scumm_stricmp(baseSoundName+4, "loop") == 0)
- _loopingAudioName = Common::String(baseSoundName);
+ if (baseSoundName.size() == 8 && baseSoundName.hasSuffixIgnoreCase("loop"))
+ _loopingAudioName = baseSoundName;
if (!_vm->_sfxEnabled || !_vm->_sfxWorking)
return;
/*
+ // This is probably just driver initialization stuff...
if (word_5113a == 0)
sub_2aaa3();
*/
@@ -156,7 +184,7 @@ void Sound::playSoundEffect(const char *baseSoundName) {
return;
}
- debugC(3, kDebugSound, "No sound slot to play '%s'", baseSoundName);
+ debugC(3, kDebugSound, "No sound slot to play '%s'", baseSoundName.c_str());
}
void Sound::playSpeech(const Common::String &basename) {
@@ -196,6 +224,17 @@ void Sound::playSpeech(const Common::String &basename) {
_playingSpeech = true;
}
+/**
+ * Called when disabling sfx.
+ */
+void Sound::stopAllVocSounds() {
+ stopPlayingSpeech();
+
+ for (int i = 0; i < MAX_SFX_PLAYING; i++) {
+ _vm->_system->getMixer()->stopHandle(_sfxHandles[i]);
+ }
+}
+
void Sound::stopPlayingSpeech() {
if (_playingSpeech) {
debugC(5, kDebugSound, "Canceled speech playback");
@@ -205,8 +244,40 @@ void Sound::stopPlayingSpeech() {
}
+void Sound::setMusicEnabled(bool enable) {
+ if (!_vm->_musicWorking || _vm->_musicEnabled == enable)
+ return;
+
+ _vm->_musicEnabled = enable;
+
+ if (enable)
+ playMidiMusicTracks(_loopingMidiTrack, _loopingMidiTrack);
+ else
+ clearMidiSlot(0);
+}
+
+void Sound::setSfxEnabled(bool enable) {
+ if (!_vm->_sfxWorking || _vm->_sfxEnabled == enable)
+ return;
+
+ _vm->_sfxEnabled = enable;
+
+ if (!enable) {
+ for (int i = 1; i < 8; i++)
+ clearMidiSlot(i);
+ }
+
+ if (!enable) {
+ stopAllVocSounds();
+ }
+ else if (!_loopingAudioName.empty()) {
+ playVoc(_loopingAudioName);
+ }
+}
+
+
// XMIDI or SM sound
-void Sound::loadPCMusicFile(const char *baseSoundName) {
+void Sound::loadPCMusicFile(const Common::String &baseSoundName) {
Common::String soundName = baseSoundName;
soundName += '.';
diff --git a/engines/startrek/sound.h b/engines/startrek/sound.h
index a9116627d5..2caa1d0010 100644
--- a/engines/startrek/sound.h
+++ b/engines/startrek/sound.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL: https://scummvm-startrek.googlecode.com/svn/trunk/sound.h $
- * $Id: sound.h 15 2010-06-27 06:13:42Z clone2727 $
- *
*/
#ifndef STARTREK_SOUND_H
@@ -41,7 +38,7 @@ namespace StarTrek {
class StarTrekEngine;
-const int MAX_LOADED_SFX_FILES = 8;
+// Max # of VOC files that can play at once
const int MAX_SFX_PLAYING = 4;
struct MidiPlaybackSlot {
@@ -57,24 +54,29 @@ public:
~Sound();
void playMidiTrack(int track);
-
- void loadMusicFile(const char *baseSoundName);
- void playSoundEffect(const char *baseSoundName);
+ void playMidiTrackInSlot(int slot, int track);
+ void loadMusicFile(const Common::String &baseSoundName);
+ void playMidiMusicTracks(int startTrack, int loopTrack);
+ void playVoc(const Common::String &baseSoundName);
void playSpeech(const Common::String &basename);
+ void stopAllVocSounds();
void stopPlayingSpeech();
+ void setMusicEnabled(bool enable);
+ void setSfxEnabled(bool enable);
private:
StarTrekEngine *_vm;
Audio::SoundHandle *_soundHandle;
- void loadPCMusicFile(const char *baseSoundName);
+ void loadPCMusicFile(const Common::String &baseSoundName);
void clearMidiSlot(int slot);
void clearAllMidiSlots();
// MIDI-Related Variables
MidiDriver *_midiDriver;
MidiPlaybackSlot _midiSlots[8]; // 0 is for music; 1-7 are for sfx
- Common::List<MidiPlaybackSlot*> _sfxSlotList; // Sorts midi slots by most recently used
+ Common::List<MidiPlaybackSlot*> _midiSlotList; // Sorts midi slots by most recently used
+ int _loopingMidiTrack;
byte *loadedSoundData;
uint32 _midiDevice;
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 82df4beac1..40fa8d76da 100644
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -81,7 +81,7 @@ Common::Error StarTrekEngine::run() {
assert(_macResFork->hasDataFork() && _macResFork->hasResFork());
}
- initGraphics(320, 200);
+ initGraphics(SCREEN_WIDTH, SCREEN_HEIGHT);
initializeEventsAndMouse();
@@ -199,49 +199,49 @@ void StarTrekEngine::pollSystemEvents() {
void StarTrekEngine::playSoundEffectIndex(int index) {
switch(index) {
case 0x04:
- _sound->playSoundEffect("tricorde");
+ _sound->playVoc("tricorde");
break;
case 0x05:
- _sound->playSoundEffect("STDOOR1");
+ _sound->playVoc("STDOOR1");
break;
case 0x06:
- _sound->playSoundEffect("PHASSHOT");
+ _sound->playVoc("PHASSHOT");
break;
case 0x07:
_sound->playMidiTrack(index);
break;
case 0x08:
- _sound->playSoundEffect("TRANSDEM");
+ _sound->playVoc("TRANSDEM");
break;
case 0x09:
- _sound->playSoundEffect("TRANSMAT");
+ _sound->playVoc("TRANSMAT");
break;
case 0x0a:
- _sound->playSoundEffect("TRANSENE");
+ _sound->playVoc("TRANSENE");
break;
case 0x10: // Menu selection sound
_sound->playMidiTrack(index);
break;
case 0x22:
- _sound->playSoundEffect("HAILING");
+ _sound->playVoc("HAILING");
break;
case 0x24:
- _sound->playSoundEffect("PHASSHOT");
+ _sound->playVoc("PHASSHOT");
break;
case 0x25:
- _sound->playSoundEffect("PHOTSHOT");
+ _sound->playVoc("PHOTSHOT");
break;
case 0x26:
- _sound->playSoundEffect("HITSHIEL");
+ _sound->playVoc("HITSHIEL");
break;
case 0x27:
_sound->playMidiTrack(index);
break;
case 0x28:
- _sound->playSoundEffect("REDALERT");
+ _sound->playVoc("REDALERT");
break;
case 0x29:
- _sound->playSoundEffect("WARP");
+ _sound->playVoc("WARP");
break;
default:
break;
diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h
index 0453c6af7c..5e81f77a26 100644
--- a/engines/startrek/startrek.h
+++ b/engines/startrek/startrek.h
@@ -164,11 +164,11 @@ public:
bool _inQuitGameMenu;
-private:
Graphics *_gfx;
Sound *_sound;
- Common::MacResManager *_macResFork;
+private:
+ Common::MacResManager *_macResFork;
Room *_room;
};
diff --git a/engines/startrek/text.cpp b/engines/startrek/text.cpp
index e9c22d4f4c..9f1285b4d6 100644
--- a/engines/startrek/text.cpp
+++ b/engines/startrek/text.cpp
@@ -816,7 +816,7 @@ void Graphics::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
SharedPtr<FileStream> stream = _vm->openFile(mnuFilename + ".MNU");
_activeMenu->menuFile = stream;
- _activeMenu->numButtons = _activeMenu->menuFile->size()/16;
+ _activeMenu->numButtons = _activeMenu->menuFile->size() / 16;
for (int i = 0; i < _activeMenu->numButtons; i++) {
memset(&_activeMenu->sprites[i], 0, sizeof(Sprite));
@@ -824,9 +824,9 @@ void Graphics::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
_activeMenu->sprites[i].drawMode = 2;
char bitmapBasename[11];
- stream->seek(i*16, SEEK_SET);
+ stream->seek(i * 16, SEEK_SET);
stream->read(bitmapBasename, 10);
- for (int j=0; j<10; j++) {
+ for (int j = 0; j < 10; j++) {
if (bitmapBasename[j] == ' ')
bitmapBasename[j] = '\0';
}
@@ -840,7 +840,7 @@ void Graphics::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
_activeMenu->sprites[i].field6 = 8;
}
- if (_activeMenu->retvals[_activeMenu->numButtons-1] == 0) {
+ if (_activeMenu->retvals[_activeMenu->numButtons - 1] == 0) {
// Set default retvals for buttons
for (int i = 0; i < _activeMenu->numButtons; i++)
_activeMenu->retvals[i] = i;
@@ -1065,16 +1065,16 @@ void Graphics::showOptionsMenu(int x, int y) {
showLoadMenu();
break;
case 2: // Enable music
- setMusicEnabled(true);
+ _vm->_sound->setMusicEnabled(true);
break;
case 3: // Disable music
- setMusicEnabled(false);
+ _vm->_sound->setMusicEnabled(false);
break;
case 4: // Enable sfx
- setSfxEnabled(true);
+ _vm->_sound->setSfxEnabled(true);
break;
case 5: // Disable sfx
- setSfxEnabled(false);
+ _vm->_sound->setSfxEnabled(false);
break;
case 6: // Quit
showQuitGamePrompt(20, 20);
@@ -1095,14 +1095,6 @@ void Graphics::showLoadMenu() {
// TODO
}
-void Graphics::setMusicEnabled(bool enabled) {
- // TODO
-}
-
-void Graphics::setSfxEnabled(bool enabled) {
- // TODO
-}
-
void Graphics::showQuitGamePrompt(int x, int y) {
const char *options[] = {
"Quit Game",