Exemplo n.º 1
0
void Mission::onUpdateActivity(float dt)
{
        _fadTimeout -= dt;
        _interruptTimeout -= dt;

        // important action: ESC - interrupt mission
        if( Gameplay::iGameplay->getKeyboardState()->keyState[0x01] & 0x80 )
        {
                if( _endOfPlayerActivity )
                {
                        _scene->getCareer()->setMissionWalkthroughFlag( _tournamentInfo, _wtmid, true );
                        _endOfMission = true;
                }
                else if( _interruptTimeout < 0 )
                {
                        assert( _scene->getCamera() );
                        _scene->getCamera()->updateActivity( 0.0f );
                        new Interrupt( _scene, _scene->getCamera()->getPose(), &_endOfMission, ( _player->getPhase() != jpRoaming ) );
                        _interruptTimeout = 0.25f;
                        return;
                }
        }

        // soft time acceleration
        if( _fadValue != _fadTargetValue )
        {
                float fadSpeed =     1.0f;
                float direction = _fadTargetValue - _fadValue;
                if( direction < 0 )
                {
                        _fadValue -= fadSpeed * dt;
                        if( _fadValue < _fadTargetValue ) _fadValue = _fadTargetValue;
                }
                else
                {
                        _fadValue += fadSpeed * dt;
                        if( _fadValue > _fadTargetValue ) _fadValue = _fadTargetValue;
                }
                _scene->setTimeSpeedMultiplier( _fadValue );
        }

        // action: first person mode
        if( Gameplay::iGameplay->getActionChannel( iaCameraMode0 )->getTrigger() )
        {
                setFirstPersonCamera();
        }
        // action: third person mode
        if( Gameplay::iGameplay->getActionChannel( iaCameraMode1 )->getTrigger() )
        {
                setThirdPersonCamera();
        }
        // action: follow mode
        if( Gameplay::iGameplay->getActionChannel( iaCameraMode4 )->getTrigger() )
        {
                setFollowCamera();
        }
        // action : flyway mode
        if( Gameplay::iGameplay->getActionChannel( iaCameraMode2 )->getTrigger() )
        {
                _player->happen( this, EVENT_JUMPER_THIRDPERSON, _player );
                _scene->setCamera( _fwcamera );
                _fwcamera->setupCamera( _player, 2.0f, 0.75f );
        }
        // action : free camera
        if( Gameplay::iGameplay->getActionChannel( iaCameraMode3 )->getTrigger() )
        {
                _player->happen( this, EVENT_JUMPER_THIRDPERSON, _player );
                _scene->setCamera( _frcamera );
        }    
        // action: time acceleration
        if( Gameplay::iGameplay->getActionChannel( ::iaAccelerateFlightTime )->getTrigger() && 
                _fadTimeout < 0 && ( _player->getPhase() == ::jpFlight || _player->getPhase() == ::jpRoaming ) )
        {
                _fadTargetValue *= 2.0f;
                if( _fadTargetValue > 4.0f ) _fadTargetValue = 4.0f;
                _fadTimeout = 0.25f;
        }
        // action: time deceleration
        if( Gameplay::iGameplay->getActionChannel( ::iaDecelerateFlightTime )->getTrigger() && 
                _fadTimeout < 0 && ( _player->getPhase() == ::jpFlight || _player->getPhase() == ::jpRoaming ) )
        {
                _fadTargetValue *= 0.5f;
                if( _fadTargetValue < 1.0f ) _fadTargetValue = 1.0f;
                _fadTimeout = 0.25f;
        }

        // reset time deceleration/acceleration
        if( _player->getPhase() == ::jpFreeFalling )
        {
                _fadTargetValue = 1.0f;
        }

        // collect forest actors
        unsigned int forestId;
        std::vector<Forest*> forests;
        getScene()->getScenery()->happen( this, EVENT_FOREST_ENUMERATE, &forests );

        // update physics
        _phTimeLeft += dt;
        while( _phTimeLeft > simulationStepTime )
        {
                // begin to simulate physics
                _scene->getPhScene()->simulate( simulationStepTime );
                _scene->getPhScene()->flushStream();
                _scene->getPhScene()->fetchResults( NX_RIGID_BODY_FINISHED, true );
                updatePhysics();
                _phTimeLeft -= simulationStepTime;

                // forest interaction
                for( forestId=0; forestId<forests.size(); forestId++ )
                {
                        forests[forestId]->simulateInteraction( _player );
                }
        }
        _scene->getPhScene()->visualize();

        // player is over its activity?
        if( !_endOfPlayerActivity && _player->isOverActivity() )
        {
                // raise local switch
                _endOfPlayerActivity = true;  

                // hide HUD
                happen( this, EVENT_HUD_HIDE );
        }

        // important action: TAB - show goals
        if( ( Gameplay::iGameplay->getKeyboardState()->keyState[0x0F] & 0x80 ) || _endOfPlayerActivity )
        {
                if( !goalsIsVisible() )
                {
                        showGoals( true );
                }
        }
        else
        {
                if( goalsIsVisible() )
                {
                        showGoals( false );
                }
        }
}
Exemplo n.º 2
0
void Mission::onUpdateActivity(float dt)
{
    _fadTimeout -= dt;
    _interruptTimeout -= dt;

    // important action: ESC - interrupt mission
    if( Gameplay::iGameplay->getKeyboardState()->keyState[0x01] & 0x80 )
    {
        if( _endOfPlayerActivity )
        {
            _scene->getCareer()->setMissionWalkthroughFlag( _wttid, _wtmid, true );
            _endOfMission = true;
        }
        else if( _interruptTimeout < 0 )
        {
            assert( _scene->getCamera() );
            _scene->getCamera()->updateActivity( 0.0f );
            new Interrupt( _scene, _scene->getCamera()->getPose(), &_endOfMission, ( _player->getPhase() != jpRoaming ) );
            _interruptTimeout = 0.25f;
            return;
        }
    }

    // soft time acceleration
    if( _fadValue != _fadTargetValue )
    {
        float fadSpeed =     1.0f;
        float direction = _fadTargetValue - _fadValue;
        if( direction < 0 )
        {
            _fadValue -= fadSpeed * dt;
            if( _fadValue < _fadTargetValue ) _fadValue = _fadTargetValue;
        }
        else
        {
            _fadValue += fadSpeed * dt;
            if( _fadValue > _fadTargetValue ) _fadValue = _fadTargetValue;
        }
        //_scene->setTimeSpeedMultiplier( _fadValue );
    }

    // action: first person mode
    if( Gameplay::iGameplay->getActionChannel( iaCameraMode0 )->getTrigger() )
    {
        setFirstPersonCamera();
		Gameplay::iGameplay->getActionChannel( iaCameraMode0 )->reset();
    }
    // action: third person mode
    if( Gameplay::iGameplay->getActionChannel( iaCameraMode1 )->getTrigger() )
    {
        setThirdPersonCamera();
    }
    // action : flyway mode
    if( Gameplay::iGameplay->getActionChannel( iaCameraMode2 )->getTrigger() )
    {
        _player->happen( this, EVENT_JUMPER_THIRDPERSON, _player );
        _scene->setCamera( _fwcamera );
        _fwcamera->setupCamera( _player, 2.0f, 0.75f );
    }
    // action : free camera
    if( Gameplay::iGameplay->getActionChannel( iaCameraMode3 )->getTrigger() )
    {
        _player->happen( this, EVENT_JUMPER_THIRDPERSON, _player );
        _scene->setCamera( _frcamera );
    }    
    // action: time acceleration
    if( Gameplay::iGameplay->getActionChannel( ::iaAccelerateFlightTime )->getTrigger() && 
        _fadTimeout < 0 && ( _player->getPhase() == ::jpFlight || _player->getPhase() == ::jpRoaming ) )
    {
        _fadTargetValue *= 2.0f;
        if( _fadTargetValue > 4.0f ) _fadTargetValue = 4.0f;
        _fadTimeout = 0.25f;
    }
    // action: time deceleration
    if( Gameplay::iGameplay->getActionChannel( ::iaDecelerateFlightTime )->getTrigger() && 
        _fadTimeout < 0 && ( _player->getPhase() == ::jpFlight || _player->getPhase() == ::jpRoaming ) )
    {
        _fadTargetValue *= 0.5f;
        if( _fadTargetValue < 1.0f ) _fadTargetValue = 1.0f;
        _fadTimeout = 0.25f;
    }

    // reset time deceleration/acceleration
    if( _player->getPhase() == ::jpFreeFalling )
    {
        _fadTargetValue = 1.0f;
    }
    
    // collect forest actors
    unsigned int forestId;
    std::vector<Forest*> forests;
    getScene()->getScenery()->happen( this, EVENT_FOREST_ENUMERATE, &forests );

    // update physics
    _phTimeLeft += dt;
    while( _phTimeLeft > simulationStepTime )
    {
        // begin to simulate physics
        _scene->getPhScene()->simulate( simulationStepTime );
        // PHYSX3
		_scene->getPhScene()->flushSimulation();
        _scene->getPhScene()->fetchResults(true);
        updatePhysics();
        _phTimeLeft -= simulationStepTime;

        // forest interaction
        for( forestId=0; forestId<forests.size(); forestId++ )
        {
            forests[forestId]->simulateInteraction( _player );
        }
    }
    
	//PHYSX3
	//_scene->getPhScene()->visualize();

    // player is over its activity?
    if( !_endOfPlayerActivity && _player->isOverActivity() )
    {
        // raise local switch
        _endOfPlayerActivity = true;  

        // hide HUD
        happen( this, EVENT_HUD_HIDE );
    }

    // important action: TAB - show goals
    if( ( Gameplay::iGameplay->getKeyboardState()->keyState[0x0F] & 0x80 ) || _endOfPlayerActivity )
    {
        if( !goalsIsVisible() )
        {
            showGoals( true );
        }
    }
    else
    {
        if( goalsIsVisible() )
        {
            showGoals( false );
        }
    }
	
	/// NETWORK
	NetworkData *packet = getScene()->network->consumePacketByReceiver(NET_REC_MISSION);
	while (packet != NULL) {
		consumePacket(packet);
		//delete packet;

		packet = getScene()->network->consumePacketByReceiver(NET_REC_MISSION);
	}

	// receive packets for jumpers
	//for (unsigned int i = 0; i < _children.size(); ++i) {
	//	if (strcmp(_children[i]->getName(), "Jumper") != 0) continue;

	//	NetworkData *packet = getScene()->network->consumePacketByReceiver(NET_REC_JUMPER, _children[i]->network_id);
	//	while (packet != NULL) {
	//		_children[i]->consumePacket(packet);
	//		packet = getScene()->network->consumePacketByReceiver(NET_REC_JUMPER, _children[i]->network_id);
	//	}
	//}
}