public MyEntityPhysicsStateGroupWithSupport(MyEntity entity, IMyReplicable ownerReplicable)
     : base(entity, ownerReplicable)
 {
     m_onSupportMove = OnSupportMove;
     m_onSupportVelocityChanged = OnSupportVelocityChanged;
     if (Sync.IsServer)
         OnMoved += PhysicsStateGroup_OnMoved;
 }
Beispiel #2
0
 public MyEntityPhysicsStateGroupWithSupport(MyEntity entity, IMyReplicable ownerReplicable)
     : base(entity, ownerReplicable)
 {
     m_onSupportMove            = OnSupportMove;
     m_onSupportVelocityChanged = OnSupportVelocityChanged;
     if (Sync.IsServer)
     {
         OnMoved += PhysicsStateGroup_OnMoved;
     }
 }
 private static extern IntPtr CreateWindow(IntPtr appPointer,
                                           Int2 size, Int2 minSize,
                                           string title,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] ResizedDelegate resizedCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] BeginResizeDelegate beginResizeCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] EndResizeDelegate endResizeCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] MovedDelegate movedCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] MinimizedDelegate minimizedCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] DeminimizedDelegate deminimizedDelegate,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] MaximizedDelegate maximizedCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] DemaximizedDelegate demaximizedCallback,
                                           [MarshalAs(UnmanagedType.FunctionPtr)] CloseRequestedDelegate closeCallback);
        static bool ReadTransform(BitStream stream, MyEntity entity, Vector3D?deltaPosBase, bool applyWhenReading, bool movingOnServer, ref Vector3D outPosition, ref Quaternion outOrientation, ref MatrixD outWorldMartix, Func <MyEntity, Vector3D, bool> posValidation = null, MovedDelegate moveHandler = null)
        {
            Vector3D position;

            if (stream.ReadBool())
            {
                position = stream.ReadVector3D(); // 24 B
            }
            else
            {
                Vector3 pos = stream.ReadVector3(); // 6 B
                if (deltaPosBase != null)
                {
                    position = pos + deltaPosBase.Value;
                }
                else
                {
                    position = pos;
                }
            }
            Quaternion orientation;
            bool       lowPrecisionOrientation = stream.ReadBool();

            if (lowPrecisionOrientation)
            {
                orientation = stream.ReadQuaternionNormCompressed(); // 29b
            }
            else
            {
                orientation = stream.ReadQuaternionNorm(); // 52b
            }

            if (entity != null)
            {
                if (applyWhenReading && (posValidation == null || posValidation(entity, position)))
                {
                    MatrixD matrix = MatrixD.CreateFromQuaternion(orientation);
                    if (matrix.IsValid())
                    {
                        matrix.Translation = position;

                        outPosition    = matrix.Translation;
                        outOrientation = orientation;
                        outWorldMartix = matrix;
                        return(true);
                    }
                    return(false);
                }
            }
            return(false);
        }
        /// <summary>
        /// Serializes transform into 10 to 30.5 bytes.
        /// </summary>
        protected static bool SerializeTransform(BitStream stream, MyEntity entity, Vector3D?deltaPosBase, bool lowPrecisionOrientation, bool applyWhenReading, bool movingOnServer, uint timeStamp, Func <MyEntity, Vector3D, bool> posValidation = null, MovedDelegate moveHandler = null)
        {
            stream.Serialize(ref timeStamp);
            if (stream.Writing)
            {
                WriteTransform(stream, entity, deltaPosBase, lowPrecisionOrientation);
                return(true);
            }
            else
            {
                bool apply = ReadTransform(stream, entity, deltaPosBase, applyWhenReading, movingOnServer, ref m_readTranslation, ref m_readQuaternion, ref m_readMatrix, posValidation, moveHandler);
                if (apply)
                {
                    var old = entity.PositionComp.WorldMatrix;
                    entity.PositionComp.SetWorldMatrix(m_readMatrix, null);

                    if (moveHandler != null)
                    {
                        moveHandler(ref old, ref m_readMatrix);
                    }
                }
                return(apply);
            }
        }
