Changeset 2019 for code/branches/objecthierarchy/src/orxonox/objects/infos
- Timestamp:
- Oct 27, 2008, 4:08:51 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects/infos
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/infos/Info.cc
r1947 r2019 34 34 namespace orxonox 35 35 { 36 Info::Info( )36 Info::Info(BaseObject* creator) : BaseObject(creator) 37 37 { 38 38 RegisterObject(Info); -
code/branches/objecthierarchy/src/orxonox/objects/infos/Info.h
r1940 r2019 40 40 { 41 41 public: 42 Info( );42 Info(BaseObject* creator); 43 43 virtual ~Info() {} 44 44 }; -
code/branches/objecthierarchy/src/orxonox/objects/infos/Level.cc
r2012 r2019 30 30 #include "Level.h" 31 31 32 #include <OgreSceneManager.h>33 #include <OgreLight.h>34 35 32 #include "core/CoreIncludes.h" 36 33 #include "core/XMLPort.h" 37 #include "core/Core.h"38 #include "core/ConsoleCommand.h"39 34 #include "core/Loader.h" 40 35 #include "core/XMLFile.h" 41 36 #include "core/Template.h" 42 37 43 #include "GraphicsEngine.h"44 38 #include "Settings.h" 39 #include "LevelManager.h" 45 40 #include "PlayerInfo.h" 41 #include "objects/gametypes/Gametype.h" 46 42 47 43 #include "util/Math.h" … … 49 45 namespace orxonox 50 46 { 51 SetConsoleCommand(Level, listPlayers, true);52 53 47 CreateFactory(Level); 54 48 55 Level::Level( )49 Level::Level(BaseObject* creator) : Info(creator) 56 50 { 57 51 RegisterObject(Level); 58 52 59 this->rootGametype_ = 0;60 53 this->registerVariables(); 61 62 // test test test 63 { 64 Ogre::Light* light; 65 light = GraphicsEngine::getInstance().getLevelSceneManager()->createLight("Light0"); 66 light->setType(Ogre::Light::LT_DIRECTIONAL); 67 light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0)); 68 light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0)); 69 light->setDirection(1, -0.2, 0.2); 70 } 71 // test test test 54 this->xmlfilename_ = this->getFilename(); 72 55 73 56 COUT(0) << "created Level" << std::endl; 74 57 } 75 58 76 Level * Level::getActiveLevel()59 Level::~Level() 77 60 { 78 for (ObjectList<Level>::iterator it = ObjectList<Level>::begin(); it != ObjectList<Level>::end(); ++it)79 if (it->isActive())80 return (*it);61 if (this->isInitialized()) 62 { 63 LevelManager::getInstance().releaseActivity(this); 81 64 82 return 0; 83 } 84 85 PlayerInfo* Level::getClient(unsigned int clientID) 86 { 87 Level* level = Level::getActiveLevel(); 88 89 if (level) 90 { 91 std::map<unsigned int, PlayerInfo*>::const_iterator it = level->clients_.find(clientID); 92 if (it != level->clients_.end()) 93 return it->second; 65 if (this->xmlfile_) 66 Loader::unload(this->xmlfile_); 94 67 } 95 else96 {97 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)98 if (it->getClientID() == clientID)99 return (*it);100 }101 return 0;102 }103 104 void Level::listPlayers()105 {106 Level* level = Level::getActiveLevel();107 108 if (level->getGametype())109 {110 for (std::set<PlayerInfo*>::const_iterator it = level->getGametype()->getPlayers().begin(); it != level->getGametype()->getPlayers().end(); ++it)111 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;112 }113 else114 {115 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)116 COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;117 }118 }119 120 void Level::clientConnected(unsigned int clientID)121 {122 COUT(0) << "client connected" << std::endl;123 124 // create new PlayerInfo instance125 PlayerInfo* player = new PlayerInfo();126 player->setGametype(this->getGametype());127 player->setClientID(clientID);128 129 // add to clients-map130 assert(!this->clients_[clientID]);131 this->clients_[clientID] = player;132 }133 134 void Level::clientDisconnected(unsigned int clientID)135 {136 COUT(0) << "client disconnected" << std::endl;137 138 // remove from clients-map139 PlayerInfo* player = this->clients_[clientID];140 this->clients_.erase(clientID);141 142 // delete PlayerInfo instance143 delete player;144 68 } 145 69 … … 150 74 XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode); 151 75 XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype"); 152 XMLPortParam(Level, "skybox", setSkybox, getSkybox, xmlelement, mode);153 XMLPortParam(Level, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2, 0.2, 0.2, 1));154 76 155 this->xmlfile_ = this->getFilename();77 XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); 156 78 } 157 79 158 80 void Level::registerVariables() 159 81 { 160 REGISTERSTRING(this->xmlfile _,network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));82 REGISTERSTRING(this->xmlfilename_, network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile)); 161 83 REGISTERSTRING(this->name_, network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::changedName)); 162 84 REGISTERSTRING(this->description_, network::direction::toclient); 163 REGISTERSTRING(this->skybox_, network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::networkcallback_applySkybox));164 REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::networkcallback_applyAmbientLight));165 85 } 166 86 167 87 void Level::networkcallback_applyXMLFile() 168 88 { 169 COUT(0) << "Loading level \"" << this->xmlfile _ << "\"..." << std::endl;89 COUT(0) << "Loading level \"" << this->xmlfilename_ << "\"..." << std::endl; 170 90 171 91 ClassTreeMask mask; … … 173 93 mask.include(Class(Template)); 174 94 175 XMLFile* file = new XMLFile(Settings::getDataPath() + this->xmlfile_, mask);95 this->xmlfile_ = new XMLFile(Settings::getDataPath() + this->xmlfilename_, mask); 176 96 177 Loader::open(file); 178 } 179 180 void Level::setSkybox(const std::string& skybox) 181 { 182 if (Core::showsGraphics()) 183 if (GraphicsEngine::getInstance().getLevelSceneManager()) 184 GraphicsEngine::getInstance().getLevelSceneManager()->setSkyBox(true, skybox); 185 186 this->skybox_ = skybox; 187 } 188 189 void Level::setAmbientLight(const ColourValue& colour) 190 { 191 if (Core::showsGraphics()) 192 GraphicsEngine::getInstance().getLevelSceneManager()->setAmbientLight(colour); 193 194 this->ambientLight_ = colour; 97 Loader::open(this->xmlfile_); 195 98 } 196 99 … … 198 101 { 199 102 Identifier* identifier = ClassByString(gametype); 200 if (identifier )103 if (identifier && identifier->isA(Class(Gametype))) 201 104 { 202 105 this->gametype_ = gametype; 203 this->gametypeIdentifier_ = identifier; 204 this->rootGametype_ = this->gametypeIdentifier_.fabricate(); 205 this->getConnectedClients(); 106 107 Gametype* rootgametype = dynamic_cast<Gametype*>(identifier->fabricate(this)); 108 this->setGametype(rootgametype); 109 110 for (std::list<BaseObject*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) 111 (*it)->setGametype(rootgametype); 112 113 LevelManager::getInstance().requestActivity(this); 206 114 } 207 115 } 116 117 118 void Level::addObject(BaseObject* object) 119 { 120 this->objects_.push_back(object); 121 object->setGametype(this->getGametype()); 122 } 123 124 BaseObject* Level::getObject(unsigned int index) const 125 { 126 unsigned int i = 0; 127 for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) 128 { 129 if (i == index) 130 return (*it); 131 ++i; 132 } 133 return 0; 134 } 135 136 void Level::playerEntered(PlayerInfo* player) 137 { 138 COUT(0) << "player entered level" << std::endl; 139 player->setGametype(this->getGametype()); 140 } 141 142 void Level::playerLeft(PlayerInfo* player) 143 { 144 player->setGametype(0); 145 } 208 146 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/Level.h
r2012 r2019 33 33 34 34 #include "Info.h" 35 #include "util/Math.h"36 #include "core/Identifier.h"37 38 #include "objects/gametypes/Gametype.h"39 #include "network/ClientConnectionListener.h"40 35 41 36 namespace orxonox 42 37 { 43 class _OrxonoxExport Level : public Info , public network::ClientConnectionListener38 class _OrxonoxExport Level : public Info 44 39 { 45 40 public: 46 Level( );47 virtual ~Level() {}41 Level(BaseObject* creator); 42 virtual ~Level(); 48 43 49 44 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 45 void registerVariables(); 51 52 inline const std::map<unsigned int, PlayerInfo*>& getClients() const53 { return this->clients_; }54 46 55 47 inline void setDescription(const std::string& description) … … 58 50 { return this->description_; } 59 51 60 void setSkybox(const std::string& skybox); 61 inline const std::string& getSkybox() const 62 { return this->skybox_; } 52 void playerEntered(PlayerInfo* player); 53 void playerLeft(PlayerInfo* player); 63 54 64 void setAmbientLight(const ColourValue& colour);65 inline const ColourValue& getAmbientLight() const66 { return this->ambientLight_; }55 private: 56 void addObject(BaseObject* object); 57 BaseObject* getObject(unsigned int index) const; 67 58 68 59 void setGametypeString(const std::string& gametype); 69 60 inline const std::string& getGametypeString() const 70 61 { return this->gametype_; } 71 inline Gametype* getGametype() const72 { return this->rootGametype_; }73 74 static Level* getActiveLevel();75 static void listPlayers();76 static PlayerInfo* getClient(unsigned int clientID);77 78 private:79 virtual void clientConnected(unsigned int clientID);80 virtual void clientDisconnected(unsigned int clientID);81 62 82 63 void networkcallback_applyXMLFile(); 83 64 84 void networkcallback_applySkybox() 85 { this->setSkybox(this->skybox_); } 86 void networkcallback_applyAmbientLight() 87 { this->setAmbientLight(this->ambientLight_); } 88 89 std::map<unsigned int, PlayerInfo*> clients_; 90 std::string description_; 91 std::string skybox_; 92 ColourValue ambientLight_; 93 std::string gametype_; 94 SubclassIdentifier<Gametype> gametypeIdentifier_; 95 Gametype* rootGametype_; 96 std::string xmlfile_; 65 std::string description_; 66 std::string gametype_; 67 std::string xmlfilename_; 68 XMLFile* xmlfile_; 69 std::list<BaseObject*> objects_; 97 70 }; 98 71 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r2006 r2019 27 27 */ 28 28 29 #include <cassert> 30 29 31 #include "OrxonoxStableHeaders.h" 30 32 #include "PlayerInfo.h" 31 33 32 #include <OgreSceneManager.h>33 34 34 #include "core/CoreIncludes.h" 35 #include "core/ConfigValueIncludes.h"36 #include "core/XMLPort.h"37 #include "core/Core.h"38 39 #include "network/Host.h"40 35 #include "network/ClientInformation.h" 41 42 #include "GraphicsEngine.h"43 36 #include "objects/gametypes/Gametype.h" 44 #include "objects/worldentities/ControllableEntity.h"45 #include "objects/controllers/HumanController.h"46 37 47 38 namespace orxonox 48 39 { 49 CreateUnloadableFactory(PlayerInfo); 50 51 PlayerInfo::PlayerInfo() 40 PlayerInfo::PlayerInfo(BaseObject* creator) : Info(creator) 52 41 { 53 42 RegisterObject(PlayerInfo); 54 43 55 this->ping_ = -1;56 44 this->clientID_ = network::CLIENTID_UNKNOWN; 45 this->bHumanPlayer_ = false; 57 46 this->bLocalPlayer_ = false; 58 this->bHumanPlayer_ = false; 59 this->bFinishedSetup_ = false; 60 this->gametype_ = 0; 47 this->bReadyToSpawn_ = false; 48 this->controller_ = 0; 49 this->controllableEntity_ = 0; 50 this->controllableEntityID_ = network::CLIENTID_UNKNOWN; 61 51 62 this->pawn_ = 0;63 this->pawnID_ = network::OBJECTID_UNKNOWN;64 this->controller_ = 0;65 this->setDefaultController(Class(HumanController));66 67 this->setConfigValues();68 52 this->registerVariables(); 69 53 } … … 73 57 if (this->isInitialized()) 74 58 { 75 if (this->gametype_) 76 this->gametype_->removePlayer(this); 59 this->stopControl(this->controllableEntity_); 77 60 78 61 if (this->controller_) 62 { 79 63 delete this->controller_; 80 81 if (this->pawn_) 82 this->pawn_->removePlayer(); 64 this->controller_ = 0; 65 } 83 66 } 84 67 } 85 68 86 void PlayerInfo:: setConfigValues()69 void PlayerInfo::registerVariables() 87 70 { 88 SetConfigValue(nick_, "Player").callback(this, &PlayerInfo::checkNick); 89 } 90 91 void PlayerInfo::checkNick() 92 { 93 if (this->bLocalPlayer_) 94 { 95 this->playerName_ = this->nick_; 96 97 if (Core::isMaster()) 98 this->setName(this->playerName_); 99 } 71 REGISTERSTRING(this->name_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName)); 72 REGISTERDATA (this->controllableEntityID_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedcontrollableentityID)); 100 73 } 101 74 102 75 void PlayerInfo::changedName() 103 76 { 104 if (this-> gametype_)105 this->g ametype_->playerChangedName(this);77 if (this->isReady() && this->getGametype()) 78 this->getGametype()->playerChangedName(this); 106 79 } 107 80 108 void PlayerInfo:: registerVariables()81 void PlayerInfo::changedGametype() 109 82 { 110 REGISTERSTRING(name_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName)); 111 REGISTERSTRING(playerName_, network::direction::toserver, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::clientChangedName)); 112 REGISTERDATA(clientID_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::checkClientID)); 113 REGISTERDATA(ping_, network::direction::toclient); 114 REGISTERDATA(bHumanPlayer_, network::direction::toclient); 115 REGISTERDATA(pawnID_, network::direction::toclient, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::updatePawn)); 116 REGISTERDATA(bFinishedSetup_, network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::finishedSetup)); 117 } 83 if (this->isReady()) 84 { 85 if (this->getOldGametype()) 86 { 87 if (this->getGametype()) 88 this->getOldGametype()->playerSwitched(this, this->getGametype()); 89 else 90 this->getOldGametype()->playerLeft(this); 91 } 118 92 119 void PlayerInfo::clientChangedName() 120 { 121 this->setName(this->playerName_); 122 } 123 124 void PlayerInfo::checkClientID() 125 { 126 this->bHumanPlayer_ = true; 127 128 if (this->clientID_ == network::Host::getPlayerID()) 129 { 130 this->takeLocalControl(); 131 132 if (Core::isClient()) 133 this->setObjectMode(network::direction::bidirectional); 134 else 93 if (this->getGametype()) 135 94 { 136 this->clientChangedName(); 137 this->bFinishedSetup_ = true; 138 this->finishedSetup(); 95 if (this->getOldGametype()) 96 this->getGametype()->playerSwitchedBack(this, this->getOldGametype()); 97 else 98 this->getGametype()->playerEntered(this); 139 99 } 140 100 } 141 101 } 142 102 143 void PlayerInfo:: finishedSetup()103 void PlayerInfo::createController() 144 104 { 145 if (Core::isClient()) 146 this->bFinishedSetup_ = true; 147 else if (this->bFinishedSetup_) 105 this->controller_ = this->defaultController_.fabricate(this); 106 assert(this->controller_); 107 this->controller_->setPlayer(this); 108 if (this->controllableEntity_) 109 this->controller_->setControllableEntity(this->controllableEntity_); 110 } 111 112 void PlayerInfo::startControl(ControllableEntity* entity) 113 { 114 if (this->controllableEntity_) 115 this->stopControl(this->controllableEntity_); 116 117 this->controllableEntity_ = entity; 118 119 if (entity) 148 120 { 149 if (this->gametype_) 150 this->gametype_->addPlayer(this); 121 this->controllableEntityID_ = entity->getObjectID(); 122 entity->setPlayer(this); 123 } 124 else 125 { 126 this->controllableEntityID_ = network::OBJECTID_UNKNOWN; 127 } 128 129 if (this->controller_) 130 this->controller_->setControllableEntity(entity); 131 } 132 133 void PlayerInfo::stopControl(ControllableEntity* entity) 134 { 135 if (entity && this->controllableEntity_ == entity) 136 { 137 this->controllableEntity_ = 0; 138 this->controllableEntityID_ = network::OBJECTID_UNKNOWN; 139 140 if (this->controller_) 141 this->controller_->setControllableEntity(0); 142 143 entity->removePlayer(); 151 144 } 152 145 } 153 146 154 void PlayerInfo:: startControl(ControllableEntity* pawn)147 void PlayerInfo::networkcallback_changedcontrollableentityID() 155 148 { 156 pawn->setPlayer(this); 157 this->pawn_ = pawn; 158 this->pawnID_ = pawn->getObjectID(); 149 if (this->controllableEntityID_ != network::OBJECTID_UNKNOWN) 150 { 151 Synchronisable* temp = Synchronisable::getSynchronisable(this->controllableEntityID_); 152 ControllableEntity* entity = dynamic_cast<ControllableEntity*>(temp); 159 153 160 if (this->controller_) 161 this->controller_->setPawn(this->pawn_); 162 } 163 164 void PlayerInfo::stopControl() 165 { 166 if (this->pawn_) 167 this->pawn_->removePlayer(); 168 this->pawn_ = 0; 169 this->pawnID_ = network::OBJECTID_UNKNOWN; 170 } 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 185 void PlayerInfo::updatePawn() 186 { 187 this->pawn_ = dynamic_cast<ControllableEntity*>(network::Synchronisable::getSynchronisable(this->pawnID_)); 188 if (this->pawn_ && (this->pawn_->getPlayer() != this)) 189 this->pawn_->setPlayer(this); 154 this->startControl(entity); 155 } 156 else 157 { 158 this->stopControl(this->controllableEntity_); 159 } 190 160 } 191 161 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r2006 r2019 41 41 { 42 42 public: 43 PlayerInfo( );43 PlayerInfo(BaseObject* creator); 44 44 virtual ~PlayerInfo(); 45 45 46 void setConfigValues();47 46 void registerVariables(); 48 47 49 48 virtual void changedName(); 50 51 inline void setClientID(unsigned int clientID) 52 { this->clientID_ = clientID; this->checkClientID(); } 53 inline unsigned int getClientID() const 54 { return this->clientID_; } 49 virtual void changedGametype(); 55 50 56 51 inline bool isHumanPlayer() const 57 52 { return this->bHumanPlayer_; } 58 59 53 inline bool isLocalPlayer() const 60 54 { return this->bLocalPlayer_; } 55 inline unsigned int getClientID() const 56 { return this->clientID_; } 57 inline bool isReadyToSpawn() const 58 { return this->bReadyToSpawn_; } 61 59 62 virtual void startControl(ControllableEntity* pawn); 63 virtual void stopControl(); 60 virtual bool isReady() const = 0; 61 virtual float getPing() const = 0; 62 virtual float getPacketLossRatio() const = 0; 64 63 65 inline ControllableEntity* getPawn() const 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 inline void setGametype(Gametype* gametype) 74 { this->gametype_ = gametype; } 75 inline Gametype* getGametype() const 76 { return this->gametype_; } 64 inline void setReadyToSpawn(bool bReady) 65 { this->bReadyToSpawn_ = bReady; } 66 67 void startControl(ControllableEntity* entity); 68 void stopControl(ControllableEntity* entity); 69 70 inline ControllableEntity* getControllableEntity() const 71 { return this->controllableEntity_; } 77 72 78 73 protected: 79 inline void setDefaultController(Identifier* identifier)80 { this->defaultController_ = identifier; }74 void createController(); 75 void networkcallback_changedcontrollableentityID(); 81 76 82 private: 83 virtual void createController(); 84 virtual void takeLocalControl(); 85 86 void checkClientID(); 87 void finishedSetup(); 88 void checkNick(); 89 void clientChangedName(); 90 void updatePawn(); 91 77 bool bHumanPlayer_; 78 bool bLocalPlayer_; 79 bool bReadyToSpawn_; 80 SubclassIdentifier<Controller> defaultController_; 81 Controller* controller_; 82 ControllableEntity* controllableEntity_; 83 unsigned int controllableEntityID_; 92 84 unsigned int clientID_; 93 float ping_;94 bool bLocalPlayer_;95 bool bHumanPlayer_;96 bool bFinishedSetup_;97 98 std::string playerName_;99 std::string nick_;100 101 ControllableEntity* pawn_;102 unsigned int pawnID_;103 Controller* controller_;104 SubclassIdentifier<Controller> defaultController_;105 Gametype* gametype_;106 85 }; 107 86 }
Note: See TracChangeset
for help on using the changeset viewer.