Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/libraries/core/EventIncludes.h @ 5879

Last change on this file since 5879 was 5879, checked in by landauf, 15 years ago

More changes in the event-system: processEvent() is now locally executed in BaseObject. The event states (like activity, visibility, …) are now defined in XMLEventPort, a function which closely resembles XMLPort. This function is used to define event states and to parse event sources from XML.

Connected the main-state directly with the event-system. After a state was declared as the "main state", the Functor from the corresponding EventState-object is used to call the function. This reduces the redundancy of declaring event-states and main-states separately. Of course only boolean event-states (like activity or visibility) can be used as main-state, while memoryless states (like spawn in ParticleSpawner) and individual states which need the triggering object (like execute in QuestEffectBeacon) won't work.

  • Property svn:eol-style set to native
File size: 3.6 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
35/**
36    @brief Defines a new event state (a state of the object which can be changed by events).
37   
38    @param classname    The name of this class
39    @param subclassname Usually BaseObject - if different, only instances of this class can send events to this object
40    @param statename    The name (string) of this state
41    @param function     The function which should be used to set the state
42    @param xmlelement   Argument for XMLPort
43    @param mode         Argument for XMLPort
44*/
45#define XMLPortEventState(classname, subclassname, statename, function, xmlelement, mode) \
46    orxonox::EventState* containername##function = this->getEventState(statename); \
47    if (!containername##function) \
48    { \
49        containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
50        this->addEventState(statename, containername##function); \
51    } \
52    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
53
54/**
55    @brief Like XMLPortEventState but with additional template arguments to identify the function of the state (if ambiguous).
56*/
57#define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \
58    orxonox::EventState* containername##function = this->getEventState(statename); \
59    if (!containername##function) \
60    { \
61        containername##function = new orxonox::EventState(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
62        this->addEventState(statename, containername##function); \
63    } \
64    XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode)
65
66#define XMLPortEventStateIntern(name, classname, statename, xmlelement, mode) \
67    static orxonox::ExecutorMember<classname>* xmlsetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::addEventSource), std::string( #classname ) + "::" + "addEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \
68    static orxonox::ExecutorMember<classname>* xmlgetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::getEventSource), std::string( #classname ) + "::" + "getEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \
69    XMLPortObjectGeneric(xmlport##name, classname, orxonox::BaseObject, statename, xmlsetfunctor##name, xmlgetfunctor##name, xmlelement, mode, false, true)
70 
71#endif /* _EventIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.