public RailClientRoom(RailResource resource, RailClient client) : base(resource, client) { eventCreator = resource; ToUpdate = new List <RailEntityClient>(); ToRemove = new List <RailEntityClient>(); IEqualityComparer <EntityId> entityIdComparer = EntityId.CreateEqualityComparer(); pendingEntities = new Dictionary <EntityId, RailEntityClient>(entityIdComparer); knownEntities = new Dictionary <EntityId, RailEntityClient>(entityIdComparer); localPeer = new RailController(resource, ExternalEntityVisibility.All, null); this.client = client; }
/// <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()); }
private static void DecodeEvents( RailPacketIncoming packet, IRailEventConstruction eventCreator, RailBitBuffer buffer) { IEnumerable <RailEvent> decoded = buffer.UnpackAll( buf => RailEvent.Decode( eventCreator, eventCreator.EventTypeCompressor, buf, packet.SenderTick)); foreach (RailEvent evnt in decoded) { packet.Events.Add(evnt); } }
/// <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); }
/// <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 static RailEvent Decode( IRailEventConstruction eventCreator, RailIntCompressor compressor, RailBitBuffer buffer, Tick packetTick) { // Read: [EventType] int factoryType = buffer.ReadInt(compressor); RailEvent evnt = eventCreator.CreateEvent(factoryType); // Read: [EventId] evnt.EventId = buffer.ReadSequenceId(); // Read: [EventData] evnt.DataSerializer.ReadData(buffer, packetTick); return(evnt); }
public static void Decode( this RailPacketIncoming packet, IRailCommandConstruction commandCreator, IRailStateConstruction stateCreator, IRailEventConstruction eventCreator, RailBitBuffer buffer) { // Read: [Header] DecodeHeader(packet, buffer); // Read: [Events] (Early Pack) DecodeEvents(packet, eventCreator, buffer); // Read: [Payload] packet.DecodePayload(commandCreator, stateCreator, buffer); // Read: [Events] (Fill Pack) DecodeEvents(packet, eventCreator, buffer); }