adds an animspeed and animoffset to tsstatic instances so clones can be set to break up syncing on multiples

This commit is contained in:
AzaezelX 2020-06-13 12:08:01 -05:00
parent 341c7eeee1
commit 136bc8874f
2 changed files with 43 additions and 13 deletions

View file

@ -142,6 +142,8 @@ TSStatic::TSStatic()
#ifdef TORQUE_AFX_ENABLED #ifdef TORQUE_AFX_ENABLED
afxZodiacData::convertGradientRangeFromDegrees(mGradientRange, mGradientRangeUser); afxZodiacData::convertGradientRangeFromDegrees(mGradientRange, mGradientRangeUser);
#endif #endif
mAnimOffset = 0.0f;
mAnimSpeed = 1.0f;
mShapeAsset = StringTable->EmptyString(); mShapeAsset = StringTable->EmptyString();
mShapeAssetId = StringTable->EmptyString(); mShapeAssetId = StringTable->EmptyString();
@ -164,9 +166,17 @@ ImplementEnumType(TSMeshType,
{ TSStatic::VisibleMesh, "Visible Mesh", "Rendered mesh polygons." }, { TSStatic::VisibleMesh, "Visible Mesh", "Rendered mesh polygons." },
EndImplementEnumType; EndImplementEnumType;
FRangeValidator percentValidator(0.0f, 1.0f);
F32 AnimSpeedMax = 4.0f;
FRangeValidator speedValidator(0.0f, AnimSpeedMax);
void TSStatic::initPersistFields() void TSStatic::initPersistFields()
{ {
addFieldV("AnimOffset", TypeF32, Offset(mAnimOffset, TSStatic), &percentValidator,
"Percent Animation Offset.");
addFieldV("AnimSpeed", TypeF32, Offset(mAnimSpeed, TSStatic), &speedValidator,
"Percent Animation Speed.");
addGroup("Shape"); addGroup("Shape");
addProtectedField("shapeAsset", TypeShapeAssetId, Offset(mShapeAssetId, TSStatic), addProtectedField("shapeAsset", TypeShapeAssetId, Offset(mShapeAssetId, TSStatic),
@ -454,12 +464,8 @@ bool TSStatic::_createShape()
mShapeInstance = new TSShapeInstance(mShape, isClientObject()); mShapeInstance = new TSShapeInstance(mShape, isClientObject());
if (isClientObject()) if (isClientObject())
{
mShapeInstance->cloneMaterialList(); mShapeInstance->cloneMaterialList();
}
if (isClientObject())
mShapeInstance->cloneMaterialList();
if (isGhost()) if (isGhost())
{ {
// Reapply the current skin // Reapply the current skin
@ -475,8 +481,8 @@ bool TSStatic::_createShape()
if (ambientSeq > -1 && !mAmbientThread) if (ambientSeq > -1 && !mAmbientThread)
mAmbientThread = mShapeInstance->addThread(); mAmbientThread = mShapeInstance->addThread();
if (mAmbientThread) if ( mAmbientThread )
mShapeInstance->setSequence(mAmbientThread, ambientSeq, 0); mShapeInstance->setSequence(mAmbientThread, ambientSeq, mAnimOffset);
// Resolve CubeReflectorDesc. // Resolve CubeReflectorDesc.
if (cubeDescName.isNotEmpty()) if (cubeDescName.isNotEmpty())
@ -720,9 +726,11 @@ void TSStatic::reSkin()
void TSStatic::processTick(const Move* move) void TSStatic::processTick(const Move* move)
{ {
if (isServerObject() && mPlayAmbient && mAmbientThread) if ( isServerObject() && mPlayAmbient && mAmbientThread )
mShapeInstance->advanceTime(TickSec, mAmbientThread); {
mShapeInstance->setTimeScale(mAmbientThread, mAnimSpeed);
mShapeInstance->advanceTime( TickSec, mAmbientThread );
}
if (isMounted()) if (isMounted())
{ {
MatrixF mat(true); MatrixF mat(true);
@ -737,8 +745,11 @@ void TSStatic::interpolateTick(F32 delta)
void TSStatic::advanceTime(F32 dt) void TSStatic::advanceTime(F32 dt)
{ {
if (mPlayAmbient && mAmbientThread) if ( mPlayAmbient && mAmbientThread )
mShapeInstance->advanceTime(dt, mAmbientThread); {
mShapeInstance->setTimeScale(mAmbientThread, mAnimSpeed);
mShapeInstance->advanceTime( dt, mAmbientThread );
}
if (isMounted()) if (isMounted())
{ {
@ -982,6 +993,12 @@ U32 TSStatic::packUpdate(NetConnection* con, U32 mask, BitStream* stream)
stream->write(mForceDetail); stream->write(mForceDetail);
if (stream->writeFlag(mAnimOffset != 0.0f))
stream->writeFloat(mAnimOffset, 7);
if (stream->writeFlag(mAnimSpeed != 1.0f))
stream->writeSignedFloat(mAnimSpeed / AnimSpeedMax, 7);
stream->writeFlag(mPlayAmbient); stream->writeFlag(mPlayAmbient);
} }
@ -1094,6 +1111,13 @@ void TSStatic::unpackUpdate(NetConnection* con, BitStream* stream)
stream->read(&mRenderNormalScalar); stream->read(&mRenderNormalScalar);
stream->read(&mForceDetail); stream->read(&mForceDetail);
if (stream->readFlag())
mAnimOffset = stream->readFloat(7);
if (stream->readFlag())
mAnimSpeed = stream->readSignedFloat(7) * AnimSpeedMax;
mPlayAmbient = stream->readFlag(); mPlayAmbient = stream->readFlag();

View file

@ -48,6 +48,10 @@
#include "scene/reflector.h" #include "scene/reflector.h"
#endif #endif
#ifndef _COLLADA_UTILS_H_
#include "ts/collada/colladaUtils.h"
#endif
#ifndef _ASSET_PTR_H_ #ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h" #include "assets/assetPtr.h"
#endif #endif
@ -202,8 +206,9 @@ protected:
String mAppliedSkinName; String mAppliedSkinName;
bool mPlayAmbient; bool mPlayAmbient;
TSThread* mAmbientThread; TSThread* mAmbientThread;
F32 mAnimOffset;
F32 mAnimSpeed;
/// The type of mesh data to return for collision queries. /// The type of mesh data to return for collision queries.
MeshType mCollisionType; MeshType mCollisionType;
@ -272,6 +277,7 @@ public:
const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; } const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; }
const Vector<S32>& getLOSDetails() const { return mLOSDetails; } const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
bool hasAnim() { return mAmbientThread != NULL; }
virtual void onInspect(GuiInspector*); virtual void onInspect(GuiInspector*);