[Orxonox-commit 2596] r7301 - in code/trunk/src: libraries/core modules/objects/triggers
dafrick at orxonox.net
dafrick at orxonox.net
Tue Aug 31 23:31:37 CEST 2010
Author: dafrick
Date: 2010-08-31 23:31:37 +0200 (Tue, 31 Aug 2010)
New Revision: 7301
Modified:
code/trunk/src/libraries/core/EventIncludes.h
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
code/trunk/src/modules/objects/triggers/DistanceTrigger.cc
code/trunk/src/modules/objects/triggers/DistanceTrigger.h
code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc
code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h
code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc
code/trunk/src/modules/objects/triggers/EventMultiTrigger.h
code/trunk/src/modules/objects/triggers/MultiTrigger.cc
code/trunk/src/modules/objects/triggers/MultiTrigger.h
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h
Log:
Improving documentation for MultiTriggers, also some small bugfixes, simplifications and added features.
Modified: code/trunk/src/libraries/core/EventIncludes.h
===================================================================
--- code/trunk/src/libraries/core/EventIncludes.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/libraries/core/EventIncludes.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -52,6 +52,11 @@
} \
XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
+/**
+ @brief Like XMLPortEventState but creates an event sink instead of an event state.
+ The most important destinction between an EventState and an EventSink is, that an EventState only processes events which change the state of the EventState, where as an EventSink is an EventState that processes any Event that reaches it.
+*/
+
#define XMLPortEventSink(classname, subclassname, statename, function, xmlelement, mode) \
orxonox::EventState* containername##function = this->getEventState(statename); \
if (!containername##function) \
@@ -61,10 +66,7 @@
} \
XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
-/**
- @brief Like XMLPortEventState but creates an event sink instead of an event state.
- The most important destinction between an EventState and an EventSink is, that an EventState only processes event which change the state of the EventState, where as an EventSink is an EventState that processes any Event that reaches it.
-*/
+
#define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \
orxonox::EventState* containername##function = this->getEventState(statename); \
if (!containername##function) \
Modified: code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc
===================================================================
--- code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc 2010-08-31 21:31:37 UTC (rev 7301)
@@ -61,6 +61,7 @@
*/
DistanceMultiTrigger::~DistanceMultiTrigger()
{
+
}
/**
@@ -80,6 +81,8 @@
This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
In this implementation we iterate through all possible objects and check whether the fact that they are in range or not has changed and fire and hand a state ofer to the MultiTrigger if so.
+ @return
+ Returns a pointer to a queue of MultiTriggerState pointers, containing all the necessary information to decide whether these states should indeed become new states of the MultiTrigger.
*/
std::queue<MultiTriggerState*>* DistanceMultiTrigger::letTrigger(void)
{
@@ -91,9 +94,10 @@
{
WorldEntity* entity = it->second->get();
WorldEntity* key = it->first;
+ it++; // Incrementing the iterator in advance, since we don't need the current anymore and we potentially are going to delete the current element thus invalidating the iterator.
+ // If the entity no longer exists.
if(entity == NULL)
{
- ++it;
this->removeFromRange(key);
continue;
}
@@ -102,11 +106,9 @@
// If the object is no longer in range.
if (distanceVec.length() > this->distance_)
{
+ // If for some reason the entity could not be removed.
if(!this->removeFromRange(key))
- {
- ++it;
continue;
- }
// If no queue has been created, yet.
if(queue == NULL)
@@ -114,30 +116,27 @@
// Create a state and append it to the queue.
MultiTriggerState* state = new MultiTriggerState;
- state->bTriggered = false;
+ state->bTriggered = false; // Because the entity went out of range.
state->originator = entity;
queue->push(state);
}
- else
- ++it;
}
- ClassTreeMask& targetMask = this->getTargetMask();
-
// Check for new objects that are in range
- for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it)
+ for(ClassTreeMaskObjectIterator it = this->getTargetMask().begin(); it != this->getTargetMask().end(); ++it)
{
WorldEntity* entity = static_cast<WorldEntity*>(*it);
- if (entity == NULL) //If the object is no WorldEntity or is already in range.
- continue;
- // If the DistanceMultiTrigger is in single-target-mode.
+ // If the DistanceMultiTrigger is in single-target mode.
if(this->singleTargetMode_)
{
// If the object that is a target is no DistanceTriggerBeacon, then the DistanceMultiTrigger can't be in single-target-mode.
- if(!(*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()))
+ if(!entity->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()))
+ {
this->singleTargetMode_ = false;
- // If the target name and the name of the DistancTriggreBeacon don't match.
+ COUT(2) << "DistanceMultiTrigger " << this->getName() << " (&" << this << ")" << "is in single-target mode but the target is '" << entity->getIdentifier()->getName() << "' instead of DistanceTriggerBeacon. Setting single-target mode to false." << std::endl;
+ }
+ // If the target name and the name of the DistancTriggerBeacon don't match.
else if(entity->getName().compare(this->targetName_) != 0)
continue;
}
@@ -147,6 +146,7 @@
if (distanceVec.length() <= this->distance_)
{
// Add the object to the objects that are in range.
+ // Objects that already are in range are not added twice, because in a map (this->range_) each key can only exist once and thus addToRange() will reject all attempts of duplicate entries.
if(!this->addToRange(entity))
continue;
@@ -160,7 +160,7 @@
// Create a state and append it to the queue.
MultiTriggerState* state = new MultiTriggerState;
- state->bTriggered = true;
+ state->bTriggered = true; // Because the entity came into range.
state->originator = entity;
queue->push(state);
}
@@ -169,4 +169,60 @@
return queue;
}
+ /**
+ @brief
+ Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
+ @param targetname
+ The name of the DistanceTriggerBeacon as a string.
+ */
+ void DistanceMultiTrigger::setTargetName(const std::string& targetname)
+ {
+ // If the targetname is no blank string single-target mode is enabled.
+ if(targetname.compare(BLANKSTRING) != 0)
+ this->singleTargetMode_ = true;
+ else
+ this->singleTargetMode_ = false;
+
+ this->targetName_ = targetname;
+ }
+
+ /**
+ @brief
+ Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
+ @param entity
+ A pointer to the entity.
+ @return
+ Returns true if successful, false if not.
+ */
+ bool DistanceMultiTrigger::addToRange(WorldEntity* entity)
+ {
+ WeakPtr<WorldEntity>* weakptr = new WeakPtr<WorldEntity>(entity);
+ std::pair<std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator, bool> pair = this->range_.insert(std::pair<WorldEntity*, WeakPtr<WorldEntity>* >(entity, weakptr));
+
+ if(!pair.second)
+ {
+ delete weakptr;
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ @brief
+ Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
+ @param entity
+ A pointer ot the entity.
+ @return
+ Returns true if successful.
+ */
+ bool DistanceMultiTrigger::removeFromRange(WorldEntity* entity)
+ {
+ WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second;
+ bool erased = this->range_.erase(entity) > 0;
+ if(erased)
+ delete weakptr;
+ return erased;
+ }
+
}
Modified: code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h
===================================================================
--- code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -47,7 +47,21 @@
/**
@brief
- 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 hav a DistanceTriggerBeacon with that name attached will trigger the DistanceMultiTrigger.
+ 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.
+ Parameters are (additional to the ones of MultiTrigger):
+ 'distance', which specifies the maximum distance at which the DistanceMultiTrigger still triggers. Default is 100.
+ '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.
+
+ A simple DistanceMultiTrigger would look like this:
+ @code
+ <DistanceMultiTrigger position="0,0,0" switch="true" target="Pawn" distance="20" />
+ @endcode
+
+ An implementation that only reacts to objects with a DistanceTriggerBeacon attached would look like this:
+ @code
+ <DistanceMultiTrigger position="0,0,0" target="DistanceMultiTrigger" targetname="beacon1" distance="30" />
+ @endcode
+ This particular DistanceMultiTrigger would only react if an object was in range, that had a DistanceTriggerBeacon with the name 'beacon1' attached.
@see MultiTrigger.h
For more information on MultiTriggers.
@author
@@ -58,17 +72,12 @@
public:
DistanceMultiTrigger(BaseObject* creator); //!< Default Constructor. Registers the object and initializes default values.
- ~DistanceMultiTrigger(); //!< Destructor.
+ virtual ~DistanceMultiTrigger(); //!< Destructor.
void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a DistanceMultiTrigger object through XML.
+ void setTargetName(const std::string& targetname); //!< Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
/**
- @brief Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
- @param targename The name of the DistanceTriggerBeacon as a string.
- */
- inline void setTargetName(const std::string& targetname)
- { if(targetname.compare(BLANKSTRING) != 0) this->singleTargetMode_ = true; else this->singleTargetMode_ = false; this->targetName_ = targetname; }
- /**
@brief Get the target name of the DistanceTriggerbeacon, that triggers this DistanceMultiTrigger.
@return Returns the target name as a string.
*/
@@ -91,20 +100,8 @@
protected:
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.
- /**
- @brief Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
- @param entity A pointer to the entity.
- @return Returns true if successful, false if not.
- */
- inline bool addToRange(WorldEntity* entity)
- { std::pair<std::map<WorldEntity*, WeakPtr<WorldEntity>* >::iterator, bool> pair = this->range_.insert(std::pair<WorldEntity*, WeakPtr<WorldEntity>* >(entity, new WeakPtr<WorldEntity>(entity))); return pair.second; }
- /**
- @brief Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
- @param entity A pointer ot the entity.
- @return Returns true if successful.
- */
- inline bool removeFromRange(WorldEntity* entity)
- { WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second; bool erased = this->range_.erase(entity) > 0; if(erased) delete weakptr; return erased; }
+ bool addToRange(WorldEntity* entity); //!< Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
+ bool removeFromRange(WorldEntity* entity); //!< Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
private:
float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
Modified: code/trunk/src/modules/objects/triggers/DistanceTrigger.cc
===================================================================
--- code/trunk/src/modules/objects/triggers/DistanceTrigger.cc 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/DistanceTrigger.cc 2010-08-31 21:31:37 UTC (rev 7301)
@@ -128,10 +128,16 @@
if (!entity)
continue;
+ // If the DistanceTrigger is in single-target mode.
if(this->singleTargetMode_)
{
+ // If the object that is a target is no DistanceTriggerBeacon, then the DistanceTrigger can't be in single-target-mode.
if(!(*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()))
+ {
this->singleTargetMode_ = false;
+ COUT(2) << "DistanceTrigger " << this->getName() << " (&" << this << ")" << "is in single-target mode but the target is '" << entity->getIdentifier()->getName() << "' instead of DistanceTriggerBeacon. Setting single-target mode to false." << std::endl;
+ }
+ // If the target name and the name of the DistancTriggerBeacon don't match.
else if(entity->getName().compare(this->targetName_) != 0)
continue;
}
@@ -144,6 +150,7 @@
if(this->isForPlayer())
{
+ // Change the entity to the parent of the DistanceTriggerBeacon (if in single-target-mode), which is the entity to which the beacon is attached.
if(this->singleTargetMode_)
entity = entity->getParent();
Modified: code/trunk/src/modules/objects/triggers/DistanceTrigger.h
===================================================================
--- code/trunk/src/modules/objects/triggers/DistanceTrigger.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/DistanceTrigger.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -22,7 +22,7 @@
* Author:
* Benjamin Knecht
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
Modified: code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc
===================================================================
--- code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.cc 2010-08-31 21:31:37 UTC (rev 7301)
@@ -26,6 +26,11 @@
*
*/
+/**
+ @file DistanceTriggerBeacon.cc
+ @brief Implementation of the DistanceTriggerBeacon class.
+*/
+
#include "DistanceTriggerBeacon.h"
#include "core/CoreIncludes.h"
@@ -35,6 +40,12 @@
CreateFactory(DistanceTriggerBeacon);
+ /**
+ @brief
+ Constructor. Registers the object.
+ @param creator
+ The creator of this object.
+ */
DistanceTriggerBeacon::DistanceTriggerBeacon(BaseObject* creator) : StaticEntity(creator)
{
RegisterObject(DistanceTriggerBeacon);
Modified: code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h
===================================================================
--- code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/DistanceTriggerBeacon.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -26,6 +26,11 @@
*
*/
+/**
+ @file DistanceTriggerBeacon.h
+ @brief Definition of the DistanceTriggerBeacon class.
+*/
+
#ifndef _DistanceTriggerBeacon_H__
#define _DistanceTriggerBeacon_H__
@@ -36,14 +41,20 @@
namespace orxonox
{
+ /**
+ @brief
+ A DistanceTriggerBeacon can be used together with a DistanceTrigger or a DistanceMultiTrigger to make them only react to specific objects.
+ 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.
+ @author
+ Damian 'Mozork' Frick
+ */
class _ObjectsExport DistanceTriggerBeacon : public StaticEntity
{
public:
+ DistanceTriggerBeacon(BaseObject* creator); //!< Constructor.
+ virtual ~DistanceTriggerBeacon() {} //!< Destructor.
- DistanceTriggerBeacon(BaseObject* creator);
- ~DistanceTriggerBeacon() {}
-
};
}
Modified: code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc
===================================================================
--- code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/EventMultiTrigger.cc 2010-08-31 21:31:37 UTC (rev 7301)
@@ -36,24 +36,35 @@
#include "core/CoreIncludes.h"
#include "core/EventIncludes.h"
#include "core/XMLPort.h"
+#include "MultiTriggerContainer.h"
namespace orxonox
{
CreateFactory(EventMultiTrigger);
+ /**
+ @brief
+ Constructor. Registers the object.
+ */
EventMultiTrigger::EventMultiTrigger(BaseObject* creator) : MultiTrigger(creator)
{
RegisterObject(EventMultiTrigger);
-
- this->bEventTriggered_ = false;
}
+ /**
+ @brief
+ Destructor.
+ */
EventMultiTrigger::~EventMultiTrigger()
{
}
+ /**
+ @brief
+ Method for creating an EventMultiTrigger object through XML.
+ */
void EventMultiTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(EventMultiTrigger, XMLPort, xmlelement, mode);
@@ -61,6 +72,10 @@
this->setBroadcast(true);
}
+ /**
+ @brief
+ Creates an event port.
+ */
void EventMultiTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(EventMultiTrigger, XMLEventPort, xmlelement, mode);
@@ -68,5 +83,35 @@
XMLPortEventState(EventMultiTrigger, BaseObject, "trigger", trigger, xmlelement, mode);
}
+ /**
+ @brief
+ Method that causes the EventMultiTrigger to trigger upon receiving an event.
+ @param bTriggered
+ Whether the event is a triggering or an un-triggering event.
+ @param originator
+ A pointer to the entity the event originates from.
+ */
+ void EventMultiTrigger::trigger(bool bTriggered, BaseObject* originator)
+ {
+ // If the originator is a MultiTriggerContainer, the event originates from a MultiTrigger and thus the event only triggers the EventMultiTrigger for the originator that caused the MultiTrigger to trigger.
+ if(originator != NULL && originator->isA(ClassIdentifier<MultiTriggerContainer>::getIdentifier()))
+ {
+ MultiTriggerContainer* container = static_cast<MultiTriggerContainer*>(originator);
+ // If the entity that triggered the MultiTrigger is no target of this EventMultiTrigger we process it as it weren't an event caused by a MultiTrigger.
+ // But if it is the EventMultiTrigger only triggers for the entity tha caused the MultiTrigger to trigger.
+ if(this->isTarget(container->getData()))
+ {
+ if(this->isTriggered(container->getData()) ^ bTriggered)
+ this->changeTriggered(container->getData());
+
+ return;
+ }
+ }
+
+ // If we don't know who exactly caused the event we just send a broadcast.
+ if(this->isTriggered() ^ bTriggered)
+ this->changeTriggered();
+ }
+
}
Modified: code/trunk/src/modules/objects/triggers/EventMultiTrigger.h
===================================================================
--- code/trunk/src/modules/objects/triggers/EventMultiTrigger.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/EventMultiTrigger.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -41,21 +41,41 @@
namespace orxonox
{
+ /**
+ @brief
+ The EventMultiTrigger class is the equivalent of the EventTrigger class for MultiTriggers.
+ Consequentially what it does is it provides a way to have a MultiTrigger triggered by any kinds of events.
+ 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.
+
+ Example:
+ @code
+ <EventMultiTrigger invert="true">
+ <events>
+ <trigger>
+ <MultiTrigger ... />
+ <EventListener ... />
+ </trigger>
+ </events>
+ </EventMultiTrigger>
+ @endcode
+ @see MultiTrigger.h
+ For more information on MultiTriggers.
+ @author
+ Damian 'Mozork' Frick
+ */
class _ObjectsExport EventMultiTrigger : public MultiTrigger
{
public:
- EventMultiTrigger(BaseObject* creator);
- ~EventMultiTrigger();
+ EventMultiTrigger(BaseObject* creator); //!< Constructor. Registers the object.
+ virtual ~EventMultiTrigger(); //!< Destructor.
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating an EventMultiTrigger object through XML.
virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
- inline void trigger(bool bTriggered)
- { this->bEventTriggered_ = bTriggered; this->changeTriggered(); }
+ private:
+ void trigger(bool bTriggered, BaseObject* originator); //!< Method that causes the EventMultiTrigger to trigger upon receiving an event.
- private:
- bool bEventTriggered_;
};
}
Modified: code/trunk/src/modules/objects/triggers/MultiTrigger.cc
===================================================================
--- code/trunk/src/modules/objects/triggers/MultiTrigger.cc 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/MultiTrigger.cc 2010-08-31 21:31:37 UTC (rev 7301)
@@ -22,7 +22,7 @@
* Author:
* Damian 'Mozork' Frick
* Co-authors:
- * Benjamin Knecht
+ * ...
*
*/
@@ -66,7 +66,7 @@
this->bStayActive_ = false;
this->remainingActivations_ = INF_s;
- this->maxNumSimultaniousTriggerers_ = INF_s;
+ this->maxNumSimultaneousTriggerers_ = INF_s;
this->bInvertMode_ = false;
this->mode_ = MultiTriggerMode::EventTriggerAND;
@@ -108,13 +108,12 @@
XMLPortParam(MultiTrigger, "switch", setSwitch, getSwitch, xmlelement, mode);
XMLPortParam(MultiTrigger, "stayactive", setStayActive, getStayActive, xmlelement, mode);
XMLPortParam(MultiTrigger, "activations", setActivations, getActivations, xmlelement, mode);
- XMLPortParam(MultiTrigger, "simultaniousTriggerers", setSimultaniousTriggerers, getSimultaniousTriggerers, xmlelement, mode);
+ XMLPortParam(MultiTrigger, "simultaneousTriggerers", setSimultaneousTriggerers, getSimultaneousTriggerers, xmlelement, mode);
XMLPortParam(MultiTrigger, "invert", setInvert, getInvert, xmlelement, mode);
XMLPortParamTemplate(MultiTrigger, "mode", setMode, getModeString, xmlelement, mode, const std::string&);
XMLPortParam(MultiTrigger, "broadcast", setBroadcast, getBroadcast, xmlelement, mode);
XMLPortParamLoadOnly(MultiTrigger, "target", addTargets, xmlelement, mode).defaultValues("Pawn"); //TODO: Remove load only
- //TODO: Maybe nicer with explicit subgroup, e.g. triggers
XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode);
COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl;
@@ -130,11 +129,11 @@
void MultiTrigger::tick(float dt)
{
// If this is the first tick.
- //TODO: Determine need for this, else kick it out.
if(this->bFirstTick_)
{
this->bFirstTick_ = false;
- this->fire(false);
+ // Fire for all objects that are targets.
+ this->broadcast(false);
}
// Check if the object is active (this is NOT MultiTrigger::isActive()!)
@@ -153,7 +152,7 @@
// If the state is NULL. (This really shouldn't happen)
if(state == NULL)
{
- COUT(1) << "In MultiTrigger '" << this->getName() << "' (&" << this << "), Error: State of new states queue was NULL." << std::endl;
+ COUT(1) << "In MultiTrigger '" << this->getName() << "' (&" << this << "), Error: State of new states queue was NULL. State ignored." << std::endl;
queue->pop();
continue;
}
@@ -161,18 +160,15 @@
// The new triggered state dependent on the requested state, the mode and the invert-mode.
bool bTriggered = (state->bTriggered & this->isModeTriggered(state->originator)) ^ this->bInvertMode_;
- // If the 'triggered' state has changed a new state is added to the state queue.
- //TODO: Do something against flooding, when there is delay.
- if(this->delay_ != 0.0f || bTriggered ^ this->isTriggered(state->originator))
+ // 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.
+ if(this->delay_ > 0.0f || bTriggered ^ this->isTriggered(state->originator))
{
state->bTriggered = bTriggered;
this->addState(state);
}
+ // Else the change is irrelevant.
else
- {
- COUT(1) << "BUH" << std::endl;
delete state;
- }
queue->pop();
}
@@ -180,7 +176,7 @@
}
// Go through the state queue and activate all pending states whose remaining time has expired.
- if (this->stateQueue_.size() > 0)
+ if(this->stateQueue_.size() > 0)
{
MultiTriggerState* state;
float timeRemaining;
@@ -194,30 +190,26 @@
// If the remaining time has expired, the state has to be set as the state of the MultiTrigger.
if(timeRemaining <= dt)
{
- // If the maximum number of objects simultaniously triggering this MultiTrigger is not exceeded.
- if(this->maxNumSimultaniousTriggerers_ == INF_s || this->triggered_.size() < (unsigned int)this->maxNumSimultaniousTriggerers_)
+ // If the maximum number of objects simultaneously triggering this MultiTrigger is not exceeded.
+ if(this->maxNumSimultaneousTriggerers_ == INF_s || this->triggered_.size() < (unsigned int)this->maxNumSimultaneousTriggerers_)
{
bool bStateChanged = false;
- // If the 'triggered' state is different form what it is now, change it.
+ // If the 'triggered' state is different from what it is now, change it.
if(state->bTriggered ^ this->isTriggered(state->originator))
{
// Add the originator to the objects triggering this MultiTrigger.
if(state->bTriggered == true)
- {
this->triggered_.insert(state->originator);
- }
// Remove the originator from the objects triggering this MultiTrigger.
else
- {
this->triggered_.erase(state->originator);
- }
bStateChanged = true;
}
// Get the activity of the new state.
bool bActive;
- // If the MultiTrigger is in switch mode.
+ // If the MultiTrigger is in switch mode the 'active'-state only changes of the state changed to triggered.
if(this->bSwitch_ && !state->bTriggered)
bActive = this->isActive(state->originator);
else
@@ -232,37 +224,33 @@
// Add the originator to the objects activating this MultiTrigger.
if(bActive == true)
{
- if(this->remainingActivations_ != 0)
+ // If the MultiTrigger has not exceeded its remaining activations.
+ if(this->remainingActivations_ > 0)
{
this->active_.insert(state->originator);
if(this->remainingActivations_ != INF_s)
this->remainingActivations_--; // Decrement the remaining activations.
}
else
- {
bFire = false;
- }
}
// Remove the originator from the objects activating this MultiTrigger.
else
{
- if(!this->bStayActive_ || this->remainingActivations_ != 0)
- {
+ // If the MultiTrigger doesn't stay active or hasn't' exceeded its remaining activations.
+ if(!this->bStayActive_ || this->remainingActivations_ > 0)
this->active_.erase(state->originator);
- }
else
- {
bFire = false;
- }
}
// Fire the Event if the activity has changed.
if(bFire)
{
+ // If the MultiTrigger is set to broadcast and has no originator a boradcast is fired.
if(this->bBroadcast_ && state->originator == NULL)
- {
this->broadcast(bActive);
- }
+ // Else a normal event is fired.
else
this->fire(bActive, state->originator);
@@ -270,18 +258,20 @@
}
}
- // Print some debug output if the state has changed.
if(bStateChanged)
{
+ // Print some debug output if the state has changed.
if(state->originator != NULL)
COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
else
COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: NULL, active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
+
+ // If the MultiTrigger has a parent trigger it needs to call a method to notify him, that its activity has changed.
if(this->parentTrigger_ != NULL)
- this->parentTrigger_->subTrigggerActivityChanged(state->originator);
+ this->parentTrigger_->subTriggerActivityChanged(state->originator);
}
- // If the MultiTrigger has exceeded its amount of activations and it doesn't stay active, it has to be destroyed,
+ // If the MultiTrigger has exceeded its amount of activations and it doesn't stay active, it has to be deactivated.
if(this->remainingActivations_ == 0 && !bActive)
{
this->BaseObject::setActive(false);
@@ -292,9 +282,8 @@
// Remove the state from the state queue.
this->stateQueue_.pop_front();
delete state;
- size -= 1;
}
- // If the remaining time has not yet expired. Decrement the remainig time.
+ // If the remaining time has not yet expired. Decrement the remainig time and put the state at the end of the queue.
else
{
this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(timeRemaining-dt, state));
@@ -307,7 +296,7 @@
/**
@brief
Get whether the MultiTrigger is active for a given object.
- @param triggerers
+ @param triggerer
A pointer to the object.
@return
Returns true if the MultiTrigger is active, false if not.
@@ -334,6 +323,8 @@
this->setMode(MultiTriggerMode::EventTriggerOR);
else if (modeName == MultiTrigger::xor_s)
this->setMode(MultiTriggerMode::EventTriggerXOR);
+ else
+ COUT(2) << "Invalid mode '" << modeName << "' in MultiTrigger " << this->getName() << " &(" << this << "). Leaving mode at '" << this->getModeString() << "'." << std::endl;
}
/**
@@ -350,7 +341,7 @@
return MultiTrigger::or_s;
else if (this->mode_ == MultiTriggerMode::EventTriggerXOR)
return MultiTrigger::xor_s;
- else
+ else // This can never happen, but the compiler needs it to feel secure.
return MultiTrigger::and_s;
}
@@ -364,23 +355,23 @@
{
Identifier* target = ClassByString(targetStr);
+ // If the target is not a valid class name display an error.
if (target == NULL)
{
- COUT(1) << "Error: \"" << targetStr << "\" is not a valid class name to include in ClassTreeMask (in " << this->getName() << ", class " << this->getIdentifier()->getName() << ')' << std::endl;
+ COUT(1) << "Error: '" << targetStr << "' is not a valid class name to include in ClassTreeMask (in " << this->getName() << ", class " << this->getIdentifier()->getName() << ")" << std::endl;
return;
}
this->targetMask_.include(target);
- // A MultiTriggers shouldn't react to itself or other MultiTriggers.
+ // A MultiTrigger shouldn't react to itself or other MultiTriggers.
this->targetMask_.exclude(Class(MultiTrigger), true);
// We only want WorldEntities
+ //TODO: Really?
ClassTreeMask WEMask;
WEMask.include(Class(WorldEntity));
this->targetMask_ *= WEMask;
-
- this->notifyMaskUpdate();
}
/**
@@ -392,6 +383,14 @@
void MultiTrigger::removeTargets(const std::string& targetStr)
{
Identifier* target = ClassByString(targetStr);
+
+ // If the target is not a valid class name display an error.
+ if (target == NULL)
+ {
+ COUT(1) << "Error: '" << targetStr << "' is not a valid class name to include in ClassTreeMask (in " << this->getName() << ", class " << this->getIdentifier()->getName() << ")" << std::endl;
+ return;
+ }
+
this->targetMask_.exclude(target);
}
@@ -400,7 +399,7 @@
Adds a MultiTrigger as a sub-trigger to the trigger.
Beware: Loops are not prevented and potentially very bad, so just don't create any loops.
@param trigger
- The trigger to be added.
+ The MultiTrigger to be added.
*/
void MultiTrigger::addTrigger(MultiTrigger* trigger)
{
@@ -435,10 +434,10 @@
/**
@brief
This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
- This method is the device for the behaviour (the conditions under which the MultiTrigger triggers) of any derived class from MultiTrigger.
+ This method is the device for the behavior (the conditions under which the MultiTrigger triggers) of any derived class of MultiTrigger.
@return
- A pointer to a queue of MultiTriggerState pointers is returned, containing all the neccessary information to decide whether these states should indeed become new states of the MultiTrigger.
- Please be aware that both the queue and the states in the queue need to be deleted one they have been used. This is already done in the tick() method of this class but would have to be done by any method calling this method.
+ Returns a pointer to a queue of MultiTriggerState pointers, containing all the necessary information to decide whether these states should indeed become new states of the MultiTrigger.
+ Please be aware that both the queue and the states in the queue need to be deleted once they have been used. This is already done in the tick() method of this class but would have to be done by any method calling this method.
*/
std::queue<MultiTriggerState*>* MultiTrigger::letTrigger(void)
{
@@ -463,11 +462,11 @@
/**
@brief
- This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
+ This method is called by any sub-trigger to advertise changes in its state to its parent-trigger.
@param originator
The object that caused the change in activity.
*/
- void MultiTrigger::subTrigggerActivityChanged(BaseObject* originator)
+ void MultiTrigger::subTriggerActivityChanged(BaseObject* originator)
{
MultiTriggerState* state = new MultiTriggerState;
state->bTriggered = (this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->bInvertMode_;
@@ -478,7 +477,7 @@
/**
@brief
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.
- 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 ofr the given object.
+ 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.
@param triggerer
The object.
@return
@@ -486,11 +485,11 @@
*/
bool MultiTrigger::isModeTriggered(BaseObject* triggerer)
{
- if (this->subTriggers_.size() != 0)
+ if(this->subTriggers_.size() != 0)
{
bool returnVal = false;
- switch (this->mode_)
+ switch(this->mode_)
{
case MultiTriggerMode::EventTriggerAND:
returnVal = checkAnd(triggerer);
@@ -501,7 +500,7 @@
case MultiTriggerMode::EventTriggerXOR:
returnVal = checkXor(triggerer);
break;
- default:
+ default: // This will never happen.
returnVal = false;
break;
}
@@ -531,7 +530,7 @@
/**
@brief
Helper method. Creates an Event for the given status and originator and fires it.
- Or more precisely creates a MultiTriggerContainer to encompass all neccesary information and creates an Event from that and sends it.
+ Or more precisely creates a MultiTriggerContainer to encompass all neccesary information, creates an Event from that and sends it.
@param status
The status of the Event to be fired. This is equivalent to the activity of the MultiTrigger.
@param originator
@@ -561,13 +560,8 @@
*/
void MultiTrigger::broadcast(bool status)
{
- ClassTreeMask& targetMask = this->getTargetMask();
-
- for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it)
- {
- BaseObject* object = static_cast<BaseObject*>(*it);
- this->fire(status, object);
- }
+ for(ClassTreeMaskObjectIterator it = this->getTargetMask().begin(); it != this->getTargetMask().end(); ++it)
+ this->fire(status, static_cast<BaseObject*>(*it));
}
/**
@@ -575,16 +569,21 @@
Helper method. Adds a state to the state queue, where the state will wait to become active.
@param state
The state to be added.
+ @return
+ Returns true if the state has been added, false if not. If the state has not been added this method destroys it.
*/
bool MultiTrigger::addState(MultiTriggerState* state)
{
- assert(state);
+ assert(state); // The state really shouldn't be NULL.
// If the originator is no target of this MultiTrigger.
if(!this->isTarget(state->originator))
+ {
+ delete state;
return false;
+ }
- // Add it ot the state queue.
+ // Add it ot the state queue with the delay specified for the MultiTrigger.
this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(this->delay_, state));
return true;
@@ -596,14 +595,13 @@
@param triggerer
The object.
@return
- Returns true if they do.
+ Returns true if all the sub-triggers are active.
*/
bool MultiTrigger::checkAnd(BaseObject* triggerer)
{
- std::set<MultiTrigger*>::iterator it;
- for(it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
+ for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
{
- if (!(*it)->isActive(triggerer))
+ if(!(*it)->isActive(triggerer))
return false;
}
return true;
@@ -615,14 +613,13 @@
@param triggerer
The object.
@return
- Returns true if they do.
+ Returns true if at least one sub-trigger is active.
*/
bool MultiTrigger::checkOr(BaseObject* triggerer)
{
- std::set<MultiTrigger*>::iterator it;
- for(it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
+ for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
{
- if ((*it)->isActive(triggerer))
+ if((*it)->isActive(triggerer))
return true;
}
return false;
@@ -634,17 +631,17 @@
@param triggerer
The object.
@return
- Returns true if they do.
+ Returns true if exactly one sub-trigger is active.
*/
bool MultiTrigger::checkXor(BaseObject* triggerer)
{
- std::set<MultiTrigger*>::iterator it;
bool test = false;
- for(it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
+ for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); ++it)
{
- if (test && (*it)->isActive(triggerer))
+ if(test && (*it)->isActive(triggerer))
return false;
- if ((*it)->isActive(triggerer))
+
+ if((*it)->isActive(triggerer))
test = true;
}
return test;
Modified: code/trunk/src/modules/objects/triggers/MultiTrigger.h
===================================================================
--- code/trunk/src/modules/objects/triggers/MultiTrigger.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/MultiTrigger.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -22,7 +22,7 @@
* Author:
* Damian 'Mozork' Frick
* Co-authors:
- * Benjamin Knecht
+ * ...
*
*/
@@ -69,30 +69,40 @@
/**
@brief
The MultiTrigger class implements a trigger that has a distinct state for each object triggering it.
- In more detail: A Trigger is an object that can either be active or inactive, whith a specified behaviour how to switch between the two. A MultiTrigger generalizes that behaviour for multiple objects trigggering 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, containig a pointer to the pointer that caused the Event and a pointer to the object that caused the trigger to change it's activity.
+ 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.
- MultiTriggers also allow for additional complexity which can be added trough the choice of the parameters explained (briefly) below:
- 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 behaviour is, that the cativity changes, when the MultiTrigger transits from being triggered to not being triggered or the other way around.
+ MultiTriggers also allow for additional complexity which can be added through the choice of the parameters explained (briefly) below:
+ 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.
The parameters are:
'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.
'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.
- '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 -1, which is infinity.
+ '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.
'activations': The number of activations until the trigger can't be triggered anymore. The default is -1, which is infinity.
- '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 behaviour of the MultiTrigger. The default is false.
- 'simultaniousTriggerers': The number of simultanious triggerers limits the number of object that are allowed to trigger the MultiTrigger at the same time. Or a little more precisely, the number of distinct objects the MultiTrigger has 'triggered' states for, at each point in time.
- '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 appendend MultiTriggers is active. And 'xor', meaning that the MultiTrigger can only be triggered if one and only one appended MultiTrigger is active. Notice, that I wrote 'can only be active', that implies, that there is an addtitional 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'.
- 'broadcast' Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaining, 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.
+ '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.
+ '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.
+ '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'.
+ '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.
'target': The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is 'Pawn'.
- Also there is the possibility of appending MultiTriggers to the MultiTrigger just by adding them as subobjects in the XML description of your MultiTrigger.
+ 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.
+ An example of a MultiTrigger created through XML would look like this:
+ @code
+ <MultiTrigger position="0,0,0" delay="1.3" switch="true" stayactive="true" activations="7" invert="true" simultaneousTriggerers="2" mode="xor" broadcast="false" target="Pawn">
+ <MultiTrigger />
+ ...
+ <MultiTrigger />
+ </MultiTrigger>
+ @endcode
+
@author
Damian 'Mozork' Frick
+ Many concepts and loads of inspiration from the Trigger class by Benjamin Knecht.
*/
class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable
{
public:
MultiTrigger(BaseObject* creator); //!< Constructor. Registers the objects and initializes default values.
- ~MultiTrigger(); //!< Destructor.
+ virtual ~MultiTrigger(); //!< Destructor.
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a MultiTrigger object through XML.
virtual void tick(float dt); //!< A method that is executed each tick.
@@ -104,7 +114,7 @@
@param delay The delay to be set.
*/
inline void setDelay(float delay)
- { if(delay > 0) this->delay_= delay; }
+ { if(delay > 0.0f) this->delay_= delay; }
/**
@brief Get the delay of the MultiTrigger.
@return The delay.
@@ -139,12 +149,6 @@
{ return this->bStayActive_; }
/**
- @brief Set the number of activations the MultiTrigger can go through.
- @param activations The number of activations. -1 denotes infinitely many activations.
- */
- inline void setActivations(int activations)
- { if(activations >= 0 || activations == INF_s) this->remainingActivations_ = activations; }
- /**
@brief Get the number of remaining activations of the MultiTrigger.
@return The number of activations. -1 denotes infinity.
*/
@@ -152,17 +156,17 @@
{ return this->remainingActivations_; }
/**
- @brief Set the number of objects that are allowed to simultaniously trigger this MultiTrigger.
+ @brief Set the number of objects that are allowed to simultaneously trigger this MultiTrigger.
@param triggerers The number of objects. -1 denotes infinitely many.
*/
- inline void setSimultaniousTriggerers(int triggerers)
- { if(triggerers >= 0 || triggerers == INF_s) this->maxNumSimultaniousTriggerers_ = triggerers; }
+ inline void setSimultaneousTriggerers(int triggerers)
+ { if(triggerers >= 0 || triggerers == INF_s) this->maxNumSimultaneousTriggerers_ = triggerers; }
/**
- @brief Get the number of objects that are allowed to simultaniously trigger this MultiTriggger.
+ @brief Get the number of objects that are allowed to simultaneously trigger this MultiTriggger.
@return Returns the number of objects. -1 denotes infinity.
*/
- inline int getSimultaniousTriggerers(void)
- { return this->maxNumSimultaniousTriggerers_; }
+ inline int getSimultaneousTriggerers(void)
+ { return this->maxNumSimultaneousTriggerers_; }
/**
@brief Set the invert-mode of the MultiTrigger.
@@ -212,8 +216,6 @@
*/
inline bool isTarget(BaseObject* target)
{ if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
- void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
- void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
void addTrigger(MultiTrigger* trigger); //!< Adds a MultiTrigger as a sub-trigger to the trigger.
const MultiTrigger* getTrigger(unsigned int index) const; //!< Get the sub-trigger of this MultiTrigger at the given index.
@@ -230,6 +232,16 @@
void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
/**
+ @brief Set the number of activations the MultiTrigger can go through.
+ @param activations The number of activations. -1 denotes infinitely many activations.
+ */
+ inline void setActivations(int activations)
+ { if(activations >= 0 || activations == INF_s) this->remainingActivations_ = activations; }
+
+ void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
+ void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
+
+ /**
@brief Adds the parent of a MultiTrigger.
@param parent A pointer to the parent MultiTrigger.
*/
@@ -242,11 +254,6 @@
*/
inline ClassTreeMask& getTargetMask(void)
{ return this->targetMask_; }
- /**
- @brief Is called, when the target mask changes.
- */
- //TODO: Check if something mus be done here.
- virtual void notifyMaskUpdate(void) {}
private:
static const int INF_s; //!< Magic number for infinity.
@@ -255,7 +262,7 @@
static const std::string or_s;
static const std::string xor_s;
- void subTrigggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
+ void subTriggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active.
@@ -277,14 +284,14 @@
bool bStayActive_; //!< Bool for the stay-active-mode, if true the MultiTrigger stays active after its last activation.;
int remainingActivations_; //!< The remaining activations of this MultiTrigger.
- int maxNumSimultaniousTriggerers_; //!< The maximum number of objects simultaniously trigggering this MultiTrigger.
+ int maxNumSimultaneousTriggerers_; //!< The maximum number of objects simultaneously trigggering this MultiTrigger.
bool bInvertMode_; //!< Bool for the invert-mode, if true the MultiTrigger is inverted.
MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger.
bool bBroadcast_; //!< Bool for the broadcast-mode, if true all triggers go to all possible targets.
- MultiTrigger* parentTrigger_;
+ MultiTrigger* parentTrigger_; //!< The parent-trigger of theis MultiTrigger.
std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
std::set<BaseObject*> active_; //!< The set of all objects the MultiTrigger is active for.
Modified: code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc
===================================================================
--- code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc 2010-08-31 21:31:37 UTC (rev 7301)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * ...
+ * Damian 'Mozork' Frick
* Co-authors:
* ...
*
@@ -57,7 +57,7 @@
@param creator
The creator.
@param originator
- A pointer to the originator of the Event, i.e. the MultiTrigger that fired the Event. (or is about to)
+ A pointer to the originator of the Event, i.e. the MultiTrigger that fired the Event. (or is about to fire)
@param data
A pointer to the data that should be sent with the container.
*/
Modified: code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h
===================================================================
--- code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h 2010-08-31 21:19:49 UTC (rev 7300)
+++ code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h 2010-08-31 21:31:37 UTC (rev 7301)
@@ -53,7 +53,7 @@
public:
MultiTriggerContainer(BaseObject* creator); //!< Default constructor. Registers the object and creates an empty container.
MultiTriggerContainer(BaseObject* creator, MultiTrigger* originator, BaseObject* data); //!< Constructor. Registers the object and sets the input values.
- ~MultiTriggerContainer(); //!< Destructor.
+ virtual ~MultiTriggerContainer(); //!< Destructor.
/**
@brief Get the originator of the Event. (The MultiTrigger that fired the Event)
More information about the Orxonox-commit
mailing list