How to wait until animation controller finishes animation

Hi all. This is my first topic here. :slight_smile:

I have one problem. I am writing a 3D variant of tetris.

There is update method for tetris field


public void update(float tpf)
{
   _timeSinceLastUpdate += tpf;
   if (_timeSinceLastUpdate >= SDAOptions.stepInterval / getSpeed()
      && !isPause())
   {
      if (canMoveDown())
      {
         moveDown();
      }
      else
      {
         // game over
         if (_tetPos.y == _initTetPos.y)
         {
            setPause(true);
            for (ISDAFieldListener listener : getListeners())
            {
               listener.gameOver(this);
            }
         }
         // place tetramino
         else
         {
            placeTetramino();
                           
            if (isLine())
            {
               int numberOfNewLines = _lineProcessor.processLines(_data, getRootNode());

               for (ISDAFieldListener listener : getListeners())
               {
                  listener.lineCompleted(this, numberOfNewLines);
               }
            }
               
            useNextTetramino();
         }
            
      }
      _timeSinceLastUpdate = 0;
         
   }
}


The problematic block is near _lineProcessor.processLines(). Line processor is a class that clears a line(s) and shifts down all boxes. Here is main routines of lineprocessor


public int processLines(Box[][] data, final Node rootNode)
{
   int result = 0;
   int maxY = SDAConstants.fieldSize.y;
   _animateble.clear();
   
   for (int y = 0; y < maxY; y++)
   {
      if (isCompleted(y, data))
      {
         detachLine(y, data, rootNode);
         shiftDown(y, data);            
         y--;   
         maxY--;
         result++;
      }
   }
      
   return result;
}



Now assuming I want add animation for field shifting. My idea is collect all detached boxes into some collection (e.i.

Map<Box, Vector3f>

, where key is box and value is its final direction in animation). Then just before return statement create new node, attach all my collected boxed to it and create controller for animation.
The main problem this is that if you see at

 Field#update

method there are some routines (e.i. sending messages to listener, generating next tetramino), that are called after line processing and animation are already completed. BUT controller  works during few seconds asynchronously to my

Field#update

and I don’t know how to wait when it finished its work.
Couldn’t you offer some idea to resolve this challenge? :? Maybe there is some other method to implement update cycle in such (per-second) games.
I hope my explanations are distinct.  :D If you want access full code, it’s available at http://code.google.com/p/sdatetris/source/checkout

Ok… It seems there is no way to run 'modal' animation since Controller#update and GameState#update are performed in one (logical) thread. And if I no exit my Field#update, animation will never begins, because I prevent next game cycle to start.

But what are the other ways to implement such stuff? What is the common usage pattern in such games? :?