summaryrefslogtreecommitdiff
path: root/src/connectionhandler.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-05-14 17:02:43 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-05-14 17:02:43 +0000
commit48fbf8e4c5faebdfc5a3be568c2366f137b98d75 (patch)
treeffa0dea61f96623c212cab72b81dda76bceee2b7 /src/connectionhandler.cpp
parent99c97f75e2b93ea2cb36f126cd75b298bda5f5a9 (diff)
downloadmanaserv-48fbf8e4c5faebdfc5a3be568c2366f137b98d75.tar.gz
manaserv-48fbf8e4c5faebdfc5a3be568c2366f137b98d75.tar.bz2
manaserv-48fbf8e4c5faebdfc5a3be568c2366f137b98d75.tar.xz
manaserv-48fbf8e4c5faebdfc5a3be568c2366f137b98d75.zip
Applied a patch by Guillaume that fixes and optimizes
ConnectionHandler::sendAround.
Diffstat (limited to 'src/connectionhandler.cpp')
-rw-r--r--src/connectionhandler.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index b7d1b1ba..e7ef6b9f 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -263,18 +263,18 @@ void ConnectionHandler::sendToEveryone(MessageOut &msg)
void ConnectionHandler::sendAround(tmwserv::BeingPtr beingPtr, MessageOut &msg)
{
- for (NetComputers::iterator i = clients.begin();
- i != clients.end();
- i++) {
+ unsigned speakerMapId = beingPtr->getMapId();
+ std::pair<unsigned, unsigned> speakerXY = beingPtr->getXY();
+ for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
+ i != i_end;
+ ++i) {
// See if the other being is near enough, then send the message
- if (abs((*i)->getCharacter().get()->getX() - beingPtr.get()->getX()) <= (int)AROUND_AREA_IN_TILES )
- {
- if (abs((*i)->getCharacter().get()->getY() - beingPtr.get()->getY()) <= (int)AROUND_AREA_IN_TILES )
- {
- (*i)->send(msg.getPacket());
- break;
- }
- }
+ tmwserv::Being const *listener = (*i)->getCharacter().get();
+ if (listener->getMapId() != speakerMapId) continue;
+ std::pair<unsigned, unsigned> listenerXY = listener->getXY();
+ if (abs(listenerXY.first - speakerXY.first ) > (int)AROUND_AREA_IN_TILES) continue;
+ if (abs(listenerXY.second - speakerXY.second) > (int)AROUND_AREA_IN_TILES) continue;
+ (*i)->send(msg.getPacket());
}
}