Adonthell 0.4
event_handler.cc
Go to the documentation of this file.
00001 /*
00002    $Id: event_handler.cc,v 1.5 2003/02/23 23:14:34 ksterker Exp $
00003 
00004    Copyright (C) 2000/2001/2002 Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 
00016 /**
00017  * @file   event_handler.cc
00018  * @author Kai Sterker <kaisterker@linuxgames.com>
00019  * 
00020  * @brief  Implements the event_handler class.
00021  * 
00022  */
00023  
00024 #include "event_handler.h"
00025 #include "map_event.h"
00026 #include "map_event_handler.h"
00027 #include "time_event.h"
00028 #include "time_event_handler.h"
00029 
00030 // Array with registered event handlers
00031 event_handler_base* event_handler::Handler[MAX_EVENTS];
00032 
00033 // functions that return newly instanciated events
00034 // of a certain type
00035 NEW_EVENT (time_event)
00036 NEW_EVENT (enter_event); 
00037 NEW_EVENT (leave_event); 
00038 NEW_EVENT (action_event); 
00039 
00040 // Initialize the game event system
00041 void event_handler::init ()
00042 {
00043     // register event handlers
00044     Handler[ENTER_EVENT] = new map_event_handler;
00045     Handler[LEAVE_EVENT] = new map_event_handler;
00046     Handler[ACTION_EVENT] = new map_event_handler;
00047     Handler[TIME_EVENT] = new time_event_handler;
00048 
00049     // register events
00050     REGISTER_EVENT (TIME_EVENT, time_event)
00051     REGISTER_EVENT (ENTER_EVENT, enter_event)
00052     REGISTER_EVENT (LEAVE_EVENT, leave_event) 
00053     REGISTER_EVENT (ACTION_EVENT, action_event) 
00054 }
00055 
00056 // Clear the registered handlers
00057 void event_handler::cleanup ()
00058 {
00059     for (int i = 0; i < MAX_EVENTS; i++)
00060         if (Handler[i] != NULL)
00061             delete Handler[i];
00062 }