public static void EncodeEventArg(this RailBitBuffer buffer, Argument arg)
        {
            buffer.Write(NumberOfBitsForArgType, Convert.ToByte(arg.EventType));
            switch (arg.EventType)
            {
            case EventArgType.EntityReference:
                buffer.WriteEntityId(arg.RailId.Value);
                break;

            case EventArgType.MBGUID:
                buffer.WriteMBGUID(arg.MbGUID.Value);
                break;

            case EventArgType.Null:
                // Empty
                break;

            case EventArgType.Int:
                buffer.WriteInt(arg.Int.Value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        internal static void EncodeDelta(
            RailBitBuffer buffer,
            RailStateDelta delta)
        {
            // Write: [EntityId]
            buffer.WriteEntityId(delta.EntityId);

            // Write: [IsFrozen]
            buffer.WriteBool(delta.IsFrozen);

            if (delta.IsFrozen == false)
            {
                // Write: [FactoryType]
                RailState state = delta.State;
                buffer.WriteInt(RailState.FactoryTypeCompressor, state.factoryType);

                // Write: [IsRemoved]
                buffer.WriteBool(state.RemovedTick.IsValid);

                if (state.RemovedTick.IsValid)
                {
                    // Write: [RemovedTick]
                    buffer.WriteTick(state.RemovedTick);

                    // End Write
                }
                else
                {
                    // Write: [HasControllerData]
                    buffer.WriteBool(state.HasControllerData);

                    // Write: [HasImmutableData]
                    buffer.WriteBool(state.HasImmutableData);

                    // Write: [Flags]
                    buffer.Write(state.FlagBits, state.Flags);

                    // Write: [Mutable Data]
                    state.EncodeMutableData(buffer, state.Flags);

                    if (state.HasControllerData)
                    {
                        // Write: [Controller Data]
                        state.EncodeControllerData(buffer);

                        // Write: [Command Ack]
                        buffer.WriteTick(state.CommandAck);
                    }

                    if (state.HasImmutableData)
                    {
                        // Write: [Immutable Data]
                        state.EncodeImmutableData(buffer);
                    }
                }
            }
        }
Beispiel #3
0
        public static void EncodeDelta(
            IRailStateConstruction stateCreator,
            RailBitBuffer buffer,
            RailStateDelta delta)
        {
            // Write: [EntityId]
            buffer.WriteEntityId(delta.EntityId);

            // Write: [IsFrozen]
            buffer.WriteBool(delta.IsFrozen);

            if (delta.IsFrozen == false)
            {
                // Write: [FactoryType]
                RailState state = delta.State;
                buffer.WriteInt(stateCreator.EntityTypeCompressor, state.FactoryType);

                // Write: [IsRemoved]
                buffer.WriteBool(delta.RemovedTick.IsValid);

                if (delta.RemovedTick.IsValid)
                // Write: [RemovedTick]
                {
                    buffer.WriteTick(delta.RemovedTick);
                }

                // Write: [HasControllerData]
                buffer.WriteBool(state.HasControllerData);

                // Write: [HasImmutableData]
                buffer.WriteBool(state.HasImmutableData);

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

                // Write: [Flags]
                buffer.Write(state.DataSerializer.FlagBits, state.Flags);

                // Write: [Mutable Data]
                state.DataSerializer.EncodeMutableData(buffer, state.Flags);

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

                    // Write: [Command Ack]
                    buffer.WriteTick(delta.CommandAck);
                }
            }
        }
Beispiel #4
0
        public void Encode(RailBitBuffer buffer)
        {
            // Write: [EntityId]
            buffer.WriteEntityId(EntityId);

            // Write: [Count]
            buffer.Write(BUFFER_COUNT_BITS, (uint)commands.Count);

            // Write: [Commands]
            foreach (RailCommand command in commands.GetValues())
            {
                command.Encode(buffer);
            }
        }
 public static void WriteFloat(
     this RailBitBuffer buffer,
     RailFloatCompressor compressor,
     float value)
 {
     if (compressor.RequiredBits > RailConfig.VARINT_FALLBACK_SIZE)
     {
         buffer.WriteUInt(compressor.Pack(value));
     }
     else
     {
         buffer.Write(compressor.RequiredBits, compressor.Pack(value));
     }
 }
Beispiel #6
0
 public static void WriteInt64(
     this RailBitBuffer buffer,
     RailInt64Compressor compressor,
     long value)
 {
     if (compressor.RequiredBits > RailConfig.VARINT_FALLBACK_SIZE)
     {
         buffer.WriteUInt64(compressor.Pack(value));
     }
     else
     {
         buffer.Write(compressor.RequiredBits, (uint)compressor.Pack(value));
     }
 }
Beispiel #7
0
 public static void WriteInts(
     this RailBitBuffer buffer,
     RailIntCompressor compressor,
     int[] values)
 {
     if (compressor.RequiredBits > RailConfig.VARINT_FALLBACK_SIZE)
     {
         foreach (int value in values)
         {
             buffer.WriteUInt(compressor.Pack(value));
         }
     }
     else
     {
         foreach (int value in values)
         {
             buffer.Write(compressor.RequiredBits, compressor.Pack(value));
         }
     }
 }
Beispiel #8
0
 public void Write(RailBitBuffer buffer)
 {
     buffer.Write(BITS_USED, rawValue);
 }