Changeset 7601 for code/trunk/src/modules/objects
- Timestamp:
- Oct 30, 2010, 1:54:49 PM (14 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 added
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/Attacher.h
r5781 r7601 26 26 * 27 27 */ 28 29 /** 30 @file Attacher.h 31 @brief Definition of the Attacher class. 32 @ingroup Objects 33 */ 28 34 29 35 #ifndef _Attacher_H__ -
code/trunk/src/modules/objects/ForceField.h
r5781 r7601 27 27 */ 28 28 29 /** 30 @file ForceField.h 31 @brief Definition of the ForceField class. 32 @ingroup Objects 33 */ 29 34 30 35 #ifndef _ForceField_H__ -
code/trunk/src/modules/objects/ObjectsPrereqs.h
r7163 r7601 93 93 class MultiTriggerContainer; 94 94 class Trigger; 95 class TriggerBase; 95 96 } 96 97 -
code/trunk/src/modules/objects/Planet.h
r7163 r7601 26 26 * 27 27 */ 28 29 /** 30 @file Planet.h 31 @brief Definition of the Planet class. 32 @ingroup Objects 33 */ 28 34 29 35 #ifndef _Planet_H__ -
code/trunk/src/modules/objects/Script.h
r7486 r7601 28 28 */ 29 29 30 /** 31 @file Script.h 32 @brief Definition of the Script class. 33 @ingroup Objects 34 */ 35 30 36 #ifndef _Script_H__ 31 37 #define _Script_H__ … … 42 48 { 43 49 50 /** 51 @brief The mode a specific @ref orxonox::Script "Script" is in. 52 */ 44 53 namespace ScriptMode 45 54 { 46 //! Modes of the Script class.47 55 enum Value 48 56 { 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. 51 59 }; 52 60 } … … 56 64 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. 57 65 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". 63 71 64 72 Here are two examples illustrating the usage: … … 66 74 <Script code="showGUI QuestGUI" needsGraphics=true /> 67 75 @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 needsGraphicsis 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. 69 77 70 78 @code … … 77 85 </Script> 78 86 @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 80 89 @author 81 90 Benjamin Knecht -
code/trunk/src/modules/objects/collisionshapes/BoxCollisionShape.h
r7163 r7601 26 26 * 27 27 */ 28 29 /** 30 @file BoxCollisionShape.h 31 @brief Definition of the BoxCollisionShape class. 32 @ingroup Collisionshapes 33 */ 28 34 29 35 #ifndef _BoxCollisionShape_H__ -
code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h
r7163 r7601 26 26 * 27 27 */ 28 29 /** 30 @file ConeCollisionShape.h 31 @brief Definition of the ConeCollisionShape class. 32 @ingroup Collisionshapes 33 */ 28 34 29 35 #ifndef _ConeCollisionShape_H__ -
code/trunk/src/modules/objects/collisionshapes/PlaneCollisionShape.h
r7163 r7601 26 26 * 27 27 */ 28 29 /** 30 @file PlaneCollisionShape.h 31 @brief Definition of the PlaneCollisionShape class. 32 @ingroup Collisionshapes 33 */ 28 34 29 35 #ifndef _PlaneCollisionShape_H__ -
code/trunk/src/modules/objects/collisionshapes/SphereCollisionShape.h
r7163 r7601 26 26 * 27 27 */ 28 29 /** 30 @file SphereCollisionShape.h 31 @brief Definition of the SphereCollisionShape class. 32 @ingroup Collisionshapes 33 */ 28 34 29 35 #ifndef _SphereCollisionShape_H__ -
code/trunk/src/modules/objects/eventsystem/EventDispatcher.h
r5929 r7601 26 26 * 27 27 */ 28 29 /** 30 @file EventDispatcher.h 31 @brief Definition of the EventDispatcher class. 32 @ingroup Eventsystem 33 */ 28 34 29 35 #ifndef _EventDispatcher_H__ -
code/trunk/src/modules/objects/eventsystem/EventFilter.h
r5929 r7601 26 26 * 27 27 */ 28 29 /** 30 @file EventFilter.h 31 @brief Definition of the EventFilter class. 32 @ingroup Eventsystem 33 */ 28 34 29 35 #ifndef _EventFilter_H__ -
code/trunk/src/modules/objects/eventsystem/EventListener.h
r5929 r7601 26 26 * 27 27 */ 28 29 /** 30 @file EventListener.h 31 @brief Definition of the EventListener class. 32 @ingroup Eventsystem 33 */ 28 34 29 35 #ifndef _EventListener_H__ -
code/trunk/src/modules/objects/eventsystem/EventName.h
r5929 r7601 27 27 */ 28 28 29 /** 30 @file EventName.h 31 @brief Definition of the EventName class. 32 @ingroup Eventsystem 33 */ 34 29 35 #ifndef _EventName_H__ 30 36 #define _EventName_H__ -
code/trunk/src/modules/objects/eventsystem/EventTarget.h
r6417 r7601 26 26 * 27 27 */ 28 29 /** 30 @file EventTarget.h 31 @brief Definition of the EventTarget class. 32 @ingroup Eventsystem 33 */ 28 34 29 35 #ifndef _EventTarget_H__ -
code/trunk/src/modules/objects/triggers/CMakeLists.txt
r6906 r7601 9 9 MultiTriggerContainer.cc 10 10 Trigger.cc 11 TriggerBase.cc 11 12 ) -
code/trunk/src/modules/objects/triggers/CheckPoint.cc
r7163 r7601 26 26 * 27 27 */ 28 29 /** 30 @file CheckPoint.cc 31 @brief Implementation of the CheckPoint class. 32 @ingroup NormalTrigger 33 */ 28 34 29 35 #include "CheckPoint.h" -
code/trunk/src/modules/objects/triggers/CheckPoint.h
r5781 r7601 28 28 29 29 /** 30 @file 31 @brief 30 @file CheckPoint.h 31 @brief Definition of the CheckPoint class. 32 @ingroup NormalTrigger 32 33 */ 33 34 … … 42 43 namespace orxonox 43 44 { 45 46 /** 47 @brief 48 49 @author 50 Aurelian Jaggi 51 52 @ingroup NormalTrigger 53 */ 44 54 class _ObjectsExport CheckPoint : public DistanceTrigger, public RadarViewable 45 55 { -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
r7301 r7601 30 30 @file DistanceMultiTrigger.cc 31 31 @brief Implementation of the DistanceMultiTrigger class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 36 37 #include "core/CoreIncludes.h" 37 38 #include "core/XMLPort.h" 39 38 40 #include "DistanceTriggerBeacon.h" 39 41 … … 131 133 if(this->singleTargetMode_) 132 134 { 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. 134 136 if(!entity->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier())) 135 137 { -
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
r7301 r7601 30 30 @file DistanceMultiTrigger.h 31 31 @brief Definition of the DistanceMultiTrigger class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 37 38 #include "objects/ObjectsPrereqs.h" 38 39 40 #include <map> 41 42 #include "core/WeakPtr.h" 43 39 44 #include "worldentities/WorldEntity.h" 40 #include "core/WeakPtr.h"41 #include <map>42 45 43 46 #include "MultiTrigger.h" … … 48 51 /** 49 52 @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 attachedwill 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. 51 54 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. 54 57 55 58 A simple DistanceMultiTrigger would look like this: … … 58 61 @endcode 59 62 60 An implementation that only reacts to objects with a DistanceTriggerBeaconattached would look like this:63 An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this: 61 64 @code 62 65 <DistanceMultiTrigger position="0,0,0" target="DistanceMultiTrigger" targetname="beacon1" distance="30" /> 63 66 @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 66 70 For more information on MultiTriggers. 71 67 72 @author 68 73 Damian 'Mozork' Frick 74 75 @ingroup MultiTrigger 69 76 */ 70 77 class _ObjectsExport DistanceMultiTrigger : public MultiTrigger … … 106 113 private: 107 114 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. 110 117 111 118 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 27 27 */ 28 28 29 /** 30 @file DistanceTrigger.cc 31 @brief Implementation of the DistanceTrigger class. 32 @ingroup NormalTrigger 33 */ 34 29 35 #include "DistanceTrigger.h" 30 36 … … 46 52 this->targetName_ = BLANKSTRING; 47 53 this->singleTargetMode_ = false; 48 this->setForPlayer(false); //!< Normally hasn't just players as targets.49 54 } 50 55 -
code/trunk/src/modules/objects/triggers/DistanceTrigger.h
r7301 r7601 27 27 */ 28 28 29 /** 30 @file DistanceTrigger.h 31 @brief Definition of the DistanceTrigger class. 32 @ingroup NormalTrigger 33 */ 34 29 35 #ifndef _DistanceTrigger_H__ 30 36 #define _DistanceTrigger_H__ … … 39 45 namespace orxonox 40 46 { 47 48 /** 49 @brief 50 51 @author 52 Benjamin Knecht 53 @author 54 Damian 'Mozork' Frick 55 56 @ingroup NormalTrigger 57 */ 41 58 class _ObjectsExport DistanceTrigger : public Trigger, public PlayerTrigger 42 59 { -
code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc
r7301 r7601 30 30 @file DistanceTriggerBeacon.cc 31 31 @brief Implementation of the DistanceTriggerBeacon class. 32 @ingroup Triggers 32 33 */ 33 34 -
code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h
r7301 r7601 30 30 @file DistanceTriggerBeacon.h 31 31 @brief Definition of the DistanceTriggerBeacon class. 32 @ingroup Triggers 32 33 */ 33 34 … … 44 45 /** 45 46 @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 48 50 @author 49 51 Damian 'Mozork' Frick 52 53 @ingroup Triggers 50 54 */ 51 55 class _ObjectsExport DistanceTriggerBeacon : public StaticEntity -
code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc
r7301 r7601 30 30 @file EventMultiTrigger.cc 31 31 @brief Implementation of the EventMultiTrigger class. 32 @ingroup MultiTrigger 32 33 */ 33 34 -
code/trunk/src/modules/objects/triggers/EventMultiTrigger.h
r7301 r7601 30 30 @file EventMultiTrigger.h 31 31 @brief Definition of the EventMultiTrigger class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 44 45 /** 45 46 @brief 46 The EventMultiTrigger class is the equivalent of the EventTriggerclass 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". 49 50 50 51 Example: … … 59 60 </EventMultiTrigger> 60 61 @endcode 61 @see MultiTrigger.h 62 63 @see MultiTrigger 62 64 For more information on MultiTriggers. 65 63 66 @author 64 67 Damian 'Mozork' Frick 68 69 @ingroup MultiTrigger 65 70 */ 66 71 class _ObjectsExport EventMultiTrigger : public MultiTrigger … … 75 80 76 81 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". 78 83 79 84 }; -
code/trunk/src/modules/objects/triggers/EventTrigger.cc
r5929 r7601 26 26 * 27 27 */ 28 29 /** 30 @file EventTrigger.cc 31 @brief Implementation of the EventTrigger class. 32 @ingroup NormalTrigger 33 */ 28 34 29 35 #include "EventTrigger.h" -
code/trunk/src/modules/objects/triggers/EventTrigger.h
r5929 r7601 27 27 */ 28 28 29 /** 30 @file EventTrigger.h 31 @brief Definition of the EventTrigger class. 32 @ingroup NormalTrigger 33 */ 34 29 35 #ifndef _EventTrigger_H__ 30 36 #define _EventTrigger_H__ … … 35 41 namespace orxonox 36 42 { 43 44 /** 45 @brief 46 47 @author 48 Fabian 'x3n' Landau 49 50 @ingroup NormalTrigger 51 */ 37 52 class _ObjectsExport EventTrigger : public Trigger 38 53 { -
code/trunk/src/modules/objects/triggers/MultiTrigger.cc
r7301 r7601 30 30 @file MultiTrigger.cc 31 31 @brief Implementation of the MultiTrigger class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 41 42 namespace orxonox 42 43 { 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";49 44 50 45 CreateFactory(MultiTrigger); … … 56 51 The creator. 57 52 */ 58 MultiTrigger::MultiTrigger(BaseObject* creator) : StaticEntity(creator)53 MultiTrigger::MultiTrigger(BaseObject* creator) : TriggerBase(creator) 59 54 { 60 55 RegisterObject(MultiTrigger); 61 56 62 this->bFirstTick_ = true;63 64 this->delay_ = 0.0f;65 this->bSwitch_ = false;66 this->bStayActive_ = false;67 68 this->remainingActivations_ = INF_s;69 57 this->maxNumSimultaneousTriggerers_ = INF_s; 70 58 71 this->bInvertMode_ = false;72 this->mode_ = MultiTriggerMode::EventTriggerAND;73 74 59 this->bBroadcast_ = false; 75 60 76 this->parentTrigger_ = NULL;77 78 61 this->targetMask_.exclude(Class(BaseObject)); 62 63 this->bMultiTrigger_ = true; 79 64 80 65 this->setSyncMode(0x0); … … 105 90 SUPER(MultiTrigger, XMLPort, xmlelement, mode); 106 91 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);111 92 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&);114 93 XMLPortParam(MultiTrigger, "broadcast", setBroadcast, getBroadcast, xmlelement, mode); 115 94 XMLPortParamLoadOnly(MultiTrigger, "target", addTargets, xmlelement, mode).defaultValues("Pawn"); //TODO: Remove load only 116 95 117 XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode);118 119 96 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl; 120 97 } … … 124 101 @brief 125 102 A method that is executed each tick. 103 Most of the magic of MultiTriggers happens here. 126 104 @param dt 127 105 The duration of the last tick. 128 106 */ 107 //TODO: Segment into some helper methods? 129 108 void MultiTrigger::tick(float dt) 130 109 { … … 159 138 160 139 // 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(); 162 141 163 142 // 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)) 165 144 { 166 145 state->bTriggered = bTriggered; … … 192 171 { 193 172 // 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()) 195 174 { 196 175 bool bStateChanged = false; … … 211 190 bool bActive; 212 191 // 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) 214 193 bActive = this->isActive(state->originator); 215 194 else … … 239 218 { 240 219 // 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) 242 221 this->active_.erase(state->originator); 243 222 else … … 249 228 { 250 229 // 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) 252 231 this->broadcast(bActive); 253 232 // Else a normal event is fired. … … 267 246 COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: NULL, active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl; 268 247 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->parent Trigger_ != 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); 272 251 } 273 252 … … 302 281 Returns true if the MultiTrigger is active, false if not. 303 282 */ 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); 307 286 if(it == this->active_.end()) 308 287 return false; 309 288 return true; 310 }311 312 /**313 @brief314 Set the mode of the MultiTrigger.315 @param modeName316 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 else327 COUT(2) << "Invalid mode '" << modeName << "' in MultiTrigger " << this->getName() << " &(" << this << "). Leaving mode at '" << this->getModeString() << "'." << std::endl;328 }329 330 /**331 @brief332 Get the mode of the MultiTrigger.333 @return334 Returns the mode as a string.335 */336 const std::string& MultiTrigger::getModeString() const337 {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;346 289 } 347 290 … … 397 340 /** 398 341 @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 trigger402 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 @brief413 Get the sub-trigger of this MultiTrigger at the given index.414 @param index415 The index.416 @return417 Returns a pointer ot the MultiTrigger. NULL if no such trigger exists.418 */419 const MultiTrigger* MultiTrigger::getTrigger(unsigned int index) const420 {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 @brief436 342 This method is called by the MultiTrigger to get information about new trigger events that need to be looked at. 437 343 This method is the device for the behavior (the conditions under which the MultiTrigger triggers) of any derived class of MultiTrigger. … … 456 362 { 457 363 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(); 459 365 state->originator = originator; 460 366 this->addState(state); … … 463 369 /** 464 370 @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. 466 372 @param originator 467 373 The object that caused the change in activity. 468 374 */ 469 void MultiTrigger:: subTriggerActivityChanged(BaseObject* originator)375 void MultiTrigger::childActivityChanged(BaseObject* originator) 470 376 { 471 377 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(); 473 379 state->originator = originator; 474 380 this->addState(state); … … 477 383 /** 478 384 @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-triggerswere 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. 481 387 @param triggerer 482 388 The object. 483 389 @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. 485 391 */ 486 392 bool MultiTrigger::isModeTriggered(BaseObject* triggerer) 487 393 { 488 if(this-> subTriggers_.size() != 0)489 { 490 bool returnVal= false;394 if(this->children_.size() != 0) 395 { 396 bool triggered = false; 491 397 492 398 switch(this->mode_) 493 399 { 494 case MultiTriggerMode::EventTriggerAND:495 returnVal= checkAnd(triggerer);400 case TriggerMode::EventTriggerAND: 401 triggered = checkAnd(triggerer); 496 402 break; 497 case MultiTriggerMode::EventTriggerOR:498 returnVal= checkOr(triggerer);403 case TriggerMode::EventTriggerOR: 404 triggered = checkOr(triggerer); 499 405 break; 500 case MultiTriggerMode::EventTriggerXOR:501 returnVal= checkXor(triggerer);406 case TriggerMode::EventTriggerXOR: 407 triggered = checkXor(triggerer); 502 408 break; 503 409 default: // This will never happen. 504 returnVal= false;410 triggered = false; 505 411 break; 506 412 } 507 413 508 return returnVal;414 return triggered; 509 415 } 510 416 … … 585 491 586 492 // 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)); 588 494 589 495 return true; … … 592 498 /** 593 499 @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. 595 501 @param triggerer 596 502 The object. … … 600 506 bool MultiTrigger::checkAnd(BaseObject* triggerer) 601 507 { 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 } 606 521 } 607 522 return true; … … 610 525 /** 611 526 @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. 613 528 @param triggerer 614 529 The object. … … 618 533 bool MultiTrigger::checkOr(BaseObject* triggerer) 619 534 { 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 } 624 548 } 625 549 return false; … … 628 552 /** 629 553 @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. 631 555 @param triggerer 632 556 The object. … … 636 560 bool MultiTrigger::checkXor(BaseObject* triggerer) 637 561 { 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; 648 592 } 649 593 -
code/trunk/src/modules/objects/triggers/MultiTrigger.h
r7301 r7601 30 30 @file MultiTrigger.h 31 31 @brief Definition of the MultiTrigger class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 43 44 #include <deque> 44 45 45 #include "tools/interfaces/Tickable.h" 46 #include "worldentities/StaticEntity.h" 46 #include "TriggerBase.h" 47 47 48 48 namespace orxonox 49 49 { 50 50 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 */ 63 57 struct MultiTriggerState 64 58 { … … 70 64 @brief 71 65 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 Eventand 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. 73 67 74 68 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 activitychanges, 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. 76 70 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 activityonly 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-objectsin 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. 87 81 88 82 An example of a MultiTrigger created through XML would look like this: 89 83 @code 90 84 <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 /> 92 86 ... 93 < MultiTrigger/>87 <TriggerBase /> 94 88 </MultiTrigger> 95 89 @endcode … … 97 91 @author 98 92 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 100 97 */ 101 class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable98 class _ObjectsExport MultiTrigger : public TriggerBase 102 99 { 103 100 public: … … 108 105 virtual void tick(float dt); //!< A method that is executed each tick. 109 106 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. 157 114 158 115 /** … … 161 118 */ 162 119 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; } 164 121 /** 165 122 @brief Get the number of objects that are allowed to simultaneously trigger this MultiTriggger. … … 168 125 inline int getSimultaneousTriggerers(void) 169 126 { 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) const182 { 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() const197 { return mode_; }198 127 199 128 /** … … 218 147 { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); } 219 148 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 223 149 protected: 224 150 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. … … 226 152 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. 227 153 228 bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whether x 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. 229 155 bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object. 230 156 … … 232 158 void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target. 233 159 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 241 160 void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger. 242 161 void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger. 243 162 244 163 /** 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 /**252 164 @brief Get the target mask used to identify the targets of this MultiTrigger. 253 165 @return Returns the target mask. … … 257 169 258 170 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. 266 172 267 173 bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active. 268 174 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. 272 178 273 179 /** … … 278 184 { return this->active_; } 279 185 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.287 186 int maxNumSimultaneousTriggerers_; //!< The maximum number of objects simultaneously trigggering this MultiTrigger. 288 187 289 bool bInvertMode_; //!< Bool for the invert-mode, if true the MultiTrigger is inverted.290 MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger.291 292 188 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.296 189 297 190 std::set<BaseObject*> active_; //!< The set of all objects the MultiTrigger is active for. -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc
r7403 r7601 30 30 @file MultiTriggerContainer.cc 31 31 @brief Implementation of the MultiTriggerContainer class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 35 36 36 37 #include "core/CoreIncludes.h" 38 37 39 #include "worldentities/pawns/Pawn.h" 38 40 -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h
r7403 r7601 30 30 @file MultiTriggerContainer.h 31 31 @brief Definition of the MultiTriggerContainer class. 32 @ingroup MultiTrigger 32 33 */ 33 34 … … 38 39 39 40 #include "core/BaseObject.h" 41 40 42 #include "interfaces/PlayerTrigger.h" 41 43 … … 45 47 /** 46 48 @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 48 51 @author 49 52 Damian 'Mozork' Frick 53 54 @ingroup MultiTrigger 50 55 */ 51 56 class _ObjectsExport MultiTriggerContainer : public BaseObject, public PlayerTrigger -
code/trunk/src/modules/objects/triggers/Trigger.cc
r7284 r7601 26 26 * 27 27 */ 28 29 /** 30 @file Trigger.cc 31 @brief Implementation of the Trigger class. 32 @ingroup NormalTrigger 33 */ 28 34 29 35 #include "Trigger.h" … … 42 48 CreateFactory(Trigger); 43 49 44 Trigger::Trigger(BaseObject* creator) : StaticEntity(creator)50 Trigger::Trigger(BaseObject* creator) : TriggerBase(creator) 45 51 { 46 52 RegisterObject(Trigger); 47 53 48 this->mode_ = TriggerMode::EventTriggerAND;49 50 this->bFirstTick_ = true;51 54 this->bActive_ = false; 52 55 this->bTriggered_ = false; 53 56 this->latestState_ = 0x0; 54 57 55 this->bInvertMode_ = false;56 this->bSwitch_ = false;57 this->bStayActive_ = false;58 this->delay_ = 0.0f;59 58 this->remainingTime_ = 0.0f; 60 59 this->timeSinceLastEvent_ = 0.0f; 61 this->remainingActivations_ = -1;62 60 63 61 // this->bUpdating_ = false; … … 82 80 { 83 81 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);93 82 } 94 83 95 84 void Trigger::tick(float dt) 96 85 { 97 if 86 if(this->bFirstTick_) 98 87 { 99 88 this->bFirstTick_ = false; … … 107 96 SUPER(Trigger, tick, dt); 108 97 109 bool newTriggered = this->isTriggered() ^ this-> bInvertMode_;98 bool newTriggered = this->isTriggered() ^ this->getInvert(); 110 99 111 100 // check if new triggering event is really new … … 121 110 { 122 111 this->latestState_ &= 0xFE; // set trigger bit to 0 123 if (!this-> bSwitch_)112 if (!this->getSwitch()) 124 113 this->switchState(); 125 114 } … … 145 134 this->remainingTime_ = this->stateChanges_.front().first; 146 135 else 147 this->timeSinceLastEvent_ = this-> delay_;136 this->timeSinceLastEvent_ = this->getDelay(); 148 137 } 149 138 … … 197 186 bool Trigger::checkAnd() 198 187 { 199 std::set<Trigger *>::iterator it;188 std::set<TriggerBase*>::iterator it; 200 189 for(it = this->children_.begin(); it != this->children_.end(); ++it) 201 190 { … … 208 197 bool Trigger::checkOr() 209 198 { 210 std::set<Trigger *>::iterator it;199 std::set<TriggerBase*>::iterator it; 211 200 for(it = this->children_.begin(); it != this->children_.end(); ++it) 212 201 { … … 219 208 bool Trigger::checkXor() 220 209 { 221 std::set<Trigger *>::iterator it;210 std::set<TriggerBase*>::iterator it; 222 211 bool test = false; 223 212 for(it = this->children_.begin(); it != this->children_.end(); ++it) … … 233 222 bool Trigger::switchState() 234 223 { 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))) 237 226 return false; 238 227 else … … 261 250 } 262 251 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(); 309 255 } 310 256 -
code/trunk/src/modules/objects/triggers/Trigger.h
r5781 r7601 27 27 */ 28 28 29 /** 30 @file Trigger.h 31 @brief Definition of the Trigger class. 32 @ingroup NormalTrigger 33 */ 34 29 35 #ifndef _Trigger_H__ 30 36 #define _Trigger_H__ … … 36 42 37 43 #include "tools/BillboardSet.h" 38 #include "tools/interfaces/Tickable.h" 39 #include " worldentities/StaticEntity.h"44 45 #include "TriggerBase.h" 40 46 41 47 namespace orxonox 42 48 { 43 namespace TriggerMode44 {45 enum Value46 {47 EventTriggerAND,48 EventTriggerOR,49 EventTriggerXOR,50 };51 }52 49 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 54 59 { 55 60 public: … … 60 65 virtual void tick(float dt); 61 66 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_; } 93 69 94 70 inline void setVisible(bool visibility) 95 71 { this->debugBillboard_.setVisible(visibility); } 96 72 97 void setDelay(float delay); 98 inline float getDelay() const 99 { return this->delay_; } 73 void delayChanged(void); 100 74 101 75 bool switchState(); … … 115 89 void setBillboardColour(const ColourValue& colour); 116 90 void storeState(); 117 std::string getModeString() const;118 91 119 92 bool bActive_; 120 93 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_;129 94 130 95 char latestState_; … … 135 100 BillboardSet debugBillboard_; 136 101 137 std::set<Trigger*> children_;138 102 std::queue<std::pair<float, char> > stateChanges_; 139 103 };
Note: See TracChangeset
for help on using the changeset viewer.