- Timestamp:
- Oct 24, 2008, 2:48:43 AM (16 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.