Changeset 2428
- Timestamp:
- Dec 13, 2008, 10:54:26 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src
- Files:
-
- 4 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/core/BaseObject.h
r2369 r2428 135 135 inline Scene* getScene() const { return this->scene_; } 136 136 137 inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); } 137 inline void setGametype(Gametype* gametype) 138 { 139 if (gametype != this->gametype_) 140 { 141 this->oldGametype_ = this->gametype_; 142 this->gametype_ = gametype; 143 this->changedGametype(); 144 } 145 } 138 146 inline Gametype* getGametype() const { return this->gametype_; } 139 147 inline Gametype* getOldGametype() const { return this->oldGametype_; } 140 virtual inlinevoid changedGametype() {}148 virtual void changedGametype() {} 141 149 142 150 void fireEvent(); … … 197 205 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 198 206 SUPER_FUNCTION(9, BaseObject, changedName, false); 207 SUPER_FUNCTION(10, BaseObject, changedGametype, false); 199 208 } 200 209 -
code/branches/objecthierarchy2/src/core/Super.h
r2369 r2428 265 265 #define SUPER_changedName(classname, functionname, ...) \ 266 266 SUPER_NOARGS(classname, functionname) 267 268 #define SUPER_changedGametype(classname, functionname, ...) \ 269 SUPER_NOARGS(classname, functionname) 267 270 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 268 271 … … 513 516 514 517 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false) 518 () 519 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 520 521 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false) 515 522 () 516 523 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; … … 568 575 SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup); 569 576 SUPER_INTRUSIVE_DECLARATION(changedName); 577 SUPER_INTRUSIVE_DECLARATION(changedGametype); 570 578 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 571 579 -
code/branches/objecthierarchy2/src/network/Synchronisable.h
r2171 r2428 111 111 static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 112 112 113 inline unsigned int getObjectID() {return objectID;}114 inline unsigned int getClassID() {return classID;}113 inline unsigned int getObjectID() const { return objectID; } 114 inline unsigned int getClassID() const { return classID; } 115 115 protected: 116 116 Synchronisable(BaseObject* creator); -
code/branches/objecthierarchy2/src/orxonox/OrxonoxPrereqs.h
r2422 r2428 187 187 class OverlayGroup; 188 188 class OverlayText; 189 class GametypeStatus; 189 190 190 191 //gui -
code/branches/objecthierarchy2/src/orxonox/objects/controllers/Controller.cc
r2087 r2428 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "overlays/OverlayGroup.h" 33 34 34 35 namespace orxonox … … 42 43 this->player_ = 0; 43 44 this->controllableEntity_ = 0; 45 this->hud_ = 0; 46 this->bUpdateHUD_ = false; 44 47 } 45 48 46 49 Controller::~Controller() 47 50 { 51 if (this->isInitialized() && this->hud_) 52 delete this->hud_; 53 } 54 55 void Controller::changedControllableEntity() 56 { 57 if (this->bUpdateHUD_) 58 { 59 this->updateHUD(); 60 this->bUpdateHUD_ = false; 61 } 62 63 if (this->hud_) 64 this->hud_->setOwner(this->getControllableEntity()); 65 } 66 67 void Controller::updateHUD() 68 { 69 if (this->hud_) 70 { 71 delete this->hud_; 72 this->hud_ = 0; 73 } 74 75 if (this->hudtemplate_ != "") 76 { 77 this->hud_ = new OverlayGroup(this); 78 this->hud_->addTemplate(this->hudtemplate_); 79 this->hud_->setOwner(this->getControllableEntity()); 80 } 48 81 } 49 82 } -
code/branches/objecthierarchy2/src/orxonox/objects/controllers/Controller.h
r2362 r2428 57 57 inline ControllableEntity* getControllableEntity() const 58 58 { return this->controllableEntity_; } 59 virtual void changedControllableEntity() {} 59 virtual void changedControllableEntity(); 60 61 inline void setHUDTemplate(const std::string& name) 62 { 63 if (name != this->hudtemplate_) 64 { 65 this->hudtemplate_ = name; 66 if (this->controllableEntity_) 67 this->updateHUD(); 68 else 69 this->bUpdateHUD_ = true; 70 } 71 } 72 inline const std::string& getHUDTemplate() const 73 { return this->hudtemplate_; } 74 75 inline OverlayGroup* getHUD() const 76 { return this->hud_; } 60 77 61 78 protected: 79 void updateHUD(); 80 62 81 PlayerInfo* player_; 63 82 ControllableEntity* controllableEntity_; 83 std::string hudtemplate_; 84 OverlayGroup* hud_; 85 bool bUpdateHUD_; 64 86 }; 65 87 } -
code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc
r2369 r2428 34 34 35 35 #include "core/CoreIncludes.h" 36 #include "core/ConfigValueIncludes.h" 36 37 #include "objects/infos/PlayerInfo.h" 37 38 #include "objects/worldentities/pawns/Spectator.h" … … 44 45 CreateUnloadableFactory(Gametype); 45 46 46 Gametype::Gametype(BaseObject* creator) : BaseObject(creator) 47 Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator) 47 48 { 48 49 RegisterObject(Gametype); … … 50 51 this->defaultControllableEntity_ = Class(Spectator); 51 52 52 this->bStarted_ = false;53 this->bEnded_ = false;54 53 this->bAutoStart_ = false; 55 54 this->bForceSpawn_ = false; 56 55 57 56 this->initialStartCountdown_ = 3; 58 this->startCountdown_ = 0; 59 this->bStartCountdownRunning_ = false; 57 58 this->setConfigValues(); 59 } 60 61 void Gametype::setConfigValues() 62 { 63 SetConfigValue(initialStartCountdown_, 3.0f); 60 64 } 61 65 … … 64 68 SUPER(Gametype, tick, dt); 65 69 66 if (this-> bStartCountdownRunning_ && !this->bStarted_)67 this-> startCountdown_ -= dt;68 69 if (!this-> bStarted_)70 if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_) 71 this->gtinfo_.startCountdown_ -= dt; 72 73 if (!this->gtinfo_.bStarted_) 70 74 this->checkStart(); 71 75 else … … 78 82 { 79 83 COUT(0) << "game started" << std::endl; 80 this-> bStarted_ = true;84 this->gtinfo_.bStarted_ = true; 81 85 82 86 this->spawnPlayersIfRequested(); … … 86 90 { 87 91 COUT(0) << "game ended" << std::endl; 88 this-> bEnded_ = true;92 this->gtinfo_.bEnded_ = true; 89 93 } 90 94 … … 173 177 it->second = PlayerState::Dead; 174 178 175 if (!it->first->isReadyToSpawn() || !this-> bStarted_)179 if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_) 176 180 { 177 181 SpawnPoint* spawn = this->getBestSpawnPoint(it->first); … … 196 200 void Gametype::checkStart() 197 201 { 198 if (!this-> bStarted_)199 { 200 if (this-> bStartCountdownRunning_)201 { 202 if (this-> startCountdown_ <= 0)203 { 204 this-> bStartCountdownRunning_ = false;205 this-> startCountdown_ = 0;202 if (!this->gtinfo_.bStarted_) 203 { 204 if (this->gtinfo_.bStartCountdownRunning_) 205 { 206 if (this->gtinfo_.startCountdown_ <= 0) 207 { 208 this->gtinfo_.bStartCountdownRunning_ = false; 209 this->gtinfo_.startCountdown_ = 0; 206 210 this->start(); 207 211 } … … 226 230 if (allplayersready && hashumanplayers) 227 231 { 228 this-> startCountdown_ = this->initialStartCountdown_;229 this-> bStartCountdownRunning_ = true;232 this->gtinfo_.startCountdown_ = this->initialStartCountdown_; 233 this->gtinfo_.bStartCountdownRunning_ = true; 230 234 } 231 235 } -
code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.h
r2171 r2428 38 38 #include "objects/worldentities/ControllableEntity.h" 39 39 #include "objects/Tickable.h" 40 #include "objects/infos/GametypeInfo.h" 40 41 41 42 namespace orxonox … … 60 61 virtual ~Gametype() {} 61 62 63 void setConfigValues(); 64 62 65 virtual void tick(float dt); 63 66 67 inline const GametypeInfo* getGametypeInfo() const 68 { return &this->gtinfo_; } 69 64 70 inline bool hasStarted() const 65 { return this-> bStarted_; }71 { return this->gtinfo_.bStarted_; } 66 72 inline bool hasEnded() const 67 { return this-> bEnded_; }73 { return this->gtinfo_.bEnded_; } 68 74 69 75 virtual void start(); … … 88 94 89 95 inline bool isStartCountdownRunning() const 90 { return this-> bStartCountdownRunning_; }96 { return this->gtinfo_.bStartCountdownRunning_; } 91 97 inline float getStartCountdown() const 92 { return this-> startCountdown_; }98 { return this->gtinfo_.startCountdown_; } 93 99 94 100 private: … … 104 110 void spawnDeadPlayersIfRequested(); 105 111 106 bool bStarted_;107 bool bEnded_; 112 GametypeInfo gtinfo_; 113 108 114 bool bAutoStart_; 109 115 bool bForceSpawn_; 110 116 111 117 float initialStartCountdown_; 112 float startCountdown_;113 bool bStartCountdownRunning_;114 118 115 119 std::map<PlayerInfo*, PlayerState::Enum> players_; -
code/branches/objecthierarchy2/src/orxonox/objects/infos/CMakeLists.txt
r2362 r2428 4 4 PlayerInfo.cc 5 5 HumanPlayer.cc 6 GametypeInfo.cc 6 7 ) 7 8 -
code/branches/objecthierarchy2/src/orxonox/objects/infos/HumanPlayer.cc
r2171 r2428 37 37 #include "objects/controllers/HumanController.h" 38 38 #include "objects/gametypes/Gametype.h" 39 #include "overlays/OverlayGroup.h" 39 40 40 41 namespace orxonox … … 63 64 { 64 65 SetConfigValue(nick_, "Player").callback(this, &HumanPlayer::configvaluecallback_changednick); 66 SetConfigValue(hudtemplate_, "defaultHUD").callback(this, &HumanPlayer::configvaluecallback_changedHUDTemplate); 65 67 } 66 68 … … 69 71 REGISTERSTRING(this->synchronize_nick_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick)); 70 72 71 REGISTERDATA(this->clientID_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));73 REGISTERDATA(this->clientID_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged)); 72 74 REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized)); 73 75 REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized)); … … 83 85 this->setName(this->nick_); 84 86 } 87 } 88 89 void HumanPlayer::configvaluecallback_changedHUDTemplate() 90 { 91 this->changedController(); 85 92 } 86 93 … … 138 145 this->networkcallback_clientIDchanged(); 139 146 } 147 148 void HumanPlayer::changedController() 149 { 150 if (this->getController()) 151 { 152 this->getController()->setHUDTemplate(this->hudtemplate_); 153 154 if (this->getController() && this->getController()->getHUD()) 155 this->getController()->getHUD()->setOwner(this->getControllableEntity()); 156 } 157 } 140 158 } -
code/branches/objecthierarchy2/src/orxonox/objects/infos/HumanPlayer.h
r2362 r2428 51 51 void setClientID(unsigned int clientID); 52 52 53 virtual void changedController(); 54 53 55 protected: 54 56 void configvaluecallback_changednick(); 57 void configvaluecallback_changedHUDTemplate(); 55 58 void networkcallback_changednick(); 56 59 void networkcallback_clientIDchanged(); … … 60 63 std::string nick_; 61 64 std::string synchronize_nick_; 65 std::string hudtemplate_; 62 66 bool server_initialized_; 63 67 bool client_initialized_; -
code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.cc
r2369 r2428 112 112 if (this->controllableEntity_) 113 113 this->controller_->setControllableEntity(this->controllableEntity_); 114 this->changedController(); 114 115 } 115 116 116 117 void PlayerInfo::startControl(ControllableEntity* entity) 117 118 { 119 if (entity == this->controllableEntity_) 120 return; 121 118 122 if (this->controllableEntity_) 119 123 this->stopControl(this->controllableEntity_); -
code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.h
r2362 r2428 71 71 { return this->controllableEntity_; } 72 72 73 inline Controller* getController() const 74 { return this->controller_; } 75 virtual void changedController() {} 76 73 77 protected: 74 78 void createController(); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc
r2361 r2428 38 38 #include "objects/worldentities/Camera.h" 39 39 #include "objects/worldentities/CameraPosition.h" 40 #include "objects/gametypes/Gametype.h" 40 41 #include "overlays/OverlayGroup.h" 41 42 … … 59 60 this->bDestroyWhenPlayerLeft_ = false; 60 61 62 this->gtinfo_ = 0; 63 this->gtinfoID_ = OBJECTID_UNKNOWN; 64 this->changedGametype(); 65 61 66 this->velocity_ = Vector3::ZERO; 62 67 this->acceleration_ = Vector3::ZERO; … … 98 103 99 104 XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode); 105 } 106 107 void ControllableEntity::changedGametype() 108 { 109 SUPER(ControllableEntity, changedGametype); 110 111 this->gtinfo_ = 0; 112 this->gtinfoID_ = OBJECTID_UNKNOWN; 113 114 if (this->getGametype() && this->getGametype()->getGametypeInfo()) 115 { 116 this->gtinfo_ = this->getGametype()->getGametypeInfo(); 117 this->gtinfoID_ = this->gtinfo_->getObjectID(); 118 } 100 119 } 101 120 … … 199 218 } 200 219 220 void ControllableEntity::networkcallback_changedgtinfoID() 221 { 222 if (this->gtinfoID_ != OBJECTID_UNKNOWN) 223 { 224 this->gtinfo_ = dynamic_cast<GametypeInfo*>(Synchronisable::getSynchronisable(this->gtinfoID_)); 225 226 if (!this->gtinfo_) 227 this->gtinfoID_ = OBJECTID_UNKNOWN; 228 } 229 } 230 201 231 void ControllableEntity::startLocalHumanControl() 202 232 { … … 268 298 269 299 REGISTERDATA(this->playerID_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); 300 REGISTERDATA(this->gtinfoID_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedgtinfoID)); 270 301 } 271 302 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h
r2362 r2428 46 46 virtual void tick(float dt); 47 47 void registerVariables(); 48 49 virtual void changedGametype(); 48 50 49 51 virtual void setPlayer(PlayerInfo* player); … … 143 145 { return this->bHasHumanController_; } 144 146 147 inline const GametypeInfo* getGametypeInfo() const 148 { return this->gtinfo_; } 149 145 150 protected: 146 151 virtual void startLocalHumanControl(); … … 165 170 166 171 void networkcallback_changedplayerID(); 172 void networkcallback_changedgtinfoID(); 167 173 168 174 unsigned int server_overwrite_; … … 190 196 std::list<CameraPosition*> cameraPositions_; 191 197 std::string cameraPositionTemplate_; 198 199 const GametypeInfo* gtinfo_; 200 unsigned int gtinfoID_; 192 201 }; 193 202 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2422 r2428 57 57 this->roll_ = 0; 58 58 this->setHudTemplate("spectatorhud"); 59 this->hudmode_ = 0;60 59 61 60 this->setDestroyWhenPlayerLeft(true); … … 96 95 REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 97 96 REGISTERDATA(this->bGreeting_, direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 98 REGISTERDATA(this->hudmode_, direction::toclient);99 97 } 100 98 … … 112 110 void Spectator::tick(float dt) 113 111 { 114 this->updateHUD();115 116 112 if (this->hasLocalController()) 117 113 { … … 193 189 } 194 190 } 195 196 void Spectator::updateHUD()197 {198 // <hack>199 if (Core::isMaster())200 {201 if (this->getPlayer() && this->getGametype())202 {203 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())204 {205 if (!this->getPlayer()->isReadyToSpawn())206 this->hudmode_ = 0;207 else208 this->hudmode_ = 1;209 }210 else if (!this->getGametype()->hasEnded())211 {212 if (this->getGametype()->isStartCountdownRunning())213 this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());214 else215 this->hudmode_ = 3;216 }217 else218 this->hudmode_ = 4;219 }220 else221 return;222 }223 224 if (this->getHUD())225 {226 std::string text;227 int hudmode = this->hudmode_ % 10;228 229 switch (hudmode)230 {231 case 0:232 text = "Press [Fire] to start the match";233 break;234 case 1:235 text = "Waiting for other players";236 break;237 case 2:238 text = convertToString((this->hudmode_ - 2) / 10);239 break;240 case 3:241 text = "Press [Fire] to respawn";242 break;243 case 4:244 text = "Game has ended";245 break;246 default:;247 }248 249 std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();250 for (; it != this->getHUD()->getOverlays().end(); ++it)251 {252 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")253 {254 OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);255 if (overlay)256 overlay->setCaption(text);257 break;258 }259 }260 }261 // </hack>262 }263 191 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.h
r2362 r2428 63 63 void changedGreeting(); 64 64 void changedFlareVisibility(); 65 void updateHUD();66 65 67 66 BillboardSet* greetingFlare_; … … 75 74 float pitch_; 76 75 float roll_; 77 78 int hudmode_;79 76 }; 80 77 } -
code/branches/objecthierarchy2/src/orxonox/overlays/hud/CMakeLists.txt
r2369 r2428 6 6 HUDHealthBar.cc 7 7 ChatOverlay.cc 8 GametypeStatus.cc 8 9 ) 9 10
Note: See TracChangeset
for help on using the changeset viewer.