diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/gameclient.cpp | 3 | ||||
-rw-r--r-- | src/gamehandler.cpp | 18 | ||||
-rw-r--r-- | src/player.h | 20 |
4 files changed, 24 insertions, 18 deletions
@@ -16,6 +16,7 @@ src/controller.cpp, src/dalstorage.cpp, src/object.h, src/state.cpp, src/gamehandler.cpp: Made Point a POD type. Simplified server algorithm for moving objects; it now matches the one in the client. + 2006-08-28 Eugenio Favalli <elvenprogrammer@gmail.com> diff --git a/src/gameclient.cpp b/src/gameclient.cpp index 562d85f4..26d8aaac 100644 --- a/src/gameclient.cpp +++ b/src/gameclient.cpp @@ -43,6 +43,8 @@ void GameClient::setCharacter(PlayerPtr ch) { assert(mCharacterPtr.get() == NULL); mCharacterPtr = ch; + assert(mCharacterPtr->mClient == NULL); + mCharacterPtr->mClient = this; gameState->addObject(ObjectPtr(mCharacterPtr)); gameState->informPlayer(mCharacterPtr); } @@ -52,5 +54,6 @@ void GameClient::unsetCharacter() if (mCharacterPtr.get() == NULL) return; // remove being from world gameState->removeObject(ObjectPtr(mCharacterPtr)); + mCharacterPtr->mClient = NULL; mCharacterPtr = PlayerPtr(NULL); } diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp index cb38eacc..5186f92d 100644 --- a/src/gamehandler.cpp +++ b/src/gamehandler.cpp @@ -23,7 +23,7 @@ #include "gamehandler.h" -#include <iostream> +#include <cassert> #include <map> #include "gameclient.h" @@ -254,17 +254,7 @@ void GameHandler::sayAround(GameClient &computer, std::string const &text) void GameHandler::sendTo(PlayerPtr beingPtr, MessageOut &msg) { - /* TODO: This implementation is very inefficient. An alternative would be - * store the NetComputer reference with the player class, so that it can - * be directly accessed. - */ - for (NetComputers::iterator i = clients.begin(); i != clients.end(); ++i) - { - PlayerPtr clientChar = static_cast<GameClient *>(*i)->getCharacter(); - if (clientChar.get() == beingPtr.get()) - { - (*i)->send(msg); - break; - } - } + GameClient *client = beingPtr->getClient(); + assert(client != NULL); + client->send(msg); } diff --git a/src/player.h b/src/player.h index e812a73d..03917703 100644 --- a/src/player.h +++ b/src/player.h @@ -33,6 +33,8 @@ /** Maximum number of equipped slots */ const unsigned int MAX_EQUIP_SLOTS = 5; +class GameClient; + class Player : public Being { public: @@ -40,7 +42,8 @@ class Player : public Being Player(std::string const &name, int id = -1) : Being(OBJECT_PLAYER, 65535), mDatabaseID(id), - mName(name) + mName(name), + mClient(NULL) {} /** @@ -201,25 +204,32 @@ class Player : public Being unequip(unsigned char slot); /** - * Get database ID. + * Gets database ID. * - * @return the database ID, a negative number if none yet, or if not relevant. + * @return the database ID, a negative number if none yet. */ int getDatabaseID() const { return mDatabaseID; } /** - * Set database ID. + * Sets database ID. * The object shall not have any ID yet. */ void setDatabaseID(int id); + /** + * Gets client computer. + */ + GameClient *getClient() const + { return mClient; } + private: Player(Player const &); Player &operator=(Player const &); int mDatabaseID; /**< Player database ID (unique with respect to its type) */ std::string mName; /**< name of the being */ + GameClient *mClient; /**< client computer, directly set by GameClient */ Gender mGender; /**< gender of the being */ unsigned char mHairStyle; /**< Hair Style of the being */ unsigned char mHairColor; /**< Hair Color of the being */ @@ -231,6 +241,8 @@ class Player : public Being /** Equipped item ID's (from inventory) */ unsigned int equipment[MAX_EQUIP_SLOTS]; + + friend class GameClient; }; /** |