public static void WriteMethodCall(this RailBitBuffer buffer, MethodCall pack)
 {
     buffer.WriteInt(pack.Id.InternalValue);
     buffer.EncodeEventArg(pack.Instance);
     buffer.WriteInt(pack.Arguments.Count);
     foreach (Argument arg in pack.Arguments)
     {
         buffer.EncodeEventArg(arg);
     }
 }
        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 #3
0
        private void ReadWriteInt(int expected)
        {
            RailBitBuffer buffer = new RailBitBuffer();

            buffer.WriteInt(expected);
            long actual = buffer.ReadInt();

            Assert.Equal(expected, actual);
        }
Beispiel #4
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 #5
0
        /// <summary>
        ///     Note that the packetTick may not be the tick this event was created on
        ///     if we're re-trying to send this event in subsequent packets. This tick
        ///     is intended for use in tick diffs for compression.
        /// </summary>
        public void Encode(RailIntCompressor compressor, RailBitBuffer buffer, Tick packetTick)
        {
            // Write: [EventType]
            buffer.WriteInt(compressor, FactoryType);

            // Write: [EventId]
            buffer.WriteSequenceId(EventId);

            // Write: [EventData]
            DataSerializer.WriteData(buffer, packetTick);
        }
Beispiel #6
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 #7
0
        private void DecodeReadsTickAndCommandData(int iData)
        {
            RailMemoryPool <RailCommand> pool =
                new RailMemoryPool <RailCommand>(new RailFactory <TestUtils.Command>());
            Mock <IRailCommandConstruction> mockCreator = new Mock <IRailCommandConstruction>();

            mockCreator.Setup(m => m.CreateCommand()).Returns(pool.Allocate());

            RailBitBuffer bitBuffer   = new RailBitBuffer(2);
            Tick          writtenTick = Tick.START.GetNext();

            bitBuffer.WriteTick(writtenTick);
            bitBuffer.WriteInt(iData);

            RailCommand decodedGenericCommand = RailCommand.Decode(mockCreator.Object, bitBuffer);

            Assert.IsType <TestUtils.Command>(decodedGenericCommand);
            TestUtils.Command decodedCommand = decodedGenericCommand as TestUtils.Command;
            Assert.NotNull(decodedCommand);
            Assert.Equal(writtenTick, decodedCommand.ClientTick);
            Assert.Equal(iData, decodedCommand.Data);
        }
Beispiel #8
0
 public void WriteData(RailBitBuffer buffer)
 {
     buffer.WriteInt(Data);
 }
Beispiel #9
0
 public void Write(RailBitBuffer buffer, int i)
 {
     buffer.WriteInt(this, i);
 }
Beispiel #10
0
 public static void Encode(this RailBitBuffer buffer, Foo instance)
 {
     buffer.WriteInt(instance.A);
     buffer.WriteInt(instance.B);
 }
Beispiel #11
0
 protected override void EncodeImmutableData(RailBitBuffer buffer)
 {
     buffer.WriteInt(this.ArchetypeId);
     buffer.WriteInt(this.UserId);
 }