Exemplo n.º 1
0
        private static void DecodeHeader(RailPacketIncoming packet, RailBitBuffer buffer)
        {
            // Read: [LocalTick]
            packet.SenderTick = buffer.ReadTick();

            // Read: [LastAckTick]
            packet.LastAckTick = buffer.ReadTick();

            // Read: [AckReliableEventId]
            packet.LastAckEventId = buffer.ReadSequenceId();
        }
Exemplo n.º 2
0
        internal static RailCommand Decode(
            RailBitBuffer buffer)
        {
            RailCommand command = RailCommand.Create();

            // Read: [SenderTick]
            command.ClientTick = buffer.ReadTick();

            // Read: [Command Data]
            command.DecodeData(buffer);

            return(command);
        }
Exemplo n.º 3
0
        public static RailCommand Decode(
            IRailCommandConstruction commandCreator,
            RailBitBuffer buffer)
        {
            RailCommand command = commandCreator.CreateCommand();

            // Read: [SenderTick]
            command.ClientTick = buffer.ReadTick();

            // Read: [Command Data]
            command.DataSerializer.DecodeData(buffer);

            return(command);
        }
Exemplo n.º 4
0
        private void EncodeWritesTickAndCommandData(int iData)
        {
            RailBitBuffer bitBuffer = new RailBitBuffer(2);

            TestUtils.Command command = new TestUtils.Command(iData)
            {
                ClientTick   = Tick.START,
                IsNewCommand = true
            };
            ((IRailPoolable <RailCommand>)command).Allocated();
            command.Encode(bitBuffer);

            Tick writtenTick = bitBuffer.ReadTick();
            int  writtenData = bitBuffer.ReadInt();

            Assert.Equal(Tick.START, writtenTick);
            Assert.Equal(iData, writtenData);
        }
Exemplo n.º 5
0
    public void DecodeView(RailBitBuffer buffer)
    {
      IEnumerable<KeyValuePair<EntityId, RailViewEntry>> decoded =
        buffer.UnpackAll(
          () =>
          {
            return new KeyValuePair<EntityId, RailViewEntry>(
              buffer.ReadEntityId(),  // Read: [EntityId] 
              new RailViewEntry(
                buffer.ReadTick(),    // Read: [Tick]
                buffer.ReadBool()));  // Read: [IsFrozen]
          });

      foreach (var pair in decoded)
        this.view.RecordUpdate(pair.Key, pair.Value);
#endif
    }
Exemplo 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);
        }
Exemplo 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);
        }