Skip to content

Commit

Permalink
JADE: Play area background music
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 6, 2019
1 parent 2267cb8 commit e5182af
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/engines/jade/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "src/common/error.h"
#include "src/common/readstream.h"

#include "src/sound/sound.h"
#include "src/sound/xactsoundbank.h"

#include "src/aurora/resman.h"
#include "src/aurora/gff3file.h"

Expand Down Expand Up @@ -81,6 +84,11 @@ void Area::load() {

Aurora::GFF3File sav(_resRef, Aurora::kFileTypeSAV, MKTAG('S', 'A', 'V', ' '));
loadSAV(sav.getTopLevel());

try {
_musicBank.reset(Sound::XACTSoundBank::load("musicbank"));
} catch (...) {
}
}

void Area::clear() {
Expand Down Expand Up @@ -110,6 +118,8 @@ void Area::show() {
GfxMan.unlockFrame();

AreaLayout::show();

playMusic();
}

void Area::hide() {
Expand All @@ -118,6 +128,8 @@ void Area::hide() {

removeFocus();

stopMusic();

GfxMan.lockFrame();

// Hide objects
Expand All @@ -129,9 +141,36 @@ void Area::hide() {
AreaLayout::hide();
}

void Area::playMusic() {
if (!_musicBank || (_ambientMusicState <= 0))
return;

try {
_music = _musicBank->playCue(0, _ambientMusicState, Sound::kSoundTypeMusic);
SoundMan.startChannel(_music);

} catch (...) {
Common::exceptionDispatcherWarning();
}
}

void Area::stopMusic() {
SoundMan.stopChannel(_music);
}

void Area::loadARE(const Aurora::GFF3Struct &are) {
_layout = are.getString("Layout");

if (are.hasField("SoundEnvironment")) {
const Aurora::GFF3List &soundEnvs = are.getList("SoundEnvironment");
if (!soundEnvs.empty() && soundEnvs.front()) {
const Aurora::GFF3Struct &soundEnv = *soundEnvs.front();

_ambientMusicState = soundEnv.getSint("MusicState");
_combatMusicState = soundEnv.getSint("CombatMusicState");
}
}

// Scripts
readScripts(are);
}
Expand Down
17 changes: 17 additions & 0 deletions src/engines/jade/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
#include <list>
#include <map>

#include "src/common/scopedptr.h"
#include "src/common/ptrlist.h"
#include "src/common/mutex.h"

#include "src/sound/types.h"

#include "src/aurora/types.h"

#include "src/events/types.h"
Expand All @@ -40,6 +43,10 @@
#include "src/engines/jade/module.h"
#include "src/engines/jade/object.h"

namespace Sound {
class XACTSoundBank;
}

namespace Engines {

namespace Jade {
Expand All @@ -64,6 +71,11 @@ class Area : public AreaLayout, public Object, public Events::Notifyable {
void show();
void hide();

// Music/Sound

void playMusic();
void stopMusic();

// Events

/** Add a single event for consideration into the area event queue. */
Expand All @@ -86,6 +98,11 @@ class Area : public AreaLayout, public Object, public Events::Notifyable {

Module *_module; ///< The module this area is in.

Common::ScopedPtr<Sound::XACTSoundBank> _musicBank;
Sound::ChannelHandle _music;

int32 _ambientMusicState;
int32 _combatMusicState;

ObjectList _objects; ///< List of all objects in the area.
ObjectMap _objectMap; ///< Map of all non-static objects in the area.
Expand Down

0 comments on commit e5182af

Please sign in to comment.