Changeset 2019 for code/branches/objecthierarchy/src/orxonox
- Timestamp:
- Oct 27, 2008, 4:08:51 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox
- Files:
-
- 8 added
- 67 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/CMakeLists.txt
r2012 r2019 43 43 tools/WindowEventListener.cc 44 44 45 LevelManager.cc 46 47 objects/Scene.cc 45 48 objects/worldentities/WorldEntity.cc 46 49 objects/worldentities/PositionableEntity.cc … … 63 66 objects/DistanceTrigger.cc 64 67 68 objects/worldentities/SpawnPoint.cc 69 65 70 objects/worldentities/pawns/Spectator.cc 66 71 … … 71 76 objects/infos/Level.cc 72 77 objects/infos/PlayerInfo.cc 78 objects/infos/HumanPlayer.cc 73 79 74 80 objects/gametypes/Gametype.cc -
code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h
r2012 r2019 80 80 class RadarListener; 81 81 82 class LevelManager; 83 82 84 // objects 85 class Scene; 86 83 87 class WorldEntity; 84 88 class PositionableEntity; 85 89 class MovableEntity; 86 90 class ControllableEntity; 91 class Sublevel; 87 92 88 93 class Model; 94 class Billboard; 95 class Light; 96 class DirectionalLight; 97 98 class Camera; 99 class SpawnPoint; 89 100 90 101 class Spectator; 102 class Pawn; 103 class SpaceShip; 91 104 92 105 class Controller; … … 94 107 95 108 class Backlight; 96 class Camera;97 109 class ParticleSpawner; 98 110 … … 100 112 class Level; 101 113 class PlayerInfo; 114 class HumanPlayer; 102 115 103 116 class Gametype; 117 118 class Scores; 104 119 105 120 // tools -
code/branches/objecthierarchy/src/orxonox/objects/Camera.cc
r2006 r2019 32 32 33 33 #include <string> 34 #include <cassert> 34 35 35 36 #include <OgreSceneManager.h> … … 41 42 #include "util/SubString.h" 42 43 #include "util/Math.h" 44 #include "util/String.h" 43 45 #include "util/Debug.h" 44 46 #include "core/CoreIncludes.h" 47 #include "core/ConfigValueIncludes.h" 45 48 #include "GraphicsEngine.h" 49 #include "objects/Scene.h" 46 50 47 51 namespace orxonox 48 52 { 49 CreateUnloadableFactory(Camera);53 CreateFactory(Camera); 50 54 51 Camera::Camera()52 {53 RegisterObject(Camera);55 Camera::Camera(BaseObject* creator) : PositionableEntity(creator) 56 { 57 RegisterObject(Camera); 54 58 55 this->bHasFocus_ = false; 56 this->bDrag_ = false; 57 this->cameraNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(); 58 this->setObjectMode(0x0); 59 } 59 assert(this->getScene()); 60 assert(this->getScene()->getSceneManager()); 60 61 61 Camera::~Camera() 62 { 63 if (this->isInitialized()) 62 this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); 63 this->getNode()->attachObject(this->camera_); 64 65 this->bHasFocus_ = false; 66 this->bDrag_ = false; 67 this->nearClipDistance_ = 1; 68 69 this->setObjectMode(0x0); 70 71 this->setConfigValues(); 72 this->configvaluecallback_changedNearClipDistance(); 73 74 this->requestFocus(); // ! HACK ! REMOVE THIS ! 75 } 76 77 Camera::~Camera() 64 78 { 65 CameraHandler::getInstance()->releaseFocus(this); 66 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(this->cameraNode_->getName()); 79 if (this->isInitialized()) 80 { 81 this->releaseFocus(); 82 } 67 83 } 68 }69 84 70 void Camera::tick(float dt)71 {72 // this stuff here may need some adjustments73 float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f);85 void Camera::setConfigValues() 86 { 87 SetConfigValue(nearClipDistance_, 1.0f).callback(this, &Camera::configvaluecallback_changedNearClipDistance); 88 } 74 89 75 Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); 76 this->cameraNode_->translate(coeff * offset); 90 void Camera::configvaluecallback_changedNearClipDistance() 91 { 92 this->camera_->setNearClipDistance(this->nearClipDistance_); 93 } 77 94 78 this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); 79 } 95 void Camera::tick(float dt) 96 { 97 /* 98 // this stuff here may need some adjustments 99 float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); 80 100 81 /** 82 don't move anything before here! here the Ogre camera is set to values of this camera 83 always call update after changes 84 */ 85 void Camera::update() 86 { 87 this->cameraNode_->setPosition(this->getWorldPosition()); 88 this->cameraNode_->setOrientation(this->getWorldOrientation()); 89 } 101 Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); 102 this->cameraNode_->translate(coeff * offset); 90 103 91 /** 92 what to do when camera loses focus (do not request focus in this function!!) 93 this is called by the CameraHandler singleton class to notify the camera 94 */ 95 void Camera::removeFocus() 96 { 97 this->bHasFocus_ = false; 98 this->cameraNode_->detachObject(this->cam_); 99 } 104 this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); 105 */ 106 } 100 107 101 void Camera::setFocus(Ogre::Camera* ogreCam) 102 { 103 this->bHasFocus_ = true; 104 this->cam_ = ogreCam; 105 this->cam_->setOrientation(this->cameraNode_->getWorldOrientation()); 106 this->cameraNode_->attachObject(this->cam_); 107 } 108 void Camera::requestFocus() 109 { 110 CameraHandler::getInstance().requestFocus(this); 111 } 108 112 109 void Camera::requestFocus() 110 { 111 CameraHandler::getInstance()->requestFocus(this); 112 } 113 void Camera::releaseFocus() 114 { 115 CameraHandler::getInstance().releaseFocus(this); 116 } 117 118 /** 119 what to do when camera loses focus (do not request focus in this function!!) 120 this is called by the CameraHandler singleton class to notify the camera 121 */ 122 void Camera::removeFocus() 123 { 124 this->bHasFocus_ = false; 125 } 126 127 void Camera::setFocus(Ogre::Viewport* viewport) 128 { 129 this->bHasFocus_ = true; 130 viewport->setCamera(this->camera_); 131 } 113 132 } -
code/branches/objecthierarchy/src/orxonox/objects/Camera.h
r2006 r2019 42 42 class _OrxonoxExport Camera : public PositionableEntity, public Tickable 43 43 { 44 friend class CameraHandler;44 friend class CameraHandler; 45 45 46 public:47 Camera();48 virtual ~Camera();46 public: 47 Camera(BaseObject* creator); 48 virtual ~Camera(); 49 49 50 virtual void tick(float dt);51 void update();50 void setConfigValues(); 51 virtual void tick(float dt); 52 52 53 void requestFocus(); 54 inline bool hasFocus() 55 { return this->bHasFocus_; } 53 void requestFocus(); 54 void releaseFocus(); 56 55 57 inline void setDrag(bool bDrag) 58 { this->bDrag_ = bDrag; } 59 inline bool getDrag() const 60 { return this->bDrag_; } 56 inline bool hasFocus() 57 { return this->bHasFocus_; } 61 58 62 private: 63 void removeFocus(); 64 void setFocus(Ogre::Camera* ogreCam); 59 inline void setDrag(bool bDrag) 60 { this->bDrag_ = bDrag; } 61 inline bool getDrag() const 62 { return this->bDrag_; } 65 63 66 Ogre::Camera* cam_; 67 Ogre::SceneNode* cameraNode_; 68 Ogre::Vector3 oldPos; 69 bool bHasFocus_; 70 bool bDrag_; 64 private: 65 void removeFocus(); 66 void setFocus(Ogre::Viewport* viewport); 67 void configvaluecallback_changedNearClipDistance(); 68 69 Ogre::Camera* camera_; 70 float nearClipDistance_; 71 bool bHasFocus_; 72 bool bDrag_; 71 73 }; 72 74 } -
code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.cc
r2006 r2019 33 33 34 34 #include "core/ObjectList.h" 35 #include "core/Core.h" 35 36 #include "Camera.h" 36 37 #include "GraphicsEngine.h" … … 38 39 #include <OgreCamera.h> 39 40 40 namespace orxonox { 41 namespace orxonox 42 { 43 CameraHandler::CameraHandler() 44 { 45 // GraphicsEngine::getInstance().getViewport()->setCamera(this->cam_); 46 } 41 47 42 CameraHandler* CameraHandler::singletonRef = NULL; 48 CameraHandler& CameraHandler::getInstance() 49 { 50 static CameraHandler instance; 51 return instance; 52 } 43 53 44 CameraHandler::CameraHandler() 45 { 46 this->cam_ = GraphicsEngine::getInstance().getLevelSceneManager()->createCamera("Cam"); 47 GraphicsEngine::getInstance().getViewport()->setCamera(this->cam_); 48 this->cam_->setNearClipDistance(1); 49 //GraphicsEngine::getInstance().getRenderWindow()->addViewport(this->cam_, 2, 0.4, 0.4, 0.2, 0.2); 50 /*this->activeCamera_ = *ObjectList<Camera>::begin(); 51 this->activeCamera_->cam_ = this->cam_;*/ 52 } 54 Camera* CameraHandler::getActiveCamera() const 55 { 56 if (this->cameraList_.size() > 0) 57 return this->cameraList_.front(); 58 else 59 return 0; 60 } 53 61 54 void CameraHandler::requestFocus(Camera* requestCam) 55 { 56 // notify old camera (if it exists) 57 if(focusList_.size() > 0) 58 focusList_.back()->removeFocus(); 59 // add to list 60 focusList_.push_back(requestCam); 61 // set focus to new camera and update (if necessary) 62 if(!requestCam->hasFocus()) { 63 requestCam->setFocus(this->cam_); 64 requestCam->update(); 62 void CameraHandler::requestFocus(Camera* camera) 63 { 64 if (!Core::showsGraphics()) 65 return; 66 67 // notify old camera (if it exists) 68 if (this->cameraList_.size() > 0) 69 this->cameraList_.front()->removeFocus(); 70 71 // add to list 72 this->cameraList_.push_front(camera); 73 camera->setFocus(GraphicsEngine::getInstance().getViewport()); 65 74 } 66 // delete dublicates67 focusList_.unique();68 }69 75 70 void CameraHandler::releaseFocus(Camera* cam) 71 { 72 // notify the cam of releasing the focus 73 if(cam->hasFocus()) 74 cam->removeFocus(); 75 // delete camera from list 76 focusList_.remove(cam); 77 // set new focus if necessary 78 if(focusList_.size() > 0 && !(focusList_.back()->hasFocus())) 79 focusList_.back()->setFocus(this->cam_); 80 } 81 /* 82 void CameraHandler::changeActiveCamera(Camera* setCam) 83 { 84 cam_->getParentSceneNode()->detachObject(cam_); 85 //setCam->attachCamera(cam_); 86 activeCamera_ = setCam; 87 } 88 */ 89 /* bool isInVector(Camera* cam) 90 { 91 for(std::vector<Camera*>::iterator it = cams_.begin(); it != cams_.end(); it++) 76 void CameraHandler::releaseFocus(Camera* camera) 92 77 { 93 if (*it == cam) return true; 78 if (!Core::showsGraphics()) 79 return; 80 81 // notify the cam of releasing the focus 82 if (this->cameraList_.front() == camera) 83 { 84 camera->removeFocus(); 85 this->cameraList_.pop_front(); 86 87 // set new focus if necessary 88 if (cameraList_.size() > 0) 89 cameraList_.front()->setFocus(GraphicsEngine::getInstance().getViewport()); 90 } 91 else 92 { 93 this->cameraList_.remove(camera); 94 } 94 95 } 95 return false;96 }*/97 96 } -
code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.h
r1993 r2019 36 36 #define _Camera_Handler_H__ 37 37 38 #include "OrxonoxPrereqs.h" 39 38 40 #include <list> 39 40 41 #include <OgreCamera.h> 41 42 #include "OrxonoxPrereqs.h"43 42 44 43 #include "core/BaseObject.h" … … 46 45 namespace orxonox 47 46 { 48 class _OrxonoxExport CameraHandler 49 { 47 class _OrxonoxExport CameraHandler 48 { 49 public: 50 static CameraHandler& getInstance(); 50 51 51 public: 52 inline static CameraHandler* getInstance() { if (!CameraHandler::singletonRef) CameraHandler::singletonRef = new CameraHandler(); return CameraHandler::singletonRef; } 53 inline ~CameraHandler() { CameraHandler::singletonRef = NULL; } 54 inline Camera* getActiveCamera() { return this->focusList_.back(); } 55 /*void registerCamera(Camera* newCam); 56 void changeActiveCamera(Camera* setCam);*/ 57 void requestFocus(Camera* requestCam); 58 void releaseFocus(Camera* cam); 52 Camera* getActiveCamera() const; 59 53 60 private: 61 CameraHandler(); 62 //bool isInVector(Camera* cam); 54 void requestFocus(Camera* camera); 55 void releaseFocus(Camera* camera); 63 56 64 private: 65 static CameraHandler* singletonRef; 66 Ogre::Camera* cam_; 67 std::list<Camera*> focusList_; 68 //std::vector<Camera*> cams_; 57 private: 58 CameraHandler(); 59 ~CameraHandler() {} 69 60 70 }; 61 std::list<Camera*> cameraList_; 62 }; 71 63 } 72 64 -
code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.cc
r1969 r2019 37 37 CreateFactory(DistanceTrigger); 38 38 39 DistanceTrigger::DistanceTrigger( )39 DistanceTrigger::DistanceTrigger(BaseObject* creator) : Trigger(creator) 40 40 { 41 41 RegisterObject(DistanceTrigger); -
code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.h
r1969 r2019 44 44 { 45 45 public: 46 DistanceTrigger( );46 DistanceTrigger(BaseObject* creator); 47 47 ~DistanceTrigger(); 48 48 void addTarget(Ogre::Node* targetNode); -
code/branches/objecthierarchy/src/orxonox/objects/ParticleSpawner.cc
r1755 r2019 80 80 this->setPosition(this->getNode()->getParent()->getPosition()); 81 81 this->getNode()->getParent()->removeChild(this->getNode()); 82 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(this->getNode());82 this->detachFromParent(); 83 83 if (this->particle_) 84 84 this->particle_->setEnabled(false); -
code/branches/objecthierarchy/src/orxonox/objects/Script.cc
r1961 r2019 39 39 CreateFactory(Script); 40 40 41 Script::Script( )41 Script::Script(BaseObject* creator) : BaseObject(creator) 42 42 { 43 43 RegisterObject(Script); -
code/branches/objecthierarchy/src/orxonox/objects/Script.h
r1959 r2019 39 39 { 40 40 public: 41 Script( );41 Script(BaseObject* creator); 42 42 ~Script(); 43 43 void XMLPort(Element& xmlelement, XMLPort::Mode mode); -
code/branches/objecthierarchy/src/orxonox/objects/Test.cc
r1990 r2019 36 36 CreateFactory ( Test ); 37 37 38 Test::Test( )38 Test::Test(BaseObject* creator) : BaseObject(creator) 39 39 { 40 40 RegisterObject ( Test ); -
code/branches/objecthierarchy/src/orxonox/objects/Test.h
r1990 r2019 39 39 { 40 40 public: 41 Test( );41 Test(BaseObject* creator); 42 42 virtual ~Test(); 43 43 44 44 void setConfigValues(); 45 45 void registerVariables(); 46 46 47 47 void setV1(unsigned int value){ v1 = value; } 48 48 void setV2(unsigned int value){ v2 = value; } 49 49 void setV3(unsigned int value){ v3 = value; } 50 50 51 51 void checkV1(); 52 52 void checkV2(); -
code/branches/objecthierarchy/src/orxonox/objects/Trigger.cc
r1969 r2019 35 35 #include "core/ConsoleCommand.h" 36 36 #include "core/XMLPort.h" 37 #include "objects/Scene.h" 37 38 38 39 namespace orxonox … … 43 44 CreateFactory(Trigger); 44 45 45 Trigger::Trigger( )46 Trigger::Trigger(BaseObject* creator) : PositionableEntity(creator) 46 47 { 47 48 RegisterObject(Trigger); … … 57 58 latestState_ = 0x0; 58 59 59 debugBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); 60 debugBillboard_.setVisible(false); 60 if (this->getScene() && this->getScene()->getSceneManager()) 61 { 62 debugBillboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); 63 debugBillboard_.setVisible(false); 64 } 61 65 62 66 this->getNode()->attachObject(debugBillboard_.getBillboardSet()); -
code/branches/objecthierarchy/src/orxonox/objects/Trigger.h
r2013 r2019 50 50 { 51 51 public: 52 Trigger( );52 Trigger(BaseObject* creator); 53 53 ~Trigger(); 54 54 -
code/branches/objecthierarchy/src/orxonox/objects/controllers/Controller.cc
r1993 r2019 36 36 CreateUnloadableFactory(Controller); 37 37 38 Controller::Controller( )38 Controller::Controller(BaseObject* creator) : BaseObject(creator) 39 39 { 40 40 RegisterObject(Controller); 41 41 42 42 this->player_ = 0; 43 this-> pawn_ = 0;43 this->controllableEntity_ = 0; 44 44 } 45 45 -
code/branches/objecthierarchy/src/orxonox/objects/controllers/Controller.h
r1993 r2019 39 39 { 40 40 public: 41 Controller( );41 Controller(BaseObject* creator); 42 42 virtual ~Controller(); 43 43 … … 47 47 { return this->player_; } 48 48 49 inline void setPawn(ControllableEntity* pawn)50 { this-> pawn_ = pawn; }51 inline ControllableEntity* getPawn() const52 { return this-> pawn_; }49 virtual inline void setControllableEntity(ControllableEntity* entity) 50 { this->controllableEntity_ = entity; } 51 virtual inline ControllableEntity* getControllableEntity() const 52 { return this->controllableEntity_; } 53 53 54 54 protected: 55 55 PlayerInfo* player_; 56 ControllableEntity* pawn_;56 ControllableEntity* controllableEntity_; 57 57 }; 58 58 } -
code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.cc
r2001 r2019 52 52 HumanController* HumanController::localController_s = 0; 53 53 54 HumanController::HumanController( )54 HumanController::HumanController(BaseObject* creator) : Controller(creator) 55 55 { 56 56 RegisterObject(HumanController); … … 66 66 void HumanController::moveFrontBack(const Vector2& value) 67 67 { 68 if (HumanController::localController_s && HumanController::localController_s-> pawn_)69 HumanController::localController_s-> pawn_->moveFrontBack(value.y);68 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 69 HumanController::localController_s->controllableEntity_->moveFrontBack(value.y); 70 70 } 71 71 72 72 void HumanController::moveRightLeft(const Vector2& value) 73 73 { 74 if (HumanController::localController_s && HumanController::localController_s-> pawn_)75 HumanController::localController_s-> pawn_->moveRightLeft(value.y);74 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 75 HumanController::localController_s->controllableEntity_->moveRightLeft(value.y); 76 76 } 77 77 78 78 void HumanController::moveUpDown(const Vector2& value) 79 79 { 80 if (HumanController::localController_s && HumanController::localController_s-> pawn_)81 HumanController::localController_s-> pawn_->moveUpDown(value.y);80 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 81 HumanController::localController_s->controllableEntity_->moveUpDown(value.y); 82 82 } 83 83 84 84 void HumanController::rotateYaw(const Vector2& value) 85 85 { 86 if (HumanController::localController_s && HumanController::localController_s-> pawn_)87 HumanController::localController_s-> pawn_->rotateYaw(value.y);86 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 87 HumanController::localController_s->controllableEntity_->rotateYaw(value.y); 88 88 } 89 89 90 90 void HumanController::rotatePitch(const Vector2& value) 91 91 { 92 if (HumanController::localController_s && HumanController::localController_s-> pawn_)93 HumanController::localController_s-> pawn_->rotatePitch(value.y);92 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 93 HumanController::localController_s->controllableEntity_->rotatePitch(value.y); 94 94 } 95 95 96 96 void HumanController::rotateRoll(const Vector2& value) 97 97 { 98 if (HumanController::localController_s && HumanController::localController_s-> pawn_)99 HumanController::localController_s-> pawn_->rotateRoll(value.y);98 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 99 HumanController::localController_s->controllableEntity_->rotateRoll(value.y); 100 100 } 101 101 102 102 void HumanController::fire() 103 103 { 104 if (HumanController::localController_s && HumanController::localController_s-> pawn_)105 HumanController::localController_s-> pawn_->fire();104 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 105 HumanController::localController_s->controllableEntity_->fire(); 106 106 } 107 107 108 108 void HumanController::altFire() 109 109 { 110 if (HumanController::localController_s && HumanController::localController_s-> pawn_)111 HumanController::localController_s-> pawn_->altFire();110 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 111 HumanController::localController_s->controllableEntity_->altFire(); 112 112 } 113 113 114 114 void HumanController::greet() 115 115 { 116 if (HumanController::localController_s && HumanController::localController_s-> pawn_)117 HumanController::localController_s-> pawn_->greet();116 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 117 HumanController::localController_s->controllableEntity_->greet(); 118 118 } 119 119 120 120 void HumanController::use() 121 121 { 122 if (HumanController::localController_s && HumanController::localController_s-> pawn_)123 HumanController::localController_s-> pawn_->use();122 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 123 HumanController::localController_s->controllableEntity_->use(); 124 124 } 125 125 126 126 void HumanController::switchCamera() 127 127 { 128 if (HumanController::localController_s && HumanController::localController_s-> pawn_)129 HumanController::localController_s-> pawn_->switchCamera();128 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 129 HumanController::localController_s->controllableEntity_->switchCamera(); 130 130 } 131 131 } -
code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.h
r2001 r2019 40 40 { 41 41 public: 42 HumanController( );42 HumanController(BaseObject* creator); 43 43 virtual ~HumanController(); 44 44 -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r2006 r2019 30 30 #include "Gametype.h" 31 31 32 #include <cstdlib> 33 #include <ctime> 34 32 35 #include "core/CoreIncludes.h" 33 36 #include "objects/infos/PlayerInfo.h" 34 37 #include "objects/worldentities/pawns/Spectator.h" 38 #include "objects/worldentities/SpawnPoint.h" 35 39 36 40 #include "network/Host.h" … … 40 44 CreateUnloadableFactory(Gametype); 41 45 42 Gametype::Gametype( )46 Gametype::Gametype(BaseObject* creator) : BaseObject(creator) 43 47 { 44 48 RegisterObject(Gametype); 45 49 46 50 this->defaultPawn_ = Class(Spectator); 51 this->bStarted_ = false; 52 this->bEnded_ = false; 53 this->bAutoStart_ = false; 47 54 48 55 COUT(0) << "created Gametype" << std::endl; 49 56 } 50 57 51 void Gametype::addPlayer(PlayerInfo* player) 58 void Gametype::tick(float dt) 59 { 60 if (!this->bStarted_) 61 this->checkStart(); 62 63 this->assignDefaultPawnsIfNeeded(); 64 } 65 66 void Gametype::start() 67 { 68 COUT(0) << "game started" << std::endl; 69 this->bStarted_ = true; 70 71 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 72 this->spawnPlayer(*it); 73 } 74 75 void Gametype::end() 76 { 77 COUT(0) << "game ended" << std::endl; 78 this->bEnded_ = true; 79 } 80 81 void Gametype::playerEntered(PlayerInfo* player) 52 82 { 53 83 this->players_.insert(player); 54 this->playerJoined(player); 55 56 ControllableEntity* newpawn = this->defaultPawn_.fabricate(); 57 player->startControl(newpawn); 58 } 59 60 void Gametype::removePlayer(PlayerInfo* player) 61 { 62 if (this->players_.find(player) != this->players_.end()) 63 { 64 player->stopControl(); 65 this->players_.erase(player); 66 this->playerLeft(player); 67 } 68 } 69 70 void Gametype::playerJoined(PlayerInfo* player) 71 { 84 72 85 std::string message = player->getName() + " entered the game"; 73 86 COUT(0) << message << std::endl; … … 77 90 void Gametype::playerLeft(PlayerInfo* player) 78 91 { 79 std::string message = player->getName() + " left the game"; 80 COUT(0) << message << std::endl; 81 network::Host::Broadcast(message); 92 std::set<PlayerInfo*>::iterator it = this->players_.find(player); 93 if (it != this->players_.end()) 94 { 95 this->players_.erase(it); 96 97 std::string message = player->getName() + " left the game"; 98 COUT(0) << message << std::endl; 99 network::Host::Broadcast(message); 100 } 101 } 102 103 void Gametype::playerSwitched(PlayerInfo* player, Gametype* newgametype) 104 { 105 } 106 107 void Gametype::playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype) 108 { 82 109 } 83 110 … … 94 121 } 95 122 } 123 124 void Gametype::playerSpawned(PlayerInfo* player) 125 { 126 } 127 128 void Gametype::playerDied(PlayerInfo* player) 129 { 130 } 131 132 void Gametype::playerScored(PlayerInfo* player) 133 { 134 } 135 136 SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const 137 { 138 if (this->spawnpoints_.size() > 0) 139 { 140 srand(time(0)); 141 rnd(); 142 143 unsigned int randomspawn = (unsigned int)rnd(this->spawnpoints_.size()); 144 unsigned int index = 0; 145 for (std::set<SpawnPoint*>::iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it) 146 { 147 if (index == randomspawn) 148 return (*it); 149 150 ++index; 151 } 152 } 153 return 0; 154 } 155 156 void Gametype::assignDefaultPawnsIfNeeded() const 157 { 158 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 159 { 160 if (!(*it)->getControllableEntity() && (!(*it)->isReadyToSpawn() || !this->bStarted_)) 161 { 162 SpawnPoint* spawn = this->getBestSpawnPoint(*it); 163 if (spawn) 164 { 165 // force spawn at spawnpoint with default pawn 166 ControllableEntity* newpawn = this->defaultPawn_.fabricate(spawn); 167 spawn->spawn(newpawn); 168 (*it)->startControl(newpawn); 169 } 170 else 171 { 172 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 173 abort(); 174 } 175 } 176 } 177 } 178 179 void Gametype::checkStart() 180 { 181 if (!this->bStarted_) 182 { 183 if (this->players_.size() > 0) 184 { 185 if (this->bAutoStart_) 186 { 187 this->start(); 188 } 189 else 190 { 191 bool allplayersready = true; 192 for (std::set<PlayerInfo*>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 193 { 194 if (!(*it)->isReadyToSpawn()) 195 allplayersready = false; 196 } 197 if (allplayersready) 198 this->start(); 199 } 200 } 201 } 202 } 203 204 void Gametype::spawnPlayer(PlayerInfo* player) 205 { 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 } 218 } 219 } 96 220 } -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r2006 r2019 37 37 #include "core/Identifier.h" 38 38 #include "objects/worldentities/ControllableEntity.h" 39 #include "objects/Tickable.h" 39 40 40 41 namespace orxonox 41 42 { 42 class _OrxonoxExport Gametype : public BaseObject 43 class _OrxonoxExport Gametype : public BaseObject, public Tickable 43 44 { 44 45 friend class PlayerInfo; 45 46 46 47 public: 47 Gametype( );48 Gametype(BaseObject* creator); 48 49 virtual ~Gametype() {} 50 51 virtual void tick(float dt); 52 53 virtual void start(); 54 virtual void end(); 55 virtual void playerEntered(PlayerInfo* player); 56 virtual void playerLeft(PlayerInfo* player); 57 virtual void playerSwitched(PlayerInfo* player, Gametype* newgametype); 58 virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype); 59 virtual void playerChangedName(PlayerInfo* player); 60 virtual void playerSpawned(PlayerInfo* player); 61 virtual void playerDied(PlayerInfo* player); 62 virtual void playerScored(PlayerInfo* player); 49 63 50 64 inline const std::set<PlayerInfo*>& getPlayers() const 51 65 { return this->players_; } 52 66 53 protected: 54 virtual void playerJoined(PlayerInfo* player); 55 virtual void playerLeft(PlayerInfo* player); 56 57 virtual void playerChangedName(PlayerInfo* player); 67 inline void registerSpawnPoint(SpawnPoint* spawnpoint) 68 { this->spawnpoints_.insert(spawnpoint); } 58 69 59 70 private: 71 virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const; 72 60 73 void addPlayer(PlayerInfo* player); 61 74 void removePlayer(PlayerInfo* player); 62 75 76 void assignDefaultPawnsIfNeeded() const; 77 void checkStart(); 78 void spawnPlayer(PlayerInfo* player); 79 80 bool bStarted_; 81 bool bEnded_; 82 bool bAutoStart_; 63 83 std::set<PlayerInfo*> players_; 84 std::set<SpawnPoint*> spawnpoints_; 64 85 SubclassIdentifier<ControllableEntity> defaultPawn_; 65 86 }; -
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 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc
r2006 r2019 43 43 CreateFactory(ControllableEntity); 44 44 45 ControllableEntity::ControllableEntity( )45 ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator) 46 46 { 47 47 RegisterObject(ControllableEntity); … … 71 71 ControllableEntity::~ControllableEntity() 72 72 { 73 if (this->isInitialized() && this->bControlled_) 74 this->stopLocalControl(); 73 if (this->isInitialized()) 74 { 75 if (this->bControlled_) 76 this->stopLocalControl(); 77 78 if (this->hud_) 79 delete this->hud_; 80 81 if (this->camera_) 82 delete this->camera_; 83 } 75 84 } 76 85 … … 92 101 this->player_ = player; 93 102 this->playerID_ = player->getObjectID(); 94 this->bControlled_ = player->isLocalPlayer();103 this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer()); 95 104 96 105 if (this->bControlled_) 97 106 { 98 107 this->startLocalControl(); 99 this->setObjectMode(network::direction::bidirectional); 108 109 if (!Core::isMaster()) 110 this->setObjectMode(network::direction::bidirectional); 100 111 } 101 112 } … … 115 126 } 116 127 117 void ControllableEntity::updatePlayer() 118 { 128 void ControllableEntity::networkcallback_changedplayerID() 129 { 130 // just do this in case the entity wasn't yet synchronized when the corresponding PlayerInfo got our objectID 119 131 if (this->playerID_ != network::OBJECTID_UNKNOWN) 120 132 { 121 133 this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_)); 122 if (this->player_ && (this->player_->get Pawn() != this))134 if (this->player_ && (this->player_->getControllableEntity() != this)) 123 135 this->player_->startControl(this); 124 136 } … … 128 140 { 129 141 std::cout << this->getObjectID() << " ###### start local control" << std::endl; 130 this->camera_ = new Camera( );142 this->camera_ = new Camera(this); 131 143 this->camera_->requestFocus(); 132 144 this->attach(this->camera_); … … 134 146 if (this->hudtemplate_ != "") 135 147 { 136 this->hud_ = new OverlayGroup( );148 this->hud_ = new OverlayGroup(this); 137 149 this->hud_->addTemplate(this->hudtemplate_); 138 150 } … … 184 196 REGISTERDATA(this->client_overwrite_, network::direction::toserver); 185 197 186 REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity:: updatePlayer));198 REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); 187 199 } 188 200 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h
r2006 r2019 40 40 { 41 41 public: 42 ControllableEntity( );42 ControllableEntity(BaseObject* creator); 43 43 virtual ~ControllableEntity(); 44 44 … … 56 56 inline bool getDestroyWhenPlayerLeft() const 57 57 { return this->bDestroyWhenPlayerLeft_; } 58 59 virtual void startLocalControl();60 virtual void stopLocalControl();61 58 62 59 virtual void moveFrontBack(float value) {} … … 82 79 { return this->hudtemplate_; } 83 80 84 protected:85 81 using WorldEntity::setPosition; 86 82 using WorldEntity::translate; … … 112 108 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; } 113 109 110 protected: 111 virtual void startLocalControl(); 112 virtual void stopLocalControl(); 113 114 114 inline void setHudTemplate(const std::string& name) 115 115 { this->hudtemplate_ = name; } … … 130 130 void processClientOrientation(); 131 131 132 void updatePlayer();132 void networkcallback_changedplayerID(); 133 133 134 134 unsigned int server_overwrite_; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.cc
r2006 r2019 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "objects/Scene.h" 34 35 35 36 namespace orxonox … … 37 38 CreateFactory(Model); 38 39 39 Model::Model( )40 Model::Model(BaseObject* creator) : PositionableEntity(creator) 40 41 { 41 42 RegisterObject(Model); … … 69 70 this->getNode()->detachObject(this->mesh_.getEntity()); 70 71 71 this->mesh_.setMeshSource(this-> meshSrc_);72 this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_); 72 73 73 74 if (this->mesh_.getEntity()) -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.h
r2006 r2019 39 39 { 40 40 public: 41 Model( );41 Model(BaseObject* creator); 42 42 virtual ~Model(); 43 43 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.cc
r1994 r2019 41 41 CreateFactory(MovableEntity); 42 42 43 MovableEntity::MovableEntity( )43 MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator) 44 44 { 45 45 RegisterObject(MovableEntity); -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.h
r1993 r2019 41 41 { 42 42 public: 43 MovableEntity( );43 MovableEntity(BaseObject* creator); 44 44 virtual ~MovableEntity(); 45 45 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.cc
r2006 r2019 35 35 CreateFactory(PositionableEntity); 36 36 37 PositionableEntity::PositionableEntity( )37 PositionableEntity::PositionableEntity(BaseObject* creator) : WorldEntity(creator) 38 38 { 39 39 RegisterObject(PositionableEntity); -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h
r2006 r2019 38 38 { 39 39 public: 40 PositionableEntity( );40 PositionableEntity(BaseObject* creator); 41 41 virtual ~PositionableEntity(); 42 42 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc
r2006 r2019 30 30 #include "WorldEntity.h" 31 31 32 #include <cassert> 32 33 #include <OgreSceneManager.h> 33 34 … … 37 38 38 39 #include "GraphicsEngine.h" 40 #include "objects/Scene.h" 39 41 40 42 namespace orxonox … … 47 49 const Vector3 WorldEntity::UP = Vector3::UNIT_Y; 48 50 49 WorldEntity::WorldEntity( )51 WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator) 50 52 { 51 53 RegisterObject(WorldEntity); 52 54 53 this->node_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(); 55 assert(this->getScene()); 56 assert(this->getScene()->getRootSceneNode()); 57 58 this->node_ = this->getScene()->getRootSceneNode()->createChildSceneNode(); 59 54 60 this->parent_ = 0; 55 61 this->parentID_ = (unsigned int)-1; … … 66 72 { 67 73 this->node_->detachAllObjects(); 68 GraphicsEngine::getInstance().getLevelSceneManager()->destroySceneNode(this->node_->getName()); 74 if (this->getScene()->getSceneManager()) 75 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 69 76 } 70 77 } 71 72 78 73 79 void WorldEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 131 137 object->parentID_ = (unsigned int)-1; 132 138 133 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(object->node_);139 this->getScene()->getRootSceneNode()->addChild(object->node_); 134 140 } 135 141 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h
r1989 r2019 45 45 { 46 46 public: 47 WorldEntity( );47 WorldEntity(BaseObject* creator); 48 48 virtual ~WorldEntity(); 49 49 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2006 r2019 33 33 #include "core/Core.h" 34 34 #include "objects/worldentities/Model.h" 35 #include "objects/Scene.h" 36 #include "objects/infos/PlayerInfo.h" 35 37 #include "tools/BillboardSet.h" 36 38 … … 39 41 CreateFactory(Spectator); 40 42 41 Spectator::Spectator( )43 Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator) 42 44 { 43 45 RegisterObject(Spectator); … … 54 56 55 57 // test test test 58 if (this->getScene()->getSceneManager()) 56 59 { 57 60 this->testmesh_ = new Mesh(); 58 61 this->testnode_ = this->getNode()->createChildSceneNode(); 59 this->testmesh_->setMeshSource( "assff.mesh");62 this->testmesh_->setMeshSource(this->getScene()->getSceneManager(), "assff.mesh"); 60 63 if (this->testmesh_->getEntity()) 61 64 this->testnode_->attachObject(this->testmesh_->getEntity()); … … 64 67 this->testnode_->scale(10, 10, 10); 65 68 } 69 else 70 { 71 this->testmesh_ = 0; 72 this->testnode_ = 0; 73 } 66 74 // test test test 67 75 68 76 this->greetingFlare_ = new BillboardSet(); 69 this->greetingFlare_->setBillboardSet( "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);77 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 70 78 this->getNode()->attachObject(this->greetingFlare_->getBillboardSet()); 71 79 this->greetingFlare_->setVisible(false); … … 80 88 if (this->isInitialized()) 81 89 { 82 delete this->greetingFlare_; 90 if (this->greetingFlare_) 91 { 92 this->getNode()->detachObject(this->greetingFlare_->getBillboardSet()); 93 delete this->greetingFlare_; 94 } 83 95 84 96 // test test test 85 97 { 86 delete this->testmesh_; 87 delete this->testnode_; 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()); 88 106 } 89 107 // test test test … … 177 195 void Spectator::fire() 178 196 { 197 if (this->getPlayer()) 198 this->getPlayer()->setReadyToSpawn(true); 179 199 } 180 200 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.h
r2006 r2019 39 39 { 40 40 public: 41 Spectator( );41 Spectator(BaseObject* creator); 42 42 virtual ~Spectator(); 43 43 -
code/branches/objecthierarchy/src/orxonox/overlays/OrxonoxOverlay.cc
r1755 r2019 55 55 SetConsoleCommand(OrxonoxOverlay, rotateOverlay, false).accessLevel(AccessLevel::User); 56 56 57 OrxonoxOverlay::OrxonoxOverlay() 58 : overlay_(0) 57 OrxonoxOverlay::OrxonoxOverlay(BaseObject* creator) 58 : BaseObject(creator) 59 , overlay_(0) 59 60 , background_(0) 60 61 { … … 148 149 return this->background_->getMaterialName(); 149 150 else 150 return blankString;151 return BLANKSTRING; 151 152 } 152 153 -
code/branches/objecthierarchy/src/orxonox/overlays/OrxonoxOverlay.h
r1747 r2019 84 84 85 85 public: 86 OrxonoxOverlay( );86 OrxonoxOverlay(BaseObject* creator); 87 87 virtual ~OrxonoxOverlay(); 88 88 -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.cc
r1993 r2019 50 50 SetConsoleCommand(OverlayGroup, scrollGroup, false).accessLevel(AccessLevel::User); 51 51 52 OverlayGroup::OverlayGroup( )52 OverlayGroup::OverlayGroup(BaseObject* creator) : BaseObject(creator) 53 53 { 54 54 RegisterObject(OverlayGroup); -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.h
r1747 r2019 54 54 { 55 55 public: 56 OverlayGroup( );56 OverlayGroup(BaseObject* creator); 57 57 //! Empty destructor. 58 58 ~OverlayGroup() { } -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.cc
r1993 r2019 41 41 CreateFactory(OverlayText); 42 42 43 OverlayText::OverlayText() 44 : text_(0) 43 OverlayText::OverlayText(BaseObject* creator) : OrxonoxOverlay(creator), text_(0) 45 44 { 46 45 RegisterObject(OverlayText); … … 60 59 { 61 60 this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 62 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr ()));61 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString())); 63 62 this->text_->setCharHeight(1.0); 64 63 … … 84 83 return this->text_->getFontName(); 85 84 else 86 return blankString;85 return BLANKSTRING; 87 86 } 88 87 -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.h
r1993 r2019 42 42 { 43 43 public: 44 OverlayText( );44 OverlayText(BaseObject* creator); 45 45 virtual ~OverlayText(); 46 46 -
code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugFPSText.cc
r1755 r2019 38 38 CreateFactory(DebugFPSText); 39 39 40 DebugFPSText::DebugFPSText( )40 DebugFPSText::DebugFPSText(BaseObject* creator) : OverlayText(creator) 41 41 { 42 42 RegisterObject(DebugFPSText); -
code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugFPSText.h
r1747 r2019 40 40 { 41 41 public: 42 DebugFPSText( );42 DebugFPSText(BaseObject* creator); 43 43 ~DebugFPSText(); 44 44 -
code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugRTRText.cc
r1755 r2019 38 38 CreateFactory(DebugRTRText); 39 39 40 DebugRTRText::DebugRTRText( )40 DebugRTRText::DebugRTRText(BaseObject* creator) : OverlayText(creator) 41 41 { 42 42 RegisterObject(DebugRTRText); -
code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugRTRText.h
r1747 r2019 40 40 { 41 41 public: 42 DebugRTRText( );42 DebugRTRText(BaseObject* creator); 43 43 ~DebugRTRText(); 44 44 -
code/branches/objecthierarchy/src/orxonox/overlays/hud/ChatOverlay.cc
r2012 r2019 39 39 40 40 #include "GraphicsEngine.h" 41 #include " objects/infos/Level.h"41 #include "LevelManager.h" 42 42 #include "objects/infos/PlayerInfo.h" 43 43 #include "overlays/console/InGameConsole.h" … … 50 50 CreateFactory(ChatOverlay); 51 51 52 ChatOverlay::ChatOverlay( )52 ChatOverlay::ChatOverlay(BaseObject* creator) : OverlayText(creator) 53 53 { 54 54 RegisterObject(ChatOverlay); … … 76 76 std::string name = "unknown"; 77 77 78 PlayerInfo* player = Level ::getClient(senderID);78 PlayerInfo* player = LevelManager::getInstance().getClient(senderID); 79 79 if (player) 80 80 name = player->getName(); -
code/branches/objecthierarchy/src/orxonox/overlays/hud/ChatOverlay.h
r1968 r2019 42 42 { 43 43 public: 44 ChatOverlay( );44 ChatOverlay(BaseObject* creator); 45 45 ~ChatOverlay(); 46 46 -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDBar.cc
r1854 r2019 38 38 39 39 #include "util/Convert.h" 40 #include "util/String.h" 40 41 #include "core/CoreIncludes.h" 41 42 #include "core/XMLPort.h" … … 45 46 CreateFactory(BarColour); 46 47 47 BarColour::BarColour() 48 : position_(0.0) 48 BarColour::BarColour(BaseObject* creator) : BaseObject(creator), position_(0.0) 49 49 { 50 50 RegisterObject(BarColour); … … 63 63 unsigned int HUDBar::materialcount_s = 0; 64 64 65 HUDBar::HUDBar() 66 : bar_(0) 67 , textureUnitState_(0) 65 HUDBar::HUDBar(BaseObject* creator) : OrxonoxOverlay(creator), bar_(0), textureUnitState_(0) 68 66 { 69 67 RegisterObject(HUDBar); … … 92 90 93 91 this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 94 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberStr ()));92 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString())); 95 93 this->bar_->setMaterialName(materialname); 96 94 this->background_->addChild(bar_); -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDBar.h
r1747 r2019 44 44 { 45 45 public: 46 BarColour( );46 BarColour(BaseObject* creator); 47 47 ~BarColour() { } 48 48 … … 64 64 { 65 65 public: 66 HUDBar( );66 HUDBar(BaseObject* creator); 67 67 virtual ~HUDBar(); 68 68 -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDNavigation.cc
r1993 r2019 46 46 CreateFactory(HUDNavigation); 47 47 48 HUDNavigation::HUDNavigation() 49 : navMarker_(0) 48 HUDNavigation::HUDNavigation(BaseObject* creator) 49 : OrxonoxOverlay(creator) 50 , navMarker_(0) 50 51 , aimMarker_(0) 51 52 , navText_(0) … … 72 73 // create nav text 73 74 navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 74 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberStr ()));75 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 75 76 76 77 // create nav marker 77 78 navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 78 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberStr ()));79 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 79 80 navMarker_->setMaterialName("Orxonox/NavArrows"); 80 81 wasOutOfView_ = true; // just to ensure the material is changed right the first time.. … … 82 83 // create aim marker 83 84 aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 84 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberStr ()));85 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberString())); 85 86 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 86 87 … … 112 113 return this->navText_->getFontName(); 113 114 else 114 return blankString;115 return BLANKSTRING; 115 116 } 116 117 -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDNavigation.h
r1747 r2019 41 41 { 42 42 public: 43 HUDNavigation( );43 HUDNavigation(BaseObject* creator); 44 44 ~HUDNavigation(); 45 45 -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDRadar.cc
r1916 r2019 35 35 36 36 #include "util/Math.h" 37 #include "util/String.h" 37 38 #include "core/ConsoleCommand.h" 38 39 #include "core/CoreIncludes.h" … … 45 46 CreateFactory(HUDRadar); 46 47 47 HUDRadar::HUDRadar() 48 : marker_(0) 48 HUDRadar::HUDRadar(BaseObject* creator) : OrxonoxOverlay(creator), marker_(0) 49 49 { 50 50 RegisterObject(HUDRadar); … … 69 69 { 70 70 marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 71 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberStr ()));71 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberString())); 72 72 marker_->setMaterialName("Orxonox/RadarMarker"); 73 73 overlay_->add2D(marker_); … … 107 107 // we have to create a new entry 108 108 panel = static_cast<Ogre::PanelOverlayElement*>( 109 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr ()));109 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString())); 110 110 radarDots_.push_back(panel); 111 111 // get right material -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDRadar.h
r1819 r2019 45 45 { 46 46 public: 47 HUDRadar( );47 HUDRadar(BaseObject* creator); 48 48 ~HUDRadar(); 49 49 -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDSpeedBar.cc
r1916 r2019 36 36 CreateFactory(HUDSpeedBar); 37 37 38 HUDSpeedBar::HUDSpeedBar( )38 HUDSpeedBar::HUDSpeedBar(BaseObject* creator) : HUDBar(creator) 39 39 { 40 40 RegisterObject(HUDSpeedBar); -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDSpeedBar.h
r1747 r2019 41 41 { 42 42 public: 43 HUDSpeedBar( );43 HUDSpeedBar(BaseObject* creator); 44 44 ~HUDSpeedBar(); 45 45 -
code/branches/objecthierarchy/src/orxonox/tools/BillboardSet.cc
r1755 r2019 31 31 32 32 #include <sstream> 33 33 #include <cassert> 34 34 #include <OgreSceneManager.h> 35 35 … … 46 46 } 47 47 48 void BillboardSet::setBillboardSet( const std::string& file, int count)48 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count) 49 49 { 50 assert(scenemanager); 51 50 52 std::ostringstream name; 51 53 name << (BillboardSet::billboardSetCounter_s++); 52 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);54 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count); 53 55 this->billboardSet_->createBillboard(Vector3::ZERO); 54 56 this->billboardSet_->setMaterialName(file); 57 58 this->scenemanager_ = scenemanager; 55 59 } 56 60 57 void BillboardSet::setBillboardSet( const std::string& file, const ColourValue& colour, int count)61 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count) 58 62 { 63 assert(scenemanager); 64 59 65 std::ostringstream name; 60 66 name << (BillboardSet::billboardSetCounter_s++); 61 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);67 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count); 62 68 this->billboardSet_->createBillboard(Vector3::ZERO, colour); 63 69 this->billboardSet_->setMaterialName(file); 70 71 this->scenemanager_ = scenemanager; 64 72 } 65 73 66 void BillboardSet::setBillboardSet( const std::string& file, const Vector3& position, int count)74 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count) 67 75 { 76 assert(scenemanager); 77 68 78 std::ostringstream name; 69 79 name << (BillboardSet::billboardSetCounter_s++); 70 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);80 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count); 71 81 this->billboardSet_->createBillboard(position); 72 82 this->billboardSet_->setMaterialName(file); 83 84 this->scenemanager_ = scenemanager; 73 85 } 74 86 75 void BillboardSet::setBillboardSet( const std::string& file, const ColourValue& colour, const Vector3& position, int count)87 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count) 76 88 { 89 assert(scenemanager); 90 77 91 std::ostringstream name; 78 92 name << (BillboardSet::billboardSetCounter_s++); 79 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);93 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count); 80 94 this->billboardSet_->createBillboard(position, colour); 81 95 this->billboardSet_->setMaterialName(file); 96 97 this->scenemanager_ = scenemanager; 82 98 } 83 99 84 100 BillboardSet::~BillboardSet() 85 101 { 86 if (this->billboardSet_ )87 GraphicsEngine::getInstance().getLevelSceneManager()->destroyBillboardSet(this->billboardSet_);102 if (this->billboardSet_ && this->scenemanager_) 103 this->scenemanager_->destroyBillboardSet(this->billboardSet_); 88 104 } 89 105 } -
code/branches/objecthierarchy/src/orxonox/tools/BillboardSet.h
r1602 r2019 44 44 BillboardSet(); 45 45 ~BillboardSet(); 46 void setBillboardSet( const std::string& file, int count = 1);47 void setBillboardSet( const std::string& file, const ColourValue& colour, int count = 1);48 void setBillboardSet( const std::string& file, const Vector3& position, int count = 1);49 void setBillboardSet( const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1);46 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count = 1); 47 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count = 1); 48 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count = 1); 49 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1); 50 50 51 51 inline Ogre::BillboardSet* getBillboardSet() … … 63 63 static unsigned int billboardSetCounter_s; 64 64 Ogre::BillboardSet* billboardSet_; 65 Ogre::SceneManager* scenemanager_; 65 66 }; 66 67 } -
code/branches/objecthierarchy/src/orxonox/tools/Light.cc
r1755 r2019 31 31 32 32 #include <sstream> 33 #include <cassert> 33 34 34 35 #include <OgreSceneManager.h> … … 45 46 } 46 47 47 void Light::setLight(Ogre:: Light::LightTypes type, const ColourValue& diffuse, const ColourValue& specular)48 void Light::setLight(Ogre::SceneManager* scenemanager, Ogre::Light::LightTypes type, const ColourValue& diffuse, const ColourValue& specular) 48 49 { 50 assert(scenemanager); 51 49 52 std::ostringstream name; 50 53 name << (Light::lightCounter_s++); 51 this->light_ = GraphicsEngine::getInstance().getLevelSceneManager()->createLight("Light" + name.str());54 this->light_ = scenemanager->createLight("Light" + name.str()); 52 55 this->light_->setType(type); 53 56 this->light_->setDiffuseColour(diffuse); 54 57 this->light_->setSpecularColour(specular); 58 59 this->scenemanager_ = scenemanager; 55 60 } 56 61 57 62 Light::~Light() 58 63 { 59 if (this->light_ )60 GraphicsEngine::getInstance().getLevelSceneManager()->destroyLight(this->light_);64 if (this->light_ && this->scenemanager_) 65 this->scenemanager_->destroyLight(this->light_); 61 66 } 62 67 } -
code/branches/objecthierarchy/src/orxonox/tools/Light.h
r1505 r2019 45 45 Light(); 46 46 ~Light(); 47 void setLight(Ogre:: Light::LightTypes type = Ogre::Light::LT_POINT, const ColourValue& diffuse = ColourValue(1.0, 1.0, 1.0), const ColourValue& specular = ColourValue(1.0, 1.0, 1.0));47 void setLight(Ogre::SceneManager* scenemanager, Ogre::Light::LightTypes type = Ogre::Light::LT_POINT, const ColourValue& diffuse = ColourValue(1.0, 1.0, 1.0), const ColourValue& specular = ColourValue(1.0, 1.0, 1.0)); 48 48 49 49 inline Ogre::Light* getLight() … … 56 56 static unsigned int lightCounter_s; 57 57 Ogre::Light* light_; 58 Ogre::SceneManager* scenemanager_; 58 59 }; 59 60 } -
code/branches/objecthierarchy/src/orxonox/tools/Mesh.cc
r2006 r2019 32 32 #include <sstream> 33 33 #include <OgreSceneManager.h> 34 #include <cassert> 34 35 35 36 #include "core/Core.h" … … 50 51 Mesh::~Mesh() 51 52 { 52 if (this->entity_ && Core::showsGraphics())53 GraphicsEngine::getInstance().getLevelSceneManager()->destroyEntity(this->entity_);53 if (this->entity_ && this->scenemanager_) 54 this->scenemanager_->destroyEntity(this->entity_); 54 55 } 55 56 56 void Mesh::setMeshSource( const std::string& meshsource)57 void Mesh::setMeshSource(Ogre::SceneManager* scenemanager, const std::string& meshsource) 57 58 { 58 if (Core::showsGraphics()) 59 assert(scenemanager); 60 61 this->scenemanager_ = scenemanager; 62 63 if (this->entity_) 64 this->scenemanager_->destroyEntity(this->entity_); 65 66 try 59 67 { 60 if (this->entity_) 61 GraphicsEngine::getInstance().getLevelSceneManager()->destroyEntity(this->entity_); 62 63 try 64 { 65 this->entity_ = GraphicsEngine::getInstance().getLevelSceneManager()->createEntity("Mesh" + convertToString(Mesh::meshCounter_s++), meshsource); 66 this->entity_->setCastShadows(this->bCastShadows_); 67 } 68 catch (...) 69 { 70 COUT(1) << "Error: Couln't load mesh \"" << meshsource << "\"" << std::endl; 71 } 68 this->entity_ = this->scenemanager_->createEntity("Mesh" + convertToString(Mesh::meshCounter_s++), meshsource); 69 this->entity_->setCastShadows(this->bCastShadows_); 70 } 71 catch (...) 72 { 73 COUT(1) << "Error: Couln't load mesh \"" << meshsource << "\"" << std::endl; 72 74 } 73 75 } … … 85 87 return this->entity_->getName(); 86 88 else 87 return blankString;89 return BLANKSTRING; 88 90 } 89 91 -
code/branches/objecthierarchy/src/orxonox/tools/Mesh.h
r2006 r2019 43 43 ~Mesh(); 44 44 45 void setMeshSource( const std::string& file);45 void setMeshSource(Ogre::SceneManager* scenemanager, const std::string& file); 46 46 47 47 inline Ogre::Entity* getEntity() … … 61 61 Ogre::Entity* entity_; 62 62 bool bCastShadows_; 63 Ogre::SceneManager* scenemanager_; 63 64 }; 64 65 } -
code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.cc
r1755 r2019 37 37 #include <OgreParticleEmitter.h> 38 38 #include <OgreSceneManager.h> 39 #include <cassert> 39 40 40 41 #include "GraphicsEngine.h" … … 47 48 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 48 49 49 ParticleInterface::ParticleInterface( const std::string& templateName, LODParticle::LOD detaillevel)50 ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) 50 51 { 51 52 RegisterRootObject(ParticleInterface); 52 53 54 assert(scenemanager); 55 56 this->scenemanager_ = scenemanager; 53 57 this->sceneNode_ = 0; 54 58 this->bEnabled_ = true; 55 59 this->detaillevel_ = (unsigned int)detaillevel; 56 this->particleSystem_ = GraphicsEngine::getInstance().getLevelSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);60 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 57 61 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 58 62 this->particleSystem_->setSpeedFactor(1.0f); … … 72 76 { 73 77 this->particleSystem_->removeAllEmitters(); 74 GraphicsEngine::getInstance().getLevelSceneManager()->destroyParticleSystem(particleSystem_);78 this->scenemanager_->destroyParticleSystem(particleSystem_); 75 79 } 76 80 -
code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.h
r1563 r2019 48 48 { 49 49 public: 50 ParticleInterface( const std::string& templateName, LODParticle::LOD detaillevel);50 ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel); 51 51 ~ParticleInterface(); 52 52 … … 92 92 bool bEnabled_; 93 93 unsigned int detaillevel_; //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high) 94 Ogre::SceneManager* scenemanager_; 94 95 }; 95 96 }
Note: See TracChangeset
for help on using the changeset viewer.