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/objects/worldentities
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.