Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2010, 1:54:49 PM (14 years ago)
Author:
dafrick
Message:

Adding all classes in modules/objects to Objects module (in doxygen).
Created TriggerBase which is the base class of Trigger and MultiTrigger and now provides the shared functionality and data.
Updated some of the documentation in MultiTrigger and Script.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    r7301 r7601  
    3030    @file MultiTrigger.h
    3131    @brief Definition of the MultiTrigger class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    4344#include <deque>
    4445
    45 #include "tools/interfaces/Tickable.h"
    46 #include "worldentities/StaticEntity.h"
     46#include "TriggerBase.h"
    4747
    4848namespace orxonox
    4949{
    5050
    51     //! The different modes the MultiTrigger can be in.
    52     namespace MultiTriggerMode
    53     {
    54         enum Value
    55         {
    56             EventTriggerAND,
    57             EventTriggerOR,
    58             EventTriggerXOR,
    59         };
    60     }
    61 
    62     //! Struct to handle MultiTrigger states internally.
     51    /**
     52    @brief
     53    Struct to handle @ref orxonox::MultiTrigger "MultiTrigger" states internally.
     54
     55    @ingroup MultiTrigger
     56    */
    6357    struct MultiTriggerState
    6458    {
     
    7064    @brief
    7165        The MultiTrigger class implements a trigger that has a distinct state for each object triggering it.
    72         In more detail: A Trigger is an object that can either be active or inactive, with a specified behavior how to switch between the two. A MultiTrigger generalizes that behavior for multiple objects triggering the trigger. A MultiTrigger can be active or inactive for any object triggering it, with the state for each object being completely independent of the state for other objects. Each time a switch occurs an Event is fired with as the originator a MultiTriggerContainer, containing a pointer to the MultiTrigger that caused the Event and a pointer to the object that caused the trigger to change it's activity.
     66        In more detail: A Trigger is an object that can either be <em>active</em> or <em>inactive</em>, with a specified behavior how to switch between the two. A MultiTrigger generalizes that behavior for multiple objects triggering the trigger. A MultiTrigger can be <em>active</em> or <em>inactive</em> for any object triggering it, with the state for each object being completely independent of the state for other objects. Each time a switch occurs an @ref orxonox::Event "Event" is fired with as the originator a @ref orxonox::MultiTriggerContainer "MultiTriggerContainer", containing a pointer to the MultiTrigger that caused the @ref orxonox::Event "Event" and a pointer to the object that caused the trigger to change it's activity.
    7367
    7468        MultiTriggers also allow for additional complexity which can be added through the choice of the parameters explained (briefly) below:
    75         But first you must understand a small implementational detail. There is a distinction between the MultiTrigger being triggered (there is the state 'triggered' for that) and the MultiTrigger being active (for that is the state 'activity'). From the outside only the activity is visible. The state 'triggered' tells us whether the trigger is actually triggered, but it could pretend (for some reason, some of which we will see shortly) to be triggered (or to the outside, active), while it in fact isn't. The standard behavior is, that the activity changes, when the MultiTrigger transits from being triggered to not being triggered or the other way around.
     69        But first you must understand a small implementational detail. There is a distinction between the MultiTrigger being triggered (there is the state <em>triggered</em> for that) and the MultiTrigger being active (for that is the state <em>activity</em>). From the outside only the <em>activity</em> is visible. The state <em>triggered</em> tells us whether the trigger is actually triggered, but it could pretend (for some reason, some of which we will see shortly) to be triggered (or to the outside, active), while it in fact isn't. The standard behavior is, that the <em>activity</em> changes, when the MultiTrigger transits from being triggered to not being triggered or the other way around.
    7670        The parameters are:
    77             'delay':                    The delay is the time that the trigger waits until it reacts (i.e. changes it's state) to the triggering condition being fulfilled.
    78             'switch':                   Switch is a bool, if true the MultiTrigger is in switch-mode, meaning, that the activity changes only when the trigger is triggered , this means, that now the activity only changes, when the trigger changes from not being triggered to being triggered but not the other way around. The default is false.
    79             'stayactive':               Stay active is also a bool, if true the MultiTrigger stays active after it has been activated as many times as specified by the parameter activations. The default is false.
    80             'activations':              The number of activations until the trigger can't be triggered anymore. The default is -1, which is infinity.
    81             'invert':                   Invert is a bool, if true the trigger is in invert-mode, meaning, that if the triggering condition is fulfilled the MultiTrigger will have the state not triggered and and if the condition is not fulfilled it will have the state triggered. In short it just inverts the behavior of the MultiTrigger. The default is false.
    82             'simultaneousTriggerers':   The number of simultaneous triggerers limits the number of objects that are allowed to trigger the MultiTrigger at the same time. Or more precisely, the number of distinct objects the MultiTrigger has 'triggered' states for, at each point in time. The default is -1, which denotes infinity.
    83             'mode':                     The mode describes how the MultiTrigger acts in relation to all the MultiTriggers, that are appended to it. There are 3 modes: 'and', meaning that the MultiTrigger can only be triggered if all the appended MultiTriggers are active. 'or', meaning that the MultiTrigger can only triggered if at least one of the appended MultiTriggers is active. And 'xor', meaning that the MultiTrigger can only be triggered if one and only one appended MultiTrigger is active. Note, that I wrote 'can only be active', that implies, that there is an additional condition to the activity of the MultiTrigger and that is the fulfillment of the triggering condition (the MultiTrigger itself doesn't have one, but all derived classes should). Also bear in mind, that the activity of a MultiTrigger is still coupled to the object that triggered it. The default is 'and'.
    84             'broadcast'                 Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaning, that all trigger events that are caused by no originator (originator is NULL) are broadcast as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger. The default is false.
    85             'target':                   The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is 'Pawn'.
    86             Also there is the possibility of appending MultiTriggers to the MultiTrigger just by adding them as sub-objects in the XML description of your MultiTrigger.
     71        - @b delay The delay is the time that the trigger waits until it reacts (i.e. changes it's state) to the triggering condition being fulfilled.
     72        - @b switch Switch is a boolean, if true the MultiTrigger is in switch-mode, meaning, that the <em>activity</em> changes only when the trigger is triggered, this means, that now the <em>activity</em> only changes, when the trigger changes from not being triggered to being triggered but not the other way around. The default is false.
     73        - @b stayactive Stay active is also a boolean, if true the MultiTrigger stays active after it has been activated as many times as specified by the parameter activations. The default is false.
     74        - @b activations The number of activations until the trigger can't be triggered anymore. The default is -1, which is infinity.
     75        - @b invert Invert is a boolean, if true the trigger is in <em>invert-mode</em>, meaning, that if the triggering condition is fulfilled the MultiTrigger will have the state not triggered and and if the condition is not fulfilled it will have the state triggered. In short it just inverts the behavior of the MultiTrigger. The default is false.
     76        - @b simultaneousTriggerers The number of simultaneous triggerers limits the number of objects that are allowed to trigger the MultiTrigger at the same time. Or more precisely, the number of distinct objects the MultiTrigger has <em>triggered</em> states for, at each point in time. The default is -1, which denotes infinity.
     77        - @b mode The mode describes how the MultiTrigger acts in relation to all the triggers, that are appended to it. There are 3 modes: <em>and</em>, meaning that the MultiTrigger can only be triggered if all the appended triggers are active. <em>or</em>, meaning that the MultiTrigger can only triggered if at least one of the appended triggers is active. And <em>xor</em>, meaning that the MultiTrigger can only be triggered if one and only one appended trigger is active. Note, that I wrote <em>can only be active</em>, that implies, that there is an additional condition to the activity of the MultiTrigger and that is the fulfillment of the triggering condition (the MultiTrigger itself doesn't have one, but all derived classes should). Also bear in mind, that the activity of a MultiTrigger is still coupled to the object that triggered it. The default is <em>and</em>.
     78        - @b broadcast Broadcast is a boolean, if true the MutliTrigger is in <em>broadcast-mode</em>, meaning, that all trigger events that are caused by no originator (originator is NULL) are broadcast as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger. The default is false.
     79        - @b target The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is @ref orxonox::Pawn "Pawn".
     80        - Also there is the possibility of appending triggers (as long as they inherit from TriggerBase) to the MultiTrigger just by adding them as children in the XML description of your MultiTrigger.
    8781
    8882        An example of a MultiTrigger created through XML would look like this:
    8983        @code
    9084        <MultiTrigger position="0,0,0" delay="1.3" switch="true" stayactive="true" activations="7" invert="true" simultaneousTriggerers="2" mode="xor" broadcast="false" target="Pawn">
    91             <MultiTrigger />
     85            <TriggerBase />
    9286            ...
    93             <MultiTrigger />
     87            <TriggerBase />
    9488        </MultiTrigger>
    9589        @endcode
     
    9791    @author
    9892        Damian 'Mozork' Frick
    99         Many concepts and loads of inspiration from the Trigger class by Benjamin Knecht.
     93
     94        Many concepts and loads of inspiration from the @ref orxonox::Trigger "Trigger" class by Benjamin Knecht.
     95
     96    @ingroup MultiTrigger
    10097    */
    101     class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable
     98    class _ObjectsExport MultiTrigger : public TriggerBase
    10299    {
    103100        public:
     
    108105            virtual void tick(float dt); //!< A method that is executed each tick.
    109106
    110             bool isActive(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is active for a given object.
    111 
    112             /**
    113             @brief Set the delay of the MultiTrigger.
    114             @param delay The delay to be set.
    115             */
    116             inline void setDelay(float delay)
    117                 { if(delay > 0.0f) this->delay_= delay; }
    118             /**
    119             @brief Get the delay of the MultiTrigger.
    120             @return The delay.
    121             */
    122             inline float getDelay(void) const
    123                 { return this->delay_; }
    124 
    125             /**
    126             @brief Set switch-mode of the MultiTrigger.
    127             @param bSwitch If true the MultiTrigger is set to switched.
    128             */
    129             inline void setSwitch(bool bSwitch)
    130                 { this->bSwitch_ = bSwitch; }
    131             /**
    132             @brief Get the switch-mode of the MultiTrigger.
    133             @return Returns true if the MultiTriger is in switch-mode.
    134             */
    135             inline bool getSwitch(void) const
    136                 { return this->bSwitch_; }
    137 
    138             /**
    139             @brief Set the stay-active-mode of the MultiTrigger.
    140             @param bStayActive If true the MultiTrigger is set to stay active.
    141             */
    142             inline void setStayActive(bool bStayActive)
    143                 { this->bStayActive_ = bStayActive; }
    144             /**
    145             @brief Get the stay-active-mode of the MultiTrigger.
    146             @return Returns true if the MultiTrigger stays active.
    147             */
    148             inline bool getStayActive(void) const
    149                 { return this->bStayActive_; }
    150 
    151             /**
    152             @brief Get the number of remaining activations of the MultiTrigger.
    153             @return The number of activations. -1 denotes infinity.
    154             */
    155             inline int getActivations(void) const
    156                 { return this->remainingActivations_; }
     107            /**
     108            @brief Check whether the MultiTrigger is active.
     109            @return Returns if the MultiTrigger is active.
     110            */
     111            inline bool isActive(void) const
     112                { return this->isActive(NULL); }
     113            bool isActive(BaseObject* triggerer = NULL) const; //!< Get whether the MultiTrigger is active for a given object.
    157114
    158115            /**
     
    161118            */
    162119            inline void setSimultaneousTriggerers(int triggerers)
    163                 { if(triggerers >= 0 || triggerers == INF_s) this->maxNumSimultaneousTriggerers_ = triggerers; }
     120                { if(triggerers >= 0 || triggerers == TriggerBase::INF_s) this->maxNumSimultaneousTriggerers_ = triggerers; }
    164121            /**
    165122            @brief Get the number of objects that are allowed to simultaneously trigger this MultiTriggger.
     
    168125            inline int getSimultaneousTriggerers(void)
    169126                { return this->maxNumSimultaneousTriggerers_; }
    170 
    171             /**
    172             @brief Set the invert-mode of the MultiTrigger.
    173             @param bInvert If true the MultiTrigger is set to invert.
    174             */
    175             inline void setInvert(bool bInvert)
    176                 { this->bInvertMode_ = bInvert; }
    177             /**
    178             @brief Get the invert-mode of the MultiTrigger.
    179             @return Returns true if the MultiTrigger is set to invert.
    180             */
    181             inline bool getInvert(void) const
    182                 { return this->bInvertMode_; }
    183 
    184             void setMode(const std::string& modeName); //!< Set the mode of the MultiTrigger.
    185             /**
    186             @brief Set the mode of the MultiTrigger.
    187             @param mode The mode of the MultiTrigger.
    188             */
    189             inline void setMode(MultiTriggerMode::Value mode) //!< Get the mode of the MultiTrigger.
    190                 { this->mode_ = mode; }
    191             const std::string& getModeString(void) const;
    192             /**
    193             @brief Get the mode of the MultiTrigger.
    194             @return Returns and Enum for the mode of the MultiTrigger.
    195             */
    196             inline MultiTriggerMode::Value getMode() const
    197                 { return mode_; }
    198127
    199128            /**
     
    218147                { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
    219148
    220             void addTrigger(MultiTrigger* trigger); //!< Adds a MultiTrigger as a sub-trigger to the trigger.
    221             const MultiTrigger* getTrigger(unsigned int index) const; //!< Get the sub-trigger of this MultiTrigger at the given index.
    222 
    223149        protected:
    224150            virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
     
    226152            void changeTriggered(BaseObject* originator = NULL); //!< This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator.
    227153
    228             bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers.
     154            bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whether the MultiTrigger is triggered concerning it's children.
    229155            bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.
    230156
     
    232158            void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
    233159
    234             /**
    235             @brief Set the number of activations the MultiTrigger can go through.
    236             @param activations The number of activations. -1 denotes infinitely many activations.
    237             */
    238             inline void setActivations(int activations)
    239                 { if(activations >= 0 || activations == INF_s) this->remainingActivations_ = activations; }
    240 
    241160            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
    242161            void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
    243162
    244163            /**
    245             @brief Adds the parent of a MultiTrigger.
    246             @param parent A pointer to the parent MultiTrigger.
    247             */
    248             inline void addParentTrigger(MultiTrigger* parent)
    249                 { this->parentTrigger_ = parent; }
    250 
    251             /**
    252164            @brief Get the target mask used to identify the targets of this MultiTrigger.
    253165            @return Returns the target mask.
     
    257169
    258170        private:
    259             static const int INF_s; //!< Magic number for infinity.
    260             //! Magic strings for the mode.
    261             static const std::string and_s;
    262             static const std::string or_s;
    263             static const std::string xor_s;
    264 
    265             void subTriggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
     171            void childActivityChanged(BaseObject* originator); //!< This method is called by any child to advertise changes in it's state to it's parent.
    266172
    267173            bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active.
    268174
    269             bool checkAnd(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'and' mode for a given object.
    270             bool checkOr(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'or' mode for a given object.
    271             bool checkXor(BaseObject* triggerer); //!< Checks whether the sub-triggers amount to true for the 'xor' mode for a given object.
     175            bool checkAnd(BaseObject* triggerer); //!< Checks whether the children amount to true for the <em>and</em> mode for a given object.
     176            bool checkOr(BaseObject* triggerer); //!< Checks whether the children amount to true for the <em>or</em> mode for a given object.
     177            bool checkXor(BaseObject* triggerer); //!< Checks whether the children amount to true for the <em>xor</em> mode for a given object.
    272178
    273179            /**
     
    278184                { return this->active_; }
    279185
    280             bool bFirstTick_; //!< Bool to distinguish the first tick form all the following.
    281 
    282             float delay_; //!< The delay that is imposed on all new trigger events.
    283             bool bSwitch_; //!< Bool for the switch-mode, if true the MultiTrigger behaves like a switch.
    284             bool bStayActive_; //!< Bool for the stay-active-mode, if true the MultiTrigger stays active after its last activation.;
    285 
    286             int remainingActivations_; //!< The remaining activations of this MultiTrigger.
    287186            int maxNumSimultaneousTriggerers_; //!< The maximum number of objects simultaneously trigggering this MultiTrigger.
    288187
    289             bool bInvertMode_; //!< Bool for the invert-mode, if true the MultiTrigger is inverted.
    290             MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger.
    291 
    292188            bool bBroadcast_; //!< Bool for the broadcast-mode, if true all triggers go to all possible targets.
    293 
    294             MultiTrigger* parentTrigger_; //!< The parent-trigger of theis MultiTrigger.
    295             std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
    296189
    297190            std::set<BaseObject*> active_; //!< The set of all objects the MultiTrigger is active for.
Note: See TracChangeset for help on using the changeset viewer.