Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7601


Ignore:
Timestamp:
Oct 30, 2010, 1:54:49 PM (13 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.

Location:
code/trunk
Files:
2 added
35 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/doc/api/Groups.dox

    r7552 r7601  
    184184    @defgroup Objects Objects
    185185    @ingroup Modules
     186
     187    @defgroup Collisionshapes Collisionshapes
     188    @ingroup Objects
     189
     190    @defgroup Eventsystem Eventsystem
     191    @ingroup Objects
     192
     193    @defgroup Triggers Triggers
     194    @ingroup Objects
     195
     196    @defgroup NormalTrigger Trigger
     197    @ingroup Triggers
     198
     199    @defgroup MultiTrigger MultiTrigger
     200    @ingroup Triggers
    186201*/
    187202
  • code/trunk/src/modules/objects/Attacher.h

    r5781 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file Attacher.h
     31    @brief Definition of the Attacher class.
     32    @ingroup Objects
     33*/
    2834
    2935#ifndef _Attacher_H__
  • code/trunk/src/modules/objects/ForceField.h

    r5781 r7601  
    2727 */
    2828
     29/**
     30    @file ForceField.h
     31    @brief Definition of the ForceField class.
     32    @ingroup Objects
     33*/
    2934
    3035#ifndef _ForceField_H__
  • code/trunk/src/modules/objects/ObjectsPrereqs.h

    r7163 r7601  
    9393    class MultiTriggerContainer;
    9494    class Trigger;
     95    class TriggerBase;
    9596}
    9697
  • code/trunk/src/modules/objects/Planet.h

    r7163 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file Planet.h
     31    @brief Definition of the Planet class.
     32    @ingroup Objects
     33*/
    2834
    2935#ifndef _Planet_H__
  • code/trunk/src/modules/objects/Script.h

    r7486 r7601  
    2828 */
    2929
     30/**
     31    @file Script.h
     32    @brief Definition of the Script class.
     33    @ingroup Objects
     34*/
     35
    3036#ifndef _Script_H__
    3137#define _Script_H__
     
    4248{
    4349
     50    /**
     51    @brief The mode a specific @ref orxonox::Script "Script" is in.
     52    */
    4453    namespace ScriptMode
    4554    {
    46         //! Modes of the Script class.
    4755        enum Value
    4856        {
    49             normal,
    50             lua
     57            normal, //!< The @ref orxonox::Script "Scripts'" code is executed through the @ref orxonox::CommandExecutor "CommandExecutor".
     58            lua //!< The @ref orxonox::Script "Scripts'" code is executed through lua.
    5159        };
    5260    }
     
    5664        The Script class lets you execute a piece of code, either the normal way or in lua, through XML. It can be specified whether the code is executed upon loading (creation) of the object. Additionally the code is executed each time a trigger event comes in.
    5765        There are three parameters:
    58         'code': The code that should be executed.
    59         'mode': The mode, specifying whether the set code should be executed the normal way ('normal') or in lua ('lua'). Default is 'normal'.
    60         'onLoad': Whether the code is executed upon loading (creation) of this object. If this is set the code is executed ofr all players, regardless of the value of parameter 'forAll'. Default is true.
    61         'needsGraphics': Whether the code needs graphics to be executed or not. Default is false.
    62         'forAll': Whether the code is executed for all players each time the Script is triggered or jut for the player triggering the Script. If forAll is false, which is default, the event that triggers the Script must come from a PlayerTrigger.
     66        - @b code The code that should be executed.
     67        - @b mode The mode, specifying whether the set code should be executed the normal way (<em>normal</em>) or in lua (<em>lua</em>). Default is <em>normal</em>.
     68        - @b onLoad Whether the code is executed upon loading (creation) of this object. If this is set the code is executed ofr all players, regardless of the value of parameter <em>forAll</em>. Default is true.
     69        - @b needsGraphics Whether the code needs graphics to be executed or not. Default is false.
     70        - @b forAll Whether the code is executed for all players each time the Script is triggered or jut for the player triggering the Script. If forAll is false, which is default, the event that triggers the Script must come from a @ref orxonox::PlayerTrigger "PlayerTrigger".
    6371
    6472        Here are two examples illustrating the usage:
     
    6674        <Script code="showGUI QuestGUI" needsGraphics=true />
    6775        @endcode
    68         This would show the QuestGUI opon creation of the object. The mode is 'normal', not specified here since that is the default, also onLoad is true, also not specified, since it is the default as well. Also needsGraphics is set to true because showGUI needs graphics to work.
     76        This would show the QuestGUI opon creation of the object. The <em>mode</em> is <em>normal</em>, not specified here since that is the default, also <em>onLoad</em> is true, also not specified, since it is the default as well. Also <em>needsGraphics</em> is set to true because showGUI needs graphics to work.
    6977
    7078        @code
     
    7785        </Script>
    7886        @endcode
    79         This would hide the QuestGUI as soon as a Pawn got in range of the DistanceTrigger. The mode is 'normal', it is specified here, but could be ommitted as well, since it is the default. OnLoad is false, that is why it can't be ommitted. Also needsGraphics is set to true because showGUI needs graphics to work.
     87        This would hide the QuestGUI as soon as a @ref orxonox::Pawn "Pawn" got in range of the @ref orxonox::DistanceTrigger "DistanceTrigger". The mode is <em>normal</em>, it is specified here, but could be ommitted as well, since it is the default. <em>OnLoad</em> is false, that is why it can't be ommitted. Also <em>needsGraphics</em> is set to true because showGUI needs graphics to work.
     88
    8089    @author
    8190        Benjamin Knecht
  • code/trunk/src/modules/objects/collisionshapes/BoxCollisionShape.h

    r7163 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file BoxCollisionShape.h
     31    @brief Definition of the BoxCollisionShape class.
     32    @ingroup Collisionshapes
     33*/
    2834
    2935#ifndef _BoxCollisionShape_H__
  • code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h

    r7163 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file ConeCollisionShape.h
     31    @brief Definition of the ConeCollisionShape class.
     32    @ingroup Collisionshapes
     33*/
    2834
    2935#ifndef _ConeCollisionShape_H__
  • code/trunk/src/modules/objects/collisionshapes/PlaneCollisionShape.h

    r7163 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file PlaneCollisionShape.h
     31    @brief Definition of the PlaneCollisionShape class.
     32    @ingroup Collisionshapes
     33*/
    2834
    2935#ifndef _PlaneCollisionShape_H__
  • code/trunk/src/modules/objects/collisionshapes/SphereCollisionShape.h

    r7163 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file SphereCollisionShape.h
     31    @brief Definition of the SphereCollisionShape class.
     32    @ingroup Collisionshapes
     33*/
    2834
    2935#ifndef _SphereCollisionShape_H__
  • code/trunk/src/modules/objects/eventsystem/EventDispatcher.h

    r5929 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file EventDispatcher.h
     31    @brief Definition of the EventDispatcher class.
     32    @ingroup Eventsystem
     33*/
    2834
    2935#ifndef _EventDispatcher_H__
  • code/trunk/src/modules/objects/eventsystem/EventFilter.h

    r5929 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file EventFilter.h
     31    @brief Definition of the EventFilter class.
     32    @ingroup Eventsystem
     33*/
    2834
    2935#ifndef _EventFilter_H__
  • code/trunk/src/modules/objects/eventsystem/EventListener.h

    r5929 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file EventListener.h
     31    @brief Definition of the EventListener class.
     32    @ingroup Eventsystem
     33*/
    2834
    2935#ifndef _EventListener_H__
  • code/trunk/src/modules/objects/eventsystem/EventName.h

    r5929 r7601  
    2727 */
    2828
     29/**
     30    @file EventName.h
     31    @brief Definition of the EventName class.
     32    @ingroup Eventsystem
     33*/
     34
    2935#ifndef _EventName_H__
    3036#define _EventName_H__
  • code/trunk/src/modules/objects/eventsystem/EventTarget.h

    r6417 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file EventTarget.h
     31    @brief Definition of the EventTarget class.
     32    @ingroup Eventsystem
     33*/
    2834
    2935#ifndef _EventTarget_H__
  • code/trunk/src/modules/objects/triggers/CMakeLists.txt

    r6906 r7601  
    99  MultiTriggerContainer.cc
    1010  Trigger.cc
     11  TriggerBase.cc
    1112)
  • code/trunk/src/modules/objects/triggers/CheckPoint.cc

    r7163 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file CheckPoint.cc
     31    @brief Implementation of the CheckPoint class.
     32    @ingroup NormalTrigger
     33*/
    2834
    2935#include "CheckPoint.h"
  • code/trunk/src/modules/objects/triggers/CheckPoint.h

    r5781 r7601  
    2828
    2929/**
    30     @file
    31     @brief
     30    @file CheckPoint.h
     31    @brief Definition of the CheckPoint class.
     32    @ingroup NormalTrigger
    3233*/
    3334
     
    4243namespace orxonox
    4344{
     45
     46    /**
     47    @brief
     48
     49    @author
     50        Aurelian Jaggi
     51
     52    @ingroup NormalTrigger
     53    */
    4454    class _ObjectsExport CheckPoint : public DistanceTrigger, public RadarViewable
    4555    {
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc

    r7301 r7601  
    3030    @file DistanceMultiTrigger.cc
    3131    @brief Implementation of the DistanceMultiTrigger class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    3637#include "core/CoreIncludes.h"
    3738#include "core/XMLPort.h"
     39
    3840#include "DistanceTriggerBeacon.h"
    3941
     
    131133            if(this->singleTargetMode_)
    132134            {
    133                 // If the object that is a target is no DistanceTriggerBeacon, then the DistanceMultiTrigger can't be in single-target-mode.
     135                // If the object that is a target is no DistanceTriggerBeacon, then the DistanceMultiTrigger can't be in single-target mode.
    134136                if(!entity->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()))
    135137                {
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h

    r7301 r7601  
    3030    @file DistanceMultiTrigger.h
    3131    @brief Definition of the DistanceMultiTrigger class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    3738#include "objects/ObjectsPrereqs.h"
    3839
     40#include <map>
     41
     42#include "core/WeakPtr.h"
     43
    3944#include "worldentities/WorldEntity.h"
    40 #include "core/WeakPtr.h"
    41 #include <map>
    4245
    4346#include "MultiTrigger.h"
     
    4851    /**
    4952    @brief
    50         The DistanceMultiTrigger is a trigger that triggers whenever an object (that is of the specified target type) is in a specified range of the DistanceMultiTrigger. The object can be specified further by adding a DistanceTriggerBeacon (just attaching it) to the objects that can trigger this DistanceMultiTrigger and specify the name of the DistanceTriggerBeacon with the parameter targetname and only objects that have a DistanceTriggerBeacon with that name attached will trigger the DistanceMultiTrigger.
     53        The DistanceMultiTrigger is a MultiTrigger that triggers whenever an object (that is of the specified target type) is in a specified range of the DistanceMultiTrigger. The object can be specified further by adding a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" (by just attaching it) to the objects that can trigger this DistanceMultiTrigger and specify the name of the @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with the parameter <em>targetname</em> and only objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with that name will trigger the DistanceMultiTrigger.
    5154        Parameters are (additional to the ones of MultiTrigger):
    52             'distance', which specifies the maximum distance at which the DistanceMultiTrigger still triggers. Default is 100.
    53             'targetname', which, if not left blank, causes the DistancMultiTrigger to be in single-target mode, meaning, that it only reacts to objects that have a DistanceTriggerBeacon (therefore the target has to be set to DistanceTriggerBeacon for it to work), with the name specified by targetname, attached.
     55        - @b distance Which specifies the maximum distance at which the DistanceMultiTrigger still triggers. Default is 100.
     56        - @b targetname Which, if not left blank, causes the DistancMultiTrigger to be in <em>single-target</em> mode, meaning, that it only reacts to objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" (therefore the target has to be set to @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" for it to work), with the name specified by <em>targetname</em>, attached.
    5457
    5558        A simple DistanceMultiTrigger would look like this:
     
    5861        @endcode
    5962
    60         An implementation that only reacts to objects with a DistanceTriggerBeacon attached would look like this:
     63        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
    6164        @code
    6265        <DistanceMultiTrigger position="0,0,0" target="DistanceMultiTrigger" targetname="beacon1" distance="30" />
    6366        @endcode
    64         This particular DistanceMultiTrigger would only react if an object was in range, that had a DistanceTriggerBeacon with the name 'beacon1' attached.
    65     @see MultiTrigger.h
     67        This particular DistanceMultiTrigger would only react if an object was in range, that had a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with the name <em>beacon1</em> attached.
     68
     69    @see MultiTrigger
    6670        For more information on MultiTriggers.
     71
    6772    @author
    6873        Damian 'Mozork' Frick
     74
     75    @ingroup MultiTrigger
    6976    */
    7077    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
     
    106113        private:
    107114            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
    108             std::string targetName_; //!< The target name, used in singleTargetMode.
    109             bool singleTargetMode_; //!< To indicate whe the MultiDistanceTrigger is in single-target-mode.
     115            std::string targetName_; //!< The target name, used in <em>single-target</em> mode.
     116            bool singleTargetMode_; //!< To indicate whe the MultiDistanceTrigger is in <em>single-target</em> mode.
    110117
    111118            std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
  • code/trunk/src/modules/objects/triggers/DistanceTrigger.cc

    r7301 r7601  
    2727 */
    2828
     29/**
     30    @file DistanceTrigger.cc
     31    @brief Implementation of the DistanceTrigger class.
     32    @ingroup NormalTrigger
     33*/
     34
    2935#include "DistanceTrigger.h"
    3036
     
    4652    this->targetName_ = BLANKSTRING;
    4753    this->singleTargetMode_ = false;
    48     this->setForPlayer(false); //!< Normally hasn't just players as targets.
    4954  }
    5055
  • code/trunk/src/modules/objects/triggers/DistanceTrigger.h

    r7301 r7601  
    2727 */
    2828
     29/**
     30    @file DistanceTrigger.h
     31    @brief Definition of the DistanceTrigger class.
     32    @ingroup NormalTrigger
     33*/
     34
    2935#ifndef _DistanceTrigger_H__
    3036#define _DistanceTrigger_H__
     
    3945namespace orxonox
    4046{
     47
     48  /**
     49  @brief
     50
     51  @author
     52    Benjamin Knecht
     53  @author
     54    Damian 'Mozork' Frick
     55
     56  @ingroup NormalTrigger
     57  */
    4158  class _ObjectsExport DistanceTrigger : public Trigger, public PlayerTrigger
    4259  {
  • code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc

    r7301 r7601  
    3030    @file DistanceTriggerBeacon.cc
    3131    @brief Implementation of the DistanceTriggerBeacon class.
     32    @ingroup Triggers
    3233*/
    3334
  • code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h

    r7301 r7601  
    3030    @file DistanceTriggerBeacon.h
    3131    @brief Definition of the DistanceTriggerBeacon class.
     32    @ingroup Triggers
    3233*/
    3334
     
    4445    /**
    4546    @brief
    46         A DistanceTriggerBeacon can be used together with a DistanceTrigger or a DistanceMultiTrigger to make them only react to specific objects.
    47         This can be done by attaching a DistanceTriggerBeacon to an object, giving it a unique name and setting the targetname in the DistanceTrigger (or DistanceMultiTrigger) to that name and the target to DistanceTriggerBeacon.
     47        A DistanceTriggerBeacon can be used together with a @ref orxonox::DistanceTrigger "DistanceTrigger" or a @ref orxonox::DistanceMultiTrigger "DistanceMultiTrigger" to make them only react to specific objects.
     48        This can be done by attaching a DistanceTriggerBeacon to an object, giving it a unique name and setting the targetname in the @ref orxonox::DistanceTrigger "DistanceTrigger" (or @ref orxonox::DistanceMultiTrigger "DistanceMultiTrigger") to that name and the target to DistanceTriggerBeacon.
     49
    4850    @author
    4951        Damian 'Mozork' Frick
     52
     53    @ingroup Triggers
    5054    */
    5155    class _ObjectsExport DistanceTriggerBeacon : public StaticEntity
  • code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc

    r7301 r7601  
    3030    @file EventMultiTrigger.cc
    3131    @brief Implementation of the EventMultiTrigger class.
     32    @ingroup MultiTrigger
    3233*/
    3334
  • code/trunk/src/modules/objects/triggers/EventMultiTrigger.h

    r7301 r7601  
    3030    @file EventMultiTrigger.h
    3131    @brief Definition of the EventMultiTrigger class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    4445    /**
    4546    @brief
    46         The EventMultiTrigger class is the equivalent of the EventTrigger class for MultiTriggers.
    47         Consequentially what it does is it provides a way to have a MultiTrigger triggered by any kinds of events.
    48         Events that are not caused by a MultiTrigger or by a MultiTrigger with an originator that is no target of this EventMultiTrigger are broadcasted to all entities that are the target of this EventMultitrigger. Events that are caused by MultiTriggers with an originator that is a target of this EventMultiTrigger just trigger the EventMultiTrigger for the originator that caused the MultiTrigger to trigger. Thus showing the equivalent behavior to the EventTrigger.
     47        The EventMultiTrigger class is the equivalent of the @ref orxonox::EventTrigger "EventTrigger" class for MultiTriggers.
     48        Consequentially what it does is it provides a way to have a MultiTrigger triggered by any kinds of @ref orxonox::Event "Events".
     49        @ref orxonox::Event "Events" that are not caused by a MultiTrigger, or that are caused by a MultiTrigger with an originator that is no target of this EventMultiTrigger, are broadcasted to all entities that are the target of this EventMultiTrigger. @ref orxonox::Event "Events" that are caused by @ref orxonox::MultiTrigger "MultiTriggers" with an originator that is a target of this EventMultiTrigger just trigger the EventMultiTrigger for the originator that caused the MultiTrigger to trigger. Thus showing the equivalent behavior to the @ref orxonox::EventTrigger "EventTrigger".
    4950
    5051        Example:
     
    5960        </EventMultiTrigger>
    6061        @endcode
    61     @see MultiTrigger.h
     62
     63    @see MultiTrigger
    6264        For more information on MultiTriggers.
     65
    6366    @author
    6467        Damian 'Mozork' Frick
     68
     69    @ingroup MultiTrigger
    6570    */
    6671    class _ObjectsExport EventMultiTrigger : public MultiTrigger
     
    7580
    7681        private:
    77             void trigger(bool bTriggered, BaseObject* originator); //!< Method that causes the EventMultiTrigger to trigger upon receiving an event.
     82            void trigger(bool bTriggered, BaseObject* originator); //!< Method that causes the EventMultiTrigger to trigger upon receiving an @ref orxonox::Event "Event".
    7883
    7984    };
  • code/trunk/src/modules/objects/triggers/EventTrigger.cc

    r5929 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file EventTrigger.cc
     31    @brief Implementation of the EventTrigger class.
     32    @ingroup NormalTrigger
     33*/
    2834
    2935#include "EventTrigger.h"
  • code/trunk/src/modules/objects/triggers/EventTrigger.h

    r5929 r7601  
    2727 */
    2828
     29/**
     30    @file EventTrigger.h
     31    @brief Definition of the EventTrigger class.
     32    @ingroup NormalTrigger
     33*/
     34
    2935#ifndef _EventTrigger_H__
    3036#define _EventTrigger_H__
     
    3541namespace orxonox
    3642{
     43
     44    /**
     45    @brief
     46
     47    @author
     48        Fabian 'x3n' Landau
     49
     50    @ingroup NormalTrigger
     51    */
    3752    class _ObjectsExport EventTrigger : public Trigger
    3853    {
  • code/trunk/src/modules/objects/triggers/MultiTrigger.cc

    r7301 r7601  
    3030    @file MultiTrigger.cc
    3131    @brief Implementation of the MultiTrigger class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    4142namespace orxonox
    4243{
    43 
    44     // Initialization of some static (magic) variables.
    45     /*static*/ const int MultiTrigger::INF_s = -1;
    46     /*static*/ const std::string MultiTrigger::and_s = "and";
    47     /*static*/ const std::string MultiTrigger::or_s = "or";
    48     /*static*/ const std::string MultiTrigger::xor_s = "xor";
    4944
    5045    CreateFactory(MultiTrigger);
     
    5651        The creator.
    5752    */
    58     MultiTrigger::MultiTrigger(BaseObject* creator) : StaticEntity(creator)
     53    MultiTrigger::MultiTrigger(BaseObject* creator) : TriggerBase(creator)
    5954    {
    6055        RegisterObject(MultiTrigger);
    6156
    62         this->bFirstTick_ = true;
    63 
    64         this->delay_ = 0.0f;
    65         this->bSwitch_ = false;
    66         this->bStayActive_ = false;
    67 
    68         this->remainingActivations_ = INF_s;
    6957        this->maxNumSimultaneousTriggerers_ = INF_s;
    7058
    71         this->bInvertMode_ = false;
    72         this->mode_ = MultiTriggerMode::EventTriggerAND;
    73 
    7459        this->bBroadcast_ = false;
    7560
    76         this->parentTrigger_ = NULL;
    77 
    7861        this->targetMask_.exclude(Class(BaseObject));
     62
     63        this->bMultiTrigger_ = true;
    7964
    8065        this->setSyncMode(0x0);
     
    10590        SUPER(MultiTrigger, XMLPort, xmlelement, mode);
    10691
    107         XMLPortParam(MultiTrigger, "delay", setDelay, getDelay, xmlelement, mode);
    108         XMLPortParam(MultiTrigger, "switch", setSwitch, getSwitch, xmlelement, mode);
    109         XMLPortParam(MultiTrigger, "stayactive", setStayActive, getStayActive, xmlelement, mode);
    110         XMLPortParam(MultiTrigger, "activations", setActivations, getActivations, xmlelement, mode);
    11192        XMLPortParam(MultiTrigger, "simultaneousTriggerers", setSimultaneousTriggerers, getSimultaneousTriggerers, xmlelement, mode);
    112         XMLPortParam(MultiTrigger, "invert", setInvert, getInvert, xmlelement, mode);
    113         XMLPortParamTemplate(MultiTrigger, "mode", setMode, getModeString, xmlelement, mode, const std::string&);
    11493        XMLPortParam(MultiTrigger, "broadcast", setBroadcast, getBroadcast, xmlelement, mode);
    11594        XMLPortParamLoadOnly(MultiTrigger, "target", addTargets, xmlelement, mode).defaultValues("Pawn"); //TODO: Remove load only
    11695
    117         XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode);
    118 
    11996        COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl;
    12097    }
     
    124101    @brief
    125102        A method that is executed each tick.
     103        Most of the magic of MultiTriggers happens here.
    126104    @param dt
    127105        The duration of the last tick.
    128106    */
     107    //TODO: Segment into some helper methods?
    129108    void MultiTrigger::tick(float dt)
    130109    {
     
    159138
    160139                // The new triggered state dependent on the requested state, the mode and the invert-mode.
    161                 bool bTriggered = (state->bTriggered & this->isModeTriggered(state->originator)) ^ this->bInvertMode_;
     140                bool bTriggered = (state->bTriggered & this->isModeTriggered(state->originator)) ^ this->getInvert();
    162141
    163142                // If the 'triggered' state has changed or the MultiTrigger has delay and thus we don't know whether this state will actually change the 'triggered' state, a new state is added to the state queue.
    164                 if(this->delay_ > 0.0f || bTriggered ^ this->isTriggered(state->originator))
     143                if(this->getDelay() > 0.0f || bTriggered ^ this->isTriggered(state->originator))
    165144                {
    166145                    state->bTriggered = bTriggered;
     
    192171                {
    193172                    // If the maximum number of objects simultaneously triggering this MultiTrigger is not exceeded.
    194                     if(this->maxNumSimultaneousTriggerers_ == INF_s || this->triggered_.size() < (unsigned int)this->maxNumSimultaneousTriggerers_)
     173                    if(this->getSimultaneousTriggerers() == TriggerBase::INF_s || this->triggered_.size() < (unsigned int)this->getSimultaneousTriggerers())
    195174                    {
    196175                        bool bStateChanged = false;
     
    211190                        bool bActive;
    212191                        // If the MultiTrigger is in switch mode the 'active'-state only changes of the state changed to triggered.
    213                         if(this->bSwitch_ && !state->bTriggered)
     192                        if(this->getSwitch() && !state->bTriggered)
    214193                            bActive = this->isActive(state->originator);
    215194                        else
     
    239218                            {
    240219                                // If the MultiTrigger doesn't stay active or hasn't' exceeded its remaining activations.
    241                                 if(!this->bStayActive_ || this->remainingActivations_ > 0)
     220                                if(!this->getStayActive() || this->remainingActivations_ > 0)
    242221                                    this->active_.erase(state->originator);
    243222                                else
     
    249228                            {
    250229                                // If the MultiTrigger is set to broadcast and has no originator a boradcast is fired.
    251                                 if(this->bBroadcast_ && state->originator == NULL)
     230                                if(this->getBroadcast() && state->originator == NULL)
    252231                                    this->broadcast(bActive);
    253232                                // Else a normal event is fired.
     
    267246                                COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: NULL, active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
    268247
    269                             // If the MultiTrigger has a parent trigger it needs to call a method to notify him, that its activity has changed.
    270                             if(this->parentTrigger_ != NULL)
    271                                 this->parentTrigger_->subTriggerActivityChanged(state->originator);
     248                            // If the MultiTrigger has a parent trigger, that is itself a MultiTrigger, it needs to call a method to notify him, that its activity has changed.
     249                            if(this->parent_ != NULL && this->parent_->isMultiTrigger())
     250                                static_cast<MultiTrigger*>(this->parent_)->childActivityChanged(state->originator);
    272251                        }
    273252
     
    302281        Returns true if the MultiTrigger is active, false if not.
    303282    */
    304     bool MultiTrigger::isActive(BaseObject* triggerer)
    305     {
    306         std::set<BaseObject*>::iterator it = this->active_.find(triggerer);
     283    bool MultiTrigger::isActive(BaseObject* triggerer) const
     284    {
     285        std::set<BaseObject*>::const_iterator it = this->active_.find(triggerer);
    307286        if(it == this->active_.end())
    308287            return false;
    309288        return true;
    310     }
    311 
    312     /**
    313     @brief
    314         Set the mode of the MultiTrigger.
    315     @param modeName
    316         The name of the mode as a string.
    317     */
    318     void MultiTrigger::setMode(const std::string& modeName)
    319     {
    320         if (modeName == MultiTrigger::and_s)
    321             this->setMode(MultiTriggerMode::EventTriggerAND);
    322         else if (modeName == MultiTrigger::or_s)
    323             this->setMode(MultiTriggerMode::EventTriggerOR);
    324         else if (modeName == MultiTrigger::xor_s)
    325             this->setMode(MultiTriggerMode::EventTriggerXOR);
    326         else
    327             COUT(2) << "Invalid mode '" << modeName << "' in MultiTrigger " << this->getName() << " &(" << this << "). Leaving mode at '" << this->getModeString() << "'." << std::endl;
    328     }
    329 
    330     /**
    331     @brief
    332         Get the mode of the MultiTrigger.
    333     @return
    334         Returns the mode as a string.
    335     */
    336     const std::string& MultiTrigger::getModeString() const
    337     {
    338         if (this->mode_ == MultiTriggerMode::EventTriggerAND)
    339             return MultiTrigger::and_s;
    340         else if (this->mode_ == MultiTriggerMode::EventTriggerOR)
    341             return MultiTrigger::or_s;
    342         else if (this->mode_ == MultiTriggerMode::EventTriggerXOR)
    343             return MultiTrigger::xor_s;
    344         else // This can never happen, but the compiler needs it to feel secure.
    345             return MultiTrigger::and_s;
    346289    }
    347290
     
    397340    /**
    398341    @brief
    399         Adds a MultiTrigger as a sub-trigger to the trigger.
    400         Beware: Loops are not prevented and potentially very bad, so just don't create any loops.
    401     @param trigger
    402         The MultiTrigger to be added.
    403     */
    404     void MultiTrigger::addTrigger(MultiTrigger* trigger)
    405     {
    406         if (this != trigger && trigger != NULL)
    407             this->subTriggers_.insert(trigger);
    408         trigger->addParentTrigger(this);
    409     }
    410 
    411     /**
    412     @brief
    413         Get the sub-trigger of this MultiTrigger at the given index.
    414     @param index
    415         The index.
    416     @return
    417         Returns a pointer ot the MultiTrigger. NULL if no such trigger exists.
    418     */
    419     const MultiTrigger* MultiTrigger::getTrigger(unsigned int index) const
    420     {
    421         // If the index is greater than the number of sub-triggers.
    422         if (this->subTriggers_.size() <= index)
    423             return NULL;
    424 
    425         std::set<MultiTrigger*>::const_iterator it;
    426         it = this->subTriggers_.begin();
    427 
    428         for (unsigned int i = 0; i != index; ++i)
    429             ++it;
    430 
    431         return (*it);
    432     }
    433 
    434     /**
    435     @brief
    436342        This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
    437343        This method is the device for the behavior (the conditions under which the MultiTrigger triggers) of any derived class of MultiTrigger.
     
    456362    {
    457363        MultiTriggerState* state = new MultiTriggerState;
    458         state->bTriggered = (!this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->bInvertMode_;
     364        state->bTriggered = (!this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->getInvert();
    459365        state->originator = originator;
    460366        this->addState(state);
     
    463369    /**
    464370    @brief
    465         This method is called by any sub-trigger to advertise changes in its state to its parent-trigger.
     371        This method is called by any child to advertise changes in its state to its parent.
    466372    @param originator
    467373        The object that caused the change in activity.
    468374    */
    469     void MultiTrigger::subTriggerActivityChanged(BaseObject* originator)
     375    void MultiTrigger::childActivityChanged(BaseObject* originator)
    470376    {
    471377        MultiTriggerState* state = new MultiTriggerState;
    472         state->bTriggered = (this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->bInvertMode_;
     378        state->bTriggered = (this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->getInvert();
    473379        state->originator = originator;
    474380        this->addState(state);
     
    477383    /**
    478384    @brief
    479         Checks whether the sub-triggers are in such a way that, according to the mode of the MultiTrigger, the MultiTrigger is triggered (only considering the sub-triggers, not the state of MultiTrigger itself), for a given object.
    480         To make an example: When the mode is 'and', then this would be true or a given object if all the sub-triggers were triggered for the given object.
     385        Checks whether the children are in such a way that, according to the mode of the MultiTrigger, the MultiTrigger is triggered (only considering the children, not the state of MultiTrigger itself), for a given object.
     386        To make an example: When the mode is <em>and</em>, then this would be true or a given object if all the children were triggered for the given object.
    481387    @param triggerer
    482388        The object.
    483389    @return
    484         Returns true if the MultiTrigger is triggered concerning it's sub-triggers.
     390        Returns true if the MultiTrigger is triggered concerning it's children.
    485391    */
    486392    bool MultiTrigger::isModeTriggered(BaseObject* triggerer)
    487393    {
    488         if(this->subTriggers_.size() != 0)
    489         {
    490             bool returnVal = false;
     394        if(this->children_.size() != 0)
     395        {
     396            bool triggered = false;
    491397
    492398            switch(this->mode_)
    493399            {
    494                 case MultiTriggerMode::EventTriggerAND:
    495                     returnVal = checkAnd(triggerer);
     400                case TriggerMode::EventTriggerAND:
     401                    triggered = checkAnd(triggerer);
    496402                    break;
    497                 case MultiTriggerMode::EventTriggerOR:
    498                     returnVal = checkOr(triggerer);
     403                case TriggerMode::EventTriggerOR:
     404                    triggered = checkOr(triggerer);
    499405                    break;
    500                 case MultiTriggerMode::EventTriggerXOR:
    501                     returnVal = checkXor(triggerer);
     406                case TriggerMode::EventTriggerXOR:
     407                    triggered = checkXor(triggerer);
    502408                    break;
    503409                default: // This will never happen.
    504                     returnVal = false;
     410                    triggered = false;
    505411                    break;
    506412            }
    507413
    508             return returnVal;
     414            return triggered;
    509415        }
    510416
     
    585491
    586492        // Add it ot the state queue with the delay specified for the MultiTrigger.
    587         this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(this->delay_, state));
     493        this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(this->getDelay(), state));
    588494
    589495        return true;
     
    592498    /**
    593499    @brief
    594         Checks whether the sub-triggers amount to true for the 'and' mode for a given object.
     500        Checks whether the children amount to true for the <em>and</em> mode for a given object.
    595501    @param triggerer
    596502        The object.
     
    600506    bool MultiTrigger::checkAnd(BaseObject* triggerer)
    601507    {
    602         for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
    603         {
    604             if(!(*it)->isActive(triggerer))
    605                 return false;
     508        for(std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it)
     509        {
     510            TriggerBase* trigger = *it;
     511            if(trigger->isMultiTrigger())
     512            {
     513                if(!static_cast<MultiTrigger*>(trigger)->isActive(triggerer))
     514                    return false;
     515            }
     516            else
     517            {
     518                if(!trigger->isActive())
     519                    return false;
     520            }
    606521        }
    607522        return true;
     
    610525    /**
    611526    @brief
    612         Checks whether the sub-triggers amount to true for the 'or' mode for a given object.
     527        Checks whether the children amount to true for the <em>or</em> mode for a given object.
    613528    @param triggerer
    614529        The object.
     
    618533    bool MultiTrigger::checkOr(BaseObject* triggerer)
    619534    {
    620         for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
    621         {
    622             if((*it)->isActive(triggerer))
    623                 return true;
     535        for(std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it)
     536        {
     537            TriggerBase* trigger = *it;
     538            if(trigger->isMultiTrigger())
     539            {
     540                if(static_cast<MultiTrigger*>(trigger)->isActive(triggerer))
     541                    return true;
     542            }
     543            else
     544            {
     545                if(trigger->isActive())
     546                    return true;
     547            }
    624548        }
    625549        return false;
     
    628552    /**
    629553    @brief
    630         Checks whether the sub-triggers amount to true for the 'xor' mode for a given object.
     554        Checks whether the children amount to true for the <em>xor</em> mode for a given object.
    631555    @param triggerer
    632556        The object.
     
    636560    bool MultiTrigger::checkXor(BaseObject* triggerer)
    637561    {
    638         bool test = false;
    639         for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
    640         {
    641             if(test && (*it)->isActive(triggerer))
    642                 return false;
    643 
    644             if((*it)->isActive(triggerer))
    645                 test = true;
    646         }
    647         return test;
     562        bool triggered = false;
     563        for(std::set<TriggerBase*>::iterator it = this->children_.begin(); it != this->children_.end(); ++it)
     564        {
     565            TriggerBase* trigger = *it;
     566            if(triggered)
     567            {
     568                if(trigger->isMultiTrigger())
     569                {
     570                    if(static_cast<MultiTrigger*>(trigger)->isActive(triggerer))
     571                        return false;
     572                }
     573                else
     574                {
     575                    if(trigger->isActive())
     576                        return false;
     577                }
     578            }
     579
     580            if(trigger->isMultiTrigger())
     581            {
     582                if(static_cast<MultiTrigger*>(trigger)->isActive(triggerer))
     583                    triggered = true;
     584            }
     585            else
     586            {
     587                if(trigger->isActive())
     588                    triggered = true;
     589            }
     590        }
     591        return triggered;
    648592    }
    649593
  • 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.
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc

    r7403 r7601  
    3030    @file MultiTriggerContainer.cc
    3131    @brief Implementation of the MultiTriggerContainer class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    3536
    3637#include "core/CoreIncludes.h"
     38
    3739#include "worldentities/pawns/Pawn.h"
    3840
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h

    r7403 r7601  
    3030    @file MultiTriggerContainer.h
    3131    @brief Definition of the MultiTriggerContainer class.
     32    @ingroup MultiTrigger
    3233*/
    3334
     
    3839
    3940#include "core/BaseObject.h"
     41
    4042#include "interfaces/PlayerTrigger.h"
    4143
     
    4547    /**
    4648    @brief
    47         This class is used by the MultiTrigger class to transport additional data via Events.
     49        This class is used by the MultiTrigger class to transport additional data via @ref orxonox::Event "Events".
     50
    4851    @author
    4952        Damian 'Mozork' Frick
     53
     54    @ingroup MultiTrigger
    5055    */
    5156    class _ObjectsExport MultiTriggerContainer : public BaseObject, public PlayerTrigger
  • code/trunk/src/modules/objects/triggers/Trigger.cc

    r7284 r7601  
    2626 *
    2727 */
     28
     29/**
     30    @file Trigger.cc
     31    @brief Implementation of the Trigger class.
     32    @ingroup NormalTrigger
     33*/
    2834
    2935#include "Trigger.h"
     
    4248  CreateFactory(Trigger);
    4349
    44   Trigger::Trigger(BaseObject* creator) : StaticEntity(creator)
     50  Trigger::Trigger(BaseObject* creator) : TriggerBase(creator)
    4551  {
    4652    RegisterObject(Trigger);
    4753
    48     this->mode_ = TriggerMode::EventTriggerAND;
    49 
    50     this->bFirstTick_ = true;
    5154    this->bActive_ = false;
    5255    this->bTriggered_ = false;
    5356    this->latestState_ = 0x0;
    5457
    55     this->bInvertMode_ = false;
    56     this->bSwitch_ = false;
    57     this->bStayActive_ = false;
    58     this->delay_ = 0.0f;
    5958    this->remainingTime_ = 0.0f;
    6059    this->timeSinceLastEvent_ = 0.0f;
    61     this->remainingActivations_ = -1;
    6260
    6361//    this->bUpdating_ = false;
     
    8280  {
    8381    SUPER(Trigger, XMLPort, xmlelement, mode);
    84 
    85     XMLPortParam(Trigger, "delay",       setDelay,       getDelay,       xmlelement, mode).defaultValues(0.0f);
    86     XMLPortParam(Trigger, "switch",      setSwitch,      getSwitch,      xmlelement, mode).defaultValues(false);
    87     XMLPortParam(Trigger, "stayactive",  setStayActive,  getStayActive,  xmlelement, mode).defaultValues(false);
    88     XMLPortParam(Trigger, "activations", setActivations, getActivations, xmlelement, mode).defaultValues(-1);
    89     XMLPortParam(Trigger, "invert",      setInvert,      getInvert,      xmlelement, mode).defaultValues(false);
    90     XMLPortParamTemplate(Trigger, "mode", setMode, getModeString, xmlelement, mode, const std::string&).defaultValues("or");
    91 
    92     XMLPortObject(Trigger, Trigger, "", addTrigger, getTrigger, xmlelement, mode);
    9382  }
    9483
    9584  void Trigger::tick(float dt)
    9685  {
    97     if (this->bFirstTick_)
     86    if(this->bFirstTick_)
    9887    {
    9988      this->bFirstTick_ = false;
     
    10796    SUPER(Trigger, tick, dt);
    10897
    109     bool newTriggered = this->isTriggered() ^ this->bInvertMode_;
     98    bool newTriggered = this->isTriggered() ^ this->getInvert();
    11099
    111100    // check if new triggering event is really new
     
    121110      {
    122111        this->latestState_ &= 0xFE; // set trigger bit to 0
    123         if (!this->bSwitch_)
     112        if (!this->getSwitch())
    124113          this->switchState();
    125114      }
     
    145134        this->remainingTime_ = this->stateChanges_.front().first;
    146135      else
    147         this->timeSinceLastEvent_ = this->delay_;
     136        this->timeSinceLastEvent_ = this->getDelay();
    148137    }
    149138
     
    197186  bool Trigger::checkAnd()
    198187  {
    199     std::set<Trigger*>::iterator it;
     188    std::set<TriggerBase*>::iterator it;
    200189    for(it = this->children_.begin(); it != this->children_.end(); ++it)
    201190    {
     
    208197  bool Trigger::checkOr()
    209198  {
    210     std::set<Trigger*>::iterator it;
     199    std::set<TriggerBase*>::iterator it;
    211200    for(it = this->children_.begin(); it != this->children_.end(); ++it)
    212201    {
     
    219208  bool Trigger::checkXor()
    220209  {
    221     std::set<Trigger*>::iterator it;
     210    std::set<TriggerBase*>::iterator it;
    222211    bool test = false;
    223212    for(it = this->children_.begin(); it != this->children_.end(); ++it)
     
    233222  bool Trigger::switchState()
    234223  {
    235     if (( (this->latestState_ & 2) && this->bStayActive_ && (this->remainingActivations_ <= 0))
    236      || (!(this->latestState_ & 2)                       && (this->remainingActivations_ == 0)))
     224    if (( (this->latestState_ & 2) && this->getStayActive() && (this->remainingActivations_ <= 0))
     225     || (!(this->latestState_ & 2)                          && (this->remainingActivations_ == 0)))
    237226      return false;
    238227    else
     
    261250  }
    262251
    263   void Trigger::setDelay(float delay)
    264   {
    265     this->delay_ = delay;
    266     this->timeSinceLastEvent_ = delay;
    267   }
    268 
    269   void Trigger::setMode(const std::string& modeName)
    270   {
    271     if (modeName == "and")
    272       this->setMode(TriggerMode::EventTriggerAND);
    273     else if (modeName == "or")
    274       this->setMode(TriggerMode::EventTriggerOR);
    275     else if (modeName == "xor")
    276       this->setMode(TriggerMode::EventTriggerXOR);
    277   }
    278 
    279   std::string Trigger::getModeString() const
    280   {
    281     if (this->mode_ == TriggerMode::EventTriggerAND)
    282       return "and";
    283     else if (this->mode_ == TriggerMode::EventTriggerOR)
    284       return "or";
    285     else if (this->mode_ == TriggerMode::EventTriggerXOR)
    286       return "xor";
    287     else
    288       return "and";
    289   }
    290 
    291   void Trigger::addTrigger(Trigger* trigger)
    292   {
    293     if (this != trigger)
    294       this->children_.insert(trigger);
    295   }
    296 
    297   const Trigger* Trigger::getTrigger(unsigned int index) const
    298   {
    299     if (this->children_.size() <= index)
    300       return NULL;
    301 
    302     std::set<Trigger*>::const_iterator it;
    303     it = this->children_.begin();
    304 
    305     for (unsigned int i = 0; i != index; ++i)
    306       ++it;
    307 
    308     return (*it);
     252  void Trigger::delayChanged(void)
     253  {
     254    this->timeSinceLastEvent_ = this->getDelay();
    309255  }
    310256
  • code/trunk/src/modules/objects/triggers/Trigger.h

    r5781 r7601  
    2727 */
    2828
     29/**
     30    @file Trigger.h
     31    @brief Definition of the Trigger class.
     32    @ingroup NormalTrigger
     33*/
     34
    2935#ifndef _Trigger_H__
    3036#define _Trigger_H__
     
    3642
    3743#include "tools/BillboardSet.h"
    38 #include "tools/interfaces/Tickable.h"
    39 #include "worldentities/StaticEntity.h"
     44
     45#include "TriggerBase.h"
    4046
    4147namespace orxonox
    4248{
    43   namespace TriggerMode
    44   {
    45     enum Value
    46     {
    47       EventTriggerAND,
    48       EventTriggerOR,
    49       EventTriggerXOR,
    50     };
    51   }
    5249
    53   class _ObjectsExport Trigger : public StaticEntity, public Tickable
     50  /**
     51  @brief
     52   
     53  @author
     54    Benjamin Knecht
     55
     56  @ingroup NormalTrigger
     57  */
     58  class _ObjectsExport Trigger : public TriggerBase
    5459  {
    5560    public:
     
    6065      virtual void tick(float dt);
    6166
    62       inline bool isActive() const
    63         { return bActive_; }
    64 
    65       void addTrigger(Trigger* trigger);
    66       const Trigger* getTrigger(unsigned int index) const;
    67 
    68       void setMode(const std::string& modeName);
    69       inline void setMode(TriggerMode::Value mode)
    70         { this->mode_ = mode; }
    71       inline TriggerMode::Value getMode() const
    72         { return mode_; }
    73 
    74       inline void setInvert(bool bInvert)
    75         { this->bInvertMode_ = bInvert; }
    76       inline bool getInvert() const
    77         { return this->bInvertMode_; }
    78 
    79       inline void setSwitch(bool bSwitch)
    80         { this->bSwitch_ = bSwitch; }
    81       inline bool getSwitch() const
    82         { return this->bSwitch_; }
    83 
    84       inline void setStayActive(bool bStayActive)
    85         { this->bStayActive_ = bStayActive; }
    86       inline bool getStayActive() const
    87         { return this->bStayActive_; }
    88 
    89       inline void setActivations(int activations)
    90         { this->remainingActivations_ = activations; }
    91       inline int getActivations() const
    92         { return this->remainingActivations_; }
     67      inline bool isActive(void) const
     68        { return this->bActive_; }
    9369
    9470      inline void setVisible(bool visibility)
    9571        { this->debugBillboard_.setVisible(visibility); }
    9672
    97       void setDelay(float delay);
    98       inline float getDelay() const
    99         { return this->delay_; }
     73      void delayChanged(void);
    10074
    10175      bool switchState();
     
    11589      void setBillboardColour(const ColourValue& colour);
    11690      void storeState();
    117       std::string getModeString() const;
    11891
    11992      bool bActive_;
    12093      bool bTriggered_;
    121       bool bFirstTick_;
    122 
    123       TriggerMode::Value mode_;
    124       bool bInvertMode_;
    125       bool bSwitch_;
    126       bool bStayActive_;
    127       float delay_;
    128       int remainingActivations_;
    12994
    13095      char latestState_;
     
    135100      BillboardSet debugBillboard_;
    136101
    137       std::set<Trigger*> children_;
    138102      std::queue<std::pair<float, char> > stateChanges_;
    139103  };
  • code/trunk/src/orxonox/interfaces/PlayerTrigger.h

    r5936 r7601  
    2828
    2929/**
    30     @file
    31     @brief
    32     Definition of the PlayerTrigger class.
     30    @file PlayerTrigger.h
     31    @brief Definition of the PlayerTrigger class.
     32    @ingroup Triggers
    3333*/
    3434
     
    3737
    3838#include "OrxonoxPrereqs.h"
     39
    3940#include "core/OrxonoxClass.h"
    4041
     
    4344    /**
    4445    @brief
    45         A PlayerTrigger is a trigger which is normally triggered by Pawns and can as such return a pointer to the Pawn which triggered it.
     46        PlayerTrigger is an interface if implemented by a specific trigger can be used to recover the Player (or more precisely the @ref orxonox::Pawn "Pawn") that triggered it.
     47
    4648    @author
    4749        Damian 'Mozork' Frick
     50
     51    @ingroup Triggers
    4852    */
    4953    class _OrxonoxExport PlayerTrigger : virtual public OrxonoxClass
     
    7579           { this->player_ = player; }
    7680
    77             /**
    78             @brief Set whether the PlayerTrigger normally is triggered by Pawns.
    79             @param isForPlayer Should be true when the PlayerTrigger should be set to normally be triggered by Pawns, false if not.
    80             */
     81        /**
     82        @brief Set whether the PlayerTrigger normally is triggered by Pawns.
     83        @param isForPlayer Should be true when the PlayerTrigger should be set to normally be triggered by Pawns, false if not.
     84        */
    8185        inline void setForPlayer(bool isForPlayer)
    8286           { this->isForPlayer_ = isForPlayer; }
Note: See TracChangeset for help on using the changeset viewer.