Implemented GPL2 commands for music.

Debugged everything.

svn-id: r45330
This commit is contained in:
Robert Špalek 2009-10-22 07:34:43 +00:00
parent 93517e7649
commit 819449d099
5 changed files with 44 additions and 19 deletions

View File

@ -1009,7 +1009,8 @@ void Game::loadRoom(int roomNum) {
roomReader.readUint16LE(); // Program length, not used
roomReader.readUint32LE(); // Pointer to room title, not used
_currentRoom._music = roomReader.readByte();
// Music will be played by the GPL2 command startMusic when needed.
setMusicTrack(roomReader.readByte());
int mapID = roomReader.readByte() - 1;
loadWalkingMap(mapID);
@ -1044,7 +1045,7 @@ void Game::loadRoom(int roomNum) {
_currentRoom._escRoom = roomReader.readByte() - 1;
_currentRoom._numGates = roomReader.readByte();
debugC(4, kDraciLogicDebugLevel, "Music: %d", _currentRoom._music);
debugC(4, kDraciLogicDebugLevel, "Music: %d", getMusicTrack());
debugC(4, kDraciLogicDebugLevel, "Map: %d", mapID);
debugC(4, kDraciLogicDebugLevel, "Palette: %d", _currentRoom._palette);
debugC(4, kDraciLogicDebugLevel, "Overlays: %d", _currentRoom._numOverlays);
@ -1123,12 +1124,6 @@ void Game::loadRoom(int roomNum) {
Animation *map = _vm->_anims->addAnimation(kWalkingMapOverlay, 255, false);
map->addFrame(ov, NULL);
if (_currentRoom._music) {
_vm->_music->playSMF(_currentRoom._music, true);
} else {
_vm->_music->stop();
}
}
int Game::loadAnimation(uint animNum, uint z) {
@ -1430,6 +1425,14 @@ double Game::getPersStep() const {
return _currentRoom._persStep;
}
int Game::getMusicTrack() const {
return _currentRoom._music;
}
void Game::setMusicTrack(int num) {
_currentRoom._music = num;
}
int Game::getRoomNum() const {
return _currentRoom._roomNum;
}

View File

@ -301,6 +301,8 @@ public:
double getPers0() const;
double getPersStep() const;
int getMusicTrack() const;
void setMusicTrack(int num);
int getItemStatus(int itemID) const;
void setItemStatus(int itemID, int status);

View File

@ -43,6 +43,10 @@ MusicPlayer::MusicPlayer(MidiDriver *driver, const char *pathMask) : _parser(0),
this->open();
_smfParser = MidiParser::createParser_SMF();
_midiMusicData = NULL;
// TODO: Load cmf.ins with the instrument table. It seems that an
// interface for such an operation is supported for Adlib. Maybe for
// this card, setting instruments is necessary.
}
MusicPlayer::~MusicPlayer() {
@ -224,14 +228,12 @@ void MusicPlayer::syncVolume() {
int volume = ConfMan.getInt("music_volume");
debugC(2, kDraciSoundDebugLevel, "Syncing music volume to %d", volume);
setVolume(volume);
// TODO: doesn't work in the beginning when no music is playing yet.
// It goes through all active channels (= none) and stops. Only after
// actual instruments have played in the channels, this has an effect.
// As a consequence, music is very loud in the beginning until Ctrl-F5
// is pressed for the first time.
}
// TODO:
// + volume support
// - bindings to GPL2 scripting
// - load cmf.ins
// - enable Adlib
// + resuming after configuration
// + error handling
} // End of namespace Draci

View File

@ -73,9 +73,9 @@ void Script::setupCommandList() {
{ 16, 1, "RepaintInventory", 0, { 0 }, NULL }, // not used in the original game files
{ 16, 2, "ExitInventory", 0, { 0 }, NULL }, // not used in the original game files
{ 17, 1, "ExitMap", 0, { 0 }, NULL }, // not used in the original game files
{ 18, 1, "LoadMusic", 1, { 2 }, NULL },
{ 18, 2, "StartMusic", 0, { 0 }, NULL },
{ 18, 3, "StopMusic", 0, { 0 }, NULL },
{ 18, 1, "LoadMusic", 1, { 2 }, &Script::loadMusic },
{ 18, 2, "StartMusic", 0, { 0 }, &Script::startMusic },
{ 18, 3, "StopMusic", 0, { 0 }, &Script::stopMusic },
{ 18, 4, "FadeOutMusic", 1, { 1 }, NULL },
{ 18, 5, "FadeInMusic", 1, { 1 }, NULL },
{ 19, 1, "Mark", 0, { 0 }, &Script::mark },
@ -521,6 +521,21 @@ void Script::c_Let(Common::Queue<int> &params) {
_vm->_game->setVariable(var, value);
}
void Script::loadMusic(Common::Queue<int> &params) {
int track = params.pop();
_vm->_game->setMusicTrack(track);
}
void Script::startMusic(Common::Queue<int> &params) {
// If already playing this track, nothing happens.
_vm->_music->playSMF(_vm->_game->getMusicTrack(), true);
}
void Script::stopMusic(Common::Queue<int> &params) {
_vm->_music->stop();
_vm->_game->setMusicTrack(0);
}
void Script::mark(Common::Queue<int> &params) {
_vm->_game->setMarkedAnimationIndex(_vm->_anims->getLastIndex());
}

View File

@ -109,6 +109,9 @@ private:
void c_Let(Common::Queue<int> &params);
void load(Common::Queue<int> &params);
void start(Common::Queue<int> &params);
void loadMusic(Common::Queue<int> &params);
void startMusic(Common::Queue<int> &params);
void stopMusic(Common::Queue<int> &params);
void mark(Common::Queue<int> &params);
void release(Common::Queue<int> &params);
void icoStat(Common::Queue<int> &params);