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

emichore.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 COPYRIGHT
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/grim/emi/costume/emichore.h"
00024 #include "engines/grim/emi/modelemi.h"
00025 
00026 namespace Grim {
00027 
00028 EMIChore::EMIChore(char name[32], int id, Costume *owner, int length, int numTracks) :
00029         Chore(name, id, owner, length, numTracks), _mesh(nullptr), _skeleton(nullptr),
00030         _fadeMode(Animation::None), _fade(1.f), _fadeLength(0), _startFade(1.0f) {
00031 }
00032 
00033 void EMIChore::addComponent(Component *component) {
00034     if (component->isComponentType('m', 'e', 's', 'h')) {
00035         _mesh = static_cast<EMIMeshComponent *>(component);
00036     } else if (component->isComponentType('s', 'k', 'e', 'l')) {
00037         _skeleton = static_cast<EMISkelComponent *>(component);
00038     }
00039     if (_mesh && _mesh->_obj && _skeleton) {
00040         _mesh->_obj->setSkeleton(_skeleton->_obj);
00041     }
00042 }
00043 
00044 void EMIChore::update(uint time) {
00045     if (!_playing || _paused)
00046         return;
00047 
00048     if (_fadeMode != Animation::None) {
00049         if (_fadeMode == Animation::FadeIn) {
00050             _fade += (float)time * (1.0f - _startFade) / _fadeLength;
00051             if (_fade >= 1.f) {
00052                 _fade = 1.f;
00053                 _fadeMode = Animation::None;
00054             }
00055         } else {
00056             _fade -= (float)time * _startFade / _fadeLength;
00057             if (_fade <= 0.f) {
00058                 _fade = 0.f;
00059                 stop(0);
00060                 return;
00061             }
00062         }
00063     }
00064 
00065     int newTime;
00066     if (_currTime < 0)
00067         newTime = 0; // For first time through
00068     else
00069         newTime = _currTime + time;
00070 
00071     setKeys(_currTime, newTime);
00072 
00073     if (_length >= 0 && newTime > _length) {
00074         if (!_looping && _fadeMode != Animation::FadeOut) {
00075             stop(0);
00076         }
00077         else {
00078             do {
00079                 newTime -= _length;
00080                 setKeys(-1, newTime);
00081             } while (newTime > _length);
00082         }
00083     }
00084     _currTime = newTime;
00085 }
00086 
00087 void EMIChore::stop(uint msecs) {
00088     if (msecs > 0) {
00089         fade(Animation::FadeOut, msecs);
00090     } else {
00091         _playing = false;
00092         _hasPlayed = false;
00093 
00094         for (int i = 0; i < _numTracks; i++) {
00095             Component *comp = getComponentForTrack(i);
00096             if (comp)
00097                 comp->reset();
00098         }
00099     }
00100 }
00101 
00102 void EMIChore::fade(Animation::FadeMode mode, uint msecs) {
00103     if (mode == Animation::None) {
00104         _fade = 1.0f;
00105     }
00106     _startFade = _fade;
00107     _fadeMode = mode;
00108     _fadeLength = msecs;
00109 
00110     for (int i = 0; i < _numTracks; i++) {
00111         Component *comp = getComponentForTrack(i);
00112         if (comp) {
00113             comp->fade(mode, msecs);
00114         }
00115     }
00116 }
00117 
00118 void EMIChore::saveState(SaveGame *state) const {
00119     Chore::saveState(state);
00120 
00121     state->writeLESint32((int)_fadeMode);
00122     state->writeFloat(_fade);
00123     state->writeFloat(_startFade);
00124     state->writeLESint32(_fadeLength);
00125 }
00126 
00127 void EMIChore::restoreState(SaveGame *state) {
00128     Chore::restoreState(state);
00129 
00130     if (state->saveMinorVersion() >= 10) {
00131         _fadeMode = (Animation::FadeMode)state->readLESint32();
00132         _fade = state->readFloat();
00133         _startFade = state->readFloat();
00134         _fadeLength = state->readLESint32();
00135     } else {
00136         if (_length == -1 && _playing)
00137             _currTime = -1;
00138     }
00139 }
00140 
00141 } // end of namespace Grim


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