Event.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. /*
  21. sys_event.h
  22. Event are used for scheduling tasks and for linking script commands.
  23. */
  24. #ifndef __SYS_EVENT_H__
  25. #define __SYS_EVENT_H__
  26. #define D_EVENT_MAXARGS 8 // if changed, enable the CREATE_EVENT_CODE define in Event.cpp to generate switch statement for idClass::ProcessEventArgPtr.
  27. // running the game will then generate c:\doom\base\events.txt, the contents of which should be copied into the switch statement.
  28. #define D_EVENT_VOID ( ( char )0 )
  29. #define D_EVENT_INTEGER 'd'
  30. #define D_EVENT_FLOAT 'f'
  31. #define D_EVENT_VECTOR 'v'
  32. #define D_EVENT_STRING 's'
  33. #define D_EVENT_ENTITY 'e'
  34. #define D_EVENT_ENTITY_NULL 'E' // event can handle NULL entity pointers
  35. #define D_EVENT_TRACE 't'
  36. #define MAX_EVENTS 4096
  37. class idClass;
  38. class idTypeInfo;
  39. class idEventDef {
  40. private:
  41. const char *name;
  42. const char *formatspec;
  43. unsigned int formatspecIndex;
  44. int returnType;
  45. int numargs;
  46. size_t argsize;
  47. int argOffset[ D_EVENT_MAXARGS ];
  48. int eventnum;
  49. const idEventDef * next;
  50. static idEventDef * eventDefList[MAX_EVENTS];
  51. static int numEventDefs;
  52. public:
  53. idEventDef( const char *command, const char *formatspec = NULL, char returnType = 0 );
  54. const char *GetName( void ) const;
  55. const char *GetArgFormat( void ) const;
  56. unsigned int GetFormatspecIndex( void ) const;
  57. char GetReturnType( void ) const;
  58. int GetEventNum( void ) const;
  59. int GetNumArgs( void ) const;
  60. size_t GetArgSize( void ) const;
  61. int GetArgOffset( int arg ) const;
  62. static int NumEventCommands( void );
  63. static const idEventDef *GetEventCommand( int eventnum );
  64. static const idEventDef *FindEvent( const char *name );
  65. };
  66. class idSaveGame;
  67. class idRestoreGame;
  68. class idEvent {
  69. private:
  70. const idEventDef *eventdef;
  71. byte *data;
  72. int time;
  73. idClass *object;
  74. const idTypeInfo *typeinfo;
  75. idLinkList<idEvent> eventNode;
  76. static idDynamicBlockAlloc<byte, 16 * 1024, 256> eventDataAllocator;
  77. public:
  78. static bool initialized;
  79. ~idEvent();
  80. static idEvent *Alloc( const idEventDef *evdef, int numargs, va_list args );
  81. static void CopyArgs( const idEventDef *evdef, int numargs, va_list args, int data[ D_EVENT_MAXARGS ] );
  82. void Free( void );
  83. void Schedule( idClass *object, const idTypeInfo *cls, int time );
  84. byte *GetData( void );
  85. static void CancelEvents( const idClass *obj, const idEventDef *evdef = NULL );
  86. static void ClearEventList( void );
  87. static void ServiceEvents( void );
  88. #ifdef _D3XP
  89. static void ServiceFastEvents();
  90. #endif
  91. static void Init( void );
  92. static void Shutdown( void );
  93. // save games
  94. static void Save( idSaveGame *savefile ); // archives object for save game file
  95. static void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  96. static void SaveTrace( idSaveGame *savefile, const trace_t &trace );
  97. static void RestoreTrace( idRestoreGame *savefile, trace_t &trace );
  98. };
  99. /*
  100. ================
  101. idEvent::GetData
  102. ================
  103. */
  104. ID_INLINE byte *idEvent::GetData( void ) {
  105. return data;
  106. }
  107. /*
  108. ================
  109. idEventDef::GetName
  110. ================
  111. */
  112. ID_INLINE const char *idEventDef::GetName( void ) const {
  113. return name;
  114. }
  115. /*
  116. ================
  117. idEventDef::GetArgFormat
  118. ================
  119. */
  120. ID_INLINE const char *idEventDef::GetArgFormat( void ) const {
  121. return formatspec;
  122. }
  123. /*
  124. ================
  125. idEventDef::GetFormatspecIndex
  126. ================
  127. */
  128. ID_INLINE unsigned int idEventDef::GetFormatspecIndex( void ) const {
  129. return formatspecIndex;
  130. }
  131. /*
  132. ================
  133. idEventDef::GetReturnType
  134. ================
  135. */
  136. ID_INLINE char idEventDef::GetReturnType( void ) const {
  137. return returnType;
  138. }
  139. /*
  140. ================
  141. idEventDef::GetNumArgs
  142. ================
  143. */
  144. ID_INLINE int idEventDef::GetNumArgs( void ) const {
  145. return numargs;
  146. }
  147. /*
  148. ================
  149. idEventDef::GetArgSize
  150. ================
  151. */
  152. ID_INLINE size_t idEventDef::GetArgSize( void ) const {
  153. return argsize;
  154. }
  155. /*
  156. ================
  157. idEventDef::GetArgOffset
  158. ================
  159. */
  160. ID_INLINE int idEventDef::GetArgOffset( int arg ) const {
  161. assert( ( arg >= 0 ) && ( arg < D_EVENT_MAXARGS ) );
  162. return argOffset[ arg ];
  163. }
  164. /*
  165. ================
  166. idEventDef::GetEventNum
  167. ================
  168. */
  169. ID_INLINE int idEventDef::GetEventNum( void ) const {
  170. return eventnum;
  171. }
  172. #endif /* !__SYS_EVENT_H__ */