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

keyframe_component.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 
00024 #include "engines/grim/debug.h"
00025 #include "engines/grim/costume/keyframe_component.h"
00026 #include "engines/grim/costume/model_component.h"
00027 
00028 namespace Grim {
00029 
00030 KeyframeComponent::KeyframeComponent(Component *p, int parentID, const char *filename, tag32 t) :
00031         Component(p, parentID, filename, t), _priority1(1), _priority2(5), _anim(nullptr) {
00032     const char *comma = strchr(filename, ',');
00033     if (comma) {
00034         _name = Common::String(filename, comma);
00035         sscanf(comma + 1, "%d,%d", &_priority1, &_priority2);
00036     }
00037 }
00038 
00039 KeyframeComponent::~KeyframeComponent() {
00040     delete _anim;
00041 }
00042 
00043 void KeyframeComponent::fade(Animation::FadeMode fadeMode, int fadeLength) {
00044     _anim->fade(fadeMode, fadeLength);
00045 }
00046 
00047 void KeyframeComponent::setKey(int val) {
00048     switch (val) {
00049     case 0: // "Play Once"
00050         _anim->play(Animation::Once);
00051         break;
00052     case 1: // "Play Looping"
00053         _anim->play(Animation::Looping);
00054         break;
00055     case 2: // "Play and Endpause"
00056         _anim->play(Animation::PauseAtEnd);
00057         break;
00058     case 3: // "Play and Endfade"
00059         _anim->play(Animation::FadeAtEnd);
00060         break;
00061     case 4: // "Stop"
00062         reset();
00063         break;
00064     case 5: // "Pause"
00065         _anim->pause(true);
00066         break;
00067     case 6: // "Unpause"
00068         _anim->pause(false);
00069         break;
00070     case 7: // "1.0 Fade in"
00071         fade(Animation::FadeIn, 1000);
00072         _anim->activate();
00073         break;
00074     case 8: // "0.5 Fade in"
00075         fade(Animation::FadeIn, 500);
00076         _anim->activate();
00077         break;
00078     case 9: // "0.25 Fade in"
00079         fade(Animation::FadeIn, 250);
00080         _anim->activate();
00081         break;
00082     case 10: // "0.125 Fade in"
00083         fade(Animation::FadeIn, 125);
00084         _anim->activate();
00085         break;
00086     case 11: // "1.0 Fade out"
00087         fade(Animation::FadeOut, 1000);
00088         break;
00089     case 12: // "0.5 Fade out
00090         fade(Animation::FadeOut, 500);
00091         break;
00092     case 13: // "0.25 Fade out"
00093         fade(Animation::FadeOut, 250);
00094         break;
00095     case 14: // "0.125 Fade out"
00096         fade(Animation::FadeOut, 125);
00097         break;
00098     default:
00099         Debug::warning(Debug::Costumes, "Unknown key %d for component %s", val, _name.c_str());
00100     }
00101 }
00102 
00103 void KeyframeComponent::reset() {
00104     if (_anim->getFadeMode() != Animation::FadeOut) {
00105         _anim->stop();
00106     }
00107 }
00108 
00109 int KeyframeComponent::update(uint time) {
00110     if (!_anim->getIsActive())
00111         return 0;
00112 
00113     return _anim->update((int)time);
00114 }
00115 
00116 void KeyframeComponent::init() {
00117     if (_parent->isComponentType('M','M','D','L') ||
00118         _parent->isComponentType('M','O','D','L')) {
00119         ModelComponent *mc = static_cast<ModelComponent *>(_parent);
00120         _anim = new Animation(_name, mc->getAnimManager(), _priority1, _priority2);
00121     } else {
00122         Debug::warning(Debug::Costumes, "Parent of %s was not a model", _name.c_str());
00123         _anim = nullptr;
00124     }
00125 }
00126 
00127 void KeyframeComponent::saveState(SaveGame *state) {
00128     _anim->saveState(state);
00129 }
00130 
00131 void KeyframeComponent::restoreState(SaveGame *state) {
00132     _anim->restoreState(state);
00133 }
00134 
00135 } // end of namespace Grim


Generated on Sat Aug 17 2019 05:00:36 for ResidualVM by doxygen 1.7.1
curved edge   curved edge