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

            if (_updateQueue.ContainsKey(entityID))
            {
                _updateQueue[entityID] = packet;
            }
            else
            {
                _updateQueue.TryAdd(entityID, packet);
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
            }
        }