Beispiel #6
0
        bool ReadTransform(BitStream stream, MyEntity entity, Vector3D? deltaPosBase, bool applyWhenReading, bool movingOnServer, ref Vector3D outPosition, ref Quaternion outOrientation, ref MatrixD outWorldMartix, Func<MyEntity, Vector3D, bool> posValidation = null, MovedDelegate moveHandler = null)
        {
            Vector3D position;
            if (stream.ReadBool())
            {
                position = stream.ReadVector3D(); // 24 B
            }
            else
            {
                Vector3 pos = stream.ReadVector3(); // 6 B
                if (deltaPosBase != null)
                {
                    position = pos + deltaPosBase.Value;
                }
                else
                {
                    position = pos;
                }
            }
            Quaternion orientation;
            bool lowPrecisionOrientation = stream.ReadBool();
            if (lowPrecisionOrientation)
            {
                orientation = stream.ReadQuaternionNormCompressed(); // 29b
            }
            else
            {
                orientation = stream.ReadQuaternionNorm(); // 52b
            }

            if (entity != null)
            {
                movingOnServer |= (entity.PositionComp.GetPosition() - position).LengthSquared() > epsilonSq;

                if (movingOnServer && applyWhenReading && (posValidation == null || posValidation(entity, position)))
                {
                    MatrixD matrix = MatrixD.CreateFromQuaternion(orientation);
                    if (matrix.IsValid())
                    {
                        matrix.Translation = position;

                        outPosition = matrix.Translation;
                        outOrientation = orientation;
                        outWorldMartix = matrix;
                        return true;
                    }
                    return false;
                }
            }
            return false;
        }
Beispiel #7
0
        /// <summary>
        /// Serializes transform into 10 to 30.5 bytes.
        /// </summary>
        protected bool SerializeTransform(BitStream stream, MyEntity entity, Vector3D? deltaPosBase, bool lowPrecisionOrientation, bool applyWhenReading, bool movingOnServer, uint timeStamp, Func<MyEntity, Vector3D, bool> posValidation = null, MovedDelegate moveHandler = null)
        {
            stream.Serialize(ref timeStamp);
            if(stream.Writing)
            {
                WriteTransform(stream, entity, deltaPosBase, lowPrecisionOrientation);
                return true;
            }
            else
            {
                bool apply = ReadTransform(stream, entity, deltaPosBase, applyWhenReading,movingOnServer, ref m_readTranslation, ref m_readQuaternion, ref m_readMatrix, posValidation, moveHandler);
                if (apply)
                {
                    var old = entity.PositionComp.WorldMatrix;
                    entity.PositionComp.SetWorldMatrix(m_readMatrix, null);

                    if (moveHandler != null)
                    {
                        moveHandler(ref old, ref m_readMatrix);
                    }
                }
                return apply;
            }
        }
Beispiel #8
0
        static bool ReadTransform(BitStream stream, MyEntity entity, Vector3D?deltaPosBase, bool applyWhenReading, bool movingOnServer, ref Vector3D outPosition, ref Quaternion outOrientation, ref MatrixD outWorldMartix, Func <MyEntity, Vector3D, bool> posValidation = null, MovedDelegate moveHandler = null)
        {
            Vector3D position;

            if (stream.ReadBool())
            {
                position = stream.ReadVector3D(); // 24 B
            }
            else
            {
                HalfVector3 pos = stream.ReadHalfVector3(); // 6 B
                if (deltaPosBase != null)
                {
                    position = pos + deltaPosBase.Value;
                }
                else
                {
                    position = pos.ToVector3();
                }
            }
            Quaternion orientation;
            bool       lowPrecisionOrientation = stream.ReadBool();

            if (lowPrecisionOrientation)
            {
                orientation = stream.ReadQuaternionNormCompressed(); // 29b
            }
            else
            {
                orientation = stream.ReadQuaternionNorm(); // 52b
            }

            if (entity != null)
            {
                movingOnServer |= (entity.PositionComp.GetPosition() - position).LengthSquared() > epsilonSq;
            }

            if (movingOnServer && applyWhenReading && (posValidation == null || posValidation(entity, position)))
            {
                var old = entity.PositionComp.WorldMatrix;

                MatrixD matrix = MatrixD.CreateFromQuaternion(orientation);
                if (matrix.IsValid())
                {
                    matrix.Translation = Vector3D.Round(position, NUM_DECIMAL_PRECISION + 1);

                    outPosition    = matrix.Translation;
                    outOrientation = orientation;
                    outWorldMartix = matrix;
                    return(true);
                }
                return(false);
            }
            return(false);
        }