/// <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> internal static RailEvent Decode( RailBitBuffer buffer, Tick packetTick) { // Read: [EventType] int factoryType = buffer.ReadInt(RailEvent.FactoryTypeCompressor); RailEvent evnt = RailEvent.Create(factoryType); // Read: [EventId] evnt.EventId = buffer.ReadSequenceId(); // Read: [HasEntityId] bool hasEntityId = buffer.ReadBool(); if (hasEntityId) { // Read: [EntityId] evnt.EntityId = buffer.ReadEntityId(); } // Read: [EventData] evnt.DecodeData(buffer, packetTick); return(evnt); }
internal static RailCommandUpdate Decode(RailBitBuffer buffer) { RailCommandUpdate update = RailResource.Instance.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(buffer)); } return(update); }
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 }