コード例 #1
0
void PlayerImplClient::handleNotification( const yaf3d::EntityNotification& notification )
{
    // handle some notifications
    switch( notification.getId() )
    {
        case YAF3D_NOTIFY_MENU_ENTER:

            if ( !_isRemoteClient )
            {
                getChatManager()->show( false );
                _p_inputHandler->setMenuEnabled( true );

                // reset player's movement and sound
                _p_playerPhysics->stopMovement();
                _p_playerAnimation->animIdle();
                if ( _p_playerSound )
                    _p_playerSound->stopPlayingAll();

                // very important: diable the camera when we enter menu!
                _p_camera->setEnable( false );

                // players are all rendered in menu, regardless their camera mode
                _p_playerAnimation->enableRendering( true );
            }
            break;

        case YAF3D_NOTIFY_MENU_LEAVE:
        {
            if ( !_isRemoteClient )
            {
                getChatManager()->show( true );
                _p_inputHandler->setMenuEnabled( false );

                // refresh our configuration settings
                getConfiguration();

                // very important: enable the camera when we leave menu!
                _p_camera->setEnable( true );

                // if we are in ego mode then disable player avatar rendering
                if ( _cameraMode == Ego )
                    _p_playerAnimation->enableRendering( false );
            }
        }
        break;

        case YAF3D_NOTIFY_SHUTDOWN:
        case YAF3D_NOTIFY_UNLOAD_LEVEL:
        {
            // destroy the chat manager
            destroyChatManager();
        }
        break;

        default:
            ;
    }
}
コード例 #2
0
void ZoneServerImplementation::timedShutdown(int minutes) {
	Reference<Task*> task = new ShutdownTask(_this.getReferenceUnsafeStaticCast(), minutes);
	task->schedule(60 * 1000);

	String str = "Server will shutdown in " + String::valueOf(minutes) + " minutes";
	Logger::console.info(str, true);

	getChatManager()->broadcastGalaxy(NULL, str);
}
コード例 #3
0
void PlayerImplStandalone::update( float deltaTime )
{
    // first update the physics entity
    getPlayerPhysics()->updateEntity( deltaTime );

    // update player's actual position and rotation once per frame
    getPlayerEntity()->setPosition( _currentPos ); 
    getPlayerEntity()->setRotation( _currentRot ); 

    // adjust the camera to updated position and rotation. the physics updates the translation of player.
    if ( _p_camera )
        _p_camera->setCameraTransformation( getPlayerPosition(), getPlayerRotation() );

    getChatManager()->update( deltaTime );

    // update sound
    getPlayerSound()->updatePosition( _currentPos );
}
コード例 #4
0
void PlayerImplClient::update( float deltaTime )
{
    // first update the physics entity
    getPlayerPhysics()->updateEntity( deltaTime );

    if ( !_isRemoteClient )
    {
        // update player's actual position and rotation once per frame
        getPlayerEntity()->setPosition( _currentPos );
        getPlayerEntity()->setRotation( _currentRot );

        getPlayerNetworking()->updatePosition( _currentPos._v[ 0 ], _currentPos._v[ 1 ], _currentPos._v[ 2 ] );
        getPlayerNetworking()->updateRotation( _rotZ + osg::PI );
        getPlayerNetworking()->updateAnimationFlags( getPlayerAnimation()->getAnimationFlags() );

        // adjust the camera to updated position and rotation. the physics updates the translation of player.
        _p_camera->setCameraTranslation( getPlayerPosition(), getPlayerRotation() );
        // update chat gui
        getChatManager()->update( deltaTime );
    }
    else
    {
        // update remote client's rotation and position
        osg::Vec3f lastpos = _currentPos;
        float      lastrot = _rotZ;
        osg::Vec3f clientpos;

        getPlayerNetworking()->getPosition( clientpos._v[ 0 ], clientpos._v[ 1 ], clientpos._v[ 2 ] );
        getPlayerNetworking()->getRotation( _rotZ );
        _currentRot.makeRotate( -_rotZ + osg::PI, osg::Vec3f( 0.0f, 0.0f, 1.0f ) );
        getPlayerEntity()->setRotation( _currentRot );
        getPlayerEntity()->setPosition( _currentPos );

        // calculate the current velocity
        osg::Vec3f vel( clientpos - lastpos );
        // do we need a hard position correction?
        if ( vel.length2() > NW_POS_CORRECTION_THRESHOLD )
        {
            osg::Matrix mat;
            mat.makeRotate( _currentRot );
            //mat.setTrans( lastpos + vel * deltaTime );
            mat.setTrans( clientpos );
            getPlayerPhysics()->setTransformation( mat );
            getPlayerPhysics()->setDirection( 0.0f, 0.0f );
        }
        else
        {
            vel._v[ 2 ] = 0.0f;
            // limit velocity
            if ( vel.length2() > 1.0f )
                vel.normalize();

            getPlayerPhysics()->setDirection( vel.x(), vel.y() );
        }

        // set animation depending on position and rotation changes
        if ( ( ( clientpos.z() - lastpos.z() ) > NW_JUMP_THRESHOLD ) && !getPlayerPhysics()->isJumping() )
        {
            getPlayerPhysics()->jump();
            getPlayerAnimation()->setAnimation( EnPlayerAnimation::eIdle );
            getPlayerAnimation()->setAnimation( EnPlayerAnimation::eJump );
        }
        else if ( vel.length2() > NW_WALK_THRESHOLD )
        {
            getPlayerAnimation()->setAnimation( EnPlayerAnimation::eWalk );
        } 
        else
        {
            getPlayerAnimation()->setAnimation( EnPlayerAnimation::eIdle );
        }
        
        if ( fabs( lastrot - _rotZ ) > NW_ROT_THRESHOLD )
            getPlayerAnimation()->setAnimation( EnPlayerAnimation::eTurn );
    }

    // update sound
    getPlayerSound()->updatePosition( _currentPos );
}