Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 22, 2008, 5:25:01 AM (16 years ago)
Author:
landauf
Message:

added several new classes

Location:
code/branches/objecthierarchy/src/orxonox/objects
Files:
10 added
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/Camera.cc

    r1989 r1993  
    4747namespace orxonox
    4848{
     49  CreateUnloadableFactory(Camera);
     50
    4951  Camera::Camera()
    5052  {
     
    6870  void Camera::tick(float dt)
    6971  {
     72      SUPER(Camera, tick, dt);
     73
    7074      // this stuff here may need some adjustments
    7175      float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f);
  • code/branches/objecthierarchy/src/orxonox/objects/Camera.h

    r1989 r1993  
    3636#include "OrxonoxPrereqs.h"
    3737#include "objects/worldentities/PositionableEntity.h"
     38#include "objects/Tickable.h"
    3839
    3940namespace orxonox
    4041{
    41     class _OrxonoxExport Camera : public PositionableEntity
     42    class _OrxonoxExport Camera : public PositionableEntity//, public Tickable
    4243    {
    4344      friend class CameraHandler;
     45
    4446      public:
    4547        Camera();
    4648        virtual ~Camera();
    4749
    48         void tick(float dt);
     50        virtual void tick(float dt);
    4951        void update();
    5052
  • code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.h

    r1505 r1993  
    4444#include "core/BaseObject.h"
    4545
    46 #include "Camera.h"
    47 
    4846namespace orxonox
    4947{
  • code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc

    r1989 r1993  
    3333#include "core/ConsoleCommand.h"
    3434#include "objects/infos/PlayerInfo.h"
     35#include "objects/worldentities/pawns/Spectator.h"
    3536
    3637#include "network/Host.h"
     
    4647        RegisterObject(Gametype);
    4748
     49        this->defaultPawn_ = Class(Spectator);
    4850        this->getConnectedClients();
    4951
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1989 r1993  
    4242#include "objects/gametypes/Gametype.h"
    4343#include "objects/worldentities/ControllableEntity.h"
     44#include "objects/controllers/HumanController.h"
    4445
    4546namespace orxonox
     
    5354        this->ping_ = -1;
    5455        this->clientID_ = network::CLIENTID_UNKNOWN;
    55         this->bLocalPlayer_ = Core::isStandalone();
    5656        this->bLocalPlayer_ = false;
    5757        this->bHumanPlayer_ = false;
     
    6060        this->pawn_ = 0;
    6161        this->pawnID_ = network::OBJECTID_UNKNOWN;
     62        this->controller_ = 0;
     63        this->setDefaultController(Class(HumanController));
    6264
    6365        this->setConfigValues();
    6466        this->registerVariables();
    65 
    66 //COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;
    6767    }
    6868
    6969    PlayerInfo::~PlayerInfo()
    7070    {
    71         Gametype* gametype = Gametype::getCurrentGametype();
    72         if (gametype)
    73             gametype->removePlayer(this);
    74 //COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl;
     71        if (this->isInitialized())
     72        {
     73            Gametype* gametype = Gametype::getCurrentGametype();
     74            if (gametype)
     75                gametype->removePlayer(this);
     76
     77            if (this->controller_)
     78                delete this->controller_;
     79
     80            if (this->pawn_)
     81                this->pawn_->removePlayer();
     82        }
    7583    }
    7684
     
    8290    void PlayerInfo::checkNick()
    8391    {
    84 //std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;
    8592        if (this->bLocalPlayer_)
    8693        {
     
    94101    void PlayerInfo::changedName()
    95102    {
    96 //std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;
    97103        Gametype* gametype = Gametype::getCurrentGametype();
    98104        if (gametype)
     
    113119    void PlayerInfo::clientChangedName()
    114120    {
    115 //std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl;
    116121        this->setName(this->playerName_);
    117122    }
     
    119124    void PlayerInfo::checkClientID()
    120125    {
    121 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;
    122126        this->bHumanPlayer_ = true;
    123127
    124128        if (this->clientID_ == network::Host::getPlayerID())
    125129        {
    126 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;
    127             this->bLocalPlayer_ = true;
    128             this->playerName_ = this->nick_;
    129 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl;
     130            this->takeLocalControl();
    130131
    131132            if (Core::isClient())
    132             {
    133 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;
    134133                this->setObjectMode(network::direction::bidirectional);
    135 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;
    136             }
    137134            else
    138135            {
    139 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;
    140136                this->clientChangedName();
    141137                this->bFinishedSetup_ = true;
     
    147143    void PlayerInfo::finishedSetup()
    148144    {
    149 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;
    150145        if (Core::isClient())
    151         {
    152 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;
    153146            this->bFinishedSetup_ = true;
    154         }
    155147        else if (this->bFinishedSetup_)
    156148        {
    157 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;
    158149            Gametype* gametype = Gametype::getCurrentGametype();
    159150            if (gametype)
    160151                gametype->addPlayer(this);
    161         }
    162         else
    163         {
    164 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;
    165152        }
    166153    }
     
    171158        this->pawn_ = pawn;
    172159        this->pawnID_ = pawn->getObjectID();
     160
     161        if (this->controller_)
     162            this->controller_->setPawn(this->pawn_);
    173163    }
    174164
     
    180170    }
    181171
     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
    182185    void PlayerInfo::updatePawn()
    183186    {
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r1989 r1993  
    3333
    3434#include "Info.h"
     35#include "core/Identifier.h"
     36#include "objects/controllers/Controller.h"
    3537
    3638namespace orxonox
     
    5860                { return this->bLocalPlayer_; }
    5961
    60             void startControl(ControllableEntity* pawn);
    61             void stopControl();
     62            virtual void startControl(ControllableEntity* pawn);
     63            virtual void stopControl();
    6264
    6365            inline ControllableEntity* getPawn() const
    6466                { 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        protected:
     74            inline void setDefaultController(Identifier* identifier)
     75                { this->defaultController_ = identifier; }
    6576
    6677        private:
     78            virtual void createController();
     79            virtual void takeLocalControl();
     80
    6781            void checkClientID();
    6882            void finishedSetup();
     
    8296            ControllableEntity* pawn_;
    8397            unsigned int pawnID_;
     98            Controller* controller_;
     99            SubclassIdentifier<Controller> defaultController_;
    84100    };
    85101}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc

    r1989 r1993  
    5353        this->hud_ = 0;
    5454        this->camera_ = 0;
    55 
     55        this->bDestroyWhenPlayerLeft_ = false;
    5656
    5757        this->velocity_ = Vector3::ZERO;
     
    9494
    9595        if (this->bControlled_)
     96        {
    9697            this->startLocalControl();
     98            this->setObjectMode(network::direction::bidirectional);
     99        }
    97100    }
    98101
     
    105108        this->playerID_ = network::OBJECTID_UNKNOWN;
    106109        this->bControlled_ = false;
     110        this->setObjectMode(network::direction::toclient);
     111
     112        if (this->bDestroyWhenPlayerLeft_)
     113            delete this;
    107114    }
    108115
    109116    void ControllableEntity::updatePlayer()
    110117    {
    111         this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_));
    112         if (this->player_ && (this->player_->getPawn() != this))
    113             this->player_->startControl(this);
     118        if (this->playerID_ != network::OBJECTID_UNKNOWN)
     119        {
     120            this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_));
     121            if (this->player_ && (this->player_->getPawn() != this))
     122                this->player_->startControl(this);
     123        }
    114124    }
    115125
    116126    void ControllableEntity::startLocalControl()
    117127    {
     128        std::cout << "###### start local control" << std::endl;
    118129        this->camera_ = new Camera();
    119130        this->camera_->requestFocus();
    120 
    121         this->hud_ = new OverlayGroup();
    122         this->hud_->addTemplate(this->hudtemplate_);
     131        this->attach(this->camera_);
     132
     133        if (this->hudtemplate_ != "")
     134        {
     135            this->hud_ = new OverlayGroup();
     136            this->hud_->addTemplate(this->hudtemplate_);
     137        }
    123138    }
    124139
    125140    void ControllableEntity::stopLocalControl()
    126141    {
     142        std::cout << "###### stop local control" << std::endl;
     143        this->detach(this->camera_);
    127144        delete this->camera_;
    128145        this->camera_ = 0;
     
    137154        {
    138155            this->velocity_ += (dt * this->acceleration_);
    139             this->node_->translate(dt * this->velocity_);
     156            this->node_->translate(dt * this->velocity_, Ogre::Node::TS_PARENT);
    140157
    141158            if (Core::isMaster())
     
    150167            }
    151168        }
    152 
    153 //        std::cout << this->getPosition() << std::endl;
    154169    }
    155170
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h

    r1989 r1993  
    5252                { return this->player_; }
    5353
     54            inline void setDestroyWhenPlayerLeft(bool bDestroy)
     55                { this->bDestroyWhenPlayerLeft_ = bDestroy; }
     56            inline bool getDestroyWhenPlayerLeft() const
     57                { return this->bDestroyWhenPlayerLeft_; }
     58
    5459            virtual void startLocalControl();
    5560            virtual void stopLocalControl();
     
    7075            virtual void switchCamera() {}
    7176
     77            inline const Vector3& getVelocity() const
     78                { return this->velocity_; }
     79            inline const Vector3& getAcceleration() const
     80                { return this->acceleration_; }
     81            inline const std::string& getHudTemplate() const
     82                { return this->hudtemplate_; }
     83
    7284        protected:
    7385            using WorldEntity::setPosition;
     
    7587            using WorldEntity::setOrientation;
    7688            using WorldEntity::rotate;
     89            using WorldEntity::yaw;
     90            using WorldEntity::pitch;
     91            using WorldEntity::roll;
    7792            using WorldEntity::lookAt;
    7893            using WorldEntity::setDirection;
     
    91106            inline void setVelocity(float x, float y, float z)
    92107                { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
    93             inline const Vector3& getVelocity() const
    94                 { return this->velocity_; }
    95108
    96109            inline void setAcceleration(const Vector3& acceleration)
     
    98111            inline void setAcceleration(float x, float y, float z)
    99112                { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    100             inline const Vector3& getAcceleration() const
    101                 { return this->acceleration_; }
     113
     114            inline void setHudTemplate(const std::string& name)
     115                { this->hudtemplate_ = name; }
    102116
    103117        private:
    104             inline void setHudTemplate(const std::string& name)
    105                 { this->hudtemplate_ = name; }
    106             inline const std::string& getHudTemplate() const
    107                 { return this->hudtemplate_; }
    108 
    109118            void overwrite();
    110119            void processOverwrite();
     
    139148            OverlayGroup* hud_;
    140149            Camera* camera_;
     150            bool bDestroyWhenPlayerLeft_;
    141151    };
    142152}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.cc

    r1989 r1993  
    7979            this->node_->rotate(this->rotationAxis_, this->rotationRate_  * dt);
    8080        }
    81 
    82         std::cout << this->getPosition() << std::endl;
    8381    }
    8482
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.h

    r1989 r1993  
    5252            using WorldEntity::setOrientation;
    5353            using WorldEntity::rotate;
     54            using WorldEntity::yaw;
     55            using WorldEntity::pitch;
     56            using WorldEntity::roll;
    5457            using WorldEntity::lookAt;
    5558            using WorldEntity::setDirection;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.cc

    r1960 r1993  
    5757        REGISTERDATA(this->getOrientation().z, network::direction::toclient);
    5858    }
     59
     60    void PositionableEntity::tick(float dt)
     61    {
     62        // I don't know why but this has to be done to update the position if attached to another Entity
     63        this->node_->translate(Vector3::ZERO);
     64        std::cout << this->getWorldPosition() << std::endl;
     65    }
    5966}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h

    r1989 r1993  
    3232#include "OrxonoxPrereqs.h"
    3333#include "WorldEntity.h"
     34#include "objects/Tickable.h"
    3435
    3536namespace orxonox
    3637{
    37     class _OrxonoxExport PositionableEntity : public WorldEntity
     38    class _OrxonoxExport PositionableEntity : public WorldEntity, public Tickable
    3839    {
    3940        public:
     
    4243
    4344            void registerVariables();
     45            virtual void tick(float dt);
    4446
    4547            using WorldEntity::setPosition;
     
    4749            using WorldEntity::setOrientation;
    4850            using WorldEntity::rotate;
     51            using WorldEntity::yaw;
     52            using WorldEntity::pitch;
     53            using WorldEntity::roll;
    4954            using WorldEntity::lookAt;
    5055            using WorldEntity::setDirection;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc

    r1989 r1993  
    3434#include "core/CoreIncludes.h"
    3535#include "core/XMLPort.h"
     36#include "util/Convert.h"
    3637
    3738#include "GraphicsEngine.h"
     
    110111        if (object->getParent())
    111112            object->detachFromParent();
     113        else
     114        {
     115            Ogre::Node* parent = object->node_->getParent();
     116            if (parent)
     117                parent->removeChild(object->node_);
     118        }
    112119
    113120        this->node_->addChild(object->node_);
     
    123130        object->parent_ = 0;
    124131        object->parentID_ = (unsigned int)-1;
     132
     133        GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(object->node_);
    125134    }
    126135
Note: See TracChangeset for help on using the changeset viewer.