Base class for events. More...
#include <event.h>
Public Member Functions | |
event () | |
Constructor. | |
virtual | ~event () |
Destructor. | |
void | clear () |
Cleanup. | |
void | set_script (string filename, PyObject *args=NULL) |
Sets a script to be executed whenever the event occurs. | |
void | set_callback (PyObject *callback, PyObject *args=NULL) |
Sets a python function/method to be executed whenever the event occurs. | |
void | set_callback (const Functor0 &callback) |
Sets a C function/C++ method to be executed whenever the event occurs. | |
Member access | |
u_int8 | type () const |
Get the event's type. | |
const string & | id () const |
Get the event's id. | |
void | set_id (const string &id) |
Assign an id to the event, so it may be retrieved from an event_list later on, without having a pointer to it. | |
bool | registered () const |
Test whether the event is registered with the event handler. | |
void | set_registered (bool reg) |
Set whether the event is registered with the event handler. | |
void | set_list (event_list *list) |
Tell the whether it is kept in an event_list. | |
s_int32 | repeat () const |
Return whether this event should be repeated. | |
void | set_repeat (s_int32 count) |
Set whether this event should be repeated. | |
Event Handling | |
virtual s_int32 | execute (const event *evnt)=0 |
Execute the associated python script or callback. | |
virtual bool | equals (const event *evnt)=0 |
Compare two events for equality. | |
Pausing / Resuming execution | |
virtual void | pause () |
Disable the event temporarily. | |
virtual void | resume () |
Re-enable an event that has been paused. | |
bool | is_paused () const |
Check whether the event is temporarily disabled or not. | |
Loading / Saving | |
virtual void | put_state (ogzstream &out) const |
Saves the basic event data (such as the type or script data) to a file. | |
virtual bool | get_state (igzstream &in) |
Loads the basic event date from a file. | |
Protected Member Functions | |
s_int32 | do_repeat () |
Decrease the event's repeat count and return the number of repeats left. | |
Protected Attributes | |
Basic Event Data | |
u_int8 | Type |
Event type - see enum above. | |
string | Id |
(Optional) Id of the event | |
u_int8 | Action |
What happens if the event occurs - see enum above. | |
bool | Registered |
Whether the event is registered with the event handler. | |
bool | Paused |
Whether the event temporarily disabled or not. | |
s_int32 | Repeat |
Defines how often the event should be repeated. | |
py_object * | Script |
The Python script accociated with this event. | |
PyObject * | Args |
The arguments passed to the script. | |
py_callback * | PyFunc |
Python callback that may be executed instead of the script. | |
Functor0 | Callback |
C++ callback that may be executed when the event gets triggered. | |
event_list * | List |
The event_list this event is kept in. |
Base class for events.
You can create your own event types that can be handled by the event_list and event_handler by inheriting from this class.
Events are used to notify when certain things happen during the game. They may either execute the "run" method of an exclusive python script or a simple python callback defined elsewhere.
Definition at line 71 of file event.h.
event::event | ( | ) |
void event::clear | ( | ) |
u_int8 event::type | ( | ) | const [inline] |
const string& event::id | ( | ) | const [inline] |
void event::set_id | ( | const string & | id | ) | [inline] |
Assign an id to the event, so it may be retrieved from an event_list later on, without having a pointer to it.
id | a string to identify the event. |
bool event::registered | ( | ) | const [inline] |
void event::set_registered | ( | bool | reg | ) | [inline] |
void event::set_list | ( | event_list * | list | ) |
s_int32 event::repeat | ( | ) | const [inline] |
void event::set_repeat | ( | s_int32 | count | ) | [inline] |
virtual s_int32 event::execute | ( | const event * | evnt | ) | [pure virtual] |
Execute the associated python script or callback.
evnt | The event that triggered the execution. |
virtual bool event::equals | ( | const event * | evnt | ) | [pure virtual] |
Compare two events for equality.
evnt | pointer to the event to compare with. |
void event::set_script | ( | string | filename, | |
PyObject * | args = NULL | |||
) |
Sets a script to be executed whenever the event occurs.
filename | filename of the script to set. | |
args | The arguments to pass to the script's constructor |
void event::set_callback | ( | PyObject * | callback, | |
PyObject * | args = NULL | |||
) |
Sets a python function/method to be executed whenever the event occurs.
callback | The function or method to call. | |
args | Additional arguments to pass to the callback. |
void event::set_callback | ( | const Functor0 & | callback | ) |
void event::pause | ( | ) | [virtual] |
Disable the event temporarily.
As long as it in this state, the event will neither be executed, nor will its repeat-count change. As long as the event is paused, it will be removed from its event handler.
Reimplemented in time_event.
void event::resume | ( | ) | [virtual] |
Re-enable an event that has been paused.
Re-registers it with its event handler.
Reimplemented in time_event.
bool event::is_paused | ( | ) | const [inline] |
void event::put_state | ( | ogzstream & | out | ) | const [virtual] |
Saves the basic event data (such as the type or script data) to a file.
Call this method from the derived class.
out | file where to save the event. |
Reimplemented in map_event, and time_event.
bool event::get_state | ( | igzstream & | in | ) | [virtual] |
Loads the basic event date from a file.
Call this method from the derived class.
in | file to load the event from. |
Reimplemented in map_event, and time_event.
s_int32 event::do_repeat | ( | ) | [protected] |
u_int8 event::Type [protected] |
u_int8 event::Action [protected] |
bool event::Registered [protected] |
bool event::Paused [protected] |
s_int32 event::Repeat [protected] |
py_object* event::Script [protected] |
PyObject* event::Args [protected] |
py_callback* event::PyFunc [protected] |
Functor0 event::Callback [protected] |
event_list* event::List [protected] |
The event_list this event is kept in.