diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-08-19 18:40:46 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-08-19 18:40:46 +0000 |
commit | 0841d65d15e4c318ad8f5fe4b7e257d963ef7841 (patch) | |
tree | 39ec49858fab3ddfeaaab5ef0f53a1711f78c424 /src/net/network.cpp | |
parent | ddfb75d38d54415f79a014e6e0479ae4bcaf1dab (diff) | |
download | mana-0841d65d15e4c318ad8f5fe4b7e257d963ef7841.tar.gz mana-0841d65d15e4c318ad8f5fe4b7e257d963ef7841.tar.bz2 mana-0841d65d15e4c318ad8f5fe4b7e257d963ef7841.tar.xz mana-0841d65d15e4c318ad8f5fe4b7e257d963ef7841.zip |
Removed incoming packets queue. Messages are now processed as they come in.
Diffstat (limited to 'src/net/network.cpp')
-rw-r--r-- | src/net/network.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/net/network.cpp b/src/net/network.cpp index 39a632a2..f543bfb1 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -139,29 +139,25 @@ void Network::clearHandlers() mMessageHandlers.clear(); } -void Network::dispatchMessages() +void +Network::dispatchMessage(ENetPacket *packet) { - while (!mIncomingPackets.empty()) - { - ENetPacket *packet = mIncomingPackets.front(); - MessageIn msg((const char *)packet->data, packet->dataLength); - - MessageHandlerIterator iter = mMessageHandlers.find(msg.getId()); + MessageIn msg((const char *)packet->data, packet->dataLength); - if (iter != mMessageHandlers.end()) { - logger->log("Received packet %x (%i B)", - msg.getId(), msg.getLength()); - iter->second->handleMessage(&msg); - } - else { - logger->log("Unhandled packet %x (%i B)", - msg.getId(), msg.getLength()); - } + MessageHandlerIterator iter = mMessageHandlers.find(msg.getId()); - mIncomingPackets.pop(); - // Clean up the packet now that we're done using it. - enet_packet_destroy(packet); + if (iter != mMessageHandlers.end()) { + logger->log("Received packet %x (%i B)", + msg.getId(), msg.getLength()); + iter->second->handleMessage(&msg); } + else { + logger->log("Unhandled packet %x (%i B)", + msg.getId(), msg.getLength()); + } + + // Clean up the packet now that we're done using it. + enet_packet_destroy(packet); } void Network::flush() @@ -187,7 +183,7 @@ void Network::flush() case ENET_EVENT_TYPE_RECEIVE: logger->log("Incoming data..."); - mIncomingPackets.push(event.packet); + dispatchMessage(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: mState = IDLE; @@ -213,8 +209,6 @@ void Network::flush() enet_peer_send(mServer, 0, packet); mOutgoingPackets.pop(); } - - dispatchMessages(); } } |