internal async Task RemoveEntity(Entity entity) { if (_connectionManager.Hosting) { EntityPacket packet = new EntityPacket(entity); await _connectionManager.SendPacketToAllClients(packet); } }
internal static void RemoveEntity(Entity entity) { if (ConnectionManager.IsHost) { EntityPacket packet = new EntityPacket(entity); ConnectionManager.SendToAllGamers(packet); } }
private void ProcessIncomingPacket(object sender, PacketReceivedEventArgs e) { NetworkPacket packet = e.Packet; if (packet.Type == PacketType.Entity) { EntityPacket entityPacket = packet as EntityPacket; _updateQueue.Add(entityPacket); } }
internal async Task SyncAll() { if (_connectionManager.Hosting) { foreach (Entity entity in _gameModel.GameEntities) { EntityPacket packet = new EntityPacket(entity); await _connectionManager.SendPacketToAllClients(packet); } } }
internal static void SyncAll() { if (ConnectionManager.IsHost) { foreach (Entity entity in GameModel.GameEntities) { EntityPacket packet = new EntityPacket(entity); ConnectionManager.SendToAllGamers(packet); } } }
// Note: Technically, all the clients need is a list of entities IDs // and they could be passed within a single packet which would save bandwidth. // But this works too and is simpler. // TODO: Develop TCP networking capability, as UDP is not reliable enough in // this case. (For now, let's just send the packets 5X) private async void RemoveEntities(object sender, EntitiesRemovedEventAgs e) { List <Entity> entitiesToRemove = e.EntitiesRemoved; for (int i = 0; i < 5; i++) { foreach (Entity entity in entitiesToRemove) { EntityPacket packet = new EntityPacket(entity); await _connectionManager.SendPacketToAllClients(packet); } } }
internal void Add(EntityPacket packet) { int entityID = packet.EntityID; if (_updateQueue.ContainsKey(entityID)) { _updateQueue[entityID] = packet; } else { _updateQueue.TryAdd(entityID, packet); } }
// Note: Technically, all the clients need is a list of entities IDs // and they could be passed within a single packet which would save bandwidth. // But this works too and is simpler. // TODO: Develop TCP networking capability, as UDP is not reliable enough in // this case. (For now, let's just send the packets 5X) private static void RemoveEntities(object sender, EntitiesRemovedEventAgs e) { List <Entity> entitiesToRemove = e.EntitiesRemoved; for (int i = 0; i < 5; i++) { foreach (Entity entity in entitiesToRemove) { EntityPacket packet = new EntityPacket(entity); ConnectionManager.SendToAllGamers(packet); } } }
private async Task SyncPlayer(string player) { Ship ship = _connectionManager.GetShip(player); List <EntityPacket> updates = new List <EntityPacket>(); foreach (Entity entity in _gameModel.GameEntities) { if (DistanceBetween(ship, entity) < MaxSyncDistance) { EntityPacket packet = new EntityPacket(entity); updates.Add(packet); } } await _connectionManager.SendSyncUpdatesToPlayer(player, updates); }
internal Task SyncPlayer(string player) { Ship ship = _gameInstance.GameClientConnection.GetShip(player); List <NetworkPacket> updates = new List <NetworkPacket>(); PlayerData playerToSync = _playerList[player]; foreach (Entity entity in _gameInstance.GameModel.GameEntities) { if (DistanceBetween(ship, entity) < MaxSyncDistance) { EntityPacket packet = new EntityPacket(entity); updates.Add(packet); } } return(SendUDPToPlayer(playerToSync, updates)); }
internal void Add(EntityPacket packet) { int entityID = packet.EntityID; if (_updateQueue.ContainsKey(entityID)) { if (packet.IsNewerThan(_updateQueue[entityID])) { _updateQueue[entityID] = packet; } // else ignore the packet as being older than the latest update for this entity } else { _updateQueue.TryAdd(entityID, packet); } }