event Class Reference

Base class for events. More...

#include <event.h>

Inheritance diagram for event:

Inheritance graph
[legend]
Collaboration diagram for event:

Collaboration graph
[legend]

List of all members.

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_objectScript
 The Python script accociated with this event.
PyObject * Args
 The arguments passed to the script.
py_callbackPyFunc
 Python callback that may be executed instead of the script.
Functor0 Callback
 C++ callback that may be executed when the event gets triggered.
event_listList
 The event_list this event is kept in.


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


Constructor & Destructor Documentation

event::event (  ) 

Constructor.

Needs to be called by any derived class!

Definition at line 26 of file event.cc.

event::~event (  )  [virtual]

Destructor.

Definition at line 40 of file event.cc.


Member Function Documentation

void event::clear (  ) 

Cleanup.

Clears script and its arguments.

Definition at line 52 of file event.cc.

u_int8 event::type (  )  const [inline]

Get the event's type.

Returns:
type of the event

Definition at line 98 of file event.h.

const string& event::id (  )  const [inline]

Get the event's id.

Returns:
id of the event.

Definition at line 108 of file event.h.

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:
id a string to identify the event.

Definition at line 119 of file event.h.

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

void event::set_registered ( bool  reg  )  [inline]

Set whether the event is registered with the event handler.

Parameters:
reg Set to true if it is, to false otherwise.

Definition at line 139 of file event.h.

void event::set_list ( event_list list  ) 

Tell the whether it is kept in an event_list.

Parameters:
list The event_list this event has been added to.

Definition at line 217 of file event.cc.

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

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:
count How often the event should be repeated.

Definition at line 169 of file event.h.

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

Execute the associated python script or callback.

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

Implemented in map_event, and time_event.

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

Compare two events for equality.

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

Implemented in map_event, and time_event.

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

Sets a script to be executed whenever the event occurs.

Parameters:
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.

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

Definition at line 114 of file event.cc.

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:
callback The callback, a function with no arguments returning void

Definition at line 127 of file event.cc.

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 223 of file event.cc.

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 230 of file event.cc.

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

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:
out file where to save the event.

Reimplemented in map_event, and time_event.

Definition at line 137 of file event.cc.

bool event::get_state ( igzstream in  )  [virtual]

Loads the basic event date from a file.

Call this method from the derived class.

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

Reimplemented in map_event, and time_event.

Definition at line 174 of file event.cc.

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 237 of file event.cc.


Member Data Documentation

u_int8 event::Type [protected]

Event type - see enum above.

Definition at line 305 of file event.h.

string event::Id [protected]

(Optional) Id of the event

Definition at line 310 of file event.h.

u_int8 event::Action [protected]

What happens if the event occurs - see enum above.

Definition at line 315 of file event.h.

bool event::Registered [protected]

Whether the event is registered with the event handler.

Definition at line 320 of file event.h.

bool event::Paused [protected]

Whether the event temporarily disabled or not.

Definition at line 325 of file event.h.

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

py_object* event::Script [protected]

The Python script accociated with this event.

It is executed whenever the event gets triggered.

Definition at line 338 of file event.h.

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

py_callback* event::PyFunc [protected]

Python callback that may be executed instead of the script.

Definition at line 349 of file event.h.

Functor0 event::Callback [protected]

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

Definition at line 354 of file event.h.

event_list* event::List [protected]

The event_list this event is kept in.

Definition at line 359 of file event.h.


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

Generated on Wed Jun 18 16:23:54 2008 for Adonthell by  doxygen 1.5.6