Ejemplo n.º 1
0
        public static float ReadFloat(this RailBitBuffer buffer, RailFloatCompressor compressor)
        {
            if (compressor.RequiredBits > RailConfig.VARINT_FALLBACK_SIZE)
            {
                return(compressor.Unpack(buffer.ReadUInt()));
            }

            return(compressor.Unpack(buffer.Read(compressor.RequiredBits)));
        }
Ejemplo n.º 2
0
        public static long ReadInt64(this RailBitBuffer buffer, RailInt64Compressor compressor)
        {
            if (compressor.RequiredBits > RailConfig.VARINT_FALLBACK_SIZE)
            {
                return(compressor.Unpack(buffer.ReadUInt64()));
            }

            return(compressor.Unpack(buffer.Read(compressor.RequiredBits)));
        }
Ejemplo n.º 3
0
        public static RailCommandUpdate Decode(
            IRailCommandConstruction commandCreator,
            RailBitBuffer buffer)
        {
            RailCommandUpdate update = commandCreator.CreateCommandUpdate();

            // Read: [EntityId]
            update.EntityId = buffer.ReadEntityId();

            // Read: [Count]
            int count = (int)buffer.Read(BUFFER_COUNT_BITS);

            // Read: [Commands]
            for (int i = 0; i < count; i++)
            {
                update.commands.Store(RailCommand.Decode(commandCreator, buffer));
            }

            return(update);
        }
Ejemplo n.º 4
0
 public static void ReadFloats(
     this RailBitBuffer buffer,
     RailFloatCompressor compressor,
     float[] toStore)
 {
     if (compressor.RequiredBits > RailConfig.VARINT_FALLBACK_SIZE)
     {
         for (int i = 0; i < toStore.Length; i++)
         {
             toStore[i] = compressor.Unpack(buffer.ReadUInt());
         }
     }
     else
     {
         for (int i = 0; i < toStore.Length; i++)
         {
             toStore[i] = compressor.Unpack(buffer.Read(compressor.RequiredBits));
         }
     }
 }
Ejemplo n.º 5
0
        public static Argument DecodeEventArg(this RailBitBuffer buffer)
        {
            EventArgType eType = (EventArgType)buffer.Read(NumberOfBitsForArgType);

            switch (eType)
            {
            case EventArgType.EntityReference:
                return(new Argument(buffer.ReadEntityId()));

            case EventArgType.MBGUID:
                return(new Argument(buffer.ReadMBGUID()));

            case EventArgType.Null:
                return(Argument.Null);

            case EventArgType.Int:
                return(new Argument(buffer.ReadInt()));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 6
0
        public static RailStateDelta DecodeDelta(
            IRailStateConstruction stateCreator,
            RailBitBuffer buffer,
            Tick packetTick)
        {
            RailStateDelta delta = stateCreator.CreateDelta();
            RailState      state = null;

            Tick commandAck  = Tick.INVALID;
            Tick removedTick = Tick.INVALID;

            // Read: [EntityId]
            EntityId entityId = buffer.ReadEntityId();

            // Read: [IsFrozen]
            bool isFrozen = buffer.ReadBool();

            if (isFrozen == false)
            {
                // Read: [FactoryType]
                int factoryType = buffer.ReadInt(stateCreator.EntityTypeCompressor);
                state = stateCreator.CreateState(factoryType);

                // Read: [IsRemoved]
                bool isRemoved = buffer.ReadBool();

                if (isRemoved)
                // Read: [RemovedTick]
                {
                    removedTick = buffer.ReadTick();
                }

                // Read: [HasControllerData]
                state.HasControllerData = buffer.ReadBool();

                // Read: [HasImmutableData]
                state.HasImmutableData = buffer.ReadBool();

                if (state.HasImmutableData)
                // Read: [Immutable Data]
                {
                    state.DataSerializer.DecodeImmutableData(buffer);
                }

                // Read: [Flags]
                state.Flags = buffer.Read(state.DataSerializer.FlagBits);

                // Read: [Mutable Data]
                state.DataSerializer.DecodeMutableData(buffer, state.Flags);

                if (state.HasControllerData)
                {
                    // Read: [Controller Data]
                    state.DataSerializer.DecodeControllerData(buffer);

                    // Read: [Command Ack]
                    commandAck = buffer.ReadTick();
                }
            }

            delta.Initialize(packetTick, entityId, state, removedTick, commandAck, isFrozen);
            return(delta);
        }
Ejemplo n.º 7
0
        internal static RailStateDelta DecodeDelta(
            RailBitBuffer buffer,
            Tick packetTick)
        {
            RailStateDelta delta = RailResource.Instance.CreateDelta();
            RailState      state = null;

            // Read: [EntityId]
            EntityId entityId = buffer.ReadEntityId();

            // Read: [IsFrozen]
            bool isFrozen = buffer.ReadBool();

            if (isFrozen == false)
            {
                // Read: [FactoryType]
                int factoryType = buffer.ReadInt(RailState.FactoryTypeCompressor);
                state = RailState.Create(factoryType);

                // Read: [IsRemoved]
                bool isRemoved = buffer.ReadBool();

                if (isRemoved)
                {
                    // Read: [DestroyedTick]
                    state.RemovedTick = buffer.ReadTick();

                    // End Read
                }
                else
                {
                    // Read: [HasControllerData]
                    state.HasControllerData = buffer.ReadBool();

                    // Read: [HasImmutableData]
                    state.HasImmutableData = buffer.ReadBool();

                    // Read: [Flags]
                    state.Flags = buffer.Read(state.FlagBits);

                    // Read: [Mutable Data]
                    state.DecodeMutableData(buffer, state.Flags);

                    if (state.HasControllerData)
                    {
                        // Read: [Controller Data]
                        state.DecodeControllerData(buffer);

                        // Read: [Command Ack]
                        state.CommandAck = buffer.ReadTick();
                    }

                    if (state.HasImmutableData)
                    {
                        // Read: [Immutable Data]
                        state.DecodeImmutableData(buffer);
                    }
                }
            }

            delta.Initialize(packetTick, entityId, state, isFrozen);
            return(delta);
        }
Ejemplo n.º 8
0
 public static SequenceId Read(RailBitBuffer buffer)
 {
     return(new SequenceId(buffer.Read(BITS_USED)));
 }