示例#1
0
 public static void Encode(
     this RailPacketOutgoing packet,
     RailResource resource,
     RailBitBuffer buffer)
 {
     packet.Encode(resource, resource, buffer);
 }
示例#2
0
        private static void EncodeHeader(RailPacketOutgoing packet, RailBitBuffer buffer)
        {
            RailDebug.Assert(packet.SenderTick.IsValid);

            // Write: [LocalTick]
            buffer.WriteTick(packet.SenderTick);

            // Write: [LastAckTick]
            buffer.WriteTick(packet.LastAckTick);

            // Write: [AckReliableEventId]
            buffer.WriteSequenceId(packet.LastAckEventId);
        }
示例#3
0
 /// <summary>
 ///     Writes as many events as possible up to maxSize and returns the number
 ///     of events written in the batch. Also increments the total counter.
 /// </summary>
 private static void EncodeEvents(
     RailPacketOutgoing packet,
     IRailEventConstruction eventCreator,
     RailBitBuffer buffer,
     int maxSize)
 {
     packet.EventsWritten += buffer.PackToSize(
         maxSize,
         RailConfig.MAXSIZE_EVENT,
         packet.GetNextEvents(),
         (evnt, buf) => evnt.Encode(
             eventCreator.EventTypeCompressor,
             buf,
             packet.SenderTick),
         evnt => evnt.RegisterSent());
 }
示例#4
0
        /// <summary>
        ///     After writing the header we write the packet data in three passes.
        ///     The first pass is a fill of events up to a percentage of the packet.
        ///     The second pass is the payload value, which will try to fill the
        ///     remaining packet space. If more space is available, we will try
        ///     to fill it with any remaining events, up to the maximum packet size.
        /// </summary>
        public static void Encode(
            this RailPacketOutgoing packet,
            IRailStateConstruction stateCreator,
            IRailEventConstruction eventCreator,
            RailBitBuffer buffer)
        {
            // Write: [Header]
            EncodeHeader(packet, buffer);

            // Write: [Events] (Early Pack)
            EncodeEvents(packet, eventCreator, buffer, RailConfig.PACKCAP_EARLY_EVENTS);

            // Write: [Payload] (+1 byte for the event count)
            packet.EncodePayload(stateCreator, buffer, packet.SenderTick, 1);

            // Write: [Events] (Fill Pack)
            EncodeEvents(packet, eventCreator, buffer, RailConfig.PACKCAP_MESSAGE_TOTAL);
        }
示例#5
0
        protected RailPeer(
            RailResource resource,
            IRailNetPeer netPeer,
            ExternalEntityVisibility visibility,
            uint remoteSendRate,
            RailInterpreter interpreter,
            RailPacketIncoming reusableIncoming,
            RailPacketOutgoing reusableOutgoing) : base(resource, visibility, netPeer)
        {
            Resource         = resource;
            RemoteClock      = new RailClock(remoteSendRate);
            this.interpreter = interpreter;

            outgoingEvents        = new Queue <RailEvent>();
            this.reusableIncoming = reusableIncoming;
            this.reusableOutgoing = reusableOutgoing;
            lastQueuedEventId     = SequenceId.Start.Next;
            eventHistory          = new RailHistory(RailConfig.HISTORY_CHUNKS);

            LocalTick = Tick.START;
            netPeer.PayloadReceived += OnPayloadReceived;
        }
示例#6
0
 protected void SendPacket(RailPacketOutgoing packet)
 {
     interpreter.SendPacket(Resource, NetPeer, packet);
 }