Exemple #1
0
		/// <summary>
		/// Updates this entity, flushes and handles any pending packets in the incoming queue.
		/// </summary>
		public void Update(TimeSpan dt) {
			//Handle all packets in the incoming queue
			IPacketBase packet;
			while (mIncomingQueue.TryDequeue(out packet)) {
				HandlePacket(packet);
			}

			//Send any packets that have been deferred
			foreach (var p in mDeferredSendList) {
				SendPacket(p);
			}
			mDeferredSendList.Clear();

			if (mCurrentDeferredPacket.PacketCount > 0) {
				SendPacket(mCurrentDeferredPacket);
			}

			//Reset the current deferred packet for next update
			mCurrentDeferredPacket = PacketFactory.CreatePacket<CoalescedData>();

			//Warn if any of the queues are getting swamped
			if (mOutgoingQueue.Count > 25) {
				Console.WriteLine("Outgoing queue swamped: " + mOutgoingQueue.Count);
			}
			if (mIncomingQueue.Count > 25) {
				Console.WriteLine("Incoming queue swamped: " + mIncomingQueue.Count);
			}
		}
Exemple #2
0
		/// <summary>
		/// Queues a packet to be send on the next update. Will coalesce these packets together.
		/// </summary>
		public void DeferredSendPacket(IPacketBase packet) {
			if (!mCurrentDeferredPacket.TryAddPacket(packet)) {
				mDeferredSendList.Add(mCurrentDeferredPacket);
				mCurrentDeferredPacket = PacketFactory.CreatePacket<CoalescedData>();
				mCurrentDeferredPacket.TryAddPacket(packet);
			}
		}