Ejemplo n.º 1
0
void Gameplay::entityAct(float dt)
{
    _globalTimeIT -= dt;
    dt *= _globalTimeSpeed;

    // fade soundtracks
    if( _fadedSoundTrack )
    {
        if( !_fadedSoundTrack->isPlaying() )
        {
            _fadedSoundTrack->release();
            _fadedSoundTrack = NULL;
        }
        else
        {
            float fadeVelocity = 0.125f;
            _fadedGain -= fadeVelocity * dt;
            if( _fadedGain <= 0 )
            {
                _fadedSoundTrack->release();
                _fadedSoundTrack = NULL;
            }
            else
            {
                _fadedSoundTrack->setGain( _fadedGain );
            }
        }
    }

    // update soundtrack
    if( _soundTrack && !_soundTrack->isPlaying() )
    {
        _soundTrack->release();
        _soundTrack = NULL;
    }

    // update music volume
    float tuneVelocity = 0.2f;
    // increase volume?
    if( Gameplay::iGameplay->getActionChannel( ::iaIncreaseMusicVolume )->getTrigger() )
    {
        _musicVolumeTune += tuneVelocity * dt;
    }
    // decrease volume?
    if( Gameplay::iGameplay->getActionChannel( ::iaDecreaseMusicVolume )->getTrigger() )
    {
        _musicVolumeTune -= tuneVelocity * dt;
    }
    // finalize
    if( fabs( _musicVolumeTune ) > 0.01f )
    {
        float volume = Gameplay::iGameplay->getMusicVolume();
        volume += _musicVolumeTune, _musicVolumeTune = 0;
        if( volume < 0.0f ) volume = 0.0f;
        if( volume > 1.0f ) volume = 1.0f;
        Gameplay::iGameplay->setMusicVolume( volume );
    }

    // retrieve input device state
    _inputDevice->getKeyboardState( &_keyboardState );
    _inputDevice->getMouseState( &_mouseState );
	_inputDevice->getJoystickState( &_joystickState );

    // map input actions
    for( ActionChannelI actionChannelI = _actionChannels.begin();
                        actionChannelI != _actionChannels.end();
                        actionChannelI++ )
    {
        actionChannelI->second->update( dt, &_mouseState, &_keyboardState, &_joystickState );
    }

    // global controls
    #ifdef GAMEPLAY_DEVELOPER_EDITION
        if( getActionChannel( ::iaGlobalAcceleration )->getTrigger() )
        {
            if( _globalTimeIT < 0 )
            {
                _globalTimeSpeed *= 2.0f;
                if( _globalTimeSpeed > 2.0f ) _globalTimeSpeed = 2.0f;
                _globalTimeIT = 0.25f;
            }
        }
        if( getActionChannel( ::iaGlobalDeceleration )->getTrigger() )
        {
            if( _globalTimeIT < 0 )
            {
                _globalTimeSpeed *= 0.5f;
                if( _globalTimeSpeed < 0.125f ) _globalTimeSpeed = 0.125f;
                _globalTimeIT = 0.25f;
            }
        }
    #endif

    // schedule activities
    if( _activities.size() ) 
    {
        _activities.top()->updateCooperativeActivity( dt );
    }
    else
    {
        getCore()->exit( 0 );
    }
    if( _activities.size() && _activities.top()->endOfActivity() )
    {
        Activity* activity = _activities.top();
        _activities.pop();
        activity->onBecomeInactive();

        if( _activities.size() ) 
        {
            _activities.top()->onReturnFromActivity( activity );
            delete activity;
            _activities.top()->onBecomeActive();
        }
        else
        {
            delete activity;
        }
    }
}
Ejemplo n.º 2
0
Gameplay::~Gameplay()
{
    if( !_isUnsafeCleanup )
    {
        if( _soundTrack ) 
        {
            _soundTrack->stop();
            _soundTrack->release();
        }
        if( _fadedSoundTrack )
        {
            _fadedSoundTrack->stop();
            _fadedSoundTrack->release();
        }
    
        // delete activities
        while( _activities.size() )
        {
            Activity* activity = _activities.top();
            _activities.pop();
            activity->onBecomeInactive();
            if( _activities.size() ) 
            {
                _activities.top()->onReturnFromActivity( activity );
                delete activity;
                _activities.top()->onBecomeActive();
            }
            else
            {
                delete activity;
            }
        }
    
        // delete careers
        saveCareers();
        for( unsigned int i=0; i<_careers.size(); i++ ) delete _careers[i];

        // delete user events
        cleanupUserCommunityEvents();
    
        // delete render target
        if (_renderTarget) delete _renderTarget;
    
        // delete sdks
		PxGetPhysics().release();
		pxCooking->release();
		foundation->release();
    
        // cleanup action mapping
        destroyActionMap();

        // delete input device
        _inputDevice->release();

        delete _config;
    }

    // reset internal interface pointers
    iGameplay = NULL;
    iEngine   = NULL;
    iGui      = NULL;
    iLanguage = NULL;
    iInput    = NULL;
    iAudio    = NULL;
}