Adonthell  0.4
event Class Referenceabstract

Base class for events. More...

#include <event.h>

Inheritance diagram for event:
Collaboration diagram for event:

Public Member Functions

 event ()
 Constructor. More...
 
virtual ~event ()
 Destructor. More...
 
void clear ()
 Cleanup. More...
 
void set_script (string filename, PyObject *args=NULL)
 Sets a script to be executed whenever the event occurs. More...
 
void set_callback (PyObject *callback, PyObject *args=NULL)
 Sets a python function/method to be executed whenever the event occurs. More...
 
void set_callback (const Functor0 &callback)
 Sets a C function/C++ method to be executed whenever the event occurs. More...
 
Member access
u_int8 type () const
 Get the event's type. More...
 
const string & id () const
 Get the event's id. More...
 
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. More...
 
bool registered () const
 Test whether the event is registered with the event handler. More...
 
void set_registered (bool reg)
 Set whether the event is registered with the event handler. More...
 
void set_list (event_list *list)
 Tell the whether it is kept in an event_list. More...
 
s_int32 repeat () const
 Return whether this event should be repeated. More...
 
void set_repeat (s_int32 count)
 Set whether this event should be repeated. More...
 
Event Handling
virtual s_int32 execute (const event *evnt)=0
 Execute the associated python script or callback. More...
 
virtual bool equals (const event *evnt)=0
 Compare two events for equality. More...
 
Pausing / Resuming execution
virtual void pause ()
 Disable the event temporarily. More...
 
virtual void resume ()
 Re-enable an event that has been paused. More...
 
bool is_paused () const
 Check whether the event is temporarily disabled or not. More...
 
Loading / Saving
virtual void put_state (ogzstream &out) const
 Saves the basic event data (such as the type or script data) to a file. More...
 
virtual bool get_state (igzstream &in)
 Loads the basic event date from a file. More...
 

Protected Member Functions

s_int32 do_repeat ()
 Decrease the event's repeat count and return the number of repeats left. More...
 

Protected Attributes

Basic Event Data
u_int8 Type
 Event type - see enum above. More...
 
string Id
 (Optional) Id of the event More...
 
u_int8 Action
 What happens if the event occurs - see enum above. More...
 
bool Registered
 Whether the event is registered with the event handler. More...
 
bool Paused
 Whether the event temporarily disabled or not. More...
 
s_int32 Repeat
 Defines how often the event should be repeated. More...
 
py_objectScript
 The Python script accociated with this event. More...
 
PyObject * Args
 The arguments passed to the script. More...
 
py_callbackPyFunc
 Python callback that may be executed instead of the script. More...
 
Functor0 Callback
 C++ callback that may be executed when the event gets triggered. More...
 
event_listList
 The event_list this event is kept in. More...
 

Detailed Description

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 75 of file event.h.

Constructor & Destructor Documentation

§ event()

event::event ( )

Constructor.

Needs to be called by any derived class!

Definition at line 30 of file event.cc.

§ ~event()

event::~event ( )
virtual

Destructor.

Definition at line 44 of file event.cc.

Member Function Documentation

§ clear()

void event::clear ( )

Cleanup.

Clears script and its arguments.

Definition at line 56 of file event.cc.

§ type()

u_int8 event::type ( ) const
inline

Get the event's type.

Returns
type of the event

Definition at line 102 of file event.h.

§ id()

const string& event::id ( ) const
inline

Get the event's id.

Returns
id of the event.

Definition at line 112 of file event.h.

§ set_id()

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.

Parameters
ida string to identify the event.

Definition at line 123 of file event.h.

§ registered()

bool event::registered ( ) const
inline

Test whether the event is registered with the event handler.

Returns
true if this is the case, false otherwise.

Definition at line 133 of file event.h.

§ set_registered()

void event::set_registered ( bool  reg)
inline

Set whether the event is registered with the event handler.

Parameters
regSet to true if it is, to false otherwise.

Definition at line 143 of file event.h.

§ set_list()

void event::set_list ( event_list list)

Tell the whether it is kept in an event_list.

Parameters
listThe event_list this event has been added to.

Definition at line 221 of file event.cc.

§ repeat()

s_int32 event::repeat ( ) const
inline

Return whether this event should be repeated.

Returns
the number of times this event should be repeated or -1 in case it should be repeated unlimited times.

Definition at line 161 of file event.h.

§ set_repeat()

void event::set_repeat ( s_int32  count)
inline

