Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6187


Ignore:
Timestamp:
Dec 1, 2009, 6:48:51 PM (15 years ago)
Author:
rgrieder
Message:

Added better engine effects: you can still add any WorldEntity to the MultiStateEngine, but you have to enclose it in an EffectContainer that has one XMLParameter called "condition". There you can write conditions containing the following words: and, or, not, idle, normal, boost, brake. The last four words are mutually exclusive states.
For an example see spaceship_assff.oxt

Location:
code/branches/presentation2
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/levels/templates/spaceship_assff.oxt

    r6147 r6187  
    7070   accelerationupdown    =  125
    7171  >
    72     <active>
     72    <EffectContainer condition="idle">
     73      <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" loop=1 active=false/>
     74    </EffectContainer>
     75    <EffectContainer condition="not idle">
    7376      <FadingBillboard mainstate=activity active=false scale=0.1 position="0, 0, 9" colour="0.2, 0.65, 1.0, 1.0" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    7477<!--
     
    7679      <Light mainstate=visibility position="-8, 0, 8" diffuse="0.3, 0.6, 1.0" specular="0.3, 0.6, 1.0" attenuation="600, 1.0, 0.007, 0.0002" type=point />
    7780-->
    78       <!--WorldSound mainstate=activity source="sounds/Engine_low.ogg" loop=1 /-->
    79     </active>
    80     <forward>
     81    </EffectContainer>
     82    <EffectContainer condition="normal or brake">
     83      <WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false/>
     84    </EffectContainer>
     85    <EffectContainer condition="normal or boost">
    8186      <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    8287      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    83       <WorldSound mainstate=activity source="sounds/Engine_low.ogg" loop=1 />
    84     </forward>
    85     <boost>
     88    </EffectContainer>
     89    <EffectContainer condition="boost">
    8690      <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" />
    8791      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" />
    88       <!--WorldSound mainstate=activity source="sounds/Engine_high.ogg" loop=1 /-->
    89     </boost>
    90     <brake>
     92      <WorldSound mainstate="activity" source="sounds/Engine_high.ogg" loop=1 active=false/>
     93    </EffectContainer>
     94    <EffectContainer condition="brake">
    9195      <FadingBillboard mainstate=activity active=false scale=0.3 position=" 8, 0, 6" colour="0.5, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    9296      <FadingBillboard mainstate=activity active=false scale=0.3 position="-8, 0, 6" colour="0.5, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    9397      <FadingBillboard mainstate=activity active=false scale=0.15 position=" 8, 0, 6" colour="1.0, 0.0, 0.0, 1.0" material="Flares/backlightflare" turnontime=0.5 turnofftime=0.5 />
    9498      <FadingBillboard mainstate=activity active=false scale=0.15 position="-8, 0, 6" colour="1.0, 0.0, 0.0, 1.0" material="Flares/backlightflare" turnontime=0.5 turnofftime=0.5 />
    95     </brake>
     99    </EffectContainer>
    96100  </MultiStateEngine>
    97101</Template>
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc

    r5929 r6187  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    2930#include "MultiStateEngine.h"
    3031
     32extern "C" {
     33#include <lua.h>
     34}
     35
     36#include "util/Convert.h"
    3137#include "core/CoreIncludes.h"
    3238#include "core/GameMode.h"
     39#include "core/LuaState.h"
    3340#include "core/XMLPort.h"
     41#include "worldentities/EffectContainer.h"
    3442#include "worldentities/pawns/SpaceShip.h"
    3543
     
    3745{
    3846    static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20;
    39 
    40     static const unsigned char STATE_ACTIVE  = 1;
    41     static const unsigned char STATE_FORWARD = 2;
    42     static const unsigned char STATE_BOOST   = 4;
    43     static const unsigned char STATE_BRAKE   = 8;
    4447
    4548    CreateFactory(MultiStateEngine);
     
    4952        RegisterObject(MultiStateEngine);
    5053
     54        this->lua_ = new LuaState();
    5155        this->state_ = 0;
    5256
     
    5963        {
    6064            // We have no ship, so the effects are not attached and won't be destroyed automatically
    61             for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
    62                 (*it)->destroy();
    63             for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    64                 (*it)->destroy();
    65             for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    66                 (*it)->destroy();
    67             for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    68                 (*it)->destroy();
     65            for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     66                for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2)
     67                    (*it2)->destroy();
     68            delete this->lua_;
    6969        }
    7070    }
     
    7373    {
    7474        SUPER(MultiStateEngine, XMLPort, xmlelement, mode);
    75 
    76         XMLPortObject(MultiStateEngine, WorldEntity, "active",  addActiveEffect,  getActiveEffect,  xmlelement, mode);
    77         XMLPortObject(MultiStateEngine, WorldEntity, "forward", addForwardEffect, getForwardEffect, xmlelement, mode);
    78         XMLPortObject(MultiStateEngine, WorldEntity, "boost",   addBoostEffect,   getBoostEffect,   xmlelement, mode);
    79         XMLPortObject(MultiStateEngine, WorldEntity, "brake",   addBrakeEffect,   getBrakeEffect,   xmlelement, mode);
     75        XMLPortObject(MultiStateEngine, EffectContainer, "",  addEffectContainer,  getEffectContainer,  xmlelement, mode);
    8076    }
    8177
     
    9793
    9894                bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD);
    99                 bool boost = (this->getShip()->getBoost() && forward);
    100                 bool brake = (direction.z > 0 && velocity.z < 0);
    101                 bool active = (direction != Vector3::ZERO && !brake);
    10295
    103                 if (active)
    104                     this->state_ |= STATE_ACTIVE;
     96                int newState = 0;
     97                if (this->getShip()->getBoost() && forward)
     98                    newState = Boost;
     99                else if (forward && !newState) // newState == Boost
     100                    newState = Normal;
     101                else if (direction.z > 0 && velocity.z < 0)
     102                    newState = Brake;
    105103                else
    106                     this->state_ &= ~STATE_ACTIVE;
     104                    newState = Idle;
    107105
    108                 if (forward)
    109                     this->state_ |= STATE_FORWARD;
    110                 else
    111                     this->state_ &= ~STATE_FORWARD;
     106                if (newState != this->state_)
     107                {
     108                    int changes = newState | this->state_;
     109                    if (changes & Idle)
     110                    {
     111                        lua_pushboolean(this->lua_->getInternalLuaState(), newState & Idle);
     112                        lua_setglobal(this->lua_->getInternalLuaState(), "idle");
     113                    }
     114                    if (changes & Normal)
     115                    {
     116                        lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal);
     117                        lua_setglobal(this->lua_->getInternalLuaState(), "normal");
     118                    }
     119                    if (changes & Brake)
     120                    {
     121                        lua_pushboolean(this->lua_->getInternalLuaState(), newState & Brake);
     122                        lua_setglobal(this->lua_->getInternalLuaState(), "brake");
     123                    }
     124                    if (changes & Boost)
     125                    {
     126                        lua_pushboolean(this->lua_->getInternalLuaState(), newState & Boost);
     127                        lua_setglobal(this->lua_->getInternalLuaState(), "boost");
     128                    }
    112129
    113                 if (boost)
    114                     this->state_ |= STATE_BOOST;
    115                 else
    116                     this->state_ &= ~STATE_BOOST;
     130                    // Update all effect conditions
     131                    for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     132                        (*it)->updateCondition();
    117133
    118                 if (brake)
    119                     this->state_ |= STATE_BRAKE;
    120                 else
    121                     this->state_ &= ~STATE_BRAKE;
     134                    this->state_ = newState;
     135                }
    122136            }
    123137
    124138            if (GameMode::isMaster())
    125139            {
    126                 for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
    127                     (*it)->setMainState(this->state_ & STATE_ACTIVE);
    128                 for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    129                     (*it)->setMainState(this->state_ & STATE_FORWARD);
    130                 for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    131                     (*it)->setMainState(this->state_ & STATE_BOOST);
    132                 for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    133                     (*it)->setMainState(this->state_ & STATE_BRAKE);
    134140            }
    135141        }
     
    145151            return;
    146152
    147         for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
    148             ship->attach(*it);
    149         for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    150             ship->attach(*it);
    151         for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    152             ship->attach(*it);
    153         for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    154             ship->attach(*it);
     153        for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
     154            for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsEnd(); ++it2)
     155                this->getShip()->attach(*it2);
    155156    }
    156157
    157     void MultiStateEngine::addActiveEffect(WorldEntity* effect)
     158    void MultiStateEngine::addEffectContainer(EffectContainer* effect)
    158159    {
    159         this->activeEffects_.push_back(effect);
     160        if (effect == NULL)
     161            return;
     162        effect->setLuaState(this->lua_, "f" + multi_cast<std::string>(this->effectContainers_.size()));
     163        this->effectContainers_.push_back(effect);
    160164        if (this->getShip())
    161             this->getShip()->attach(effect);
     165        {
     166            for (std::vector<WorldEntity*>::const_iterator it = effect->getEffectsBegin(); it != effect->getEffectsBegin(); ++it)
     167                this->getShip()->attach(*it);
     168        }
    162169    }
    163170
    164     void MultiStateEngine::addForwardEffect(WorldEntity* effect)
    165     {
    166         this->forwardEffects_.push_back(effect);
    167         if (this->getShip())
    168             this->getShip()->attach(effect);
    169     }
    170 
    171     void MultiStateEngine::addBoostEffect(WorldEntity* effect)
    172     {
    173         this->boostEffects_.push_back(effect);
    174         if (this->getShip())
    175             this->getShip()->attach(effect);
    176     }
    177 
    178     void MultiStateEngine::addBrakeEffect(WorldEntity* effect)
    179     {
    180         this->brakeEffects_.push_back(effect);
    181         if (this->getShip())
    182             this->getShip()->attach(effect);
    183     }
    184 
    185     WorldEntity* MultiStateEngine::getActiveEffect(unsigned int index) const
     171    EffectContainer* MultiStateEngine::getEffectContainer(unsigned int index) const
    186172    {
    187173        unsigned int i = 0;
    188         for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
     174        for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it)
    189175        {
    190176            if (i == index)
    191177                return (*it);
    192             ++i;
    193178        }
    194         return 0;
    195     }
    196 
    197     WorldEntity* MultiStateEngine::getForwardEffect(unsigned int index) const
    198     {
    199         unsigned int i = 0;
    200         for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
    201         {
    202             if (i == index)
    203                 return (*it);
    204             ++i;
    205         }
    206         return 0;
    207     }
    208 
    209     WorldEntity* MultiStateEngine::getBoostEffect(unsigned int index) const
    210     {
    211         unsigned int i = 0;
    212         for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
    213         {
    214             if (i == index)
    215                 return (*it);
    216             ++i;
    217         }
    218         return 0;
    219     }
    220 
    221     WorldEntity* MultiStateEngine::getBrakeEffect(unsigned int index) const
    222     {
    223         unsigned int i = 0;
    224         for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
    225         {
    226             if (i == index)
    227                 return (*it);
    228             ++i;
    229         }
    230         return 0;
     179        return NULL;
    231180    }
    232181}
  • code/branches/presentation2/src/orxonox/items/MultiStateEngine.h

    r5781 r6187  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    3233#include "OrxonoxPrereqs.h"
    3334
    34 #include <list>
     35#include <vector>
    3536#include "Engine.h"
    3637
    3738namespace orxonox
    3839{
     40    // forward declaration
     41    class EffectContainer;
     42
    3943    class _OrxonoxExport MultiStateEngine : public Engine
    4044    {
    4145        public:
     46            enum EngineState
     47            {
     48                Idle    = 1,
     49                Normal  = 2,
     50                Brake   = 4,
     51                Boost   = 8
     52            };
     53
    4254            MultiStateEngine(BaseObject* creator);
    4355            virtual ~MultiStateEngine();
     
    5062            virtual void addToSpaceShip(SpaceShip* ship);
    5163
    52             void addActiveEffect(WorldEntity* effect);
    53             void addForwardEffect(WorldEntity* effect);
    54             void addBoostEffect(WorldEntity* effect);
    55             void addBrakeEffect(WorldEntity* effect);
    56 
    57             WorldEntity* getActiveEffect(unsigned int index) const;
    58             WorldEntity* getForwardEffect(unsigned int index) const;
    59             WorldEntity* getBoostEffect(unsigned int index) const;
    60             WorldEntity* getBrakeEffect(unsigned int index) const;
     64            void addEffectContainer(EffectContainer* effect);
     65            EffectContainer* getEffectContainer(unsigned int index) const;
    6166
    6267        private:
    63             unsigned char state_;
    64             std::list<WorldEntity*> activeEffects_;
    65             std::list<WorldEntity*> forwardEffects_;
    66             std::list<WorldEntity*> boostEffects_;
    67             std::list<WorldEntity*> brakeEffects_;
     68            int state_;
     69            LuaState* lua_;
     70            std::vector<EffectContainer*> effectContainers_;
    6871    };
    6972}
  • code/branches/presentation2/src/orxonox/worldentities/CMakeLists.txt

    r5781 r6187  
    77
    88  BigExplosion.cc
     9  EffectContainer.cc
    910  ExplosionChunk.cc
    1011  CameraPosition.cc
Note: See TracChangeset for help on using the changeset viewer.