ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

animsoundtrigger.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/resources/animsoundtrigger.h"
00024 
00025 #include "engines/stark/formats/xrc.h"
00026 #include "engines/stark/resources/anim.h"
00027 #include "engines/stark/resources/location.h"
00028 #include "engines/stark/resources/sound.h"
00029 #include "engines/stark/services/global.h"
00030 #include "engines/stark/services/services.h"
00031 
00032 namespace Stark {
00033 namespace Resources {
00034 
00035 AnimSoundTrigger::~AnimSoundTrigger() {
00036 }
00037 
00038 AnimSoundTrigger::AnimSoundTrigger(Object *parent, byte subType, uint16 index, const Common::String &name) :
00039         Object(parent, subType, index, name),
00040         _soundStockType(0),
00041         _soundTriggerTime(0),
00042         _anim(nullptr),
00043         _alreadyPlayed(false),
00044         _timeRemainingBeforeLoop(34) {
00045     _type = TYPE;
00046 }
00047 
00048 void AnimSoundTrigger::onAllLoaded() {
00049     Object::onAllLoaded();
00050     _anim = Object::cast<AnimSkeleton>(_parent);
00051 }
00052 
00053 void AnimSoundTrigger::onGameLoop() {
00054     Object::onGameLoop();
00055 
00056     if (!_anim || !_anim->isInUse()) {
00057         return;
00058     }
00059 
00060     if (_alreadyPlayed && _anim->getCurrentTime() < 33) {
00061         // Animation loop detected, reset
00062         _alreadyPlayed = false;
00063     }
00064 
00065     if ((!_alreadyPlayed && _anim->getCurrentTime() >= _soundTriggerTime) || _timeRemainingBeforeLoop < 33) {
00066         if (_timeRemainingBeforeLoop >= 33) {
00067             _alreadyPlayed = true;
00068         }
00069 
00070         if (_subType == kAnimTriggerSound) {
00071             Location *location = StarkGlobal->getCurrent()->getLocation();
00072             Sound *sound = location->findStockSound(_soundStockType);
00073             if (sound && !StarkGlobal->isFastForward()) {
00074                 // TODO: If the location has a 3D layer set the source position of the sound to the item position
00075                 sound->stop();
00076                 sound->play();
00077             }
00078         } else {
00079             warning("Unknown animation trigger subtype '%d'", _subType);
00080         }
00081     }
00082 
00083     // Special handling for trigger times right before the animation loop point
00084     if (!_alreadyPlayed && _soundTriggerTime - _anim->getCurrentTime() < 33) {
00085         _timeRemainingBeforeLoop = _anim->getRemainingTime();
00086     } else {
00087         _timeRemainingBeforeLoop = 34;
00088     }
00089 }
00090 
00091 void AnimSoundTrigger::readData(Formats::XRCReadStream *stream) {
00092     _soundTriggerTime = stream->readUint32LE();
00093     _soundStockType = stream->readUint32LE();
00094 }
00095 
00096 void AnimSoundTrigger::printData() {
00097     debug("triggerTime: %d", _soundTriggerTime);
00098     debug("soundStockType: %d", _soundStockType);
00099 }
00100 
00101 } // End of namespace Resources
00102 } // End of namespace Stark


Generated on Sat Mar 16 2019 05:01:19 for ResidualVM by doxygen 1.7.1
curved edge   curved edge