Changeset 1950 for code/branches/objecthierarchy/src/orxonox/objects
- Timestamp:
- Oct 19, 2008, 5:32:58 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r1947 r1950 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "core/ConsoleCommand.h" 33 34 #include "objects/infos/PlayerInfo.h" 34 35 35 36 namespace orxonox 36 37 { 38 SetConsoleCommand(Gametype, listPlayers, true); 39 37 40 CreateUnloadableFactory(Gametype); 38 41 … … 54 57 } 55 58 59 void Gametype::listPlayers() 60 { 61 Gametype* gametype = Gametype::getCurrentGametype(); 62 63 if (gametype) 64 { 65 for (std::set<PlayerInfo*>::const_iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it) 66 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl; 67 } 68 else 69 { 70 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it) 71 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl; 72 } 73 } 74 56 75 void Gametype::clientConnected(unsigned int clientID) 57 76 { 58 77 COUT(0) << "client connected" << std::endl; 59 78 79 // create new PlayerInfo instance 60 80 PlayerInfo* player = new PlayerInfo(); 61 81 player->setClientID(clientID); 82 83 // add to clients-map 84 assert(!this->clients_[clientID]); 85 this->clients_[clientID] = player; 62 86 } 63 87 … … 65 89 { 66 90 COUT(0) << "client disconnected" << std::endl; 91 92 // remove from clients-map 93 PlayerInfo* player = this->clients_[clientID]; 94 this->clients_.erase(clientID); 95 96 // delete PlayerInfo instance 97 delete player; 67 98 } 68 99 … … 88 119 COUT(0) << "player " << player->getName() << " left" << std::endl; 89 120 } 121 122 void Gametype::playerChangedName(PlayerInfo* player) 123 { 124 if (this->players_.find(player) != this->players_.end()) 125 { 126 if (player->getName() != player->getOldName()) 127 { 128 COUT(0) << "player " << player->getOldName() << " changed name to " << player->getName() << std::endl; 129 } 130 } 131 } 90 132 } -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r1940 r1950 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include <map> 35 34 36 #include "core/BaseObject.h" 35 37 #include "network/ClientConnectionListener.h" … … 39 41 class _OrxonoxExport Gametype : public BaseObject, public network::ClientConnectionListener 40 42 { 43 friend class PlayerInfo; 44 41 45 public: 42 46 Gametype(); … … 44 48 45 49 static Gametype* getCurrentGametype(); 46 void addPlayer(PlayerInfo* player); 47 void removePlayer(PlayerInfo* player); 50 static void listPlayers(); 48 51 49 52 protected: … … 54 57 virtual void playerLeft(PlayerInfo* player); 55 58 59 virtual void playerChangedName(PlayerInfo* player); 60 56 61 private: 62 void addPlayer(PlayerInfo* player); 63 void removePlayer(PlayerInfo* player); 64 57 65 std::set<PlayerInfo*> players_; 66 std::map<unsigned int, PlayerInfo*> clients_; 58 67 }; 59 68 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1949 r1950 51 51 52 52 this->ping_ = -1; 53 this->clientID_ = (unsigned int)-1; 53 54 this->bLocalPlayer_ = Core::isStandalone(); 54 55 this->bLocalPlayer_ = false; … … 85 86 { 86 87 std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl; 88 Gametype* gametype = Gametype::getCurrentGametype(); 89 if (gametype) 90 gametype->playerChangedName(this); 87 91 } 88 92 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h
r1940 r1950 44 44 45 45 inline void setPosition(const Vector3& position) 46 { this->node_->setPosition(position); std::cout << "set position to " << position << std::endl;}46 { this->node_->setPosition(position); } 47 47 inline void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 48 48 { this->node_->translate(distance, relativeTo); }
Note: See TracChangeset
for help on using the changeset viewer.