From 48fbf8e4c5faebdfc5a3be568c2366f137b98d75 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 14 May 2006 17:02:43 +0000 Subject: Applied a patch by Guillaume that fixes and optimizes ConnectionHandler::sendAround. --- src/connectionhandler.cpp | 22 +++++++++++----------- src/object.cpp | 5 +++-- src/object.h | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src') 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 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 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()); } } diff --git a/src/object.cpp b/src/object.cpp index 1eb31fc4..82be242a 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -139,8 +139,9 @@ Object::getStatistics(void) return mStats; } -const unsigned int -Object::getMapId() { +unsigned int +Object::getMapId() const +{ return mMapId; } diff --git a/src/object.h b/src/object.h index 17237be0..962f8202 100644 --- a/src/object.h +++ b/src/object.h @@ -156,8 +156,8 @@ class Object * * @return Name of map being is located. */ - const unsigned int - getMapId(); + unsigned int + getMapId() const; /** * Set map being is located -- cgit v1.2.3-70-g09d2