void AnimationTask::execute(unsigned long timeDelta)
	{
		double deltaSec;
		std::list<memUInt> finishedAnimations;
		std::list<memUInt>::iterator finishedAnimationsIter;
		AnimationMapIterator iter;
		Value val;

		if (getState() != TS_RUNNING)
		{
			setState(TS_RUNNING);
		}

		// Dispatch all waiting messages of this task
		NotificationManager::getSingleton().dispatchQueuedNotifications((memUInt) this);

		deltaSec = ((double) timeDelta) / MICROSECONDS_IN_SECOND;

		{
			Poco::ScopedRWLock lock(mRWLockActiveAnimations, false);
			// Update animations
			for (iter = activeAnimations.begin(); iter != activeAnimations.end(); ++iter)
			{
				AnimationMapValueEntry entry = iter->second;
				Ogre::AnimationState *animationState = entry.first;

				// Check if the animation has ended, and add it to a list of animations to be removed from the active list
				if ((animationState->hasEnded()) || (!animationState->getEnabled()))
				{
					finishedAnimations.push_back(iter->first);
					animationState->setEnabled(false);

					// If the animation has a stop callback, call it
					callCallback(animationState, &mStopCallbacks);
				}
				else
				{
					// Add the time since the last update to the animation
					animationState->addTime(deltaSec);

					// Check if this animation is just starting, if it is call its start callback
					if (mStartingAnimations.erase(reinterpret_cast<memUInt>(animationState)) == 1)
					{
						callCallback(animationState, &mStartCallbacks);
					}
				}
			}
		}

		mStartingAnimations.clear();

		{
			Poco::ScopedRWLock lock(mRWLockActiveAnimations, true);
			Poco::ScopedRWLock lockCallbacks(mRWLockCallbacks, true);

			// Remove the animations that have ended from the list of active animations
			for (finishedAnimationsIter = finishedAnimations.begin(); finishedAnimationsIter != finishedAnimations.end(); ++finishedAnimationsIter)
			{
				memUInt animationAddress = *finishedAnimationsIter;
				activeAnimations.erase(animationAddress);

				// Remove any callbacks associated with this animation
				mStartCallbacks.erase(animationAddress);
				mStopCallbacks.erase(animationAddress);
			}
		}
	}
Exemple #2
0
bool
PlayState::frameStarted
(const Ogre::FrameEvent& evt)
{
   std::cout << "frameStarted PLAY" << std::endl;

  Ogre::Vector3 vt(0,0,0);     Ogre::Real tSpeed = 20.0;  
  _deltaT = evt.timeSinceLastFrame;

  _world->stepSimulation(_deltaT); // Actualizar simulacion Bullet
  _timeLastObject -= _deltaT;

  _camera->moveRelative(vt * _deltaT * tSpeed);
  if (_camera->getPosition().length() < 10.0) {
    _camera->moveRelative(-vt * _deltaT * tSpeed);
  }

  _camera->yaw(Degree(CAM_ROTATION_SPEED * _deltaT * _mouseRotation.x)); //, Node::TS_PARENT
  _camera->pitch(Degree(CAM_ROTATION_SPEED * _deltaT * _mouseRotation.y)); //, Node::TS_LOCAL
  _mouseRotation = Vector2::ZERO;

  //CONTROLAR LA DIRECCION DE LA CAMARA DEL PROYECTIL
  _projectileCamera->lookAt(_camera->getDerivedDirection());
  
  if(_trackedBody){
    _projectileCamera->setPosition(_trackedBody->getCenterOfMassPosition());
    Ogre::Vector3 trackedBodyPosition = _trackedBody->getCenterOfMassPosition();
    Ogre::Vector3 projectileLookAt(trackedBodyPosition.x - _camera->getPosition().x, trackedBodyPosition.y - _camera->getPosition().y, trackedBodyPosition.z - _camera->getPosition().z);
    //_projectileCamera->lookAt(_camera->getDerivedDirection());
    _projectileCamera->lookAt(trackedBodyPosition + projectileLookAt);
  }
   std::cout << "CAMERAS" << std::endl;
  if(_shootKeyDown){
    _keyDownTime = _keyDownTime + _deltaT;
  }
 
  if(_keyDownTime * THROW_FORCE > 100){
    _forcePercent = 100;
  }  
  else{
    _forcePercent = _keyDownTime * THROW_FORCE;
  }

  //_points++;
  _sPF->updatePower(_forcePercent);
  _sPF->updatePoints(_points);
  //std::cout<<_sPF->getSheet()->getChild("PowerWindow")->getUpdateMode() <<std::endl;
  //_sPF->getSheet()->getChild("PowerWindow")->update(_deltaT);
  //CEGUI::System::getSingleton().injectTimePulse(_deltaT);
  //DetectCollisionPig();
   std::cout << "points power" << std::endl;
  _physicsController->detectCollision();  //Este es el bueno. Hay que cambiarlo para que compruebe colisiones sobre todo
   std::cout << "pisis" << std::endl;
  _movementController->moveAll();
  std::cout << "collision moveall" << std::endl;
  if(_finalGame){
      pushState(FinalState::getSingletonPtr());
  }
  lifeWolf();
 std::cout << "wolf" << std::endl;
  if (_lanzaranimationPig){
    for (int i = 0; i < 3; ++i){
      std::ostringstream os;
      os << "pigA" <<i; 
      Ogre::AnimationState* animStatePig = _sceneMgr->getEntity(os.str())-> getAnimationState("SaltoR");
      animStatePig->setTimePosition(0.0);
      animStatePig->setEnabled(true);
      animStatePig->setLoop(true);
      _vector_anims_pig -> push_back(animStatePig);
    }
    _lanzaranimationPig = false;
  }
  

  for (int i = 0; i < 3; ++i){
      Ogre::AnimationState* animStatePig = _vector_anims_pig->at(i);
      if (animStatePig != NULL){
        if (animStatePig->hasEnded()){
          animStatePig->setTimePosition(0.0);
          animStatePig->setEnabled(false);
        }else{
          animStatePig->addTime(_deltaT);
        }
      }
  }
   std::cout << "animation" << std::endl;
  //RecorreVectorTAOAnadirMovimientoConstante();
  //std::cout << "Hasta aqui todo bien 1" << std::endl;

  return true;
  
}