Changeset 2006 for code/branches/objecthierarchy/src/orxonox/objects/infos
- Timestamp:
- Oct 24, 2008, 2:48:43 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects/infos
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/infos/LevelInfo.cc
r1968 r2006 31 31 32 32 #include <OgreSceneManager.h> 33 #include <OgreLight.h> 33 34 34 35 #include "core/CoreIncludes.h" 35 36 #include "core/XMLPort.h" 36 37 #include "core/Core.h" 38 #include "core/ConsoleCommand.h" 39 #include "core/Loader.h" 40 #include "core/Template.h" 37 41 38 42 #include "GraphicsEngine.h" 43 #include "Settings.h" 44 #include "PlayerInfo.h" 45 46 #include "util/Math.h" 39 47 40 48 namespace orxonox 41 49 { 50 SetConsoleCommand(LevelInfo, listPlayers, true); 51 42 52 CreateFactory(LevelInfo); 43 53 … … 46 56 RegisterObject(LevelInfo); 47 57 48 this-> gametypeInstance_ = 0;58 this->rootGametype_ = 0; 49 59 this->registerVariables(); 50 60 61 // test test test 62 { 63 Ogre::Light* light; 64 light = GraphicsEngine::getInstance().getLevelSceneManager()->createLight("Light0"); 65 light->setType(Ogre::Light::LT_DIRECTIONAL); 66 light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0)); 67 light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0)); 68 light->setDirection(1, -0.2, 0.2); 69 } 70 // test test test 71 51 72 COUT(0) << "created LevelInfo" << std::endl; 52 73 } 53 74 75 LevelInfo* LevelInfo::getActiveLevelInfo() 76 { 77 for (ObjectList<LevelInfo>::iterator it = ObjectList<LevelInfo>::begin(); it != ObjectList<LevelInfo>::end(); ++it) 78 if (it->isActive()) 79 return (*it); 80 81 return 0; 82 } 83 84 PlayerInfo* LevelInfo::getClient(unsigned int clientID) 85 { 86 LevelInfo* levelinfo = LevelInfo::getActiveLevelInfo(); 87 88 if (levelinfo) 89 { 90 std::map<unsigned int, PlayerInfo*>::const_iterator it = levelinfo->clients_.find(clientID); 91 if (it != levelinfo->clients_.end()) 92 return it->second; 93 } 94 else 95 { 96 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it) 97 if (it->getClientID() == clientID) 98 return (*it); 99 } 100 return 0; 101 } 102 103 void LevelInfo::listPlayers() 104 { 105 LevelInfo* levelinfo = LevelInfo::getActiveLevelInfo(); 106 107 if (levelinfo->getGametype()) 108 { 109 for (std::set<PlayerInfo*>::const_iterator it = levelinfo->getGametype()->getPlayers().begin(); it != levelinfo->getGametype()->getPlayers().end(); ++it) 110 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl; 111 } 112 else 113 { 114 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it) 115 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl; 116 } 117 } 118 119 void LevelInfo::clientConnected(unsigned int clientID) 120 { 121 COUT(0) << "client connected" << std::endl; 122 123 // create new PlayerInfo instance 124 PlayerInfo* player = new PlayerInfo(); 125 player->setGametype(this->getGametype()); 126 player->setClientID(clientID); 127 128 // add to clients-map 129 assert(!this->clients_[clientID]); 130 this->clients_[clientID] = player; 131 } 132 133 void LevelInfo::clientDisconnected(unsigned int clientID) 134 { 135 COUT(0) << "client disconnected" << std::endl; 136 137 // remove from clients-map 138 PlayerInfo* player = this->clients_[clientID]; 139 this->clients_.erase(clientID); 140 141 // delete PlayerInfo instance 142 delete player; 143 } 144 54 145 void LevelInfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) 55 146 { … … 57 148 58 149 XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode); 59 XMLPortParam(LevelInfo, "gametype", setGametype , getGametype, xmlelement, mode).defaultValues("Gametype");150 XMLPortParam(LevelInfo, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype"); 60 151 XMLPortParam(LevelInfo, "skybox", setSkybox, getSkybox, xmlelement, mode); 61 152 XMLPortParam(LevelInfo, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2, 0.2, 0.2, 1)); 153 154 this->levelfile_ = this->getLevelfile(); 62 155 } 63 156 64 157 void LevelInfo::registerVariables() 65 158 { 66 REGISTERSTRING(name_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::changedName)); 67 REGISTERSTRING(description_, network::direction::toclient); 68 REGISTERSTRING(skybox_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applySkybox)); 69 REGISTERDATA(ambientLight_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applyAmbientLight)); 159 REGISTERSTRING(this->levelfile_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applyLevel)); 160 REGISTERSTRING(this->name_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::changedName)); 161 REGISTERSTRING(this->description_, network::direction::toclient); 162 REGISTERSTRING(this->skybox_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applySkybox)); 163 REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applyAmbientLight)); 164 } 165 166 void LevelInfo::applyLevel() 167 { 168 COUT(0) << "Loading level \"" << this->levelfile_ << "\"..." << std::endl; 169 170 ClassTreeMask mask; 171 mask.exclude(Class(BaseObject)); 172 mask.include(Class(Template)); 173 174 Level* level = new Level(Settings::getDataPath() + this->levelfile_, mask); 175 176 Loader::open(level); 70 177 } 71 178 … … 87 194 } 88 195 89 void LevelInfo::setGametype (const std::string& gametype)196 void LevelInfo::setGametypeString(const std::string& gametype) 90 197 { 91 198 Identifier* identifier = ClassByString(gametype); … … 94 201 this->gametype_ = gametype; 95 202 this->gametypeIdentifier_ = identifier; 96 this->gametypeInstance_ = this->gametypeIdentifier_.fabricate(); 203 this->rootGametype_ = this->gametypeIdentifier_.fabricate(); 204 this->getConnectedClients(); 97 205 } 98 206 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/LevelInfo.h
r1940 r2006 37 37 38 38 #include "objects/gametypes/Gametype.h" 39 #include "network/ClientConnectionListener.h" 39 40 40 41 namespace orxonox 41 42 { 42 class _OrxonoxExport LevelInfo : public Info 43 class _OrxonoxExport LevelInfo : public Info, public network::ClientConnectionListener 43 44 { 44 45 public: … … 48 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 50 void registerVariables(); 51 52 inline const std::map<unsigned int, PlayerInfo*>& getClients() const 53 { return this->clients_; } 50 54 51 55 inline void setDescription(const std::string& description) … … 62 66 { return this->ambientLight_; } 63 67 64 void setGametype (const std::string& gametype);65 inline const std::string& getGametype () const68 void setGametypeString(const std::string& gametype); 69 inline const std::string& getGametypeString() const 66 70 { return this->gametype_; } 71 inline Gametype* getGametype() const 72 { return this->rootGametype_; } 73 74 static LevelInfo* getActiveLevelInfo(); 75 static void listPlayers(); 76 static PlayerInfo* getClient(unsigned int clientID); 67 77 68 78 private: 79 virtual void clientConnected(unsigned int clientID); 80 virtual void clientDisconnected(unsigned int clientID); 81 82 void applyLevel(); 83 69 84 void applySkybox() 70 85 { this->setSkybox(this->skybox_); } … … 72 87 { this->setAmbientLight(this->ambientLight_); } 73 88 89 std::map<unsigned int, PlayerInfo*> clients_; 74 90 std::string description_; 75 91 std::string skybox_; … … 77 93 std::string gametype_; 78 94 SubclassIdentifier<Gametype> gametypeIdentifier_; 79 Gametype* gametypeInstance_; 95 Gametype* rootGametype_; 96 std::string levelfile_; 80 97 }; 81 98 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1993 r2006 38 38 39 39 #include "network/Host.h" 40 #include "network/ClientInformation.h" 40 41 41 42 #include "GraphicsEngine.h" … … 57 58 this->bHumanPlayer_ = false; 58 59 this->bFinishedSetup_ = false; 60 this->gametype_ = 0; 59 61 60 62 this->pawn_ = 0; … … 71 73 if (this->isInitialized()) 72 74 { 73 Gametype* gametype = Gametype::getCurrentGametype(); 74 if (gametype) 75 gametype->removePlayer(this); 75 if (this->gametype_) 76 this->gametype_->removePlayer(this); 76 77 77 78 if (this->controller_) … … 101 102 void PlayerInfo::changedName() 102 103 { 103 Gametype* gametype = Gametype::getCurrentGametype(); 104 if (gametype) 105 gametype->playerChangedName(this); 104 if (this->gametype_) 105 this->gametype_->playerChangedName(this); 106 106 } 107 107 … … 147 147 else if (this->bFinishedSetup_) 148 148 { 149 Gametype* gametype = Gametype::getCurrentGametype(); 150 if (gametype) 151 gametype->addPlayer(this); 149 if (this->gametype_) 150 this->gametype_->addPlayer(this); 152 151 } 153 152 } … … 165 164 void PlayerInfo::stopControl() 166 165 { 167 this->pawn_->removePlayer(); 166 if (this->pawn_) 167 this->pawn_->removePlayer(); 168 168 this->pawn_ = 0; 169 169 this->pawnID_ = network::OBJECTID_UNKNOWN; -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r1993 r2006 71 71 { return this->controller_; } 72 72 */ 73 inline void setGametype(Gametype* gametype) 74 { this->gametype_ = gametype; } 75 inline Gametype* getGametype() const 76 { return this->gametype_; } 77 73 78 protected: 74 79 inline void setDefaultController(Identifier* identifier) … … 98 103 Controller* controller_; 99 104 SubclassIdentifier<Controller> defaultController_; 105 Gametype* gametype_; 100 106 }; 101 107 }
Note: See TracChangeset
for help on using the changeset viewer.