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 | |
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.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/game.cpp | 1 | ||||
-rw-r--r-- | src/net/network.cpp | 38 | ||||
-rw-r--r-- | src/net/network.h | 7 |
4 files changed, 23 insertions, 28 deletions
@@ -1,3 +1,8 @@ +2006-08-19 Bjørn Lindeijer <bjorn@lindeijer.nl> + + * src/game.cpp, src/net/network.h, src/net/network.cpp: Removed + incoming packets queue. Messages are now processed as they come in. + 2006-08-15 Bjørn Lindeijer <bjorn@lindeijer.nl> * src/gui/char_select.cpp, src/net/charserverhandler.h, diff --git a/src/game.cpp b/src/game.cpp index eada1128..2f62148c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -376,7 +376,6 @@ void Game::logic() // Handle network stuff mNetwork->flush(); - mNetwork->dispatchMessages(); } } 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(); } } diff --git a/src/net/network.h b/src/net/network.h index f91c926b..eb2ce8ab 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -56,7 +56,7 @@ class Network int getState() const { return mState; } bool isConnected() const { return mState == CONNECTED; } - void dispatchMessages(); + void dispatchMessage(ENetPacket *packet); void flush(); void send(const MessageOut &msg); @@ -69,12 +69,10 @@ class Network NET_ERROR }; + private: ENetHost *mClient; ENetPeer *mServer; - protected: - - std::string mAddress; short mPort; @@ -87,7 +85,6 @@ class Network MessageHandlers mMessageHandlers; std::queue<ENetPacket *> mOutgoingPackets; - std::queue<ENetPacket *> mIncomingPackets; bool realConnect(); void receive(); |