diff options
author | Paul Gilbert | 2017-01-30 22:18:37 -0500 |
---|---|---|
committer | Paul Gilbert | 2017-01-30 22:18:37 -0500 |
commit | 02ebaf06b95235d3a2c8b83ec625e9c2d29178cc (patch) | |
tree | 3911b07dd4e49469b761b007f5e0ff78f95540b2 /engines/titanic | |
parent | 05e36920b36bae2da8c0f0d1413c0470344fcb84 (diff) | |
download | scummvm-rg350-02ebaf06b95235d3a2c8b83ec625e9c2d29178cc.tar.gz scummvm-rg350-02ebaf06b95235d3a2c8b83ec625e9c2d29178cc.tar.bz2 scummvm-rg350-02ebaf06b95235d3a2c8b83ec625e9c2d29178cc.zip |
TITANIC: Implementing music room handler update & trigger
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/sound/music_player.cpp | 8 | ||||
-rw-r--r-- | engines/titanic/sound/music_player.h | 4 | ||||
-rw-r--r-- | engines/titanic/sound/music_room_handler.cpp | 43 | ||||
-rw-r--r-- | engines/titanic/sound/music_room_handler.h | 19 | ||||
-rw-r--r-- | engines/titanic/sound/music_wave.cpp | 28 | ||||
-rw-r--r-- | engines/titanic/sound/music_wave.h | 14 |
6 files changed, 100 insertions, 16 deletions
diff --git a/engines/titanic/sound/music_player.cpp b/engines/titanic/sound/music_player.cpp index 1f8a847cd2..6fb073b189 100644 --- a/engines/titanic/sound/music_player.cpp +++ b/engines/titanic/sound/music_player.cpp @@ -39,7 +39,7 @@ void CMusicPlayer::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); file->writeNumberLine(_isActive, indent); file->writeQuotedLine(_stopTarget, indent); - file->writeNumberLine(_stopWaves, indent); + file->writeNumberLine(_musicActive, indent); file->writeNumberLine(_volume, indent); CGameObject::save(file, indent); @@ -49,7 +49,7 @@ void CMusicPlayer::load(SimpleFile *file) { file->readNumber(); _isActive = file->readNumber(); _stopTarget = file->readString(); - _stopWaves = file->readNumber(); + _musicActive = file->readNumber(); _volume = file->readNumber(); CGameObject::load(file); @@ -122,7 +122,7 @@ bool CMusicPlayer::LeaveRoomMsg(CLeaveRoomMsg *msg) { bool CMusicPlayer::CreateMusicPlayerMsg(CCreateMusicPlayerMsg *msg) { if (CMusicRoom::_musicHandler) { - CMusicRoom::_musicHandler->setStopWaves(_stopWaves); + CMusicRoom::_musicHandler->setActive(_musicActive); return true; } @@ -158,7 +158,7 @@ bool CMusicPlayer::CreateMusicPlayerMsg(CCreateMusicPlayerMsg *msg) { wave->load(5, "z#505.wav", 53); wave->load(6, "z#501.wav", 58); - CMusicRoom::_musicHandler->setStopWaves(_stopWaves); + CMusicRoom::_musicHandler->setActive(_musicActive); } return true; diff --git a/engines/titanic/sound/music_player.h b/engines/titanic/sound/music_player.h index 3495439297..4d322e01dc 100644 --- a/engines/titanic/sound/music_player.h +++ b/engines/titanic/sound/music_player.h @@ -41,12 +41,12 @@ class CMusicPlayer : public CGameObject { protected: bool _isActive; CString _stopTarget; - bool _stopWaves; + bool _musicActive; int _volume; public: CLASSDEF; CMusicPlayer() : CGameObject(), - _isActive(false), _stopWaves(false), _volume(100) {} + _isActive(false), _musicActive(false), _volume(100) {} /** * Save the data for the class to file diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp index 5a6f48ae17..fdc98b93f3 100644 --- a/engines/titanic/sound/music_room_handler.cpp +++ b/engines/titanic/sound/music_room_handler.cpp @@ -23,14 +23,17 @@ #include "titanic/sound/music_room_handler.h" #include "titanic/sound/sound_manager.h" #include "titanic/core/project_item.h" +#include "titanic/titanic.h" namespace Titanic { CMusicRoomHandler::CMusicRoomHandler(CProjectItem *project, CSoundManager *soundManager) : - _project(project), _soundManager(soundManager), _stopWaves(false), - _soundHandle(-1), _waveFile(nullptr), _soundVolume(100), - _field108(0) { + _project(project), _soundManager(soundManager), _active(false), + _soundHandle(-1), _waveFile(nullptr), _volume(100) { Common::fill(&_musicWaves[0], &_musicWaves[4], (CMusicWave *)nullptr); + _field108 = 0; + _field118 = 0; + _startTicks = _soundStartTicks = 0; } CMusicRoomHandler::~CMusicRoomHandler() { @@ -62,7 +65,8 @@ CMusicWave *CMusicRoomHandler::createMusicWave(MusicInstrument instrument, int c } void CMusicRoomHandler::createWaveFile(int musicVolume) { - _soundVolume = musicVolume; + _volume = musicVolume; + // TODO // _waveFile = _soundManager->loadMusic() } @@ -80,9 +84,14 @@ void CMusicRoomHandler::stop() { } for (int idx = 0; idx < 4; ++idx) { - if (_stopWaves && _musicWaves[idx]) + _musicWaves[idx]->reset(); + if (_active && _musicWaves[idx]) _musicWaves[idx]->stop(); } + + _field108 = 0; + _field118 = 0; + _startTicks = _soundStartTicks = 0; } bool CMusicRoomHandler::checkInstrument(MusicInstrument instrument) const { @@ -143,4 +152,28 @@ bool CMusicRoomHandler::isBusy() { return _field108 > 0; } +void CMusicRoomHandler::trigger() { + if (_active) { + for (int idx = 0; idx < 4; ++idx) + _musicWaves[idx]->trigger(); + } +} + +void CMusicRoomHandler::update() { + uint currentTicks = g_vm->_events->getTicksCount(); + + if (!_startTicks) { + trigger(); + _startTicks = currentTicks; + } else if (!_soundStartTicks && currentTicks >= (_startTicks + 3000)) { + if (_waveFile) { + CProximity prox; + prox._channelVolume = _volume; + _soundHandle = _soundManager->playSound(*_waveFile, prox); + } + + _soundStartTicks = currentTicks; + } +} + } // End of namespace Titanic diff --git a/engines/titanic/sound/music_room_handler.h b/engines/titanic/sound/music_room_handler.h index aad8ca1bd9..68a0c51e21 100644 --- a/engines/titanic/sound/music_room_handler.h +++ b/engines/titanic/sound/music_room_handler.h @@ -56,11 +56,16 @@ private: MusicRoomInstrument _array1[4]; MusicRoomInstrument _array2[4]; Array5Entry _array5[4]; - bool _stopWaves; + bool _active; CWaveFile *_waveFile; int _soundHandle; - int _soundVolume; int _field108; + int _field118; + uint _soundStartTicks; + uint _startTicks; + int _volume; +private: + void trigger(); public: CMusicRoomHandler(CProjectItem *project, CSoundManager *soundManager); ~CMusicRoomHandler(); @@ -83,10 +88,9 @@ public: bool isBusy(); /** - * Flags whether the loaded music waves will be stopped when the - * music handler is stopped + * Flags whether the music handler is active */ - void setStopWaves(bool flag) { _stopWaves = flag; } + void setActive(bool flag) { _active = flag; } /** * Stop playing the music @@ -142,6 +146,11 @@ public: * Sets the mute control value */ void setMuteControl(MusicInstrument instrument, bool value); + + /** + * Handles regular updates + */ + void update(); }; } // End of namespace Titanic diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp index b4bb216d06..5038780457 100644 --- a/engines/titanic/sound/music_wave.cpp +++ b/engines/titanic/sound/music_wave.cpp @@ -30,17 +30,29 @@ namespace Titanic { bool CMusicWave::_pianoToggle; int CMusicWave::_pianoCtr; int CMusicWave::_bassCtr; +byte *CMusicWave::_buffer; void CMusicWave::init() { _pianoToggle = false; _pianoCtr = 0; _bassCtr = 0; + _buffer = nullptr; +} + +void CMusicWave::deinit() { + delete[] _buffer; + _buffer = nullptr; } CMusicWave::CMusicWave(CProjectItem *project, CSoundManager *soundManager, MusicWaveInstrument instrument) : _soundManager(soundManager), _instrument(instrument) { Common::fill(&_gameObjects[0], &_gameObjects[4], (CGameObject *)nullptr); _field20 = _field24 = 0; + _field34 = -1; + _field38 = 0; + _field3C = 0; + _field40 = 0; + _field44 = 0; _field4C = 0; switch (instrument) { @@ -239,4 +251,20 @@ void CMusicWave::trigger() { } } +void CMusicWave::reset() { + _field34 = 0; + _field38 = 0; + _field3C = 0; + _field40 = 0; + _field44 = 0; +} + +void CMusicWave::setState(int val) { + _field34 = -1; + _field38 = 0; + _field3C = 0; + _field40 = val; + _field44 = 0; +} + } // End of namespace Titanic diff --git a/engines/titanic/sound/music_wave.h b/engines/titanic/sound/music_wave.h index bbafbb7abe..eee21a96c2 100644 --- a/engines/titanic/sound/music_wave.h +++ b/engines/titanic/sound/music_wave.h @@ -45,6 +45,7 @@ private: static bool _pianoToggle; static int _pianoCtr; static int _bassCtr; + static byte *_buffer; private: CSoundManager *_soundManager; Common::Array<CMusicWaveFile> _items; @@ -53,6 +54,11 @@ private: CGameObject *_gameObjects[4]; int _field20; int _field24; + int _field34; + int _field38; + int _field3C; + int _field40; + int _field44; int _field4C; private: /** @@ -64,6 +70,11 @@ public: * Handles initialization of static fields */ static void init(); + + /** + * Deinitialization of static fields + */ + static void deinit(); public: CMusicWave(CProjectItem *project, CSoundManager *soundManager, MusicWaveInstrument instrument); @@ -92,6 +103,9 @@ public: * musical instrument associated with the instance */ void trigger(); + + void reset(); + void setState(int val); }; } // End of namespace Titanic |