diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-05-14 17:02:43 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-05-14 17:02:43 +0000 |
commit | 48fbf8e4c5faebdfc5a3be568c2366f137b98d75 (patch) | |
tree | ffa0dea61f96623c212cab72b81dda76bceee2b7 /src | |
parent | 99c97f75e2b93ea2cb36f126cd75b298bda5f5a9 (diff) | |
download | manaserv-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')
-rw-r--r-- | src/connectionhandler.cpp | 22 | ||||
-rw-r--r-- | src/object.cpp | 5 | ||||
-rw-r--r-- | src/object.h | 4 |
3 files changed, 16 insertions, 15 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()); } } 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 |