Torque3D/Engine/source/afx/afxPhrase.cpp

196 lines
4.2 KiB
C++
Raw Normal View History

2017-07-26 08:35:44 +00:00
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#include "afx/arcaneFX.h"
#include "afx/afxEffectVector.h"
#include "afx/afxPhrase.h"
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// afxPhrase
void
afxPhrase::init_fx(S32 group_index)
{
mFX->ev_init(mInit_chor, *mInit_fx_list, mOn_server, mWill_stop, mInit_time_factor, mInit_dur, group_index);
2017-07-26 08:35:44 +00:00
}
//~~~~~~~~~~~~~~~~~~~~//
afxPhrase::afxPhrase(bool on_server, bool will_stop)
{
mOn_server = on_server;
mWill_stop = will_stop;
2017-07-26 08:35:44 +00:00
mInit_fx_list = NULL;
mInit_dur = 0.0f;
mInit_chor = NULL;
mInit_time_factor = 1.0f;
2017-07-26 08:35:44 +00:00
mFX = new afxEffectVector;
mFX2 = NULL;
mStartTime = 0;
mDur = 0;
2017-07-26 08:35:44 +00:00
mNum_loops = 1;
mLoop_cnt = 1;
2017-07-26 08:35:44 +00:00
mExtra_time = 0.0f;
mExtra_stoptime = 0.0f;
2017-07-26 08:35:44 +00:00
}
afxPhrase::~afxPhrase()
{
delete mFX;
delete mFX2;
2017-07-26 08:35:44 +00:00
};
void
afxPhrase::init(afxEffectList& fx_list, F32 dur, afxChoreographer* chor, F32 time_factor,
S32 n_loops, S32 group_index, F32 extra_time)
{
mInit_fx_list = &fx_list;
mInit_dur = dur;
mInit_chor = chor;
mInit_time_factor = time_factor;
2017-07-26 08:35:44 +00:00
mNum_loops = n_loops;
mExtra_time = extra_time;
mDur = (mInit_dur < 0) ? mInit_dur : mInit_dur*mInit_time_factor;
2017-07-26 08:35:44 +00:00
init_fx(group_index);
}
void
afxPhrase::start(F32 startstamp, F32 timestamp)
{
mStartTime = startstamp;
2017-07-26 08:35:44 +00:00
F32 loopstart = timestamp - startstamp;
if (mDur > 0 && loopstart > mDur)
2017-07-26 08:35:44 +00:00
{
mLoop_cnt += (S32) (loopstart/ mDur);
loopstart = mFmod(loopstart, mDur);
2017-07-26 08:35:44 +00:00
}
if (!mFX->empty())
mFX->start(loopstart);
2017-07-26 08:35:44 +00:00
}
void
afxPhrase::update(F32 dt, F32 timestamp)
{
if (mFX->isActive())
mFX->update(dt);
2017-07-26 08:35:44 +00:00
if (mFX2 && mFX2->isActive())
mFX2->update(dt);
2017-07-26 08:35:44 +00:00
if (mExtra_stoptime > 0 && timestamp > mExtra_stoptime)
2017-07-26 08:35:44 +00:00
{
stop(timestamp);
}
}
void
afxPhrase::stop(F32 timestamp)
{
if (mExtra_time > 0 && !(mExtra_stoptime > 0))
2017-07-26 08:35:44 +00:00
{
mExtra_stoptime = timestamp + mExtra_time;
2017-07-26 08:35:44 +00:00
return;
}
if (mFX->isActive())
mFX->stop();
2017-07-26 08:35:44 +00:00
if (mFX2 && mFX2->isActive())
mFX2->stop();
2017-07-26 08:35:44 +00:00
}
bool
afxPhrase::expired(F32 timestamp)
{
if (mDur < 0)
2017-07-26 08:35:44 +00:00
return false;
return ((timestamp - mStartTime) > mLoop_cnt*mDur);
2017-07-26 08:35:44 +00:00
}
F32
afxPhrase::elapsed(F32 timestamp)
{
return (timestamp - mStartTime);
2017-07-26 08:35:44 +00:00
}
bool
afxPhrase::recycle(F32 timestamp)
{
if (mNum_loops < 0 || mLoop_cnt < mNum_loops)
2017-07-26 08:35:44 +00:00
{
if (mFX2)
delete mFX2;
2017-07-26 08:35:44 +00:00
mFX2 = mFX;
2017-07-26 08:35:44 +00:00
mFX = new afxEffectVector;
2017-07-26 08:35:44 +00:00
init_fx();
if (mFX2 && !mFX2->empty())
mFX2->stop();
2017-07-26 08:35:44 +00:00
if (!mFX->empty())
mFX->start(0.0F);
2017-07-26 08:35:44 +00:00
mLoop_cnt++;
2017-07-26 08:35:44 +00:00
return true;
}
return false;
}
void
afxPhrase::interrupt(F32 timestamp)
{
if (mFX->isActive())
mFX->interrupt();
2017-07-26 08:35:44 +00:00
if (mFX2 && mFX2->isActive())
mFX2->interrupt();
2017-07-26 08:35:44 +00:00
}
F32 afxPhrase::calcDoneTime()
{
return mStartTime + mFX->getTotalDur();
2017-07-26 08:35:44 +00:00
}
F32 afxPhrase::calcAfterLife()
{
return mFX->getAfterLife();
2017-07-26 08:35:44 +00:00
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//