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();
            }
        }
示例#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);
                    }
                }
            }
        }
示例#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);
                }
            }
        }
示例#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);
            }
        }
示例#5
0
    protected void EncodeView(RailBitBuffer buffer, int reservedBytes)
    {
      buffer.PackToSize(
        RailConfig.PACKCAP_MESSAGE_TOTAL - reservedBytes,
        int.MaxValue,
        this.view.GetOrdered(),
        (pair) =>
        {
          buffer.WriteEntityId(pair.Key);        // Write: [EntityId]
          buffer.WriteTick(pair.Value.Tick);     // Write: [Tick]
          buffer.WriteBool(pair.Value.IsFrozen); // Write: [IsFrozen]
        });
#endif
    }