Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/EventIncludes.h @ 7143

Last change on this file since 7143 was 6800, checked in by dafrick, 15 years ago

Created a new class of triggers called Multitriggers.
MultiTriggers are triggers which (as opposed to normal triggers) have a state for each object triggering the MultiTrigger, that means, that a MultiTrigger can be triggered for two different Players, while not being triggered for a third.
To go with this MultiTrigger I created a data structure (MultitriggerContainer), which helps relaying important information to the objects, that receive the Events of the trigger.
Also there is a MultiDistanceTrigger, which is just the DistanceTrigger as a MultiTrigger.

To make this work I had to make some adjustements to the eventsystem, namely an EventState can now be either an EventState (as it was before) or an EventSink, which means that every efent arriving at the EventState is processed as opposed to just the ones which change the state.
There is a new makro (XMLPortEventSink) to create an EventState with sink behaviour. It can be used exacly as the XMLPortEventState makro.

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _EventIncludes_H__
30#define _EventIncludes_H__
31
32#include "CorePrereqs.h"
33#include "Executor.h"
34#include "XMLPort.h"
35
36/**
37    @brief Defines a new event state (a state of the object which can be changed by events).
38
39    @param classname    The name of this class
40    @param subclassname Usually BaseObject - if different, only instances of this class can send events to this object
41    @param statename    The name (string) of this state
42    @param function     The function which should be used to set the state
43    @param xmlelement   Argument for XMLPort
44    @param mode         Argument for XMLPort
45*/
46#define XMLPortEventState(classname, subclassname, statename, function, xmlelement, mode) \
47    orxonox::EventState* containername##function = this->getEventState(statename); \
48    if (!containername##function) \
49    { \
50        containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
51        this->addEventState(statename, containername##function); \
52    } \
53    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
54   
55#define XMLPortEventSink(classname, subclassname, statename, function, xmlelement, mode) \
56    orxonox::EventState* containername##function = this->getEventState(statename); \
57    if (!containername##function) \
58    { \
59        containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier(), true); \
60        this->addEventState(statename, containername##function); \
61    } \
62    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
63
64/**
65    @brief Like XMLPortEventState but creates an event sink instead of an event state.
66           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.
67*/
68#define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \
69    orxonox::EventState* containername##function = this->getEventState(statename); \
70    if (!containername##function) \
71    { \
72        containername##function = new orxonox::EventState(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
73        this->addEventState(statename, containername##function); \
74    } \
75    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
76
77#define XMLPortEventStateIntern(name, classname, statename, xmlelement, mode) \
78    static orxonox::ExecutorMember<classname>* xmlsetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::addEventSource), std::string( #classname ) + "::" + "addEventSource" + '(' + statename + ')')->setDefaultValue(1, statename); \
79    static orxonox::ExecutorMember<classname>* xmlgetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::getEventSource), std::string( #classname ) + "::" + "getEventSource" + '(' + statename + ')')->setDefaultValue(1, statename); \
80    XMLPortObjectGeneric(xmlport##name, classname, orxonox::BaseObject, statename, xmlsetfunctor##name, xmlgetfunctor##name, xmlelement, mode, false, true)
81
82
83/**
84    @brief Defines a new event name for a class. Named events can only have names which were defined with this macro.
85
86    @param classname The name of the class
87    @param name      The name of the event
88*/
89#define CreateEventName(classname, name) \
90    static std::string eventname##classname##name = #name
91
92/**
93    @brief This macro is needed to fire an event with this name. The event name must previously be declared with @ref CreateEventName.
94*/
95#define FireEventName(classname, name) \
96    eventname##classname##name
97
98#endif /* _EventIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.