Adonthell 0.4
|
00001 /* 00002 $Id: time_event_handler.h,v 1.4 2002/08/18 19:53:17 ksterker Exp $ 00003 00004 Copyright (C) 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 * @file time_event_handler.h 00017 * 00018 * @author Kai Sterker 00019 * @brief Declares the time_event_handler class. 00020 */ 00021 00022 #ifndef TIME_EVENT_HANDLER_H__ 00023 #define TIME_EVENT_HANDLER_H__ 00024 00025 #include <vector> 00026 #include "event_handler_base.h" 00027 00028 using std::vector; 00029 00030 /** 00031 * This class keeps track of time events, i.e. events that are raised 00032 * at a certain point in (%game) time. All registered events are 00033 * sorted by the time they need to be raised, so that only one 00034 * comparison decides upon whether an %event is to be raised. 00035 */ 00036 class time_event_handler : public event_handler_base 00037 { 00038 public: 00039 /** 00040 * Register a time %event with the %event handler. It is inserted 00041 * into the vector of registered events depending on its "alarm" 00042 * time. The %event needs to be removed before it can be safely 00043 * deleted. 00044 * 00045 * @param evnt Pointer to the %event to be registered. 00046 */ 00047 void register_event (event *evnt); 00048 00049 /** 00050 * Removes the given %event from the %event handler. Once it is 00051 * no longer needed, it can be freed. 00052 * 00053 * @param evnt Pointer to the %event to be removed. 00054 */ 00055 void remove_event (event *evnt); 00056 00057 /** 00058 * Raise one or more events in case the given time matches their 00059 * "alarm" time. When they need to be repeated, they are 00060 * re-inserted into the %event-vector. 00061 * 00062 * @param evnt An %event structure with the current %game time in 00063 * minutes. 00064 */ 00065 void raise_event (const event *evnt); 00066 00067 private: 00068 // storage for registered time events. 00069 vector<event*> Events; 00070 }; 00071 00072 #endif // TIME_EVENT_HANDLER_H__