diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-08-26 19:26:39 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-08-26 19:26:39 +0000 |
commit | c8104aa3b53448a047a0ee01835a6f68ac62f23c (patch) | |
tree | 6b0d4bae6814355b44abb694204a0a80d29b6cb9 /src | |
parent | 30d192259e6913a210156da2abce16e05b5a5825 (diff) | |
download | manaserv-c8104aa3b53448a047a0ee01835a6f68ac62f23c.tar.gz manaserv-c8104aa3b53448a047a0ee01835a6f68ac62f23c.tar.bz2 manaserv-c8104aa3b53448a047a0ee01835a6f68ac62f23c.tar.xz manaserv-c8104aa3b53448a047a0ee01835a6f68ac62f23c.zip |
Improve updates when a being just appeared.
Diffstat (limited to 'src')
-rw-r--r-- | src/object.h | 14 | ||||
-rw-r--r-- | src/state.cpp | 36 |
2 files changed, 35 insertions, 15 deletions
diff --git a/src/object.h b/src/object.h index 05b1f45d..ecd06985 100644 --- a/src/object.h +++ b/src/object.h @@ -43,6 +43,7 @@ class Object Object(int type, int id) : mType(type), mID(id), + mNew(true), mNeedUpdate(false) {} @@ -142,12 +143,25 @@ class Object void setMapId(unsigned int mapId) { mMapId = mapId; } + /** + * Tells if the object just appeared. + */ + bool isNew() const + { return mNew; } + + /** + * Sets the age of the object. + */ + void setNew(bool n) + { mNew = n; } + private: int mType; /**< Object type */ int mID; /** Object unique ID (wrt its type and its map at least) */ unsigned int mX; /**< x coordinate */ unsigned int mY; /**< y coordinate */ unsigned int mMapId; /**< id of the map being is on */ + bool mNew; /**< true if the object just appeared */ protected: bool mNeedUpdate; /**< update() must be invoked if true */ diff --git a/src/state.cpp b/src/state.cpp index 87e85015..a32d082e 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -73,19 +73,23 @@ State::update() { std::pair<unsigned, unsigned> ps = (*p)->getXY(); std::pair<unsigned, unsigned> pn = (*p)->getNextPosition(); - MessageOut msg; - msg.writeShort(GPMSG_BEINGS_MOVE); + bool po = !(*p)->isNew(); + MessageOut msg(GPMSG_BEINGS_MOVE); for (Movings::iterator o = movings.begin(), o_end = movings.end(); o != o_end; ++o) { std::pair<unsigned, unsigned> os = (*o)->getXY(); std::pair<unsigned, unsigned> on = (*o)->getNextPosition(); + bool oo = po && !(*o)->isNew(); // Are p and o both old? - bool were = areAround(ps.first, ps.second, os.first, os.second); + /* Look whether p and o "were" around the last time and whether + they "will" be around the next time. p has to be informed when + this proximity changes or if o will move in range. */ + bool were = areAround(ps.first, ps.second, os.first, os.second) && oo; bool will = areAround(pn.first, pn.second, on.first, on.second); bool has_moved = os.first != on.first || os.second != on.second; - if (!(will && has_moved) && !(were != will)) + if (!(will && has_moved) && (were == will)) continue; std::pair<unsigned, unsigned> od = (*o)->getDestination(); @@ -105,6 +109,7 @@ State::update() { std::pair<unsigned, unsigned> pos = (*o)->getNextPosition(); (*o)->setXY(pos.first, pos.second); + (*o)->setNew(false); } } } @@ -115,6 +120,7 @@ State::addObject(ObjectPtr objectPtr) unsigned mapId = objectPtr->getMapId(); if (!loadMap(mapId)) return; maps[mapId].objects.push_back(objectPtr); + objectPtr->setNew(true); if (objectPtr->getType() != OBJECT_PLAYER) return; Players &players = maps[mapId].players; PlayerPtr playerPtr(objectPtr); @@ -139,17 +145,6 @@ State::addObject(ObjectPtr objectPtr) // Add the new player to the list players.push_back(playerPtr); - - /* Since the player doesn't know yet where on the world he is after - * connecting to the map server, we send him an initial change map message. - */ - Storage &store = Storage::instance("tmw"); - MessageOut mapChangeMessage(GPMSG_PLAYER_MAP_CHANGE); - mapChangeMessage.writeString(store.getMapNameFromId(mapId)); - mapChangeMessage.writeShort(playerPtr->getX()); - mapChangeMessage.writeShort(playerPtr->getY()); - mapChangeMessage.writeByte(0); - gameHandler->sendTo(playerPtr, mapChangeMessage); } void @@ -196,6 +191,17 @@ State::informPlayer(PlayerPtr playerPtr) if (m == maps.end()) return; Players &players = m->second.players; + /* Since the player doesn't know yet where on the world he is after + * connecting to the map server, we send him an initial change map message. + */ + Storage &store = Storage::instance("tmw"); + MessageOut mapChangeMessage(GPMSG_PLAYER_MAP_CHANGE); + mapChangeMessage.writeString(store.getMapNameFromId(mapId)); + mapChangeMessage.writeShort(playerPtr->getX()); + mapChangeMessage.writeShort(playerPtr->getY()); + mapChangeMessage.writeByte(0); + gameHandler->sendTo(playerPtr, mapChangeMessage); + /* Here the player is informed about all the other players on the map. * However, the player should only be told about other players within * visual range. See also notes at addObject and removeObject. |