afxPhrase.cpp
Engine/source/afx/afxPhrase.cpp
Detailed Description
1 2 3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 5// Copyright (C) 2015 Faust Logic, Inc. 6// 7// Permission is hereby granted, free of charge, to any person obtaining a copy 8// of this software and associated documentation files (the "Software"), to 9// deal in the Software without restriction, including without limitation the 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11// sell copies of the Software, and to permit persons to whom the Software is 12// furnished to do so, subject to the following conditions: 13// 14// The above copyright notice and this permission notice shall be included in 15// all copies or substantial portions of the Software. 16// 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23// IN THE SOFTWARE. 24// 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 26 27#include "afx/arcaneFX.h" 28 29#include "afx/afxEffectVector.h" 30#include "afx/afxPhrase.h" 31 32//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 33// afxPhrase 34 35void 36afxPhrase::init_fx(S32 group_index) 37{ 38 mFX->ev_init(mInit_chor, *mInit_fx_list, mOn_server, mWill_stop, mInit_time_factor, mInit_dur, group_index); 39} 40 41//~~~~~~~~~~~~~~~~~~~~// 42 43afxPhrase::afxPhrase(bool on_server, bool will_stop) 44{ 45 mOn_server = on_server; 46 mWill_stop = will_stop; 47 48 mInit_fx_list = NULL; 49 mInit_dur = 0.0f; 50 mInit_chor = NULL; 51 mInit_time_factor = 1.0f; 52 53 mFX = new afxEffectVector; 54 mFX2 = NULL; 55 mStartTime = 0; 56 mDur = 0; 57 58 mNum_loops = 1; 59 mLoop_cnt = 1; 60 61 mExtra_time = 0.0f; 62 mExtra_stoptime = 0.0f; 63} 64 65afxPhrase::~afxPhrase() 66{ 67 delete mFX; 68 delete mFX2; 69}; 70 71void 72afxPhrase::init(afxEffectList& fx_list, F32 dur, afxChoreographer* chor, F32 time_factor, 73 S32 n_loops, S32 group_index, F32 extra_time) 74{ 75 mInit_fx_list = &fx_list; 76 mInit_dur = dur; 77 mInit_chor = chor; 78 mInit_time_factor = time_factor; 79 80 mNum_loops = n_loops; 81 mExtra_time = extra_time; 82 mDur = (mInit_dur < 0) ? mInit_dur : mInit_dur*mInit_time_factor; 83 84 init_fx(group_index); 85} 86 87void 88afxPhrase::start(F32 startstamp, F32 timestamp) 89{ 90 mStartTime = startstamp; 91 92 F32 loopstart = timestamp - startstamp; 93 94 if (mDur > 0 && loopstart > mDur) 95 { 96 mLoop_cnt += (S32) (loopstart/ mDur); 97 loopstart = mFmod(loopstart, mDur); 98 } 99 100 if (!mFX->empty()) 101 mFX->start(loopstart); 102} 103 104void 105afxPhrase::update(F32 dt, F32 timestamp) 106{ 107 if (mFX->isActive()) 108 mFX->update(dt); 109 110 if (mFX2 && mFX2->isActive()) 111 mFX2->update(dt); 112 113 if (mExtra_stoptime > 0 && timestamp > mExtra_stoptime) 114 { 115 stop(timestamp); 116 } 117} 118 119void 120afxPhrase::stop(F32 timestamp) 121{ 122 if (mExtra_time > 0 && !(mExtra_stoptime > 0)) 123 { 124 mExtra_stoptime = timestamp + mExtra_time; 125 return; 126 } 127 128 if (mFX->isActive()) 129 mFX->stop(); 130 131 if (mFX2 && mFX2->isActive()) 132 mFX2->stop(); 133} 134 135bool 136afxPhrase::expired(F32 timestamp) 137{ 138 if (mDur < 0) 139 return false; 140 141 return ((timestamp - mStartTime) > mLoop_cnt*mDur); 142} 143 144F32 145afxPhrase::elapsed(F32 timestamp) 146{ 147 return (timestamp - mStartTime); 148} 149 150bool 151afxPhrase::recycle(F32 timestamp) 152{ 153 if (mNum_loops < 0 || mLoop_cnt < mNum_loops) 154 { 155 if (mFX2) 156 delete mFX2; 157 158 mFX2 = mFX; 159 160 mFX = new afxEffectVector; 161 init_fx(); 162 163 if (mFX2 && !mFX2->empty()) 164 mFX2->stop(); 165 166 if (!mFX->empty()) 167 mFX->start(0.0F); 168 169 mLoop_cnt++; 170 return true; 171 } 172 173 return false; 174} 175 176void 177afxPhrase::interrupt(F32 timestamp) 178{ 179 if (mFX->isActive()) 180 mFX->interrupt(); 181 182 if (mFX2 && mFX2->isActive()) 183 mFX2->interrupt(); 184} 185 186F32 afxPhrase::calcDoneTime() 187{ 188 return mStartTime + mFX->getTotalDur(); 189} 190 191F32 afxPhrase::calcAfterLife() 192{ 193 return mFX->getAfterLife(); 194} 195 196 197//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 198