- Timestamp:
- Oct 24, 2008, 2:48:43 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects/gametypes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r1993 r2006 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "core/ConsoleCommand.h"34 33 #include "objects/infos/PlayerInfo.h" 35 34 #include "objects/worldentities/pawns/Spectator.h" … … 39 38 namespace orxonox 40 39 { 41 SetConsoleCommand(Gametype, listPlayers, true);42 43 40 CreateUnloadableFactory(Gametype); 44 41 … … 48 45 49 46 this->defaultPawn_ = Class(Spectator); 50 this->getConnectedClients();51 47 52 48 COUT(0) << "created Gametype" << std::endl; 53 }54 55 Gametype* Gametype::getCurrentGametype()56 {57 for (ObjectList<Gametype>::iterator it = ObjectList<Gametype>::begin(); it != ObjectList<Gametype>::end(); ++it)58 return (*it);59 60 return 0;61 }62 63 PlayerInfo* Gametype::getClient(unsigned int clientID)64 {65 Gametype* gametype = Gametype::getCurrentGametype();66 if (gametype)67 {68 std::map<unsigned int, PlayerInfo*>::const_iterator it = gametype->clients_.find(clientID);69 if (it != gametype->clients_.end())70 return it->second;71 }72 else73 {74 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)75 if (it->getClientID() == clientID)76 return (*it);77 }78 return 0;79 }80 81 void Gametype::listPlayers()82 {83 Gametype* gametype = Gametype::getCurrentGametype();84 85 if (gametype)86 {87 for (std::set<PlayerInfo*>::const_iterator it = gametype->players_.begin(); it != gametype->players_.end(); ++it)88 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;89 }90 else91 {92 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)93 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;94 }95 }96 97 void Gametype::clientConnected(unsigned int clientID)98 {99 COUT(0) << "client connected" << std::endl;100 101 // create new PlayerInfo instance102 PlayerInfo* player = new PlayerInfo();103 player->setClientID(clientID);104 105 // add to clients-map106 assert(!this->clients_[clientID]);107 this->clients_[clientID] = player;108 }109 110 void Gametype::clientDisconnected(unsigned int clientID)111 {112 COUT(0) << "client disconnected" << std::endl;113 114 // remove from clients-map115 PlayerInfo* player = this->clients_[clientID];116 this->clients_.erase(clientID);117 118 // delete PlayerInfo instance119 delete player;120 49 } 121 50 … … 131 60 void Gametype::removePlayer(PlayerInfo* player) 132 61 { 133 player->stopControl(); 134 this->players_.erase(player); 135 this->playerLeft(player); 62 if (this->players_.find(player) != this->players_.end()) 63 { 64 player->stopControl(); 65 this->players_.erase(player); 66 this->playerLeft(player); 67 } 136 68 } 137 69 -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r1989 r2006 36 36 #include "core/BaseObject.h" 37 37 #include "core/Identifier.h" 38 #include "network/ClientConnectionListener.h"39 38 #include "objects/worldentities/ControllableEntity.h" 40 39 41 40 namespace orxonox 42 41 { 43 class _OrxonoxExport Gametype : public BaseObject , public network::ClientConnectionListener42 class _OrxonoxExport Gametype : public BaseObject 44 43 { 45 44 friend class PlayerInfo; … … 49 48 virtual ~Gametype() {} 50 49 51 static Gametype* getCurrentGametype();52 static void listPlayers();53 54 inline const std::map<unsigned int, PlayerInfo*>& getClients() const55 { return this->clients_; }56 50 inline const std::set<PlayerInfo*>& getPlayers() const 57 51 { return this->players_; } 58 static PlayerInfo* getClient(unsigned int clientID);59 52 60 53 protected: 61 virtual void clientConnected(unsigned int clientID);62 virtual void clientDisconnected(unsigned int clientID);63 64 54 virtual void playerJoined(PlayerInfo* player); 65 55 virtual void playerLeft(PlayerInfo* player); … … 72 62 73 63 std::set<PlayerInfo*> players_; 74 std::map<unsigned int, PlayerInfo*> clients_;75 64 SubclassIdentifier<ControllableEntity> defaultPawn_; 76 65 };
Note: See TracChangeset
for help on using the changeset viewer.