Пример #1
0
 internal async Task RemoveEntity(Entity entity)
 {
     if (_connectionManager.Hosting)
     {
         EntityPacket packet = new EntityPacket(entity);
         await _connectionManager.SendPacketToAllClients(packet);
     }
 }
Пример #2
0
 internal static void RemoveEntity(Entity entity)
 {
     if (ConnectionManager.IsHost)
     {
         EntityPacket packet = new EntityPacket(entity);
         ConnectionManager.SendToAllGamers(packet);
     }
 }
Пример #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);
            }
        }
Пример #4
0
 internal async Task SyncAll()
 {
     if (_connectionManager.Hosting)
     {
         foreach (Entity entity in _gameModel.GameEntities)
         {
             EntityPacket packet = new EntityPacket(entity);
             await _connectionManager.SendPacketToAllClients(packet);
         }
     }
 }
Пример #5
0
 internal static void SyncAll()
 {
     if (ConnectionManager.IsHost)
     {
         foreach (Entity entity in GameModel.GameEntities)
         {
             EntityPacket packet = new EntityPacket(entity);
             ConnectionManager.SendToAllGamers(packet);
         }
     }
 }
Пример #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);
                }
            }
        }
Пример #7
0
        internal void Add(EntityPacket packet)
        {
            int entityID = packet.EntityID;

            if (_updateQueue.ContainsKey(entityID))
            {
                _updateQueue[entityID] = packet;
            }
            else
            {
                _updateQueue.TryAdd(entityID, packet);
            }
        }
Пример #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);
                }
            }
        }
Пример #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);
        }
Пример #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));
        }
Пример #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);
            }
        }