Game Development Community

Fixing StaticShape animation methods

by Justin Knight · in Torque 3D Professional · 10/10/2012 (7:39 am) · 1 replies

I'm currently trying to get the following animation methods working on StaticShape, which inherits it's animation capabilities from ShapeBase:

playThread
pauseThread
setThreadPosition

I've got the first two working by commenting out some lines in ShapeBase::updateThread...
case Thread::Pause:
			{
/*				if ( st.position != -1.f )
				{
					mShapeInstance->setTimeScale( st.thread, 1.f );
					mShapeInstance->setPos( st.thread, st.position );
				}*/

				mShapeInstance->setTimeScale( st.thread, 0.f );
				stopThreadSound( st );
			} break;

		case Thread::Play:
			{
				if (st.atEnd)
				{
					mShapeInstance->setTimeScale(st.thread,1);
					mShapeInstance->setPos( st.thread, ( st.timescale > 0.f ) ? 1.0f : 0.0f );
					mShapeInstance->setTimeScale(st.thread,0);
					stopThreadSound(st);
               st.state = Thread::Stop;
				}
				else
				{
/*					if ( st.position != -1.f )
					{
						mShapeInstance->setTimeScale( st.thread, 1.f );
						mShapeInstance->setPos( st.thread, st.position );
					}*/

					mShapeInstance->setTimeScale(st.thread, st.timescale );
					if (!st.sound)
					{
						startSequenceSound(st);
					}
				}
			} break;

But I'm struggling to get setThreadPosition to work. This is my current best attempt at a working version of the method...
bool ShapeBase::setThreadPosition( U32 slot, F32 pos )
{
	Thread& st = mScriptThread[slot];
   
	if (st.sequence != -1) {
		setMaskBits(ThreadMaskN << slot);
		st.position = pos;
		st.atEnd = false;

		mShapeInstance->setPos( st.thread, pos);
 
		return true;
	}
	return false;
}
When I call this from script on the server I can see it correctly calling setPos on the shapeInstance and in the Thread code it calculates the correct new keyframes. Future calls to getPos() on mShapeInstance return the correct new position adjusted to <new position> + <delta time>.

However on the client the animation continues playing without changing the position in the animation. My understanding is that by setting the mask bits the changes to the thread on the server should be replicated down to the client.

Does anyone have any idea what I'm missing?

#1
10/10/2012 (9:44 am)
Hi,

I wouldn't change anything in ShapeBase to get this working as that can break any of the other subclasses.

As ShapeBase is responsible for updating animations to the client and StaticShape isn't derived from ShapeBase, you'll have to implement that yourself. Setting the appropriate bitmask yourself is the way to go. On the next update, the server should tell the client what happened. Keep hammering at it, it's really quite simple when you get down to it.

I haven't touched Torque for 6 years or so but I'm trying to get up to speed on that now. This is on my TODO.

Edit: Okay ignore what I said about StaticShape not inheriting from ShapeBase. I'm definatly too rusty right now.