Exemplo n.º 1
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);
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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.º 4
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.º 5
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);
        }