Game Development Community

Playthread timing

by dudeBot · in Torque Game Engine · 08/21/2006 (12:22 pm) · 2 replies

Hello all,

I've got a static shape with some animation sequences exported out as a .dts.
I am able to play these sequences, however I am interested in playing them
with some sort of "time" control. Right now the way I have it set up, the sequences
are scripted to start when a button on a custom GUI I created is pressed, but it appears
as if all all of the sequences are playing at the same time. What I'd like to have happen
is that the first sequence plays, once it is done the second one plays, when its done
the third one plays...and so on and so on. I've got 4, which some searching revealed as
some sort of ceiling.

Anyway, I could combine all the sequences into one, but in some cases I may change the
order so seperating the sequences out and calling them with script is more desirable.
The only thing that I could think of was to use the "schedule" command, but thought there
me be a more direct way I am not aware of. (e.g. I didn't know if there was a way to tie a
function call to a seuquence once it has reached its final frame).

Thanks in advance for any insight into this!!!!!

#1
08/25/2006 (6:54 am)
I'm far from a Torque expert, but I spent an entire day going through the animation code. While I was there I noticed a handy little piece of code that just might solve your problem. In shapebase.cc you can find the following function: (for me it starts on line 2158)

void ShapeBase::advanceThreads(F32 dt)
{
   for (U32 i = 0; i < MaxScriptThreads; i++) {
      Thread& st = mScriptThread;
      if (st.thread) {
         if (!mShapeInstance->getShape()->sequences[st.sequence].isCyclic() && !st.atEnd &&
             (st.forward? mShapeInstance->getPos(st.thread) >= 1.0:
              mShapeInstance->getPos(st.thread) <= 0)) {
            st.atEnd = true;
            updateThread(st);
            if (!isGhost()) {
               char slot[16];
               dSprintf(slot,sizeof(slot),"%d",i);
               [b]Con::executef(mDataBlock,3,"onEndSequence",scriptThis(),slot);[/b]
            }
         }
         mShapeInstance->advanceTime(dt,st.thread);
      }
   }
}

The bold line is calling a function on the datablock when the animation sequence has reached its end.
I had never used this piece of functionality before, but I just tried it out and it seems to work. So, to utilize this just declare a function on your datablock named, "onEndSequence" that takes three parameters. It would like something like this:
function [i]datablockName[/i]::onEndSequence(%this, %object, %slot){
     ....
}

Hope that helps.
#2
08/25/2006 (7:11 am)
Cool.

I'm gonna try it out right now. I just endend up doing it with a series
of schedule calls which did the trick pretty good. I'm a bit of a newbie
so I haven't got to the point where I'm looking at the source code.

Thanks for your efforts and response!!!!!