示例#1
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);
            }
        }
示例#2
0
        private void WritePhysics(BitStream stream, MyEntity controlledEntity)
        {
            IMyReplicable player = MyExternalReplicable.FindByObject(controlledEntity);

            if (player == null)
            {
                stream.WriteBool(false);
                return;
            }

            var stateGroup = player.FindStateGroup <MyEntityPhysicsStateGroup>();

            if (stateGroup == null)
            {
                stream.WriteBool(false);
                return;
            }
            bool isResponsible = stateGroup.ResponsibleForUpdate(new EndpointId(Sync.MyId));

            stream.WriteBool(isResponsible);
            if (isResponsible)
            {
                stateGroup.Serialize(stream, null, 0, 65535);
            }
        }