Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 24, 2008, 1:50:47 AM (16 years ago)
Author:
landauf
Message:

Update your media repository and delete keybindings.ini if you want to use boost (space).

  • Added new class "Engine" to control the speed of a SpaceShip (Engine is an Item, MultiStateEngine is a specialized version of Engine)
  • Added FadingBillboard, a billboard with the ability to fade in and out smoothly when activated/deactivated.
  • Several changes in Backlight, it's now a child of FadingBillboard
  • Some changes concerning local control in ControllableEntity
  • Fixed a bug in WorldEntity caused by different destruction order of attached objects on server and client
  • Added a "MainState" to BaseObject. An object has several states (activity, visibility, …) and one of it can be defined as "MainState" in the XML file. Other objects can change this state without knowing which state it really is (used by MultiStateEngine).
Location:
code/branches/objecthierarchy2
Files:
10 added
22 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/bin/def_keybindings.ini

    r2103 r2254  
    119119KeySlash=
    120120KeySleep=
    121 KeySpace=
     121KeySpace=boost
    122122KeyStop=
    123123KeySystemRequest=
  • code/branches/objecthierarchy2/src/core/BaseObject.cc

    r2173 r2254  
    3636#include "CoreIncludes.h"
    3737#include "EventIncludes.h"
     38#include "Functor.h"
    3839#include "XMLPort.h"
    3940#include "XMLFile.h"
     
    6061        this->oldGametype_ = 0;
    6162
     63        this->functorSetMainState_ = 0;
     64        this->functorGetMainState_ = 0;
     65
    6266        this->setCreator(creator);
    6367        if (this->creator_)
     
    8286    BaseObject::~BaseObject()
    8387    {
    84         for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
    85             (*it)->unregisterEventListener(this);
    86 
    87         for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
    88             it->first->removeEvent(this);
     88        if (this->isInitialized())
     89        {
     90            for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
     91                (*it)->unregisterEventListener(this);
     92
     93            for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     94                it->first->removeEvent(this);
     95
     96            if (this->functorSetMainState_)
     97                delete this->functorSetMainState_;
     98            if (this->functorGetMainState_)
     99                delete this->functorGetMainState_;
     100        }
    89101    }
    90102
     
    100112        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
    101113        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
     114        XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode);
    102115
    103116        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     
    279292        SetEvent(BaseObject, "visibility", setVisible, event);
    280293    }
     294
     295    void BaseObject::setMainStateName(const std::string& name)
     296    {
     297        if (this->mainStateName_ != name)
     298        {
     299            this->mainStateName_ = name;
     300            if (this->functorSetMainState_)
     301                delete this->functorSetMainState_;
     302            if (this->functorGetMainState_)
     303                delete this->functorGetMainState_;
     304            this->changedMainState();
     305            if (!this->functorSetMainState_)
     306                COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl;
     307        }
     308    }
     309
     310    void BaseObject::setMainState(bool state)
     311    {
     312        if (this->functorSetMainState_)
     313            (*this->functorSetMainState_)(state);
     314        else
     315            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     316    }
     317
     318    bool BaseObject::getMainState() const
     319    {
     320        if (this->functorGetMainState_)
     321        {
     322            (*this->functorGetMainState_)();
     323            return this->functorGetMainState_->getReturnvalue();
     324        }
     325        else
     326        {
     327            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     328            return false;
     329        }
     330    }
     331
     332    void BaseObject::changedMainState()
     333    {
     334        SetMainState(BaseObject, "activity",   setActive,  isActive);
     335        SetMainState(BaseObject, "visibility", setVisible, isVisible);
     336    }
    281337}
  • code/branches/objecthierarchy2/src/core/BaseObject.h

    r2171 r2254  
    3636#ifndef _BaseObject_H__
    3737#define _BaseObject_H__
     38
     39#define SetMainState(classname, statename, setfunction, getfunction) \
     40    if (this->getMainStateName() == statename) \
     41    { \
     42        this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \
     43        this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \
     44    }
    3845
    3946#include <map>
     
    100107            virtual void changedVisibility() {}
    101108
     109            void setMainState(bool state);
     110            bool getMainState() const;
     111
     112            void setMainStateName(const std::string& name);
     113            inline const std::string& getMainStateName() const { return this->mainStateName_; }
     114            virtual void changedMainState();
     115
    102116            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
    103117            inline void setFile(const XMLFile* file) { this->file_ = file; }
     
    153167            std::string name_;                          //!< The name of the object
    154168            std::string oldName_;                       //!< The old name of the object
    155             mbool bActive_;                             //!< True = the object is active
    156             mbool bVisible_;                            //!< True = the object is visible
     169            mbool       bActive_;                       //!< True = the object is active
     170            mbool       bVisible_;                      //!< True = the object is visible
     171            std::string mainStateName_;
     172            Functor*    functorSetMainState_;
     173            Functor*    functorGetMainState_;
    157174
    158175        private:
     
    160177            Template* getTemplate(unsigned int index) const;
    161178
    162             bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
    163             const XMLFile*        file_;                 //!< The XMLFile that loaded this object
    164             std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
    165             Namespace*            namespace_;
    166             BaseObject*           creator_;
    167             Scene*                scene_;
    168             Gametype*             gametype_;
    169             Gametype*             oldGametype_;
    170             std::set<Template*>   templates_;
    171             std::map<BaseObject*, std::string> eventListeners_;
     179            bool                   bInitialized_;         //!< True if the object was initialized (passed the object registration)
     180            const XMLFile*         file_;                 //!< The XMLFile that loaded this object
     181            std::string            loaderIndentation_;    //!< Indentation of the debug output in the Loader
     182            Namespace*             namespace_;
     183            BaseObject*            creator_;
     184            Scene*                 scene_;
     185            Gametype*              gametype_;
     186            Gametype*              oldGametype_;
     187            std::set<Template*>    templates_;
     188            std::map<BaseObject*,  std::string> eventListeners_;
    172189            std::list<BaseObject*> events_;
    173190            std::map<std::string, EventContainer*> eventContainers_;
     
    178195    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
    179196    SUPER_FUNCTION(4, BaseObject, processEvent, false);
     197    SUPER_FUNCTION(6, BaseObject, changedMainState, false);
    180198}
    181199
  • code/branches/objecthierarchy2/src/core/Functor.h

    r2087 r2254  
    167167            }
    168168
    169             FunctorMember* setObject(T* object)
     169            FunctorMember<T>* setObject(T* object)
    170170            {
    171171                this->bConstObject_ = false;
     
    174174            }
    175175
    176             FunctorMember* setObject(const T* object)
     176            FunctorMember<T>* setObject(const T* object)
    177177            {
    178178                this->bConstObject_ = true;
  • code/branches/objecthierarchy2/src/core/Super.h

    r2212 r2254  
    236236    #define SUPER_changedScale(classname, functionname, ...) \
    237237        SUPER_NOARGS(classname, functionname)
     238
     239    #define SUPER_changedMainState(classname, functionname, ...) \
     240        SUPER_NOARGS(classname, functionname)
    238241    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    239242
     
    448451            ()
    449452        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     453
     454        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false)
     455            ()
     456        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    450457        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    451458
     
    496503    SUPER_INTRUSIVE_DECLARATION(processEvent);
    497504    SUPER_INTRUSIVE_DECLARATION(changedScale);
     505    SUPER_INTRUSIVE_DECLARATION(changedMainState);
    498506    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    499507
  • code/branches/objecthierarchy2/src/orxonox/OrxonoxPrereqs.h

    r2171 r2254  
    113113    class Billboard;
    114114    class BlinkingBillboard;
     115    class FadingBillboard;
    115116    class Light;
    116117    class Backlight;
     
    125126    class Pawn;
    126127    class SpaceShip;
     128
     129    class Item;
     130    class Engine;
     131    class MultiStateEngine;
     132    class RotatingEngine;
    127133
    128134    class Trigger;
  • code/branches/objecthierarchy2/src/orxonox/objects/CMakeLists.txt

    r2171 r2254  
    1616ADD_SOURCE_DIRECTORY(SRC_FILES gametypes)
    1717ADD_SOURCE_DIRECTORY(SRC_FILES infos)
     18ADD_SOURCE_DIRECTORY(SRC_FILES items)
    1819#ADD_SOURCE_DIRECTORY(SRC_FILES pickup)
    1920ADD_SOURCE_DIRECTORY(SRC_FILES quest)
  • code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.cc

    r2087 r2254  
    4444    SetConsoleCommand(HumanController, fire,          true).keybindMode(KeybindMode::OnHold);
    4545    SetConsoleCommand(HumanController, altFire,       true).keybindMode(KeybindMode::OnHold);
     46    SetConsoleCommand(HumanController, boost,         true).keybindMode(KeybindMode::OnHold);
    4647    SetConsoleCommand(HumanController, greet,         true);
    4748    SetConsoleCommand(HumanController, use,           true);
     
    112113    }
    113114
     115    void HumanController::boost()
     116    {
     117        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     118            HumanController::localController_s->controllableEntity_->boost();
     119    }
     120
    114121    void HumanController::greet()
    115122    {
  • code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.h

    r2087 r2254  
    5454            static void altFire();
    5555
     56            static void boost();
    5657            static void greet();
    5758            static void use();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc

    r2212 r2254  
    4343    CreateFactory(Backlight);
    4444
    45     Backlight::Backlight(BaseObject* creator) : Billboard(creator)
     45    Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator)
    4646    {
    4747        RegisterObject(Backlight);
     
    5353        this->length_ = 1.0f;
    5454        this->lifetime_ = 0.001f;
    55         this->turnofftime_ = 0.5f;
    56         this->bTurningOff_ = false;
    5755        this->maxelements_ = 1;
    5856
     
    102100        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
    103101        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
    104         XMLPortParam(Backlight, "turnofftime",   setTurnOffTime,   getTurnOffTime,   xmlelement, mode).defaultValues(0.5f);
    105102        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
    106103    }
     
    117114    void Backlight::changedColour()
    118115    {
    119         Billboard::changedColour();
    120 
    121         if (this->ribbonTrail_ && this->isActive() && this->tickcount_ >= 2)
    122             this->ribbonTrail_->setInitialColour(0, this->getColour());
     116        FadingBillboard::changedColour();
     117
     118        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     119            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
    123120    }
    124121
     
    165162    }
    166163
    167     void Backlight::changedActivity()
    168     {
    169         SUPER(Backlight, changedActivity);
     164    void Backlight::startturnonoff()
     165    {
     166        FadingBillboard::startturnonoff();
     167
     168        if (this->ribbonTrail_ && this->isActive() && this->isVisible())
     169            this->ribbonTrail_->setVisible(true);
     170    }
     171
     172    void Backlight::stopturnonoff()
     173    {
     174        this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_);
     175
     176        FadingBillboard::stopturnonoff();
    170177
    171178        if (this->ribbonTrail_)
    172         {
    173             if (this->isActive())
    174                 this->ribbonTrail_->setInitialColour(0, this->getColour());
    175             else
    176             {
    177                 this->bTurningOff_ = true;
    178                 this->turnofftimer_.setTimer(this->turnofftime_, false, this, createExecutor(createFunctor(&Backlight::stopturnoff)));
    179             }
    180         }
     179            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
     180    }
     181
     182    void Backlight::poststopturnonoff()
     183    {
     184        FadingBillboard::poststopturnonoff();
     185
     186        if (this->ribbonTrail_)
     187            this->ribbonTrail_->setVisible(false);
    181188    }
    182189
     
    187194        this->update_width();
    188195        this->update_length();
    189     }
    190 
    191     void Backlight::stopturnoff()
    192     {
    193         this->bTurningOff_ = false;
    194196    }
    195197
     
    212214        }
    213215
    214         if (this->bTurningOff_ && this->ribbonTrail_)
    215         {
    216             this->ribbonTrail_->setInitialColour(0, this->ribbonTrail_->getInitialColour(0) - this->getColour() / this->turnofftime_ * dt);
     216        SUPER(Backlight, tick, dt);
     217
     218        if (this->ribbonTrail_ && this->changedirection_ != 0)
     219        {
     220            // we use alpha_blend, only adjust alpha
     221            const ColourValue& colour = this->getColour();
     222            this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a);
    217223        }
    218224    }
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h

    r2212 r2254  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "Billboard.h"
    34 #include "objects/Tickable.h"
    35 #include "tools/Timer.h"
     33#include "FadingBillboard.h"
    3634
    3735namespace orxonox
    3836{
    39     class _OrxonoxExport Backlight : public Billboard, public Tickable
     37    class _OrxonoxExport Backlight : public FadingBillboard
    4038    {
    4139        public:
     
    4745
    4846            virtual void tick(float dt);
    49             virtual void changedActivity();
    5047            virtual void changedVisibility();
    5148
     
    5956            inline float getLifetime() const
    6057                { return this->lifetime_; }
    61 
    62             inline void setTurnOffTime(float turnofftime)
    63                 { this->turnofftime_ = turnofftime; }
    64             inline float getTurnOffTime() const
    65                 { return this->turnofftime_; }
    6658
    6759            inline void setLength(float length)
     
    8375
    8476        private:
    85             void stopturnoff();
     77            virtual void startturnonoff();
     78            virtual void stopturnonoff();
     79            virtual void poststopturnonoff();
    8680            virtual void changedColour();
    8781            void update_width();
     
    9690            float length_;
    9791            float lifetime_;
    98             float turnofftime_;
    99             bool bTurningOff_;
    10092            size_t maxelements_;
    10193            std::string trailmaterial_;
    10294            char tickcount_;
    103             Timer<Backlight> turnofftimer_;
    10495    };
    10596}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc

    r2212 r2254  
    9494        if (!this->billboard_.getBillboardSet())
    9595        {
     96/*
    9697            if (this->getScene() && this->getScene()->getSceneManager() && (this->material_ != ""))
    9798            {
     
    101102                this->billboard_.setVisible(this->isVisible());
    102103            }
     104*/
    103105        }
    104106        else
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.h

    r2182 r2254  
    6262
    6363        protected:
     64            inline BillboardSet& getBillboardSet()
     65                { return this->billboard_; }
     66
    6467            virtual void changedColour();
    6568
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/CMakeLists.txt

    r2182 r2254  
    88  Billboard.cc
    99  BlinkingBillboard.cc
     10  FadingBillboard.cc
    1011  Light.cc
    1112  Camera.cc
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2171 r2254  
    4848        RegisterObject(ControllableEntity);
    4949
    50         this->bControlled_ = false;
     50        this->bHasLocalController_ = false;
     51        this->bHasHumanController_ = false;
     52
    5153        this->server_overwrite_ = 0;
    5254        this->client_overwrite_ = 0;
     
    7476        if (this->isInitialized())
    7577        {
    76             if (this->bControlled_)
    77                 this->stopLocalControl();
     78            if (this->bHasLocalController_)
     79                this->stopLocalHumanControl();
    7880
    7981            if (this->hud_)
     
    156158        this->player_ = player;
    157159        this->playerID_ = player->getObjectID();
    158         this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
    159         if (this->bControlled_)
    160         {
    161             this->startLocalControl();
     160        this->bHasLocalController_ = player->isLocalPlayer();
     161        this->bHasHumanController_ = player->isHumanPlayer();
     162
     163        if (this->bHasLocalController_ && this->bHasHumanController_)
     164        {
     165            this->startLocalHumanControl();
    162166
    163167            if (!Core::isMaster())
     
    172176    void ControllableEntity::removePlayer()
    173177    {
    174         if (this->bControlled_)
    175             this->stopLocalControl();
     178        if (this->bHasLocalController_ && this->bHasHumanController_)
     179            this->stopLocalHumanControl();
    176180
    177181        this->player_ = 0;
    178182        this->playerID_ = OBJECTID_UNKNOWN;
    179         this->bControlled_ = false;
     183        this->bHasLocalController_ = false;
     184        this->bHasHumanController_ = false;
    180185        this->setObjectMode(direction::toclient);
    181186
     
    195200    }
    196201
    197     void ControllableEntity::startLocalControl()
     202    void ControllableEntity::startLocalHumanControl()
    198203    {
    199204//        std::cout << this->getObjectID() << " ###### start local control" << std::endl;
     
    214219    }
    215220
    216     void ControllableEntity::stopLocalControl()
     221    void ControllableEntity::stopLocalHumanControl()
    217222    {
    218223//        std::cout << "###### stop local control" << std::endl;
     
    237242                this->server_position_ = this->node_->getPosition();
    238243            }
    239             else if (this->bControlled_)
     244            else if (this->bHasLocalController_)
    240245            {
    241246//                COUT(2) << "setting client position" << endl;
     
    251256
    252257        REGISTERDATA(this->client_overwrite_,   direction::toserver);
    253        
     258
    254259        REGISTERDATA(this->server_position_,    direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
    255260        REGISTERDATA(this->server_velocity_,    direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
     
    267272    void ControllableEntity::processServerPosition()
    268273    {
    269         if (!this->bControlled_)
     274        if (!this->bHasLocalController_)
    270275            this->node_->setPosition(this->server_position_);
    271276    }
     
    273278    void ControllableEntity::processServerVelocity()
    274279    {
    275         if (!this->bControlled_)
     280        if (!this->bHasLocalController_)
    276281            this->velocity_ = this->server_velocity_;
    277282    }
     
    279284    void ControllableEntity::processServerOrientation()
    280285    {
    281         if (!this->bControlled_)
     286        if (!this->bHasLocalController_)
    282287            this->node_->setOrientation(this->server_orientation_);
    283288    }
     
    285290    void ControllableEntity::processOverwrite()
    286291    {
    287         if (this->bControlled_)
     292        if (this->bHasLocalController_)
    288293        {
    289294            this->setPosition(this->server_position_);
     
    334339            ++this->server_overwrite_;
    335340        }
    336         else if (this->bControlled_)
     341        else if (this->bHasLocalController_)
    337342        {
    338343            this->node_->setPosition(position);
     
    349354            ++this->server_overwrite_;
    350355        }
    351         else if (this->bControlled_)
     356        else if (this->bHasLocalController_)
    352357        {
    353358            this->velocity_ = velocity;
     
    364369            ++this->server_overwrite_;
    365370        }
    366         else if (this->bControlled_)
     371        else if (this->bHasLocalController_)
    367372        {
    368373            this->node_->translate(distance, relativeTo);
     
    379384            ++this->server_overwrite_;
    380385        }
    381         else if (this->bControlled_)
     386        else if (this->bHasLocalController_)
    382387        {
    383388            this->node_->setOrientation(orientation);
     
    394399            ++this->server_overwrite_;
    395400        }
    396         else if (this->bControlled_)
     401        else if (this->bHasLocalController_)
    397402        {
    398403            this->node_->rotate(rotation, relativeTo);
     
    409414            ++this->server_overwrite_;
    410415        }
    411         else if (this->bControlled_)
     416        else if (this->bHasLocalController_)
    412417        {
    413418            this->node_->yaw(angle, relativeTo);
     
    424429            ++this->server_overwrite_;
    425430        }
    426         else if (this->bControlled_)
     431        else if (this->bHasLocalController_)
    427432        {
    428433            this->node_->pitch(angle, relativeTo);
     
    439444            ++this->server_overwrite_;
    440445        }
    441         else if (this->bControlled_)
     446        else if (this->bHasLocalController_)
    442447        {
    443448            this->node_->roll(angle, relativeTo);
     
    454459            ++this->server_overwrite_;
    455460        }
    456         else if (this->bControlled_)
     461        else if (this->bHasLocalController_)
    457462        {
    458463            this->node_->lookAt(target, relativeTo, localDirectionVector);
     
    469474            ++this->server_overwrite_;
    470475        }
    471         else if (this->bControlled_)
     476        else if (this->bHasLocalController_)
    472477        {
    473478            this->node_->setDirection(direction, relativeTo, localDirectionVector);
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h

    r2087 r2254  
    6868            virtual void altFire() {}
    6969
     70            virtual void boost() {}
    7071            virtual void greet() {}
    7172            virtual void use() {}
     
    123124                { return this->cameraPositionTemplate_; }
    124125
     126            inline bool hasLocalController() const
     127                { return this->bHasLocalController_; }
     128            inline bool hasHumanController() const
     129                { return this->bHasHumanController_; }
     130
    125131        protected:
    126             virtual void startLocalControl();
    127             virtual void stopLocalControl();
     132            virtual void startLocalHumanControl();
     133            virtual void stopLocalHumanControl();
    128134
    129135            inline void setHudTemplate(const std::string& name)
    130136                { this->hudtemplate_ = name; }
    131 
    132             inline bool isLocallyControlled() const
    133                 { return this->bControlled_; }
    134137
    135138            Vector3 acceleration_;
     
    154157            Vector3 velocity_;
    155158
    156             bool bControlled_;
     159            bool bHasLocalController_;
     160            bool bHasHumanController_;
     161
    157162            Vector3 server_position_;
    158163            Vector3 client_position_;
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.cc

    r2171 r2254  
    163163    void Light::changedType()
    164164    {
    165         this->light_->setType(this->type_);
     165        if (this->light_)
     166            this->light_->setType(this->type_);
    166167    }
    167168
     
    170171        SUPER(Light, changedVisibility);
    171172
    172         this->light_->setVisible(this->isVisible());
     173        if (this->light_)
     174            this->light_->setVisible(this->isVisible());
    173175    }
    174176}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.cc

    r2213 r2254  
    7676                delete (*it);
    7777
     78            if (this->parent_)
     79                this->detachFromParent();
     80
    7881            if (this->getScene()->getSceneManager())
    7982                this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName());
     
    100103    void WorldEntity::registerVariables()
    101104    {
     105        REGISTERSTRING(this->mainStateName_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState));
     106
    102107        REGISTERDATA(this->bActive_,  direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
    103108        REGISTERDATA(this->bVisible_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
     
    122127    void WorldEntity::attach(WorldEntity* object)
    123128    {
     129        if (object == this)
     130        {
     131            COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl;
     132            return;
     133        }
     134
    124135        if (object->getParent())
    125136            object->detachFromParent();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2171 r2254  
    3232#include "core/CoreIncludes.h"
    3333#include "core/ConfigValueIncludes.h"
     34#include "core/Template.h"
    3435#include "core/XMLPort.h"
    3536#include "util/Math.h"
     37#include "objects/items/Engine.h"
    3638
    3739namespace orxonox
     
    4547        this->zeroDegree_ = 0;
    4648
    47         this->maxSpeed_ = 0;
    48         this->maxSecondarySpeed_ = 0;
     49        this->bBoost_ = false;
     50        this->steering_ = Vector3::ZERO;
     51        this->engine_ = 0;
     52
    4953        this->maxRotation_ = 0;
    50         this->translationAcceleration_ = 0;
    5154        this->rotationAcceleration_ = 0;
    5255        this->translationDamping_ = 0;
     
    6669    SpaceShip::~SpaceShip()
    6770    {
     71        if (this->isInitialized() && this->engine_)
     72            delete this->engine_;
    6873    }
    6974
     
    7277        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    7378
    74         XMLPortParam(SpaceShip, "maxspeed",          setMaxSpeed,          getMaxSpeed,          xmlelement, mode);
    75         XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode);
     79        XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    7680        XMLPortParam(SpaceShip, "maxrotation",       setMaxRotation,       getMaxRotation,       xmlelement, mode);
    77         XMLPortParam(SpaceShip, "transacc",          setTransAcc,          getTransAcc,          xmlelement, mode);
    7881        XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
    7982        XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
     
    8285    void SpaceShip::registerVariables()
    8386    {
    84         REGISTERDATA(this->maxSpeed_,                direction::toclient);
    85         REGISTERDATA(this->maxSecondarySpeed_,       direction::toclient);
    8687        REGISTERDATA(this->maxRotation_,             direction::toclient);
    87         REGISTERDATA(this->translationAcceleration_, direction::toclient);
    8888        REGISTERDATA(this->rotationAcceleration_,    direction::toclient);
    8989        REGISTERDATA(this->translationDamping_,      direction::toclient);
     
    9797    void SpaceShip::tick(float dt)
    9898    {
    99         if (this->isLocallyControlled())
     99        if (this->hasLocalController())
    100100        {
    101101            // #####################################
     
    104104
    105105            Vector3 velocity = this->getVelocity();
    106             if (velocity.x > this->maxSecondarySpeed_)
    107                 velocity.x = this->maxSecondarySpeed_;
    108             if (velocity.x < -this->maxSecondarySpeed_)
    109                 velocity.x = -this->maxSecondarySpeed_;
    110             if (velocity.y > this->maxSecondarySpeed_)
    111                 velocity.y = this->maxSecondarySpeed_;
    112             if (velocity.y < -this->maxSecondarySpeed_)
    113                 velocity.y = -this->maxSecondarySpeed_;
    114             if (velocity.z > this->maxSecondarySpeed_)
    115                 velocity.z = this->maxSecondarySpeed_;
    116             if (velocity.z < -this->maxSpeed_)
    117                 velocity.z = -this->maxSpeed_;
    118106
    119107            // normalize velocity and acceleration
     
    144132
    145133
    146         if (this->isLocallyControlled())
     134        if (this->hasLocalController())
    147135        {
    148136            this->yaw(this->yawRotation_ * dt);
     
    153141            this->roll(this->rollRotation_ * dt);
    154142
    155             this->acceleration_.x = 0;
    156             this->acceleration_.y = 0;
    157             this->acceleration_.z = 0;
    158 
    159143            this->yawRotation_   = this->zeroDegree_;
    160144            this->pitchRotation_ = this->zeroDegree_;
     
    165149    void SpaceShip::moveFrontBack(const Vector2& value)
    166150    {
    167         this->acceleration_.z = -this->translationAcceleration_ * value.x;
     151        this->steering_.z = -value.x;
    168152    }
    169153
    170154    void SpaceShip::moveRightLeft(const Vector2& value)
    171155    {
    172         this->acceleration_.x = this->translationAcceleration_ * value.x;
     156        this->steering_.x = value.x;
    173157    }
    174158
    175159    void SpaceShip::moveUpDown(const Vector2& value)
    176160    {
    177         this->acceleration_.y = this->translationAcceleration_ * value.x;
     161        this->steering_.y = value.x;
    178162    }
    179163
     
    211195    {
    212196    }
     197
     198    void SpaceShip::boost()
     199    {
     200        this->bBoost_ = true;
     201    }
     202
     203    void SpaceShip::loadEngineTemplate()
     204    {
     205        if (this->enginetemplate_ != "")
     206        {
     207            Template* temp = Template::getTemplate(this->enginetemplate_);
     208
     209            if (temp)
     210            {
     211                Identifier* identifier = temp->getBaseclassIdentifier();
     212
     213                if (identifier)
     214                {
     215                    BaseObject* object = identifier->fabricate(this);
     216                    this->engine_ = dynamic_cast<Engine*>(object);
     217
     218                    if (this->engine_)
     219                    {
     220                        this->engine_->addTemplate(temp);
     221                        this->engine_->addToSpaceShip(this);
     222                    }
     223                    else
     224                    {
     225                        delete object;
     226                    }
     227                }
     228            }
     229        }
     230    }
    213231}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2087 r2254  
    5656
    5757            virtual void fire();
     58            virtual void boost();
    5859
    59             void setMaxSpeed(float value)
    60                 { this->maxSpeed_ = value; }
    61             void setMaxSecondarySpeed(float value)
    62                 { this->maxSecondarySpeed_ = value; }
    6360            void setMaxRotation(const Degree& value)
    6461                { this->maxRotation_ = value; }
    65             void setTransAcc(float value)
    66                 { this->translationAcceleration_ = value; }
    6762            void setRotAcc(const Degree& value)
    6863                { this->rotationAcceleration_ = value; }
     
    7065                { this->translationDamping_ = value; }
    7166
    72             inline float getMaxSpeed() const
    73                 { return this->maxSpeed_; }
    74             inline float getMaxSecondarySpeed() const
    75                 { return this->maxSecondarySpeed_; }
    7667            inline float getMaxRotation() const
    7768                { return this->maxRotation_.valueDegrees(); }
    78             inline float getTransAcc() const
    79                 { return this->translationAcceleration_; }
    8069            inline float getRotAcc() const
    8170                { return this->rotationAcceleration_.valueDegrees(); }
     
    8372                { return this->translationDamping_; }
    8473
     74            inline void setSteeringDirection(const Vector3& direction)
     75                { this->steering_ = direction; }
     76            inline const Vector3& getSteeringDirection() const
     77                { return this->steering_; }
     78
     79            inline void setBoost(bool bBoost)
     80                { this->bBoost_ = bBoost; }
     81            inline bool getBoost() const
     82                { return this->bBoost_; }
     83
     84            inline void setEngineTemplate(const std::string& temp)
     85                { this->enginetemplate_ = temp; this->loadEngineTemplate(); }
     86            inline const std::string& getEngineTemplate() const
     87                { return this->enginetemplate_; }
     88
    8589        protected:
    8690            bool bInvertYAxis_;
    8791
    88             float maxSpeed_;
    89             float maxSecondarySpeed_;
    90             float translationAcceleration_;
     92            bool bBoost_;
     93            Vector3 steering_;
    9194            float translationDamping_;
    9295
     
    98101            Degree yawRotation_;
    99102            Degree rollRotation_;
     103
     104        private:
     105            void loadEngineTemplate();
     106
     107            std::string enginetemplate_;
     108            Engine* engine_;
    100109    };
    101110}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2171 r2254  
    106106        this->updateHUD();
    107107
    108         if (this->isLocallyControlled())
     108        if (this->hasLocalController())
    109109        {
    110110            Vector3 velocity = this->getVelocity();
     
    121121        SUPER(Spectator, tick, dt);
    122122
    123         if (this->isLocallyControlled())
     123        if (this->hasLocalController())
    124124        {
    125125            this->setVelocity(Vector3::ZERO);
     
    134134    }
    135135
    136     void Spectator::startLocalControl()
    137     {
    138         ControllableEntity::startLocalControl();
    139 //        if (this->isLocallyControlled())
     136    void Spectator::startLocalHumanControl()
     137    {
     138        ControllableEntity::startLocalHumanControl();
     139//        if (this->hasLocalController())
    140140//            this->testmesh_->setVisible(false);
    141141    }
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2087 r2254  
    4646
    4747            virtual void setPlayer(PlayerInfo* player);
    48             virtual void startLocalControl();
     48            virtual void startLocalHumanControl();
    4949
    5050            virtual void moveFrontBack(const Vector2& value);
Note: See TracChangeset for help on using the changeset viewer.