Changeset 10281 for code/trunk/src/orxonox/gametypes
- Timestamp:
- Feb 24, 2015, 10:54:24 PM (9 years ago)
- Location:
- code/trunk/src/orxonox/gametypes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/gametypes/Gametype.cc
r9984 r10281 45 45 #include "worldentities/pawns/Pawn.h" 46 46 #include "overlays/OverlayGroup.h" 47 #include "Scene.h" 47 48 48 49 namespace orxonox … … 525 526 GSLevel::startMainMenu(); 526 527 } 528 529 GSLevelMementoState* Gametype::exportMementoState() 530 { 531 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 532 { 533 if (it->first->isHumanPlayer() && it->first->getControllableEntity() && it->first->getControllableEntity()->getCamera()) 534 { 535 Camera* camera = it->first->getControllableEntity()->getCamera(); 536 537 GametypeMementoState* state = new GametypeMementoState(); 538 state->cameraPosition_ = camera->getWorldPosition(); 539 state->cameraOrientation_ = camera->getWorldOrientation(); 540 state->sceneName_ = camera->getScene()->getName(); 541 return state; 542 } 543 } 544 545 return NULL; 546 } 547 548 void Gametype::importMementoState(const std::vector<GSLevelMementoState*>& states) 549 { 550 // find correct memento state 551 GametypeMementoState* state = NULL; 552 for (size_t i = 0; i < states.size(); ++i) 553 { 554 state = dynamic_cast<GametypeMementoState*>(states[i]); 555 if (state) 556 break; 557 } 558 559 if (!state) 560 return; 561 562 // find correct scene 563 Scene* scene = NULL; 564 for (ObjectList<Scene>::iterator it = ObjectList<Scene>::begin(); it != ObjectList<Scene>::end(); ++it) 565 { 566 if (it->getName() == state->sceneName_) 567 { 568 scene = *it; 569 break; 570 } 571 } 572 573 if (!scene) 574 { 575 orxout(internal_warning) << "Could not find scene with name " << state->sceneName_ << endl; 576 return; 577 } 578 579 // find correct player and assign default entity with original position & orientation 580 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 581 { 582 if (it->first->isHumanPlayer()) 583 { 584 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(scene->getContext()); 585 entity->setPosition(state->cameraPosition_); 586 entity->setOrientation(state->cameraOrientation_); 587 it->first->startControl(entity); 588 break; 589 } 590 } 591 } 527 592 } -
code/trunk/src/orxonox/gametypes/Gametype.h
r9980 r10281 41 41 #include "infos/GametypeInfo.h" 42 42 #include "tools/Timer.h" 43 #include "gamestates/GSLevelMemento.h" 43 44 44 45 namespace orxonox … … 63 64 }; 64 65 65 class _OrxonoxExport Gametype : public BaseObject, public Tickable 66 class _OrxonoxExport Gametype : public BaseObject, public Tickable, public GSLevelMemento 66 67 { 67 68 friend class PlayerInfo; … … 172 173 virtual void spawnDeadPlayersIfRequested(); 173 174 175 virtual GSLevelMementoState* exportMementoState(); 176 virtual void importMementoState(const std::vector<GSLevelMementoState*>& states); 177 174 178 SmartPtr<GametypeInfo> gtinfo_; 175 179 … … 201 205 Timer showMenuTimer_; 202 206 }; 207 208 /** 209 @brief Keeps position and orientation of the camera, as well as the name of current scene. 210 */ 211 struct _OrxonoxExport GametypeMementoState : public GSLevelMementoState 212 { 213 Vector3 cameraPosition_; 214 Quaternion cameraOrientation_; 215 std::string sceneName_; 216 }; 203 217 } 204 218
Note: See TracChangeset
for help on using the changeset viewer.