Changeset 1993 for code/branches/objecthierarchy/src/orxonox/objects/infos
- Timestamp:
- Oct 22, 2008, 5:25:01 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects/infos
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1989 r1993 42 42 #include "objects/gametypes/Gametype.h" 43 43 #include "objects/worldentities/ControllableEntity.h" 44 #include "objects/controllers/HumanController.h" 44 45 45 46 namespace orxonox … … 53 54 this->ping_ = -1; 54 55 this->clientID_ = network::CLIENTID_UNKNOWN; 55 this->bLocalPlayer_ = Core::isStandalone();56 56 this->bLocalPlayer_ = false; 57 57 this->bHumanPlayer_ = false; … … 60 60 this->pawn_ = 0; 61 61 this->pawnID_ = network::OBJECTID_UNKNOWN; 62 this->controller_ = 0; 63 this->setDefaultController(Class(HumanController)); 62 64 63 65 this->setConfigValues(); 64 66 this->registerVariables(); 65 66 //COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;67 67 } 68 68 69 69 PlayerInfo::~PlayerInfo() 70 70 { 71 Gametype* gametype = Gametype::getCurrentGametype(); 72 if (gametype) 73 gametype->removePlayer(this); 74 //COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl; 71 if (this->isInitialized()) 72 { 73 Gametype* gametype = Gametype::getCurrentGametype(); 74 if (gametype) 75 gametype->removePlayer(this); 76 77 if (this->controller_) 78 delete this->controller_; 79 80 if (this->pawn_) 81 this->pawn_->removePlayer(); 82 } 75 83 } 76 84 … … 82 90 void PlayerInfo::checkNick() 83 91 { 84 //std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;85 92 if (this->bLocalPlayer_) 86 93 { … … 94 101 void PlayerInfo::changedName() 95 102 { 96 //std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;97 103 Gametype* gametype = Gametype::getCurrentGametype(); 98 104 if (gametype) … … 113 119 void PlayerInfo::clientChangedName() 114 120 { 115 //std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl;116 121 this->setName(this->playerName_); 117 122 } … … 119 124 void PlayerInfo::checkClientID() 120 125 { 121 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;122 126 this->bHumanPlayer_ = true; 123 127 124 128 if (this->clientID_ == network::Host::getPlayerID()) 125 129 { 126 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl; 127 this->bLocalPlayer_ = true; 128 this->playerName_ = this->nick_; 129 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl; 130 this->takeLocalControl(); 130 131 131 132 if (Core::isClient()) 132 {133 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;134 133 this->setObjectMode(network::direction::bidirectional); 135 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;136 }137 134 else 138 135 { 139 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;140 136 this->clientChangedName(); 141 137 this->bFinishedSetup_ = true; … … 147 143 void PlayerInfo::finishedSetup() 148 144 { 149 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;150 145 if (Core::isClient()) 151 {152 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;153 146 this->bFinishedSetup_ = true; 154 }155 147 else if (this->bFinishedSetup_) 156 148 { 157 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;158 149 Gametype* gametype = Gametype::getCurrentGametype(); 159 150 if (gametype) 160 151 gametype->addPlayer(this); 161 }162 else163 {164 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;165 152 } 166 153 } … … 171 158 this->pawn_ = pawn; 172 159 this->pawnID_ = pawn->getObjectID(); 160 161 if (this->controller_) 162 this->controller_->setPawn(this->pawn_); 173 163 } 174 164 … … 180 170 } 181 171 172 void PlayerInfo::takeLocalControl() 173 { 174 this->bLocalPlayer_ = true; 175 this->playerName_ = this->nick_; 176 this->createController(); 177 } 178 179 void PlayerInfo::createController() 180 { 181 this->controller_ = this->defaultController_.fabricate(); 182 this->controller_->setPawn(this->pawn_); 183 } 184 182 185 void PlayerInfo::updatePawn() 183 186 { -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r1989 r1993 33 33 34 34 #include "Info.h" 35 #include "core/Identifier.h" 36 #include "objects/controllers/Controller.h" 35 37 36 38 namespace orxonox … … 58 60 { return this->bLocalPlayer_; } 59 61 60 v oid startControl(ControllableEntity* pawn);61 v oid stopControl();62 virtual void startControl(ControllableEntity* pawn); 63 virtual void stopControl(); 62 64 63 65 inline ControllableEntity* getPawn() const 64 66 { return this->pawn_; } 67 /* 68 inline void setController(Controller* controller) 69 { this->controller_ = controller; } 70 inline Controller* getController() const 71 { return this->controller_; } 72 */ 73 protected: 74 inline void setDefaultController(Identifier* identifier) 75 { this->defaultController_ = identifier; } 65 76 66 77 private: 78 virtual void createController(); 79 virtual void takeLocalControl(); 80 67 81 void checkClientID(); 68 82 void finishedSetup(); … … 82 96 ControllableEntity* pawn_; 83 97 unsigned int pawnID_; 98 Controller* controller_; 99 SubclassIdentifier<Controller> defaultController_; 84 100 }; 85 101 }
Note: See TracChangeset
for help on using the changeset viewer.