public override void Destroy()
 {
     if (m_supportPhysics != null)
     {
         m_supportPhysics.OnVelocityChanged -= m_onSupportVelocityChanged;
         m_supportPhysics.OnMoved -= m_onSupportMove;
         m_supportPhysics = null;
     }
     base.Destroy();
 }
예제 #2
0
        private void WritePhysics(BitStream stream, MyEntity controlledEntity)
        {
            IMyReplicable controlledReplicable = MyExternalReplicable.FindByObject(controlledEntity);

            stream.WriteBool(controlledReplicable != null);

            if (controlledReplicable == null)
            {
                return;
            }

            IMyStateGroup stateGroup = null;

            bool             useCharacterOnServer = controlledEntity is MyCharacter && MyFakes.ENABLE_CHARACTER_CONTROL_ON_SERVER;
            bool             useGridOnServer      = controlledEntity is MyCubeGrid && MyFakes.ENABLE_SHIP_CONTROL_ON_SERVER;
            MyShipController controller           = MySession.Static.ControlledEntity as MyShipController;
            bool             hasWheels            = controller != null && controller.HasWheels;
            long?            supportId            = null;

            if (useCharacterOnServer || (useGridOnServer && hasWheels == false))
            {
                MyEntityPositionVerificationStateGroup group = controlledReplicable.FindStateGroup <MyEntityPositionVerificationStateGroup>();
                stateGroup = group;
                supportId  = group.GetSupportID();
            }
            else
            {
                stateGroup = controlledReplicable.FindStateGroup <MyEntityPhysicsStateGroup>();
            }


            stream.WriteBool(useCharacterOnServer || (useGridOnServer && hasWheels == false));
            stream.WriteBool(stateGroup != null);

            if (stateGroup == null)
            {
                return;
            }

            stream.WriteBool(supportId.HasValue);
            if (supportId.HasValue)
            {
                stream.WriteInt64(supportId.Value);
            }

            bool isResponsible = MyEntityPhysicsStateGroup.ResponsibleForUpdate(controlledEntity, new EndpointId(Sync.MyId));

            stream.WriteBool(isResponsible);
            if (isResponsible)
            {
                stateGroup.Serialize(stream, EndpointId, ClientTimeStamp, 0, 1024 * 1024);
            }
        }
        public override void ClientUpdate(uint timestamp)
        {
            base.ClientUpdate(timestamp);

            if (MySession.Static.ControlledEntity != m_character)
            {
                if(m_supportTimeStamp != null)
                {
                    m_supportTimeStamp.Clear();
                }
                return;
            }

            var physGroup = MyExternalReplicable.FindByObject(m_character).FindStateGroup<MyCharacterPhysicsStateGroup>();
            if (physGroup == null)
            {
                if (m_supportTimeStamp != null)
                {
                    m_supportTimeStamp.Clear();
                }
                return;
            }

            m_supportPhysics = physGroup.FindSupportDelegate();
            physGroup.SetSupport(m_supportPhysics);
            if (m_supportPhysics != null)
            {
                if (m_supportTimeStamp == null)
                {
                    m_supportTimeStamp = new MyTimestampHelper(null);
                }

                m_supportTimeStamp.SetEntity(m_supportPhysics.Entity);
                m_supportTimeStamp.Update(timestamp);
            }
            else
            {
                if (m_supportTimeStamp != null)
                {
                    m_supportTimeStamp.Clear();
                }
            }

        }
예제 #4
0
        private void ReadPhysics(BitStream stream, MyNetworkClient sender, MyEntity controlledEntity, uint serverTimeStamp)
        {
            bool hasPhysics = stream.ReadBool();

            m_currentServerTimeStamp = serverTimeStamp;

            if (hasPhysics && MyEntityPhysicsStateGroup.ResponsibleForUpdate(controlledEntity, new EndpointId(sender.SteamUserId)))
            {
                IMyStateGroup stateGroup = null;
                SupportId = null;
                bool enableControlOnServer = stream.ReadBool();
                bool stateGroupFound       = stream.ReadBool();
                if (stateGroupFound == false)
                {
                    return;
                }


                if (stream.ReadBool())
                {
                    SupportId = stream.ReadInt64();
                }

                if (enableControlOnServer)
                {
                    stateGroup = MyExternalReplicable.FindByObject(controlledEntity).FindStateGroup <MyEntityPositionVerificationStateGroup>();
                }
                else
                {
                    stateGroup = MyExternalReplicable.FindByObject(controlledEntity).FindStateGroup <MyEntityPhysicsStateGroup>();
                }

                if (stream.ReadBool())
                {
                    stateGroup.Serialize(stream, new EndpointId(sender.SteamUserId), ClientTimeStamp, 0, 65535);
                }
            }
        }
 protected override float GetGroupPriority(int frameCountWithoutSync, VRage.Network.MyClientInfo client, MyEntityPhysicsStateGroup.PrioritySettings settings)
 {
     return base.GetGroupPriority(frameCountWithoutSync, client, settings);
 }
 public void SetSupport(MyEntityPhysicsStateGroup physicsGroup)
 {
     if (m_supportPhysics != physicsGroup)
     {
         if (m_supportPhysics != null)
         {
             m_supportPhysics.OnMoved -= m_onSupportMove;
             m_supportPhysics.OnVelocityChanged -= m_onSupportVelocityChanged;
         }
         m_supportPhysics = physicsGroup;
         if (m_supportPhysics != null)
         {
             m_supportPhysics.OnMoved += m_onSupportMove;
             m_supportPhysics.OnVelocityChanged += m_onSupportVelocityChanged;
         }
     }
 }