Exemple #1
0
 internal async Task RemoveEntity(Entity entity)
 {
     if (_connectionManager.Hosting)
     {
         EntityPacket packet = new EntityPacket(entity);
         await _connectionManager.SendPacketToAllClients(packet);
     }
 }
Exemple #2
0
 internal static void RemoveEntity(Entity entity)
 {
     if (ConnectionManager.IsHost)
     {
         EntityPacket packet = new EntityPacket(entity);
         ConnectionManager.SendToAllGamers(packet);
     }
 }
Exemple #3
0
        private void ProcessIncomingPacket(object sender, PacketReceivedEventArgs e)
        {
            NetworkPacket packet = e.Packet;

            if (packet.Type == PacketType.Entity)
            {
                EntityPacket entityPacket = packet as EntityPacket;
                _updateQueue.Add(entityPacket);
            }
        }
Exemple #4
0
 internal async Task SyncAll()
 {
     if (_connectionManager.Hosting)
     {
         foreach (Entity entity in _gameModel.GameEntities)
         {
             EntityPacket packet = new EntityPacket(entity);
             await _connectionManager.SendPacketToAllClients(packet);
         }
     }
 }
Exemple #5
0
 internal static void SyncAll()
 {
     if (ConnectionManager.IsHost)
     {
         foreach (Entity entity in GameModel.GameEntities)
         {
             EntityPacket packet = new EntityPacket(entity);
             ConnectionManager.SendToAllGamers(packet);
         }
     }
 }
Exemple #6
0
        // 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);
                }
            }
        }
Exemple #7
0
        internal void Add(EntityPacket packet)
        {
            int entityID = packet.EntityID;

            if (_updateQueue.ContainsKey(entityID))
            {
                _updateQueue[entityID] = packet;
            }
            else
            {
                _updateQueue.TryAdd(entityID, packet);
            }
        }
Exemple #8
0
        // 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);
                }
            }
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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));
        }
Exemple #11
0
        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);
            }
        }