00001 /* 00002 00003 ************************************************************************* 00004 00005 ArmageTron -- Just another Tron Lightcycle Game in 3D. 00006 Copyright (C) 2000 Manuel Moos (manuel@moosnet.de) 00007 00008 ************************************************************************** 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00023 00024 *************************************************************************** 00025 00026 */ 00027 00028 #ifndef ArmageTron_EVENT_QUEUE_H 00029 #define ArmageTron_EVENT_QUEUE_H 00030 00031 #include "tList.h" 00032 #include "tHeap.h" 00033 00034 /* 00035 we try to establish a future event management based on the following 00036 assumption that every possible event can guarantee that it won't happen 00037 for the next x seconds; for example, if you are in the center of 00038 an arena, your max speed is 5 mps and the next wall is 30 m away, 00039 you know you won't hit a wall for the next 6 seconds. 00040 00041 To efficiently manage many such possible events, we store them 00042 in a heap-type data structure, where the most urgent events 00043 reside at the bottom (why is everything upside down in informatics?) 00044 of the heap. 00045 00046 Note: time may be replaced by other monotonely increasing functions, 00047 like fuel usage,... 00048 */ 00049 00050 // #define EVENT_DEB 00051 00052 // the events. WARNING: tEvents may be deleted by tEventQueue, 00053 // so make sure that this is allways possible. 00054 00055 00056 class tEventQueue; 00057 00058 class tEvent:public tHeapElement{ 00059 friend class tEventQueue; 00060 virtual ~tEvent(); 00061 public: 00062 tEvent(){} 00063 00064 virtual bool Check(REAL time)=0; 00065 // check the tEvent and update value. (the time we have to check it again) 00066 // return value: TRUE if the tEvent needs to be checked again 00067 // FALSE if the tEvent happened and can be deleted. 00068 00069 // tEventQueue *Queue(); 00070 // in wich queue are we? 00071 00072 virtual void Render(){} 00073 }; 00074 00075 00076 class tEventQueue:public tHeap<tEvent>{ 00077 REAL currentTime; // the current time 00078 00079 public: 00080 tEventQueue():currentTime(0){} 00081 ~tEventQueue(); 00082 00083 void Timestep(REAL time); // processes all the tEvents that 00084 // may happen until time. 00085 00086 }; 00087 00088 00089 00090 00091 #endif 00092