Changeset 2024 for code/branches/objecthierarchy/src/orxonox
- Timestamp:
- Oct 28, 2008, 3:05:17 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox
- Files:
-
- 4 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/CMakeLists.txt
r2019 r2024 69 69 70 70 objects/worldentities/pawns/Spectator.cc 71 objects/worldentities/pawns/Pawn.cc 72 objects/worldentities/pawns/SpaceShip.cc 71 73 72 74 objects/controllers/Controller.cc -
code/branches/objecthierarchy/src/orxonox/objects/Scene.cc
r2023 r2024 85 85 Scene::~Scene() 86 86 { 87 if ( Ogre::Root::getSingletonPtr())87 if (this->isInitialized()) 88 88 { 89 // this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre 90 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 91 } 92 else if (!Core::showsGraphics()) 93 { 94 delete this->sceneManager_; 89 if (Ogre::Root::getSingletonPtr()) 90 { 91 // this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre 92 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 93 } 94 else if (!Core::showsGraphics()) 95 { 96 delete this->sceneManager_; 97 } 95 98 } 96 99 } -
code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.cc
r2019 r2024 67 67 { 68 68 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 69 HumanController::localController_s->controllableEntity_->moveFrontBack(value .y);69 HumanController::localController_s->controllableEntity_->moveFrontBack(value); 70 70 } 71 71 … … 73 73 { 74 74 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 75 HumanController::localController_s->controllableEntity_->moveRightLeft(value .y);75 HumanController::localController_s->controllableEntity_->moveRightLeft(value); 76 76 } 77 77 … … 79 79 { 80 80 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 81 HumanController::localController_s->controllableEntity_->moveUpDown(value .y);81 HumanController::localController_s->controllableEntity_->moveUpDown(value); 82 82 } 83 83 … … 85 85 { 86 86 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 87 HumanController::localController_s->controllableEntity_->rotateYaw(value .y);87 HumanController::localController_s->controllableEntity_->rotateYaw(value); 88 88 } 89 89 … … 91 91 { 92 92 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 93 HumanController::localController_s->controllableEntity_->rotatePitch(value .y);93 HumanController::localController_s->controllableEntity_->rotatePitch(value); 94 94 } 95 95 … … 97 97 { 98 98 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 99 HumanController::localController_s->controllableEntity_->rotateRoll(value .y);99 HumanController::localController_s->controllableEntity_->rotateRoll(value); 100 100 } 101 101 -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r2020 r2024 48 48 RegisterObject(Gametype); 49 49 50 this->defaultPawn_ = Class(Spectator); 50 this->defaultControllableEntity_ = Class(Spectator); 51 51 52 this->bStarted_ = false; 52 53 this->bEnded_ = false; 53 54 this->bAutoStart_ = false; 55 this->bForceSpawn_ = false; 56 57 this->initialStartCountdown_ = 3; 58 this->startCountdown_ = 0; 59 this->bStartCountdownRunning_ = false; 54 60 55 61 COUT(0) << "created Gametype" << std::endl; … … 58 64 void Gametype::tick(float dt) 59 65 { 66 if (this->bStartCountdownRunning_ && !this->bStarted_) 67 this->startCountdown_ -= dt; 68 60 69 if (!this->bStarted_) 61 70 this->checkStart(); 62 71 63 72 this->assignDefaultPawnsIfNeeded(); 73 this->spawnDeadPlayersIfRequested(); 64 74 } 65 75 … … 69 79 this->bStarted_ = true; 70 80 71 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 72 this->spawnPlayer(*it); 81 this->spawnPlayersIfRequested(); 73 82 } 74 83 … … 122 131 } 123 132 124 void Gametype::playerSpawned(PlayerInfo* player) 125 { 126 } 127 128 void Gametype::playerDied(PlayerInfo* player) 133 void Gametype::pawnPreSpawn(Pawn* pawn) 134 { 135 } 136 137 void Gametype::pawnPostSpawn(Pawn* pawn) 138 { 139 } 140 141 void Gametype::pawnKilled(Pawn* victim, Pawn* killer) 129 142 { 130 143 } … … 164 177 { 165 178 // force spawn at spawnpoint with default pawn 166 ControllableEntity* newpawn = this->defaultPawn_.fabricate(spawn);167 spawn->spawn( newpawn);168 (*it)->startControl( newpawn);179 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 180 spawn->spawn(entity); 181 (*it)->startControl(entity); 169 182 } 170 183 else … … 181 194 if (!this->bStarted_) 182 195 { 183 if (this->players_.size() > 0) 196 if (this->bStartCountdownRunning_) 197 { 198 if (this->startCountdown_ <= 0) 199 { 200 this->bStartCountdownRunning_ = false; 201 this->startCountdown_ = 0; 202 this->start(); 203 } 204 } 205 else if (this->players_.size() > 0) 184 206 { 185 207 if (this->bAutoStart_) … … 196 218 } 197 219 if (allplayersready) 198 this->start(); 199 } 200 } 201 } 220 { 221 this->startCountdown_ = this->initialStartCountdown_; 222 this->bStartCountdownRunning_ = true; 223 } 224 } 225 } 226 } 227 } 228 229 void Gametype::spawnPlayersIfRequested() 230 { 231 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 232 if ((*it)->isReadyToSpawn() || this->bForceSpawn_) 233 this->spawnPlayer(*it); 234 } 235 236 void Gametype::spawnDeadPlayersIfRequested() 237 { 238 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 239 if (!(*it)->getControllableEntity()) 240 if ((*it)->isReadyToSpawn() || this->bForceSpawn_) 241 this->spawnPlayer(*it); 202 242 } 203 243 204 244 void Gametype::spawnPlayer(PlayerInfo* player) 205 245 { 206 if (player->isReadyToSpawn()) 207 { 208 SpawnPoint* spawnpoint = this->getBestSpawnPoint(player); 209 if (spawnpoint) 210 { 211 player->startControl(spawnpoint->spawn()); 212 } 213 else 214 { 215 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 216 abort(); 217 } 246 SpawnPoint* spawnpoint = this->getBestSpawnPoint(player); 247 if (spawnpoint) 248 { 249 player->startControl(spawnpoint->spawn()); 250 } 251 else 252 { 253 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 254 abort(); 218 255 } 219 256 } -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r2019 r2024 51 51 virtual void tick(float dt); 52 52 53 inline bool hasStarted() const 54 { return this->bStarted_; } 55 inline bool hasEnded() const 56 { return this->bEnded_; } 57 53 58 virtual void start(); 54 59 virtual void end(); … … 58 63 virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype); 59 64 virtual void playerChangedName(PlayerInfo* player); 60 virtual void playerSpawned(PlayerInfo* player); 61 virtual void playerDied(PlayerInfo* player); 65 62 66 virtual void playerScored(PlayerInfo* player); 67 68 virtual void pawnKilled(Pawn* victim, Pawn* killer = 0); 69 virtual void pawnPreSpawn(Pawn* pawn); 70 virtual void pawnPostSpawn(Pawn* pawn); 63 71 64 72 inline const std::set<PlayerInfo*>& getPlayers() const … … 67 75 inline void registerSpawnPoint(SpawnPoint* spawnpoint) 68 76 { this->spawnpoints_.insert(spawnpoint); } 77 78 inline bool isStartCountdownRunning() const 79 { return this->bStartCountdownRunning_; } 80 inline float getStartCountdown() const 81 { return this->startCountdown_; } 69 82 70 83 private: … … 77 90 void checkStart(); 78 91 void spawnPlayer(PlayerInfo* player); 92 void spawnPlayersIfRequested(); 93 void spawnDeadPlayersIfRequested(); 79 94 80 95 bool bStarted_; 81 96 bool bEnded_; 82 97 bool bAutoStart_; 98 bool bForceSpawn_; 99 100 float initialStartCountdown_; 101 float startCountdown_; 102 bool bStartCountdownRunning_; 103 83 104 std::set<PlayerInfo*> players_; 84 105 std::set<SpawnPoint*> spawnpoints_; 85 SubclassIdentifier<ControllableEntity> default Pawn_;106 SubclassIdentifier<ControllableEntity> defaultControllableEntity_; 86 107 }; 87 108 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r2019 r2024 121 121 this->controllableEntityID_ = entity->getObjectID(); 122 122 entity->setPlayer(this); 123 this->bReadyToSpawn_ = false; 123 124 } 124 125 else -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h
r2019 r2024 57 57 { return this->bDestroyWhenPlayerLeft_; } 58 58 59 virtual void moveFrontBack( floatvalue) {}60 virtual void moveRightLeft( floatvalue) {}61 virtual void moveUpDown( floatvalue) {}59 virtual void moveFrontBack(const Vector2& value) {} 60 virtual void moveRightLeft(const Vector2& value) {} 61 virtual void moveUpDown(const Vector2& value) {} 62 62 63 virtual void rotateYaw( floatvalue) {}64 virtual void rotatePitch( floatvalue) {}65 virtual void rotateRoll( floatvalue) {}63 virtual void rotateYaw(const Vector2& value) {} 64 virtual void rotatePitch(const Vector2& value) {} 65 virtual void rotateRoll(const Vector2& value) {} 66 66 67 67 virtual void fire() {} … … 108 108 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; } 109 109 110 inline Camera* getCamera() const 111 { return this->camera_; } 112 inline OverlayGroup* getHUD() const 113 { return this->hud_; } 114 110 115 protected: 111 116 virtual void startLocalControl(); … … 117 122 inline bool isLocallyControlled() const 118 123 { return this->bControlled_; } 124 125 Vector3 acceleration_; 119 126 120 127 private: … … 136 143 137 144 Vector3 velocity_; 138 Vector3 acceleration_;139 145 140 146 bool bControlled_; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/SpawnPoint.cc
r2019 r2024 57 57 58 58 XMLPortParam(SpawnPoint, "spawnclass", setSpawnClassName, getSpawnClassName, xmlelement, mode); 59 XMLPortParam(SpawnPoint, " design", setTemplateName, getTemplateName, xmlelement, mode);59 XMLPortParam(SpawnPoint, "pawndesign", setTemplateName, getTemplateName, xmlelement, mode); 60 60 } 61 61 … … 72 72 } 73 73 74 ControllableEntity* SpawnPoint::spawn()74 Pawn* SpawnPoint::spawn() 75 75 { 76 ControllableEntity* entity = this->spawnclass_.fabricate(this);76 Pawn* entity = this->spawnclass_.fabricate(this); 77 77 if (entity) 78 78 { 79 this->getGametype()->pawnPreSpawn(entity); 79 80 this->spawn(entity); 80 81 if (this->template_) 81 82 entity->addTemplate(this->template_); 83 entity->postSpawn(); 84 this->getGametype()->pawnPostSpawn(entity); 82 85 } 83 86 return entity; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/SpawnPoint.h
r2019 r2024 35 35 #include "core/Template.h" 36 36 #include "PositionableEntity.h" 37 #include " ControllableEntity.h"37 #include "objects/worldentities/pawns/Pawn.h" 38 38 39 39 namespace orxonox … … 57 57 { return this->template_; } 58 58 59 ControllableEntity* spawn();59 Pawn* spawn(); 60 60 void spawn(ControllableEntity* entity); 61 61 … … 69 69 { return this->templatename_; } 70 70 71 SubclassIdentifier< ControllableEntity> spawnclass_;71 SubclassIdentifier<Pawn> spawnclass_; 72 72 std::string spawnclassname_; 73 73 Template* template_; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2019 r2024 35 35 #include "objects/Scene.h" 36 36 #include "objects/infos/PlayerInfo.h" 37 #include "objects/gametypes/Gametype.h" 37 38 #include "tools/BillboardSet.h" 39 #include "overlays/OverlayText.h" 40 #include "overlays/OverlayGroup.h" 41 #include "util/Convert.h" 38 42 39 43 namespace orxonox … … 54 58 55 59 this->setDestroyWhenPlayerLeft(true); 56 57 // test test test58 if (this->getScene()->getSceneManager())59 {60 this->testmesh_ = new Mesh();61 this->testnode_ = this->getNode()->createChildSceneNode();62 this->testmesh_->setMeshSource(this->getScene()->getSceneManager(), "assff.mesh");63 if (this->testmesh_->getEntity())64 this->testnode_->attachObject(this->testmesh_->getEntity());65 this->testnode_->pitch(Degree(-90));66 this->testnode_->roll(Degree(+90));67 this->testnode_->scale(10, 10, 10);68 }69 else70 {71 this->testmesh_ = 0;72 this->testnode_ = 0;73 }74 // test test test75 60 76 61 this->greetingFlare_ = new BillboardSet(); … … 93 78 delete this->greetingFlare_; 94 79 } 95 96 // test test test97 {98 if (this->testmesh_ && this->testnode_)99 this->testnode_->detachObject(this->testmesh_->getEntity());100 101 if (this->testmesh_)102 delete this->testmesh_;103 104 if (this->testnode_)105 this->getNode()->removeAndDestroyChild(this->testnode_->getName());106 }107 // test test test108 80 } 109 81 } … … 130 102 if (this->isLocallyControlled()) 131 103 { 104 this->updateHUD(); 105 132 106 Vector3 velocity = this->getVelocity(); 133 107 velocity.normalise(); … … 159 133 { 160 134 ControllableEntity::startLocalControl(); 161 if (this->isLocallyControlled())162 this->testmesh_->setVisible(false);163 } 164 165 void Spectator::moveFrontBack( floatvalue)166 { 167 this->setVelocity(this->getVelocity() + value * this->speed_ * WorldEntity::FRONT);168 } 169 170 void Spectator::moveRightLeft( floatvalue)171 { 172 this->setVelocity(this->getVelocity() + value * this->speed_ * WorldEntity::RIGHT);173 } 174 175 void Spectator::moveUpDown( floatvalue)176 { 177 this->setVelocity(this->getVelocity() + value * this->speed_ * WorldEntity::UP);178 } 179 180 void Spectator::rotateYaw( floatvalue)181 { 182 this->yaw_ = value ;183 } 184 185 void Spectator::rotatePitch( floatvalue)186 { 187 this->pitch_ = value ;188 } 189 190 void Spectator::rotateRoll( floatvalue)191 { 192 this->roll_ = value ;135 // if (this->isLocallyControlled()) 136 // this->testmesh_->setVisible(false); 137 } 138 139 void Spectator::moveFrontBack(const Vector2& value) 140 { 141 this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT); 142 } 143 144 void Spectator::moveRightLeft(const Vector2& value) 145 { 146 this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT); 147 } 148 149 void Spectator::moveUpDown(const Vector2& value) 150 { 151 this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP); 152 } 153 154 void Spectator::rotateYaw(const Vector2& value) 155 { 156 this->yaw_ = value.y; 157 } 158 159 void Spectator::rotatePitch(const Vector2& value) 160 { 161 this->pitch_ = value.y; 162 } 163 164 void Spectator::rotateRoll(const Vector2& value) 165 { 166 this->roll_ = value.y; 193 167 } 194 168 … … 209 183 } 210 184 } 185 186 void Spectator::updateHUD() 187 { 188 // <hack> 189 if (this->getHUD()) 190 { 191 std::string text; 192 193 if (this->getPlayer() && this->getGametype()) 194 { 195 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning()) 196 { 197 if (!this->getPlayer()->isReadyToSpawn()) 198 text = "Press [Fire] to start the match"; 199 else 200 text = "Waiting for other players"; 201 } 202 else if (!this->getGametype()->hasEnded()) 203 { 204 if (this->getGametype()->isStartCountdownRunning()) 205 { 206 text = convertToString(ceil(this->getGametype()->getStartCountdown())); 207 } 208 else 209 { 210 text = "Press [Fire] to respawn"; 211 } 212 } 213 else 214 { 215 text = "Game has ended"; 216 } 217 } 218 else 219 { 220 return; 221 } 222 223 std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin(); 224 for (; it != this->getHUD()->getOverlays().end(); ++it) 225 { 226 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state") 227 { 228 OverlayText* overlay = dynamic_cast<OverlayText*>(it->second); 229 if (overlay) 230 overlay->setCaption(text); 231 break; 232 } 233 } 234 } 235 // </hack> 236 } 211 237 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.h
r2019 r2024 48 48 virtual void startLocalControl(); 49 49 50 virtual void moveFrontBack( floatvalue);51 virtual void moveRightLeft( floatvalue);52 virtual void moveUpDown( floatvalue);50 virtual void moveFrontBack(const Vector2& value); 51 virtual void moveRightLeft(const Vector2& value); 52 virtual void moveUpDown(const Vector2& value); 53 53 54 virtual void rotateYaw( floatvalue);55 virtual void rotatePitch( floatvalue);56 virtual void rotateRoll( floatvalue);54 virtual void rotateYaw(const Vector2& value); 55 virtual void rotatePitch(const Vector2& value); 56 virtual void rotateRoll(const Vector2& value); 57 57 58 58 virtual void fire(); … … 62 62 void changedGreeting(); 63 63 void changedFlareVisibility(); 64 void updateHUD(); 64 65 65 66 BillboardSet* greetingFlare_; … … 73 74 float pitch_; 74 75 float roll_; 75 76 // test test test77 Mesh* testmesh_;78 Ogre::SceneNode* testnode_;79 // test test test80 76 }; 81 77 } -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.cc
r2019 r2024 53 53 { 54 54 RegisterObject(OverlayGroup); 55 } 56 57 OverlayGroup::~OverlayGroup() 58 { 59 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 60 delete it->second; 55 61 } 56 62 -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.h
r2019 r2024 56 56 OverlayGroup(BaseObject* creator); 57 57 //! Empty destructor. 58 ~OverlayGroup() { }58 ~OverlayGroup(); 59 59 60 60 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); … … 63 63 static void scaleGroup(const std::string& name, float scale); 64 64 static void scrollGroup(const std::string& name, const Vector2& scroll); 65 66 inline const std::map<std::string, OrxonoxOverlay*>& getOverlays() const 67 { return this->hudElements_; } 65 68 66 69 void changedVisibility(); -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.cc
r2019 r2024 65 65 } 66 66 67 XMLPortParam(OverlayText, "font", setFont, getFont,xmlElement, mode).defaultValues("Monofur");68 XMLPortParam(OverlayText, "colour", setColour, getColour,xmlElement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0));69 XMLPortParam(OverlayText, "caption", setCaption, getCaption,xmlElement, mode).defaultValues("");70 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize,xmlElement, mode).defaultValues(1.0f);71 XMLPortParam Template(OverlayText, "align", setAlignment, getAlignment, xmlElement, mode, const std::string&).defaultValues("left");67 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode).defaultValues("Monofur"); 68 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); 69 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode).defaultValues(""); 70 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f); 71 XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlElement, mode).defaultValues("left"); 72 72 } 73 73 … … 106 106 } 107 107 108 void OverlayText::setAlignment(const std::string& alignment) 108 Ogre::TextAreaOverlayElement::Alignment OverlayText::getAlignment() const 109 { 110 if (this->text_) 111 return this->text_->getAlignment(); 112 else 113 return Ogre::TextAreaOverlayElement::Left; 114 } 115 116 void OverlayText::setAlignmentString(const std::string& alignment) 109 117 { 110 118 if (alignment == "right") … … 116 124 } 117 125 118 std::string OverlayText::getAlignment () const126 std::string OverlayText::getAlignmentString() const 119 127 { 120 128 if (this->text_) -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.h
r2019 r2024 47 47 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 48 48 49 protected:50 virtual void sizeChanged();51 52 49 void setCaption(const std::string& caption); 53 50 const std::string& getCaption() const { return this->caption_; } … … 60 57 61 58 void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment); 62 void setAlignment(const std::string& alignment); 63 std::string getAlignment() const; 59 Ogre::TextAreaOverlayElement::Alignment getAlignment() const; 60 61 protected: 62 virtual void sizeChanged(); 63 64 void setAlignmentString(const std::string& alignment); 65 std::string getAlignmentString() const; 64 66 65 67 void setTextSize(float size) { this->setSize(Vector2(size, size)); }
Note: See TracChangeset
for help on using the changeset viewer.