Set whether this event should be repeated.

A number greater than 0 will execute the event that many times, a number less than 0 will repeat the event forever. A number equal to 0 won't repeat the event.

Parameters
countHow often the event should be repeated.

Definition at line 173 of file event.h.

§ execute()

virtual s_int32 event::execute ( const event evnt)
pure virtual

Execute the associated python script or callback.

Parameters
evntThe event that triggered the execution.
Returns
The number of times the event needs to be repeated.

Implemented in time_event, and map_event.

§ equals()

virtual bool event::equals ( const event evnt)
pure virtual

Compare two events for equality.

Parameters
evntpointer to the event to compare with.
Returns
true if the events are equal, false otherwise.

Implemented in time_event, and map_event.

§ set_script()

void event::set_script ( string  filename,
PyObject *  args = NULL 
)

Sets a script to be executed whenever the event occurs.

Parameters
filenamefilename of the script to set.
argsThe arguments to pass to the script's constructor

Definition at line 87 of file event.cc.

§ set_callback() [1/2]

void event::set_callback ( PyObject *  callback,
PyObject *  args = NULL 
)

Sets a python function/method to be executed whenever the event occurs.

Warning
the callback won't be saved with the event. It must be restored by the event's owner.
Parameters
callbackThe function or method to call.
argsAdditional arguments to pass to the callback.

Definition at line 118 of file event.cc.

§ set_callback() [2/2]

void event::set_callback ( const Functor0 &  callback)

Sets a C function/C++ method to be executed whenever the event occurs.

Warning
the callback won't be saved with the event. It must be restored by the event's owner.
Parameters
callbackThe callback, a function with no arguments returning void

Definition at line 131 of file event.cc.

§ pause()

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.

Definition at line 227 of file event.cc.

§ resume()

void event::resume ( )
virtual

Re-enable an event that has been paused.

Re-registers it with its event handler.

Reimplemented in time_event.

Definition at line 234 of file event.cc.

§ is_paused()

bool event::is_paused ( ) const
inline

Check whether the event is temporarily disabled or not.

Returns
true if it is paused, false otherwise.

Definition at line 260 of file event.h.

§ put_state()

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.

Parameters
outfile where to save the event.

Reimplemented in time_event, and map_event.

Definition at line 141 of file event.cc.

§ get_state()

bool event::get_state ( igzstream in)
virtual

Loads the basic event date from a file.

Call this method from the derived class.

Parameters
infile to load the event from.
Returns
true if the event could be loaded, false otherwise

Reimplemented in time_event, and map_event.

Definition at line 178 of file event.cc.

§ do_repeat()

s_int32 event::do_repeat ( )
protected

Decrease the event's repeat count and return the number of repeats left.

If the repeat-count reaches 0, the event will be destroyed.

Returns
the number of times this event should be repeated or -1 in case it should be repeated unlimited times.

Definition at line 241 of file event.cc.

Member Data Documentation

§ Type

u_int8 event::Type
protected

Event type - see enum above.

Definition at line 309 of file event.h.

§ Id

string event::Id
protected

(Optional) Id of the event

Definition at line 314 of file event.h.

§ Action

u_int8 event::Action
protected

What happens if the event occurs - see enum above.

Definition at line 319 of file event.h.

§ Registered

bool event::Registered
protected

Whether the event is registered with the event handler.

Definition at line 324 of file event.h.

§ Paused

bool event::Paused
protected

Whether the event temporarily disabled or not.

Definition at line 329 of file event.h.

§ Repeat

s_int32 event::Repeat
protected

Defines how often the event should be repeated.

0 means never, -1 means infinitely and n (n > 0) means exactly n times.

Definition at line 336 of file event.h.

§ Script

py_object* event::Script
protected

The Python script accociated with this event.

It is executed whenever the event gets triggered.

Definition at line 342 of file event.h.

§ Args

PyObject* event::Args
protected

The arguments passed to the script.

This needs to be a PyTuple or NULL if there are no arguments.

Definition at line 348 of file event.h.

§ PyFunc

py_callback* event::PyFunc
protected

Python callback that may be executed instead of the script.

Definition at line 353 of file event.h.

§ Callback

Functor0 event::Callback
protected

C++ callback that may be executed when the event gets triggered.

Definition at line 358 of file event.h.

§ List

event_list* event::List
protected

The event_list this event is kept in.

Definition at line 363 of file event.h.


The documentation for this class was generated from the following files: