doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Event.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 /*
29 sys_event.h
30 
31 Event are used for scheduling tasks and for linking script commands.
32 */
33 #ifndef __SYS_EVENT_H__
34 #define __SYS_EVENT_H__
35 
36 #define D_EVENT_MAXARGS 8 // if changed, enable the CREATE_EVENT_CODE define in Event.cpp to generate switch statement for idClass::ProcessEventArgPtr.
37  // running the game will then generate c:\doom\base\events.txt, the contents of which should be copied into the switch statement.
38 
39 #define D_EVENT_VOID ( ( char )0 )
40 #define D_EVENT_INTEGER 'd'
41 #define D_EVENT_FLOAT 'f'
42 #define D_EVENT_VECTOR 'v'
43 #define D_EVENT_STRING 's'
44 #define D_EVENT_ENTITY 'e'
45 #define D_EVENT_ENTITY_NULL 'E' // event can handle NULL entity pointers
46 #define D_EVENT_TRACE 't'
47 
48 #define MAX_EVENTS 4096
49 
50 class idClass;
51 class idTypeInfo;
52 
53 class idEventDef {
54 private:
55  const char *name;
56  const char *formatspec;
57  unsigned int formatspecIndex;
59  int numargs;
60  size_t argsize;
62  int eventnum;
63  const idEventDef * next;
64 
66  static int numEventDefs;
67 
68 public:
69  idEventDef( const char *command, const char *formatspec = NULL, char returnType = 0 );
70 
71  const char *GetName( void ) const;
72  const char *GetArgFormat( void ) const;
73  unsigned int GetFormatspecIndex( void ) const;
74  char GetReturnType( void ) const;
75  int GetEventNum( void ) const;
76  int GetNumArgs( void ) const;
77  size_t GetArgSize( void ) const;
78  int GetArgOffset( int arg ) const;
79 
80  static int NumEventCommands( void );
81  static const idEventDef *GetEventCommand( int eventnum );
82  static const idEventDef *FindEvent( const char *name );
83 };
84 
85 class idSaveGame;
86 class idRestoreGame;
87 
88 class idEvent {
89 private:
92  int time;
95 
97 
99 
100 
101 public:
102  static bool initialized;
103 
104  ~idEvent();
105 
106  static idEvent *Alloc( const idEventDef *evdef, int numargs, va_list args );
107  static void CopyArgs( const idEventDef *evdef, int numargs, va_list args, int data[ D_EVENT_MAXARGS ] );
108 
109  void Free( void );
110  void Schedule( idClass *object, const idTypeInfo *cls, int time );
111  byte *GetData( void );
112 
113  static void CancelEvents( const idClass *obj, const idEventDef *evdef = NULL );
114  static void ClearEventList( void );
115  static void ServiceEvents( void );
116 #ifdef _D3XP
117  static void ServiceFastEvents();
118 #endif
119  static void Init( void );
120  static void Shutdown( void );
121 
122  // save games
123  static void Save( idSaveGame *savefile ); // archives object for save game file
124  static void Restore( idRestoreGame *savefile ); // unarchives object from save game file
125  static void SaveTrace( idSaveGame *savefile, const trace_t &trace );
126  static void RestoreTrace( idRestoreGame *savefile, trace_t &trace );
127 
128 };
129 
130 /*
131 ================
132 idEvent::GetData
133 ================
134 */
135 ID_INLINE byte *idEvent::GetData( void ) {
136  return data;
137 }
138 
139 /*
140 ================
141 idEventDef::GetName
142 ================
143 */
144 ID_INLINE const char *idEventDef::GetName( void ) const {
145  return name;
146 }
147 
148 /*
149 ================
150 idEventDef::GetArgFormat
151 ================
152 */
153 ID_INLINE const char *idEventDef::GetArgFormat( void ) const {
154  return formatspec;
155 }
156 
157 /*
158 ================
159 idEventDef::GetFormatspecIndex
160 ================
161 */
162 ID_INLINE unsigned int idEventDef::GetFormatspecIndex( void ) const {
163  return formatspecIndex;
164 }
165 
166 /*
167 ================
168 idEventDef::GetReturnType
169 ================
170 */
171 ID_INLINE char idEventDef::GetReturnType( void ) const {
172  return returnType;
173 }
174 
175 /*
176 ================
177 idEventDef::GetNumArgs
178 ================
179 */
180 ID_INLINE int idEventDef::GetNumArgs( void ) const {
181  return numargs;
182 }
183 
184 /*
185 ================
186 idEventDef::GetArgSize
187 ================
188 */
189 ID_INLINE size_t idEventDef::GetArgSize( void ) const {
190  return argsize;
191 }
192 
193 /*
194 ================
195 idEventDef::GetArgOffset
196 ================
197 */
198 ID_INLINE int idEventDef::GetArgOffset( int arg ) const {
199  assert( ( arg >= 0 ) && ( arg < D_EVENT_MAXARGS ) );
200  return argOffset[ arg ];
201 }
202 
203 /*
204 ================
205 idEventDef::GetEventNum
206 ================
207 */
208 ID_INLINE int idEventDef::GetEventNum( void ) const {
209  return eventnum;
210 }
211 
212 #endif /* !__SYS_EVENT_H__ */
int argOffset[D_EVENT_MAXARGS]
Definition: Event.h:61
void Free(void)
Definition: Event.cpp:365
int returnType
Definition: Event.h:58
assert(prefInfo.fullscreenBtn)
static void Shutdown(void)
Definition: Event.cpp:727
const char * name
Definition: Event.h:55
byte * GetData(void)
Definition: Event.h:135
size_t argsize
Definition: Event.h:60
unsigned int formatspecIndex
Definition: Event.h:57
static void RestoreTrace(idRestoreGame *savefile, trace_t &trace)
Definition: Event.cpp:970
idLinkList< idEvent > eventNode
Definition: Event.h:96
static int numEventDefs
Definition: Event.h:66
const char * formatspec
Definition: Event.h:56
static void ClearEventList(void)
Definition: Event.cpp:471
GLhandleARB obj
Definition: glext.h:3602
static idEventDef * eventDefList[MAX_EVENTS]
Definition: Event.h:65
static int NumEventCommands(void)
Definition: Event.cpp:174
Definition: Class.h:174
idClass * object
Definition: Event.h:93
const idTypeInfo * typeinfo
Definition: Event.h:94
size_t GetArgSize(void) const
Definition: Event.h:189
~idEvent()
Definition: Event.cpp:232
byte * data
Definition: Event.h:91
int numargs
Definition: Event.h:59
static const idEventDef * FindEvent(const char *name)
Definition: Event.cpp:192
const char * GetName(void) const
Definition: Event.h:144
static void Save(idSaveGame *savefile)
Definition: Event.cpp:748
Definition: Event.h:88
#define NULL
Definition: Lib.h:88
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
const idEventDef * next
Definition: Event.h:63
int time
Definition: Event.h:92
idEventDef(const char *command, const char *formatspec=NULL, char returnType=0)
Definition: Event.cpp:60
void Schedule(idClass *object, const idTypeInfo *cls, int time)
Definition: Event.cpp:385
#define D_EVENT_MAXARGS
Definition: Event.h:36
#define MAX_EVENTS
Definition: Event.h:48
int GetEventNum(void) const
Definition: Event.h:208
static const idEventDef * GetEventCommand(int eventnum)
Definition: Event.cpp:183
static bool initialized
Definition: Event.h:102
unsigned int GetFormatspecIndex(void) const
Definition: Event.h:162
int GetNumArgs(void) const
Definition: Event.h:180
int eventnum
Definition: Event.h:62
static idDynamicBlockAlloc< byte, 16 *1024, 256 > eventDataAllocator
Definition: Event.h:98
unsigned char byte
Definition: Lib.h:75
const GLcharARB * name
Definition: glext.h:3629
const idEventDef * eventdef
Definition: Event.h:90
const char * GetArgFormat(void) const
Definition: Event.h:153
static void Restore(idRestoreGame *savefile)
Definition: Event.cpp:829
static void ServiceEvents(void)
Definition: Event.cpp:493
static void SaveTrace(idSaveGame *savefile, const trace_t &trace)
Definition: Event.cpp:994
char GetReturnType(void) const
Definition: Event.h:171
static void CopyArgs(const idEventDef *evdef, int numargs, va_list args, int data[D_EVENT_MAXARGS])
Definition: Event.cpp:337
static idEvent * Alloc(const idEventDef *evdef, int numargs, va_list args)
Definition: Event.cpp:241
static void CancelEvents(const idClass *obj, const idEventDef *evdef=NULL)
Definition: Event.cpp:437
static void Init(void)
Definition: Event.cpp:693
int GetArgOffset(int arg) const
Definition: Event.h:198