LAB: Call checkRoomMusic() when changing a room

This commit is contained in:
Filippos Karapetis 2016-01-14 02:06:10 +02:00
parent 374a76c89f
commit b61ade788e
6 changed files with 12 additions and 17 deletions

View file

@ -26,6 +26,7 @@
#include "lab/console.h" #include "lab/console.h"
#include "lab/dispman.h" #include "lab/dispman.h"
#include "lab/eventman.h" #include "lab/eventman.h"
#include "lab/music.h"
#include "lab/processroom.h" #include "lab/processroom.h"
#include "lab/resource.h" #include "lab/resource.h"
@ -49,6 +50,7 @@ bool Console::Cmd_Scene(int argc, const char **argv) {
} }
_vm->_roomNum = atoi(argv[1]); _vm->_roomNum = atoi(argv[1]);
_vm->_music->checkRoomMusic(1, _vm->_roomNum);
_vm->_curFileName = " "; _vm->_curFileName = " ";
_vm->_closeDataPtr = nullptr; _vm->_closeDataPtr = nullptr;
_vm->_mainDisplay = true; _vm->_mainDisplay = true;

View file

@ -399,7 +399,6 @@ void LabEngine::mainGameLoop() {
// Since the intro hasn't been shown, init the background music here // Since the intro hasn't been shown, init the background music here
_music->resetMusic(false); _music->resetMusic(false);
_music->checkRoomMusic();
} }
uint16 curInv = kItemMap; uint16 curInv = kItemMap;
@ -480,7 +479,6 @@ void LabEngine::mainGameLoop() {
if (!curMsg) { if (!curMsg) {
// Does music load and next animation frame when you've run out of messages // Does music load and next animation frame when you've run out of messages
gotMessage = false; gotMessage = false;
_music->checkRoomMusic();
updateEvents(); updateEvents();
_anim->diffNextFrame(); _anim->diffNextFrame();

View file

@ -44,7 +44,6 @@ namespace Lab {
Music::Music(LabEngine *vm) : _vm(vm) { Music::Music(LabEngine *vm) : _vm(vm) {
_musicFile = nullptr; _musicFile = nullptr;
_curRoomMusic = 1;
_storedPos = 0; _storedPos = 0;
} }
@ -152,18 +151,13 @@ void Music::resetMusic(bool seektoStoredPos) {
changeMusic("Music:BackGround", false, seektoStoredPos); changeMusic("Music:BackGround", false, seektoStoredPos);
} }
void Music::checkRoomMusic() { void Music::checkRoomMusic(uint16 prevRoom, uint16 newRoom) {
if ((_curRoomMusic == _vm->_roomNum) || !_musicFile) if (newRoom == CLOWNROOM)
return;
if (_vm->_roomNum == CLOWNROOM)
changeMusic("Music:Laugh", true, false); changeMusic("Music:Laugh", true, false);
else if (_vm->_roomNum == DIMROOM) else if (newRoom == DIMROOM)
changeMusic("Music:Rm81", true, false); changeMusic("Music:Rm81", true, false);
else if (_curRoomMusic == CLOWNROOM || _curRoomMusic == DIMROOM) else if (prevRoom == CLOWNROOM || prevRoom == DIMROOM)
resetMusic(true); resetMusic(true);
_curRoomMusic = _vm->_roomNum;
} }
void Music::freeMusic() { void Music::freeMusic() {

View file

@ -50,7 +50,6 @@ private:
LabEngine *_vm; LabEngine *_vm;
Common::File *_musicFile; Common::File *_musicFile;
uint16 _curRoomMusic;
uint32 _storedPos; uint32 _storedPos;
Audio::SoundHandle _musicHandle; Audio::SoundHandle _musicHandle;
@ -72,7 +71,7 @@ public:
/** /**
* Checks the music that should be playing in a particular room. * Checks the music that should be playing in a particular room.
*/ */
void checkRoomMusic(); void checkRoomMusic(uint16 prevRoom, uint16 newRoom);
/** /**
* Frees up the music buffers and closes the file. * Frees up the music buffers and closes the file.

View file

@ -143,8 +143,10 @@ void LabEngine::drawDirection(const CloseData *closePtr) {
uint16 LabEngine::processArrow(uint16 curDirection, uint16 arrow) { uint16 LabEngine::processArrow(uint16 curDirection, uint16 arrow) {
if (arrow == 1) { // Forward if (arrow == 1) { // Forward
uint16 room = _rooms[_roomNum]._doors[curDirection]; uint16 room = _rooms[_roomNum]._doors[curDirection];
if (room != 0) if (room != 0) {
_music->checkRoomMusic(_roomNum, room);
_roomNum = room; _roomNum = room;
}
return curDirection; return curDirection;
} else if (arrow == 0) { // Left } else if (arrow == 0) { // Left
@ -327,6 +329,7 @@ void LabEngine::doActions(const ActionList &actionList) {
break; break;
} }
_music->checkRoomMusic(_roomNum, action->_param1);
_roomNum = action->_param1; _roomNum = action->_param1;
_direction = action->_param2 - 1; _direction = action->_param2 - 1;
_closeDataPtr = nullptr; _closeDataPtr = nullptr;

View file

@ -171,6 +171,7 @@ bool LabEngine::loadGame(int slot) {
SaveGameHeader header; SaveGameHeader header;
readSaveGameHeader(file, header); readSaveGameHeader(file, header);
_roomNum = file->readUint16LE(); _roomNum = file->readUint16LE();
_music->checkRoomMusic(1, _roomNum);
_direction = file->readUint16LE(); _direction = file->readUint16LE();
setQuarters(file->readUint16LE()); setQuarters(file->readUint16LE());
@ -233,8 +234,6 @@ bool LabEngine::saveRestoreGame() {
int slot = dialog->runModalWithCurrentTarget(); int slot = dialog->runModalWithCurrentTarget();
if (slot >= 0) { if (slot >= 0) {
isOK = loadGame(slot); isOK = loadGame(slot);
if (isOK)
_music->checkRoomMusic();
} }
delete dialog; delete dialog;
} }