Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2008, 4:08:51 AM (16 years ago)
Author:
landauf
Message:

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

Location:
code/branches/objecthierarchy/src/orxonox
Files:
8 added
67 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/CMakeLists.txt

    r2012 r2019  
    4343  tools/WindowEventListener.cc
    4444
     45  LevelManager.cc
     46
     47  objects/Scene.cc
    4548  objects/worldentities/WorldEntity.cc
    4649  objects/worldentities/PositionableEntity.cc
     
    6366  objects/DistanceTrigger.cc
    6467
     68  objects/worldentities/SpawnPoint.cc
     69
    6570  objects/worldentities/pawns/Spectator.cc
    6671
     
    7176  objects/infos/Level.cc
    7277  objects/infos/PlayerInfo.cc
     78  objects/infos/HumanPlayer.cc
    7379
    7480  objects/gametypes/Gametype.cc
  • code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h

    r2012 r2019  
    8080    class RadarListener;
    8181
     82    class LevelManager;
     83
    8284    // objects
     85    class Scene;
     86
    8387    class WorldEntity;
    8488    class PositionableEntity;
    8589    class MovableEntity;
    8690    class ControllableEntity;
     91    class Sublevel;
    8792
    8893    class Model;
     94    class Billboard;
     95    class Light;
     96    class DirectionalLight;
     97
     98    class Camera;
     99    class SpawnPoint;
    89100
    90101    class Spectator;
     102    class Pawn;
     103    class SpaceShip;
    91104
    92105    class Controller;
     
    94107
    95108    class Backlight;
    96     class Camera;
    97109    class ParticleSpawner;
    98110
     
    100112    class Level;
    101113    class PlayerInfo;
     114    class HumanPlayer;
    102115
    103116    class Gametype;
     117
     118    class Scores;
    104119
    105120    // tools
  • code/branches/objecthierarchy/src/orxonox/objects/Camera.cc

    r2006 r2019  
    3232
    3333#include <string>
     34#include <cassert>
    3435
    3536#include <OgreSceneManager.h>
     
    4142#include "util/SubString.h"
    4243#include "util/Math.h"
     44#include "util/String.h"
    4345#include "util/Debug.h"
    4446#include "core/CoreIncludes.h"
     47#include "core/ConfigValueIncludes.h"
    4548#include "GraphicsEngine.h"
     49#include "objects/Scene.h"
    4650
    4751namespace orxonox
    4852{
    49   CreateUnloadableFactory(Camera);
     53    CreateFactory(Camera);
    5054
    51   Camera::Camera()
    52   {
    53     RegisterObject(Camera);
     55    Camera::Camera(BaseObject* creator) : PositionableEntity(creator)
     56    {
     57        RegisterObject(Camera);
    5458
    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());
    6061
    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()
    6478    {
    65       CameraHandler::getInstance()->releaseFocus(this);
    66       GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(this->cameraNode_->getName());
     79        if (this->isInitialized())
     80        {
     81            this->releaseFocus();
     82        }
    6783    }
    68   }
    6984
    70   void Camera::tick(float dt)
    71   {
    72       // this stuff here may need some adjustments
    73       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    }
    7489
    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    }
    7794
    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);
    80100
    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);
    90103
    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    }
    100107
    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    }
    108112
    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    }
    113132}
  • code/branches/objecthierarchy/src/orxonox/objects/Camera.h

    r2006 r2019  
    4242    class _OrxonoxExport Camera : public PositionableEntity, public Tickable
    4343    {
    44       friend class CameraHandler;
     44        friend class CameraHandler;
    4545
    46       public:
    47         Camera();
    48         virtual ~Camera();
     46        public:
     47            Camera(BaseObject* creator);
     48            virtual ~Camera();
    4949
    50         virtual void tick(float dt);
    51         void update();
     50            void setConfigValues();
     51            virtual void tick(float dt);
    5252
    53         void requestFocus();
    54         inline bool hasFocus()
    55             { return this->bHasFocus_; }
     53            void requestFocus();
     54            void releaseFocus();
    5655
    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_; }
    6158
    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_; }
    6563
    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_;
    7173    };
    7274}
  • code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.cc

    r2006 r2019  
    3333
    3434#include "core/ObjectList.h"
     35#include "core/Core.h"
    3536#include "Camera.h"
    3637#include "GraphicsEngine.h"
     
    3839#include <OgreCamera.h>
    3940
    40 namespace orxonox {
     41namespace orxonox
     42{
     43    CameraHandler::CameraHandler()
     44    {
     45//        GraphicsEngine::getInstance().getViewport()->setCamera(this->cam_);
     46    }
    4147
    42   CameraHandler* CameraHandler::singletonRef = NULL;
     48    CameraHandler& CameraHandler::getInstance()
     49    {
     50        static CameraHandler instance;
     51        return instance;
     52    }
    4353
    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    }
    5361
    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());
    6574    }
    66     // delete dublicates
    67     focusList_.unique();
    68   }
    6975
    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)
    9277    {
    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        }
    9495    }
    95     return false;
    96   }*/
    9796}
  • code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.h

    r1993 r2019  
    3636#define _Camera_Handler_H__
    3737
     38#include "OrxonoxPrereqs.h"
     39
    3840#include <list>
    39 
    4041#include <OgreCamera.h>
    41 
    42 #include "OrxonoxPrereqs.h"
    4342
    4443#include "core/BaseObject.h"
     
    4645namespace orxonox
    4746{
    48   class _OrxonoxExport CameraHandler
    49   {
     47    class _OrxonoxExport CameraHandler
     48    {
     49        public:
     50            static CameraHandler& getInstance();
    5051
    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;
    5953
    60     private:
    61       CameraHandler();
    62       //bool isInVector(Camera* cam);
     54            void requestFocus(Camera* camera);
     55            void releaseFocus(Camera* camera);
    6356
    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() {}
    6960
    70   };
     61            std::list<Camera*> cameraList_;
     62    };
    7163}
    7264
  • code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.cc

    r1969 r2019  
    3737  CreateFactory(DistanceTrigger);
    3838
    39   DistanceTrigger::DistanceTrigger()
     39  DistanceTrigger::DistanceTrigger(BaseObject* creator) : Trigger(creator)
    4040  {
    4141    RegisterObject(DistanceTrigger);
  • code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.h

    r1969 r2019  
    4444  {
    4545    public:
    46       DistanceTrigger();
     46      DistanceTrigger(BaseObject* creator);
    4747      ~DistanceTrigger();
    4848      void addTarget(Ogre::Node* targetNode);
  • code/branches/objecthierarchy/src/orxonox/objects/ParticleSpawner.cc

    r1755 r2019  
    8080        this->setPosition(this->getNode()->getParent()->getPosition());
    8181        this->getNode()->getParent()->removeChild(this->getNode());
    82         GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(this->getNode());
     82        this->detachFromParent();
    8383        if (this->particle_)
    8484            this->particle_->setEnabled(false);
  • code/branches/objecthierarchy/src/orxonox/objects/Script.cc

    r1961 r2019  
    3939  CreateFactory(Script);
    4040
    41   Script::Script()
     41  Script::Script(BaseObject* creator) : BaseObject(creator)
    4242  {
    4343    RegisterObject(Script);
  • code/branches/objecthierarchy/src/orxonox/objects/Script.h

    r1959 r2019  
    3939  {
    4040    public:
    41       Script();
     41      Script(BaseObject* creator);
    4242      ~Script();
    4343      void XMLPort(Element& xmlelement, XMLPort::Mode mode);
  • code/branches/objecthierarchy/src/orxonox/objects/Test.cc

    r1990 r2019  
    3636        CreateFactory ( Test );
    3737
    38         Test::Test()
     38        Test::Test(BaseObject* creator) : BaseObject(creator)
    3939        {
    4040                RegisterObject ( Test );
  • code/branches/objecthierarchy/src/orxonox/objects/Test.h

    r1990 r2019  
    3939  {
    4040    public:
    41       Test();
     41      Test(BaseObject* creator);
    4242      virtual ~Test();
    4343
    4444      void setConfigValues();
    4545      void registerVariables();
    46      
     46
    4747      void setV1(unsigned int value){ v1 = value; }
    4848      void setV2(unsigned int value){ v2 = value; }
    4949      void setV3(unsigned int value){ v3 = value; }
    50      
     50
    5151      void checkV1();
    5252      void checkV2();
  • code/branches/objecthierarchy/src/orxonox/objects/Trigger.cc

    r1969 r2019  
    3535#include "core/ConsoleCommand.h"
    3636#include "core/XMLPort.h"
     37#include "objects/Scene.h"
    3738
    3839namespace orxonox
     
    4344  CreateFactory(Trigger);
    4445
    45   Trigger::Trigger()
     46  Trigger::Trigger(BaseObject* creator) : PositionableEntity(creator)
    4647  {
    4748    RegisterObject(Trigger);
     
    5758    latestState_ = 0x0;
    5859
    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    }
    6165
    6266    this->getNode()->attachObject(debugBillboard_.getBillboardSet());
  • code/branches/objecthierarchy/src/orxonox/objects/Trigger.h

    r2013 r2019  
    5050  {
    5151    public:
    52       Trigger();
     52      Trigger(BaseObject* creator);
    5353      ~Trigger();
    5454
  • code/branches/objecthierarchy/src/orxonox/objects/controllers/Controller.cc

    r1993 r2019  
    3636    CreateUnloadableFactory(Controller);
    3737
    38     Controller::Controller()
     38    Controller::Controller(BaseObject* creator) : BaseObject(creator)
    3939    {
    4040        RegisterObject(Controller);
    4141
    4242        this->player_ = 0;
    43         this->pawn_ = 0;
     43        this->controllableEntity_ = 0;
    4444    }
    4545
  • code/branches/objecthierarchy/src/orxonox/objects/controllers/Controller.h

    r1993 r2019  
    3939    {
    4040        public:
    41             Controller();
     41            Controller(BaseObject* creator);
    4242            virtual ~Controller();
    4343
     
    4747                { return this->player_; }
    4848
    49             inline void setPawn(ControllableEntity* pawn)
    50                 { this->pawn_ = pawn; }
    51             inline ControllableEntity* getPawn() const
    52                 { return this->pawn_; }
     49            virtual inline void setControllableEntity(ControllableEntity* entity)
     50                { this->controllableEntity_ = entity; }
     51            virtual inline ControllableEntity* getControllableEntity() const
     52                { return this->controllableEntity_; }
    5353
    5454        protected:
    5555            PlayerInfo* player_;
    56             ControllableEntity* pawn_;
     56            ControllableEntity* controllableEntity_;
    5757    };
    5858}
  • code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.cc

    r2001 r2019  
    5252    HumanController* HumanController::localController_s = 0;
    5353
    54     HumanController::HumanController()
     54    HumanController::HumanController(BaseObject* creator) : Controller(creator)
    5555    {
    5656        RegisterObject(HumanController);
     
    6666    void HumanController::moveFrontBack(const Vector2& value)
    6767    {
    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);
    7070    }
    7171
    7272    void HumanController::moveRightLeft(const Vector2& value)
    7373    {
    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);
    7676    }
    7777
    7878    void HumanController::moveUpDown(const Vector2& value)
    7979    {
    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);
    8282    }
    8383
    8484    void HumanController::rotateYaw(const Vector2& value)
    8585    {
    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);
    8888    }
    8989
    9090    void HumanController::rotatePitch(const Vector2& value)
    9191    {
    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);
    9494    }
    9595
    9696    void HumanController::rotateRoll(const Vector2& value)
    9797    {
    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);
    100100    }
    101101
    102102    void HumanController::fire()
    103103    {
    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();
    106106    }
    107107
    108108    void HumanController::altFire()
    109109    {
    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();
    112112    }
    113113
    114114    void HumanController::greet()
    115115    {
    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();
    118118    }
    119119
    120120    void HumanController::use()
    121121    {
    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();
    124124    }
    125125
    126126    void HumanController::switchCamera()
    127127    {
    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();
    130130    }
    131131}
  • code/branches/objecthierarchy/src/orxonox/objects/controllers/HumanController.h

    r2001 r2019  
    4040    {
    4141        public:
    42             HumanController();
     42            HumanController(BaseObject* creator);
    4343            virtual ~HumanController();
    4444
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc

    r2006 r2019  
    3030#include "Gametype.h"
    3131
     32#include <cstdlib>
     33#include <ctime>
     34
    3235#include "core/CoreIncludes.h"
    3336#include "objects/infos/PlayerInfo.h"
    3437#include "objects/worldentities/pawns/Spectator.h"
     38#include "objects/worldentities/SpawnPoint.h"
    3539
    3640#include "network/Host.h"
     
    4044    CreateUnloadableFactory(Gametype);
    4145
    42     Gametype::Gametype()
     46    Gametype::Gametype(BaseObject* creator) : BaseObject(creator)
    4347    {
    4448        RegisterObject(Gametype);
    4549
    4650        this->defaultPawn_ = Class(Spectator);
     51        this->bStarted_ = false;
     52        this->bEnded_ = false;
     53        this->bAutoStart_ = false;
    4754
    4855        COUT(0) << "created Gametype" << std::endl;
    4956    }
    5057
    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)
    5282    {
    5383        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
    7285        std::string message = player->getName() + " entered the game";
    7386        COUT(0) << message << std::endl;
     
    7790    void Gametype::playerLeft(PlayerInfo* player)
    7891    {
    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    {
    82109    }
    83110
     
    94121        }
    95122    }
     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    }
    96220}
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h

    r2006 r2019  
    3737#include "core/Identifier.h"
    3838#include "objects/worldentities/ControllableEntity.h"
     39#include "objects/Tickable.h"
    3940
    4041namespace orxonox
    4142{
    42     class _OrxonoxExport Gametype : public BaseObject
     43    class _OrxonoxExport Gametype : public BaseObject, public Tickable
    4344    {
    4445        friend class PlayerInfo;
    4546
    4647        public:
    47             Gametype();
     48            Gametype(BaseObject* creator);
    4849            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);
    4963
    5064            inline const std::set<PlayerInfo*>& getPlayers() const
    5165                { return this->players_; }
    5266
    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); }
    5869
    5970        private:
     71            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
     72
    6073            void addPlayer(PlayerInfo* player);
    6174            void removePlayer(PlayerInfo* player);
    6275
     76            void assignDefaultPawnsIfNeeded() const;
     77            void checkStart();
     78            void spawnPlayer(PlayerInfo* player);
     79
     80            bool bStarted_;
     81            bool bEnded_;
     82            bool bAutoStart_;
    6383            std::set<PlayerInfo*> players_;
     84            std::set<SpawnPoint*> spawnpoints_;
    6485            SubclassIdentifier<ControllableEntity> defaultPawn_;
    6586    };
  • code/branches/objecthierarchy/src/orxonox/objects/infos/Info.cc

    r1947 r2019  
    3434namespace orxonox
    3535{
    36     Info::Info()
     36    Info::Info(BaseObject* creator) : BaseObject(creator)
    3737    {
    3838        RegisterObject(Info);
  • code/branches/objecthierarchy/src/orxonox/objects/infos/Info.h

    r1940 r2019  
    4040    {
    4141        public:
    42             Info();
     42            Info(BaseObject* creator);
    4343            virtual ~Info() {}
    4444    };
  • code/branches/objecthierarchy/src/orxonox/objects/infos/Level.cc

    r2012 r2019  
    3030#include "Level.h"
    3131
    32 #include <OgreSceneManager.h>
    33 #include <OgreLight.h>
    34 
    3532#include "core/CoreIncludes.h"
    3633#include "core/XMLPort.h"
    37 #include "core/Core.h"
    38 #include "core/ConsoleCommand.h"
    3934#include "core/Loader.h"
    4035#include "core/XMLFile.h"
    4136#include "core/Template.h"
    4237
    43 #include "GraphicsEngine.h"
    4438#include "Settings.h"
     39#include "LevelManager.h"
    4540#include "PlayerInfo.h"
     41#include "objects/gametypes/Gametype.h"
    4642
    4743#include "util/Math.h"
     
    4945namespace orxonox
    5046{
    51     SetConsoleCommand(Level, listPlayers, true);
    52 
    5347    CreateFactory(Level);
    5448
    55     Level::Level()
     49    Level::Level(BaseObject* creator) : Info(creator)
    5650    {
    5751        RegisterObject(Level);
    5852
    59         this->rootGametype_ = 0;
    6053        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();
    7255
    7356        COUT(0) << "created Level" << std::endl;
    7457    }
    7558
    76     Level* Level::getActiveLevel()
     59    Level::~Level()
    7760    {
    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);
    8164
    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_);
    9467        }
    95         else
    96         {
    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         else
    114         {
    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 instance
    125         PlayerInfo* player = new PlayerInfo();
    126         player->setGametype(this->getGametype());
    127         player->setClientID(clientID);
    128 
    129         // add to clients-map
    130         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-map
    139         PlayerInfo* player = this->clients_[clientID];
    140         this->clients_.erase(clientID);
    141 
    142         // delete PlayerInfo instance
    143         delete player;
    14468    }
    14569
     
    15074        XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
    15175        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));
    15476
    155         this->xmlfile_ = this->getFilename();
     77        XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
    15678    }
    15779
    15880    void Level::registerVariables()
    15981    {
    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));
    16183        REGISTERSTRING(this->name_,        network::direction::toclient, new network::NetworkCallback<Level>(this, &Level::changedName));
    16284        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));
    16585    }
    16686
    16787    void Level::networkcallback_applyXMLFile()
    16888    {
    169         COUT(0) << "Loading level \"" << this->xmlfile_ << "\"..." << std::endl;
     89        COUT(0) << "Loading level \"" << this->xmlfilename_ << "\"..." << std::endl;
    17090
    17191        ClassTreeMask mask;
     
    17393        mask.include(Class(Template));
    17494
    175         XMLFile* file = new XMLFile(Settings::getDataPath() + this->xmlfile_, mask);
     95        this->xmlfile_ = new XMLFile(Settings::getDataPath() + this->xmlfilename_, mask);
    17696
    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_);
    19598    }
    19699
     
    198101    {
    199102        Identifier* identifier = ClassByString(gametype);
    200         if (identifier)
     103        if (identifier && identifier->isA(Class(Gametype)))
    201104        {
    202105            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);
    206114        }
    207115    }
     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    }
    208146}
  • code/branches/objecthierarchy/src/orxonox/objects/infos/Level.h

    r2012 r2019  
    3333
    3434#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"
    4035
    4136namespace orxonox
    4237{
    43     class _OrxonoxExport Level : public Info, public network::ClientConnectionListener
     38    class _OrxonoxExport Level : public Info
    4439    {
    4540        public:
    46             Level();
    47             virtual ~Level() {}
     41            Level(BaseObject* creator);
     42            virtual ~Level();
    4843
    4944            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5045            void registerVariables();
    51 
    52             inline const std::map<unsigned int, PlayerInfo*>& getClients() const
    53                 { return this->clients_; }
    5446
    5547            inline void setDescription(const std::string& description)
     
    5850                { return this->description_; }
    5951
    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);
    6354
    64             void setAmbientLight(const ColourValue& colour);
    65             inline const ColourValue& getAmbientLight() const
    66                 { return this->ambientLight_; }
     55        private:
     56            void addObject(BaseObject* object);
     57            BaseObject* getObject(unsigned int index) const;
    6758
    6859            void setGametypeString(const std::string& gametype);
    6960            inline const std::string& getGametypeString() const
    7061                { return this->gametype_; }
    71             inline Gametype* getGametype() const
    72                 { 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);
    8162
    8263            void networkcallback_applyXMLFile();
    8364
    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_;
    9770    };
    9871}
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r2006 r2019  
    2727 */
    2828
     29#include <cassert>
     30
    2931#include "OrxonoxStableHeaders.h"
    3032#include "PlayerInfo.h"
    3133
    32 #include <OgreSceneManager.h>
    33 
    3434#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"
    4035#include "network/ClientInformation.h"
    41 
    42 #include "GraphicsEngine.h"
    4336#include "objects/gametypes/Gametype.h"
    44 #include "objects/worldentities/ControllableEntity.h"
    45 #include "objects/controllers/HumanController.h"
    4637
    4738namespace orxonox
    4839{
    49     CreateUnloadableFactory(PlayerInfo);
    50 
    51     PlayerInfo::PlayerInfo()
     40    PlayerInfo::PlayerInfo(BaseObject* creator) : Info(creator)
    5241    {
    5342        RegisterObject(PlayerInfo);
    5443
    55         this->ping_ = -1;
    5644        this->clientID_ = network::CLIENTID_UNKNOWN;
     45        this->bHumanPlayer_ = false;
    5746        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;
    6151
    62         this->pawn_ = 0;
    63         this->pawnID_ = network::OBJECTID_UNKNOWN;
    64         this->controller_ = 0;
    65         this->setDefaultController(Class(HumanController));
    66 
    67         this->setConfigValues();
    6852        this->registerVariables();
    6953    }
     
    7357        if (this->isInitialized())
    7458        {
    75             if (this->gametype_)
    76                 this->gametype_->removePlayer(this);
     59            this->stopControl(this->controllableEntity_);
    7760
    7861            if (this->controller_)
     62            {
    7963                delete this->controller_;
    80 
    81             if (this->pawn_)
    82                 this->pawn_->removePlayer();
     64                this->controller_ = 0;
     65            }
    8366        }
    8467    }
    8568
    86     void PlayerInfo::setConfigValues()
     69    void PlayerInfo::registerVariables()
    8770    {
    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));
    10073    }
    10174
    10275    void PlayerInfo::changedName()
    10376    {
    104         if (this->gametype_)
    105             this->gametype_->playerChangedName(this);
     77        if (this->isReady() && this->getGametype())
     78            this->getGametype()->playerChangedName(this);
    10679    }
    10780
    108     void PlayerInfo::registerVariables()
     81    void PlayerInfo::changedGametype()
    10982    {
    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            }
    11892
    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())
    13594            {
    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);
    13999            }
    140100        }
    141101    }
    142102
    143     void PlayerInfo::finishedSetup()
     103    void PlayerInfo::createController()
    144104    {
    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)
    148120        {
    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();
    151144        }
    152145    }
    153146
    154     void PlayerInfo::startControl(ControllableEntity* pawn)
     147    void PlayerInfo::networkcallback_changedcontrollableentityID()
    155148    {
    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);
    159153
    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        }
    190160    }
    191161}
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r2006 r2019  
    4141    {
    4242        public:
    43             PlayerInfo();
     43            PlayerInfo(BaseObject* creator);
    4444            virtual ~PlayerInfo();
    4545
    46             void setConfigValues();
    4746            void registerVariables();
    4847
    4948            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();
    5550
    5651            inline bool isHumanPlayer() const
    5752                { return this->bHumanPlayer_; }
    58 
    5953            inline bool isLocalPlayer() const
    6054                { return this->bLocalPlayer_; }
     55            inline unsigned int getClientID() const
     56                { return this->clientID_; }
     57            inline bool isReadyToSpawn() const
     58                { return this->bReadyToSpawn_; }
    6159
    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;
    6463
    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_; }
    7772
    7873        protected:
    79             inline void setDefaultController(Identifier* identifier)
    80                 { this->defaultController_ = identifier; }
     74            void createController();
     75            void networkcallback_changedcontrollableentityID();
    8176
    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_;
    9284            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_;
    10685    };
    10786}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2006 r2019  
    4343    CreateFactory(ControllableEntity);
    4444
    45     ControllableEntity::ControllableEntity()
     45    ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)
    4646    {
    4747        RegisterObject(ControllableEntity);
     
    7171    ControllableEntity::~ControllableEntity()
    7272    {
    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        }
    7584    }
    7685
     
    92101        this->player_ = player;
    93102        this->playerID_ = player->getObjectID();
    94         this->bControlled_ = player->isLocalPlayer();
     103        this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
    95104
    96105        if (this->bControlled_)
    97106        {
    98107            this->startLocalControl();
    99             this->setObjectMode(network::direction::bidirectional);
     108
     109            if (!Core::isMaster())
     110                this->setObjectMode(network::direction::bidirectional);
    100111        }
    101112    }
     
    115126    }
    116127
    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
    119131        if (this->playerID_ != network::OBJECTID_UNKNOWN)
    120132        {
    121133            this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_));
    122             if (this->player_ && (this->player_->getPawn() != this))
     134            if (this->player_ && (this->player_->getControllableEntity() != this))
    123135                this->player_->startControl(this);
    124136        }
     
    128140    {
    129141        std::cout << this->getObjectID() << " ###### start local control" << std::endl;
    130         this->camera_ = new Camera();
     142        this->camera_ = new Camera(this);
    131143        this->camera_->requestFocus();
    132144        this->attach(this->camera_);
     
    134146        if (this->hudtemplate_ != "")
    135147        {
    136             this->hud_ = new OverlayGroup();
     148            this->hud_ = new OverlayGroup(this);
    137149            this->hud_->addTemplate(this->hudtemplate_);
    138150        }
     
    184196        REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    185197
    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));
    187199    }
    188200
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h

    r2006 r2019  
    4040    {
    4141        public:
    42             ControllableEntity();
     42            ControllableEntity(BaseObject* creator);
    4343            virtual ~ControllableEntity();
    4444
     
    5656            inline bool getDestroyWhenPlayerLeft() const
    5757                { return this->bDestroyWhenPlayerLeft_; }
    58 
    59             virtual void startLocalControl();
    60             virtual void stopLocalControl();
    6158
    6259            virtual void moveFrontBack(float value) {}
     
    8279                { return this->hudtemplate_; }
    8380
    84         protected:
    8581            using WorldEntity::setPosition;
    8682            using WorldEntity::translate;
     
    112108                { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    113109
     110        protected:
     111            virtual void startLocalControl();
     112            virtual void stopLocalControl();
     113
    114114            inline void setHudTemplate(const std::string& name)
    115115                { this->hudtemplate_ = name; }
     
    130130            void processClientOrientation();
    131131
    132             void updatePlayer();
     132            void networkcallback_changedplayerID();
    133133
    134134            unsigned int server_overwrite_;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.cc

    r2006 r2019  
    3232#include "core/CoreIncludes.h"
    3333#include "core/XMLPort.h"
     34#include "objects/Scene.h"
    3435
    3536namespace orxonox
     
    3738    CreateFactory(Model);
    3839
    39     Model::Model()
     40    Model::Model(BaseObject* creator) : PositionableEntity(creator)
    4041    {
    4142        RegisterObject(Model);
     
    6970            this->getNode()->detachObject(this->mesh_.getEntity());
    7071
    71         this->mesh_.setMeshSource(this->meshSrc_);
     72        this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
    7273
    7374        if (this->mesh_.getEntity())
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.h

    r2006 r2019  
    3939    {
    4040        public:
    41             Model();
     41            Model(BaseObject* creator);
    4242            virtual ~Model();
    4343
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.cc

    r1994 r2019  
    4141    CreateFactory(MovableEntity);
    4242
    43     MovableEntity::MovableEntity()
     43    MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)
    4444    {
    4545        RegisterObject(MovableEntity);
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.h

    r1993 r2019  
    4141    {
    4242        public:
    43             MovableEntity();
     43            MovableEntity(BaseObject* creator);
    4444            virtual ~MovableEntity();
    4545
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.cc

    r2006 r2019  
    3535    CreateFactory(PositionableEntity);
    3636
    37     PositionableEntity::PositionableEntity()
     37    PositionableEntity::PositionableEntity(BaseObject* creator) : WorldEntity(creator)
    3838    {
    3939        RegisterObject(PositionableEntity);
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h

    r2006 r2019  
    3838    {
    3939        public:
    40             PositionableEntity();
     40            PositionableEntity(BaseObject* creator);
    4141            virtual ~PositionableEntity();
    4242
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc

    r2006 r2019  
    3030#include "WorldEntity.h"
    3131
     32#include <cassert>
    3233#include <OgreSceneManager.h>
    3334
     
    3738
    3839#include "GraphicsEngine.h"
     40#include "objects/Scene.h"
    3941
    4042namespace orxonox
     
    4749    const Vector3 WorldEntity::UP    = Vector3::UNIT_Y;
    4850
    49     WorldEntity::WorldEntity()
     51    WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator)
    5052    {
    5153        RegisterObject(WorldEntity);
    5254
    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
    5460        this->parent_ = 0;
    5561        this->parentID_ = (unsigned int)-1;
     
    6672        {
    6773            this->node_->detachAllObjects();
    68             GraphicsEngine::getInstance().getLevelSceneManager()->destroySceneNode(this->node_->getName());
     74            if (this->getScene()->getSceneManager())
     75                this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName());
    6976        }
    7077    }
    71 
    7278
    7379    void WorldEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     
    131137        object->parentID_ = (unsigned int)-1;
    132138
    133         GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(object->node_);
     139        this->getScene()->getRootSceneNode()->addChild(object->node_);
    134140    }
    135141
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h

    r1989 r2019  
    4545    {
    4646        public:
    47             WorldEntity();
     47            WorldEntity(BaseObject* creator);
    4848            virtual ~WorldEntity();
    4949
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2006 r2019  
    3333#include "core/Core.h"
    3434#include "objects/worldentities/Model.h"
     35#include "objects/Scene.h"
     36#include "objects/infos/PlayerInfo.h"
    3537#include "tools/BillboardSet.h"
    3638
     
    3941    CreateFactory(Spectator);
    4042
    41     Spectator::Spectator()
     43    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
    4244    {
    4345        RegisterObject(Spectator);
     
    5456
    5557        // test test test
     58        if (this->getScene()->getSceneManager())
    5659        {
    5760            this->testmesh_ = new Mesh();
    5861            this->testnode_ = this->getNode()->createChildSceneNode();
    59             this->testmesh_->setMeshSource("assff.mesh");
     62            this->testmesh_->setMeshSource(this->getScene()->getSceneManager(), "assff.mesh");
    6063            if (this->testmesh_->getEntity())
    6164                this->testnode_->attachObject(this->testmesh_->getEntity());
     
    6467            this->testnode_->scale(10, 10, 10);
    6568        }
     69        else
     70        {
     71            this->testmesh_ = 0;
     72            this->testnode_ = 0;
     73        }
    6674        // test test test
    6775
    6876        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);
    7078        this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
    7179        this->greetingFlare_->setVisible(false);
     
    8088        if (this->isInitialized())
    8189        {
    82             delete this->greetingFlare_;
     90            if (this->greetingFlare_)
     91            {
     92                this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
     93                delete this->greetingFlare_;
     94            }
    8395
    8496            // test test test
    8597            {
    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());
    88106            }
    89107            // test test test
     
    177195    void Spectator::fire()
    178196    {
     197        if (this->getPlayer())
     198            this->getPlayer()->setReadyToSpawn(true);
    179199    }
    180200
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2006 r2019  
    3939    {
    4040        public:
    41             Spectator();
     41            Spectator(BaseObject* creator);
    4242            virtual ~Spectator();
    4343
  • code/branches/objecthierarchy/src/orxonox/overlays/OrxonoxOverlay.cc

    r1755 r2019  
    5555    SetConsoleCommand(OrxonoxOverlay, rotateOverlay, false).accessLevel(AccessLevel::User);
    5656
    57     OrxonoxOverlay::OrxonoxOverlay()
    58         : overlay_(0)
     57    OrxonoxOverlay::OrxonoxOverlay(BaseObject* creator)
     58        : BaseObject(creator)
     59        , overlay_(0)
    5960        , background_(0)
    6061    {
     
    148149            return this->background_->getMaterialName();
    149150        else
    150             return blankString;
     151            return BLANKSTRING;
    151152    }
    152153
  • code/branches/objecthierarchy/src/orxonox/overlays/OrxonoxOverlay.h

    r1747 r2019  
    8484
    8585    public:
    86         OrxonoxOverlay();
     86        OrxonoxOverlay(BaseObject* creator);
    8787        virtual ~OrxonoxOverlay();
    8888
  • code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.cc

    r1993 r2019  
    5050    SetConsoleCommand(OverlayGroup, scrollGroup, false).accessLevel(AccessLevel::User);
    5151
    52     OverlayGroup::OverlayGroup()
     52    OverlayGroup::OverlayGroup(BaseObject* creator) : BaseObject(creator)
    5353    {
    5454        RegisterObject(OverlayGroup);
  • code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.h

    r1747 r2019  
    5454    {
    5555    public:
    56         OverlayGroup();
     56        OverlayGroup(BaseObject* creator);
    5757        //! Empty destructor.
    5858        ~OverlayGroup() { }
  • code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.cc

    r1993 r2019  
    4141    CreateFactory(OverlayText);
    4242
    43     OverlayText::OverlayText()
    44         : text_(0)
     43    OverlayText::OverlayText(BaseObject* creator) : OrxonoxOverlay(creator), text_(0)
    4544    {
    4645        RegisterObject(OverlayText);
     
    6059        {
    6160            this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
    62                 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr()));
     61                .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString()));
    6362            this->text_->setCharHeight(1.0);
    6463
     
    8483            return this->text_->getFontName();
    8584        else
    86             return blankString;
     85            return BLANKSTRING;
    8786    }
    8887
  • code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.h

    r1993 r2019  
    4242    {
    4343    public:
    44         OverlayText();
     44        OverlayText(BaseObject* creator);
    4545        virtual ~OverlayText();
    4646
  • code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugFPSText.cc

    r1755 r2019  
    3838    CreateFactory(DebugFPSText);
    3939
    40     DebugFPSText::DebugFPSText()
     40    DebugFPSText::DebugFPSText(BaseObject* creator) : OverlayText(creator)
    4141    {
    4242        RegisterObject(DebugFPSText);
  • code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugFPSText.h

    r1747 r2019  
    4040    {
    4141    public:
    42         DebugFPSText();
     42        DebugFPSText(BaseObject* creator);
    4343        ~DebugFPSText();
    4444
  • code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugRTRText.cc

    r1755 r2019  
    3838    CreateFactory(DebugRTRText);
    3939
    40     DebugRTRText::DebugRTRText()
     40    DebugRTRText::DebugRTRText(BaseObject* creator) : OverlayText(creator)
    4141    {
    4242        RegisterObject(DebugRTRText);
  • code/branches/objecthierarchy/src/orxonox/overlays/debug/DebugRTRText.h

    r1747 r2019  
    4040    {
    4141    public:
    42         DebugRTRText();
     42        DebugRTRText(BaseObject* creator);
    4343        ~DebugRTRText();
    4444
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/ChatOverlay.cc

    r2012 r2019  
    3939
    4040#include "GraphicsEngine.h"
    41 #include "objects/infos/Level.h"
     41#include "LevelManager.h"
    4242#include "objects/infos/PlayerInfo.h"
    4343#include "overlays/console/InGameConsole.h"
     
    5050    CreateFactory(ChatOverlay);
    5151
    52     ChatOverlay::ChatOverlay()
     52    ChatOverlay::ChatOverlay(BaseObject* creator) : OverlayText(creator)
    5353    {
    5454        RegisterObject(ChatOverlay);
     
    7676            std::string name = "unknown";
    7777
    78             PlayerInfo* player = Level::getClient(senderID);
     78            PlayerInfo* player = LevelManager::getInstance().getClient(senderID);
    7979            if (player)
    8080                name = player->getName();
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/ChatOverlay.h

    r1968 r2019  
    4242    {
    4343        public:
    44             ChatOverlay();
     44            ChatOverlay(BaseObject* creator);
    4545            ~ChatOverlay();
    4646
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDBar.cc

    r1854 r2019  
    3838
    3939#include "util/Convert.h"
     40#include "util/String.h"
    4041#include "core/CoreIncludes.h"
    4142#include "core/XMLPort.h"
     
    4546    CreateFactory(BarColour);
    4647
    47     BarColour::BarColour()
    48         : position_(0.0)
     48    BarColour::BarColour(BaseObject* creator) : BaseObject(creator), position_(0.0)
    4949    {
    5050        RegisterObject(BarColour);
     
    6363    unsigned int HUDBar::materialcount_s = 0;
    6464
    65     HUDBar::HUDBar()
    66         : bar_(0)
    67         , textureUnitState_(0)
     65    HUDBar::HUDBar(BaseObject* creator) : OrxonoxOverlay(creator), bar_(0), textureUnitState_(0)
    6866    {
    6967        RegisterObject(HUDBar);
     
    9290
    9391            this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    94                 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberStr()));
     92                .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString()));
    9593            this->bar_->setMaterialName(materialname);
    9694            this->background_->addChild(bar_);
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDBar.h

    r1747 r2019  
    4444    {
    4545    public:
    46         BarColour();
     46        BarColour(BaseObject* creator);
    4747        ~BarColour() { }
    4848
     
    6464    {
    6565    public:
    66         HUDBar();
     66        HUDBar(BaseObject* creator);
    6767        virtual ~HUDBar();
    6868
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDNavigation.cc

    r1993 r2019  
    4646    CreateFactory(HUDNavigation);
    4747
    48     HUDNavigation::HUDNavigation()
    49         : navMarker_(0)
     48    HUDNavigation::HUDNavigation(BaseObject* creator)
     49        : OrxonoxOverlay(creator)
     50        , navMarker_(0)
    5051        , aimMarker_(0)
    5152        , navText_(0)
     
    7273            // create nav text
    7374            navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
    74                 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberStr()));
     75                .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
    7576
    7677            // create nav marker
    7778            navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    78                 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberStr()));
     79                .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
    7980            navMarker_->setMaterialName("Orxonox/NavArrows");
    8081            wasOutOfView_ = true; // just to ensure the material is changed right the first time..
     
    8283            // create aim marker
    8384            aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    84                 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberStr()));
     85                .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberString()));
    8586            aimMarker_->setMaterialName("Orxonox/NavCrosshair");
    8687
     
    112113            return this->navText_->getFontName();
    113114        else
    114             return blankString;
     115            return BLANKSTRING;
    115116    }
    116117
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDNavigation.h

    r1747 r2019  
    4141    {
    4242    public:
    43         HUDNavigation();
     43        HUDNavigation(BaseObject* creator);
    4444        ~HUDNavigation();
    4545
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDRadar.cc

    r1916 r2019  
    3535
    3636#include "util/Math.h"
     37#include "util/String.h"
    3738#include "core/ConsoleCommand.h"
    3839#include "core/CoreIncludes.h"
     
    4546    CreateFactory(HUDRadar);
    4647
    47     HUDRadar::HUDRadar()
    48         : marker_(0)
     48    HUDRadar::HUDRadar(BaseObject* creator) : OrxonoxOverlay(creator), marker_(0)
    4949    {
    5050        RegisterObject(HUDRadar);
     
    6969        {
    7070            marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    71                 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberStr()));
     71                .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberString()));
    7272            marker_->setMaterialName("Orxonox/RadarMarker");
    7373            overlay_->add2D(marker_);
     
    107107            // we have to create a new entry
    108108            panel = static_cast<Ogre::PanelOverlayElement*>(
    109                 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr()));
     109                Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString()));
    110110            radarDots_.push_back(panel);
    111111            // get right material
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDRadar.h

    r1819 r2019  
    4545    {
    4646    public:
    47         HUDRadar();
     47        HUDRadar(BaseObject* creator);
    4848        ~HUDRadar();
    4949
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDSpeedBar.cc

    r1916 r2019  
    3636    CreateFactory(HUDSpeedBar);
    3737
    38     HUDSpeedBar::HUDSpeedBar()
     38    HUDSpeedBar::HUDSpeedBar(BaseObject* creator) : HUDBar(creator)
    3939    {
    4040        RegisterObject(HUDSpeedBar);
  • code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDSpeedBar.h

    r1747 r2019  
    4141    {
    4242    public:
    43         HUDSpeedBar();
     43        HUDSpeedBar(BaseObject* creator);
    4444        ~HUDSpeedBar();
    4545
  • code/branches/objecthierarchy/src/orxonox/tools/BillboardSet.cc

    r1755 r2019  
    3131
    3232#include <sstream>
    33 
     33#include <cassert>
    3434#include <OgreSceneManager.h>
    3535
     
    4646    }
    4747
    48     void BillboardSet::setBillboardSet(const std::string& file, int count)
     48    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count)
    4949    {
     50        assert(scenemanager);
     51
    5052        std::ostringstream name;
    5153        name << (BillboardSet::billboardSetCounter_s++);
    52         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
     54        this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count);
    5355        this->billboardSet_->createBillboard(Vector3::ZERO);
    5456        this->billboardSet_->setMaterialName(file);
     57
     58        this->scenemanager_ = scenemanager;
    5559    }
    5660
    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)
    5862    {
     63        assert(scenemanager);
     64
    5965        std::ostringstream name;
    6066        name << (BillboardSet::billboardSetCounter_s++);
    61         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
     67        this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count);
    6268        this->billboardSet_->createBillboard(Vector3::ZERO, colour);
    6369        this->billboardSet_->setMaterialName(file);
     70
     71        this->scenemanager_ = scenemanager;
    6472    }
    6573
    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)
    6775    {
     76        assert(scenemanager);
     77
    6878        std::ostringstream name;
    6979        name << (BillboardSet::billboardSetCounter_s++);
    70         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
     80        this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count);
    7181        this->billboardSet_->createBillboard(position);
    7282        this->billboardSet_->setMaterialName(file);
     83
     84        this->scenemanager_ = scenemanager;
    7385    }
    7486
    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)
    7688    {
     89        assert(scenemanager);
     90
    7791        std::ostringstream name;
    7892        name << (BillboardSet::billboardSetCounter_s++);
    79         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
     93        this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + name.str(), count);
    8094        this->billboardSet_->createBillboard(position, colour);
    8195        this->billboardSet_->setMaterialName(file);
     96
     97        this->scenemanager_ = scenemanager;
    8298    }
    8399
    84100    BillboardSet::~BillboardSet()
    85101    {
    86         if (this->billboardSet_)
    87             GraphicsEngine::getInstance().getLevelSceneManager()->destroyBillboardSet(this->billboardSet_);
     102        if (this->billboardSet_ && this->scenemanager_)
     103            this->scenemanager_->destroyBillboardSet(this->billboardSet_);
    88104    }
    89105}
  • code/branches/objecthierarchy/src/orxonox/tools/BillboardSet.h

    r1602 r2019  
    4444            BillboardSet();
    4545            ~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);
    5050
    5151            inline Ogre::BillboardSet* getBillboardSet()
     
    6363            static unsigned int billboardSetCounter_s;
    6464            Ogre::BillboardSet* billboardSet_;
     65            Ogre::SceneManager* scenemanager_;
    6566    };
    6667}
  • code/branches/objecthierarchy/src/orxonox/tools/Light.cc

    r1755 r2019  
    3131
    3232#include <sstream>
     33#include <cassert>
    3334
    3435#include <OgreSceneManager.h>
     
    4546    }
    4647
    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)
    4849    {
     50        assert(scenemanager);
     51
    4952        std::ostringstream name;
    5053        name << (Light::lightCounter_s++);
    51         this->light_ = GraphicsEngine::getInstance().getLevelSceneManager()->createLight("Light" + name.str());
     54        this->light_ = scenemanager->createLight("Light" + name.str());
    5255        this->light_->setType(type);
    5356        this->light_->setDiffuseColour(diffuse);
    5457        this->light_->setSpecularColour(specular);
     58
     59        this->scenemanager_ = scenemanager;
    5560    }
    5661
    5762    Light::~Light()
    5863    {
    59         if (this->light_)
    60             GraphicsEngine::getInstance().getLevelSceneManager()->destroyLight(this->light_);
     64        if (this->light_ && this->scenemanager_)
     65            this->scenemanager_->destroyLight(this->light_);
    6166    }
    6267}
  • code/branches/objecthierarchy/src/orxonox/tools/Light.h

    r1505 r2019  
    4545            Light();
    4646            ~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));
    4848
    4949            inline Ogre::Light* getLight()
     
    5656            static unsigned int lightCounter_s;
    5757            Ogre::Light* light_;
     58            Ogre::SceneManager* scenemanager_;
    5859    };
    5960}
  • code/branches/objecthierarchy/src/orxonox/tools/Mesh.cc

    r2006 r2019  
    3232#include <sstream>
    3333#include <OgreSceneManager.h>
     34#include <cassert>
    3435
    3536#include "core/Core.h"
     
    5051    Mesh::~Mesh()
    5152    {
    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_);
    5455    }
    5556
    56     void Mesh::setMeshSource(const std::string& meshsource)
     57    void Mesh::setMeshSource(Ogre::SceneManager* scenemanager, const std::string& meshsource)
    5758    {
    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
    5967        {
    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;
    7274        }
    7375    }
     
    8587            return this->entity_->getName();
    8688        else
    87             return blankString;
     89            return BLANKSTRING;
    8890    }
    8991
  • code/branches/objecthierarchy/src/orxonox/tools/Mesh.h

    r2006 r2019  
    4343            ~Mesh();
    4444
    45             void setMeshSource(const std::string& file);
     45            void setMeshSource(Ogre::SceneManager* scenemanager, const std::string& file);
    4646
    4747            inline Ogre::Entity* getEntity()
     
    6161            Ogre::Entity* entity_;
    6262            bool bCastShadows_;
     63            Ogre::SceneManager* scenemanager_;
    6364    };
    6465}
  • code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.cc

    r1755 r2019  
    3737#include <OgreParticleEmitter.h>
    3838#include <OgreSceneManager.h>
     39#include <cassert>
    3940
    4041#include "GraphicsEngine.h"
     
    4748  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
    4849
    49   ParticleInterface::ParticleInterface(const std::string& templateName, LODParticle::LOD detaillevel)
     50  ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel)
    5051  {
    5152    RegisterRootObject(ParticleInterface);
    5253
     54    assert(scenemanager);
     55
     56    this->scenemanager_ = scenemanager;
    5357    this->sceneNode_ = 0;
    5458    this->bEnabled_ = true;
    5559    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);
    5761    //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
    5862    this->particleSystem_->setSpeedFactor(1.0f);
     
    7276  {
    7377    this->particleSystem_->removeAllEmitters();
    74     GraphicsEngine::getInstance().getLevelSceneManager()->destroyParticleSystem(particleSystem_);
     78    this->scenemanager_->destroyParticleSystem(particleSystem_);
    7579  }
    7680
  • code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.h

    r1563 r2019  
    4848  {
    4949    public:
    50       ParticleInterface(const std::string& templateName, LODParticle::LOD detaillevel);
     50      ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel);
    5151      ~ParticleInterface();
    5252
     
    9292      bool bEnabled_;
    9393      unsigned int detaillevel_;                            //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high)
     94      Ogre::SceneManager* scenemanager_;
    9495  };
    9596}
Note: See TracChangeset for help on using the changeset viewer.