void ClientRead(VRage.Library.Collections.BitStream stream)
        {
            uint timeStamp = stream.ReadUInt32();

            m_lastRecievedTimeStamp = timeStamp;

            Vector3 serverLinearVelocity  = stream.ReadVector3();
            Vector3 serverAngularVelocity = stream.ReadVector3();

            MyTimeStampValues?clientData = m_timestamp.GetTransform(timeStamp);

            if (clientData.HasValue)
            {
                Vector3D linearDelta = serverLinearVelocity / MyEntityPhysicsStateGroup.EffectiveSimulationRatio - clientData.Value.LinearVelocity;
                Entity.Physics.LinearVelocity += Vector3D.Round(linearDelta, 2);
                Vector3D angularDelta = serverAngularVelocity / MyEntityPhysicsStateGroup.EffectiveSimulationRatio - clientData.Value.AngularVelocity;
                Entity.Physics.AngularVelocity += Vector3D.Round(angularDelta, 2);

                m_timestamp.UpdateDeltaVelocities(timeStamp, ref linearDelta, ref angularDelta);
            }


            bool isUpdate = stream.ReadBool();

            if (isUpdate)
            {
                MyTransformD serverTransform = new MyTransformD();
                serverTransform.Position = stream.ReadVector3D();
                serverTransform.Rotation = stream.ReadQuaternion();
                serverTransform.Rotation = Quaternion.Identity;

                CustomClientRead(timeStamp, ref serverTransform, stream);
            }
        }
コード例 #2
0
        void ServerWrite(VRage.Library.Collections.BitStream stream, ulong clientId)
        {
            stream.WriteUInt32(m_serverClientData[clientId]);
            var matrix = Entity.WorldMatrix;

            stream.Write(matrix.Translation);
            stream.WriteQuaternionNorm(Quaternion.CreateFromForwardUp(matrix.Forward, matrix.Up));
            //HalfVector3 linear = Entity.Physics != null ? Vector3.Round(Entity.Physics.LinearVelocity * MyEntityPhysicsStateGroup.EffectiveSimulationRatio, MyEntityPhysicsStateGroup.NUM_DECIMAL_PRECISION) : Vector3.Zero;
            Vector3 linear = Entity.Physics != null ? Entity.Physics.LinearVelocity * MyEntityPhysicsStateGroup.EffectiveSimulationRatio : Vector3.Zero;

            stream.Write(linear);

            Vector3 angular = Entity.Physics != null ? Entity.Physics.AngularVelocity * MyEntityPhysicsStateGroup.EffectiveSimulationRatio : Vector3.Zero;

            stream.Write(angular);

            m_clientUpdateFlag[clientId] = false;
            CustomServerWrite(m_serverClientData[clientId], stream);
        }