Adonthell  0.4
event_handler.cc
Go to the documentation of this file.
1 /*
2  $Id: event_handler.cc,v 1.5 2003/02/23 23:14:34 ksterker Exp $
3 
4  Copyright (C) 2000/2001/2002 Kai Sterker <kaisterker@linuxgames.com>
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 
16 /**
17  * @file event_handler.cc
18  * @author Kai Sterker <kaisterker@linuxgames.com>
19  *
20  * @brief Implements the event_handler class.
21  *
22  */
23 
24 #include "event_handler.h"
25 #include "map_event.h"
26 #include "map_event_handler.h"
27 #include "time_event.h"
28 #include "time_event_handler.h"
29 
30 // Array with registered event handlers
31 event_handler_base* event_handler::Handler[MAX_EVENTS];
32 
33 // functions that return newly instanciated events
34 // of a certain type
39 
40 // Initialize the game event system
41 void event_handler::init ()
42 {
43  // register event handlers
44  Handler[ENTER_EVENT] = new map_event_handler;
45  Handler[LEAVE_EVENT] = new map_event_handler;
46  Handler[ACTION_EVENT] = new map_event_handler;
47  Handler[TIME_EVENT] = new time_event_handler;
48 
49  // register events
50  REGISTER_EVENT (TIME_EVENT, time_event)
51  REGISTER_EVENT (ENTER_EVENT, enter_event)
52  REGISTER_EVENT (LEAVE_EVENT, leave_event)
53  REGISTER_EVENT (ACTION_EVENT, action_event)
54 }
55 
56 // Clear the registered handlers
58 {
59  for (int i = 0; i < MAX_EVENTS; i++)
60  if (Handler[i] != NULL)
61  delete Handler[i];
62 }
This is the base class for actual event handlers.
Declares the event_handler class.
To notify when a mapcharacter left a mapsquare.
Definition: map_event.h:122
Declares the map_event_handler class.
To notify when a mapcharacter "act" on a square.
Definition: map_event.h:135
#define NEW_EVENT(evt)
A function that returns a new instance of an event.
Definition: event_list.h:199
To notify when a character entered a mapsquare.
Definition: map_event.h:109
This class keeps track of map events, i.e.
The time event executes the attached script or callback at a certain point in game-time.
Definition: time_event.h:34
static void cleanup()
Delete the event handlers.
Declares the time_event_handler class.
Declares the time_event class.
#define REGISTER_EVENT(type, evt)
Registers an event with the event_list, allowing it to load this event without knowing about it at co...
Definition: event_list.h:193
Declares the different map events.
It ensures global access to the individual event handlers.
Definition: event_handler.h:33
This class keeps track of time events, i.e.