예제 #1
0
        void Client_ReceivePositions( RemoteEntityWorld sender, ReceiveDataReader reader )
        {
            //clear snanshots cache if entity is not created
            if( !IsPostCreated )
                client_receivePositionsSnapshots.Clear();

            //check for invalid snapshot cache
            if( client_receivePositionsSnapshots.Count != 0 )
            {
                Client_ReceivePositionsSnapshot lastSnapshot = client_receivePositionsSnapshots[
                    client_receivePositionsSnapshots.Count - 1 ];
                if( lastSnapshot.bodies != null )
                {
                    //remove snapshot cache
                    client_receivePositionsSnapshots.Clear();
                }
            }

            Client_ReceivePositionsSnapshot snapshot = new Client_ReceivePositionsSnapshot();
            snapshot.networkTickNumber = EntitySystemWorld.Instance.NetworkTickCounter;

            //read position
            if( reader.ReadBoolean() )
            {
                snapshot.position = reader.ReadVec3();
            }
            else
            {
                //get position from previous snapshot
                if( client_receivePositionsSnapshots.Count != 0 )
                {
                    snapshot.position = client_receivePositionsSnapshots[
                        client_receivePositionsSnapshots.Count - 1 ].position;
                }
            }

            //read rotation
            if( reader.ReadBoolean() )
            {
                snapshot.rotation = reader.ReadQuat( 16 );
            }
            else
            {
                //get rotation from previous snapshot
                if( client_receivePositionsSnapshots.Count != 0 )
                {
                    snapshot.rotation = client_receivePositionsSnapshots[
                        client_receivePositionsSnapshots.Count - 1 ].rotation;
                }
            }

            //read scale
            if( reader.ReadBoolean() )
            {
                snapshot.scale = reader.ReadVec3();
            }
            else
            {
                //get position from previous snapshot
                if( client_receivePositionsSnapshots.Count != 0 )
                {
                    snapshot.scale = client_receivePositionsSnapshots[
                        client_receivePositionsSnapshots.Count - 1 ].scale;
                }
            }

            if( !reader.Complete() )
                return;

            client_receivePositionsSnapshots.Add( snapshot );

            Client_UpdatePositionsBySnapshots( false );
        }
예제 #2
0
        void Client_ReceiveBodiesPositions( RemoteEntityWorld sender, ReceiveDataReader reader )
        {
            //clear snapshots cache if entity is not created
            if( !IsPostCreated )
                client_receivePositionsSnapshots.Clear();

            //check for invalid snapshot cache
            if( client_receivePositionsSnapshots.Count != 0 )
            {
                Client_ReceivePositionsSnapshot lastSnapshot = client_receivePositionsSnapshots[
                    client_receivePositionsSnapshots.Count - 1 ];
                if( lastSnapshot.bodies == null )
                {
                    //remove snapshot cache
                    client_receivePositionsSnapshots.Clear();
                }
            }

            int count = (int)reader.ReadVariableUInt32();

            Client_ReceivePositionsSnapshot snapshot = new Client_ReceivePositionsSnapshot();
            snapshot.networkTickNumber = EntitySystemWorld.Instance.NetworkTickCounter;

            snapshot.bodies = new Client_ReceivePositionsSnapshot.BodyItem[ count ];

            //receive bodies positions and rotations
            for( int n = 0; n < count; n++ )
            {
                Client_ReceivePositionsSnapshot.BodyItem bodyItem = new
                    Client_ReceivePositionsSnapshot.BodyItem();

                //read position
                if( reader.ReadBoolean() )
                {
                    bodyItem.position = reader.ReadVec3();
                }
                else
                {
                    //get position from previous snapshot
                    if( client_receivePositionsSnapshots.Count != 0 )
                    {
                        bodyItem.position = client_receivePositionsSnapshots[
                            client_receivePositionsSnapshots.Count - 1 ].bodies[ n ].position;
                    }
                }

                //read rotation
                if( reader.ReadBoolean() )
                {
                    bodyItem.rotation = reader.ReadQuat( 16 );
                }
                else
                {
                    //get rotation from previous snapshot
                    if( client_receivePositionsSnapshots.Count != 0 )
                    {
                        bodyItem.rotation = client_receivePositionsSnapshots[
                            client_receivePositionsSnapshots.Count - 1 ].bodies[ n ].rotation;
                    }
                }

                snapshot.bodies[ n ] = bodyItem;
            }

            if( !reader.Complete() )
                return;

            client_receivePositionsSnapshots.Add( snapshot );

            if( IsPostCreated )
                Client_UpdatePositionsBySnapshots( false );
        }