/// <summary> /// Queues an event to broadcast to all clients. /// Use a Event.SEND_RELIABLE (-1) for the number of attempts /// to send the event reliable-ordered (infinite retries). /// </summary> public void QueueEventBroadcast(Event evnt, int attempts = 3) { foreach (var clientPeer in clients.Values) { clientPeer.QueueEvent(typeCode => _pools.CreateEvent(typeCode), evnt, attempts); } }
public ServerIncomingPacket Decode(byte[] data, int length) { var reusableIncoming = new ServerIncomingPacket(); _buffer.Load(data, length); _buffer.DecodePacket(reusableIncoming, _pools.EventTypeCompressor, typeCode => _pools.CreateEvent(typeCode), (buffer, packet) => { // Read: [Commands] buffer.Decode(packet.ReceivedCommandUpdates, () => { //var update = buffer.Decode_CommandUpdate(); var update = _pools.CommandUpdatePool.Allocate(); // Read: [EntityId] update.EntityId = buffer.ReadEntityId(); // Read: [Count] var count = (int)buffer.Read(CommandUpdate.BUFFER_COUNT_BITS); // Read: [Commands] for (int i = 0; i < count; i++) { //var command = buffer.Decode_Command(); var command = _pools.CommandPool.Allocate(); // Read: [SenderTick] command.ClientTick = buffer.ReadTick(); // Read: [Command Data] DecodeData(command); update.Commands.Store(command); } return(update); }); // Read: [View] var decoded = buffer.UnpackAll(() => { // Read: [EntityId], Read: [Tick], Read: [IsFrozen] return(new KeyValuePair <EntityId, ViewEntry>(buffer.ReadEntityId(), new ViewEntry(buffer.ReadTick(), buffer.ReadBool()))); }); foreach (var pair in decoded) { packet.View.RecordUpdate(pair.Key, pair.Value); } }); if (_buffer.IsFinished) { return(reusableIncoming); } else { return(default);