2012-11-26 18:58:24 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Doom 3 BFG Edition GPL Source Code
2012-11-28 15:47:07 +00:00
Copyright ( C ) 1993 - 2012 id Software LLC , a ZeniMax Media company .
2012-12-07 17:29:47 +00:00
Copyright ( C ) 2012 Robert Beckebans
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ( " Doom 3 BFG Edition Source Code " ) .
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code . If not , see < http : //www.gnu.org/licenses/>.
In addition , the Doom 3 BFG Edition 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 BFG Edition Source Code . If not , please request a copy in writing from id Software at the address below .
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 .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
/*
sys_event . h
Event are used for scheduling tasks and for linking script commands .
*/
# ifndef __SYS_EVENT_H__
# define __SYS_EVENT_H__
# define D_EVENT_MAXARGS 8 // if changed, enable the CREATE_EVENT_CODE define in Event.cpp to generate switch statement for idClass::ProcessEventArgPtr.
2012-11-28 15:47:07 +00:00
// running the game will then generate c:\doom\base\events.txt, the contents of which should be copied into the switch statement.
2012-11-26 18:58:24 +00:00
2012-12-07 17:29:47 +00:00
// RB: from dhewm3
// stack size of idVec3, aligned to native pointer size
# define E_EVENT_SIZEOF_VEC ((sizeof(idVec3) + (sizeof(intptr_t) - 1)) & ~(sizeof(intptr_t) - 1))
// RB end
2012-11-26 18:58:24 +00:00
# define D_EVENT_VOID ( ( char )0 )
# define D_EVENT_INTEGER 'd'
# define D_EVENT_FLOAT 'f'
# define D_EVENT_VECTOR 'v'
# define D_EVENT_STRING 's'
# define D_EVENT_ENTITY 'e'
# define D_EVENT_ENTITY_NULL 'E' // event can handle NULL entity pointers
# define D_EVENT_TRACE 't'
# define MAX_EVENTS 4096
class idClass ;
class idTypeInfo ;
2012-11-28 15:47:07 +00:00
class idEventDef
{
2012-11-26 18:58:24 +00:00
private :
2012-11-28 15:47:07 +00:00
const char * name ;
const char * formatspec ;
2012-11-26 18:58:24 +00:00
unsigned int formatspecIndex ;
int returnType ;
int numargs ;
size_t argsize ;
int argOffset [ D_EVENT_MAXARGS ] ;
int eventnum ;
2012-11-28 15:47:07 +00:00
const idEventDef * next ;
static idEventDef * eventDefList [ MAX_EVENTS ] ;
2012-11-26 18:58:24 +00:00
static int numEventDefs ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
public :
2012-11-28 15:47:07 +00:00
idEventDef ( const char * command , const char * formatspec = NULL , char returnType = 0 ) ;
const char * GetName ( ) const ;
const char * GetArgFormat ( ) const ;
2012-11-26 18:58:24 +00:00
unsigned int GetFormatspecIndex ( ) const ;
char GetReturnType ( ) const ;
int GetEventNum ( ) const ;
int GetNumArgs ( ) const ;
size_t GetArgSize ( ) const ;
int GetArgOffset ( int arg ) const ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
static int NumEventCommands ( ) ;
2012-11-28 15:47:07 +00:00
static const idEventDef * GetEventCommand ( int eventnum ) ;
static const idEventDef * FindEvent ( const char * name ) ;
2012-11-26 18:58:24 +00:00
} ;
class idSaveGame ;
class idRestoreGame ;
2012-11-28 15:47:07 +00:00
class idEvent
{
2012-11-26 18:58:24 +00:00
private :
2012-11-28 15:47:07 +00:00
const idEventDef * eventdef ;
byte * data ;
2012-11-26 18:58:24 +00:00
int time ;
2012-11-28 15:47:07 +00:00
idClass * object ;
const idTypeInfo * typeinfo ;
2012-11-26 18:58:24 +00:00
idLinkList < idEvent > eventNode ;
2012-11-28 15:47:07 +00:00
static idDynamicBlockAlloc < byte , 16 * 1024 , 256 > eventDataAllocator ;
2012-11-26 18:58:24 +00:00
public :
static bool initialized ;
2012-11-28 15:47:07 +00:00
~ idEvent ( ) ;
static idEvent * Alloc ( const idEventDef * evdef , int numargs , va_list args ) ;
2012-12-07 17:29:47 +00:00
// RB: 64 bit fix, changed int to intptr_t
static void CopyArgs ( const idEventDef * evdef , int numargs , va_list args , intptr_t data [ D_EVENT_MAXARGS ] ) ;
// RB end
2012-11-26 18:58:24 +00:00
void Free ( ) ;
2012-11-28 15:47:07 +00:00
void Schedule ( idClass * object , const idTypeInfo * cls , int time ) ;
byte * GetData ( ) ;
static void CancelEvents ( const idClass * obj , const idEventDef * evdef = NULL ) ;
2012-11-26 18:58:24 +00:00
static void ClearEventList ( ) ;
static void ServiceEvents ( ) ;
static void ServiceFastEvents ( ) ;
static void Init ( ) ;
static void Shutdown ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// save games
2012-11-28 15:47:07 +00:00
static void Save ( idSaveGame * savefile ) ; // archives object for save game file
static void Restore ( idRestoreGame * savefile ) ; // unarchives object from save game file
static void SaveTrace ( idSaveGame * savefile , const trace_t & trace ) ;
static void RestoreTrace ( idRestoreGame * savefile , trace_t & trace ) ;
2012-11-26 18:58:24 +00:00
} ;
/*
= = = = = = = = = = = = = = = =
idEvent : : GetData
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE byte * idEvent : : GetData ( )
{
2012-11-26 18:58:24 +00:00
return data ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetName
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE const char * idEventDef : : GetName ( ) const
{
2012-11-26 18:58:24 +00:00
return name ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetArgFormat
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE const char * idEventDef : : GetArgFormat ( ) const
{
2012-11-26 18:58:24 +00:00
return formatspec ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetFormatspecIndex
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE unsigned int idEventDef : : GetFormatspecIndex ( ) const
{
2012-11-26 18:58:24 +00:00
return formatspecIndex ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetReturnType
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE char idEventDef : : GetReturnType ( ) const
{
2012-11-26 18:58:24 +00:00
return returnType ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetNumArgs
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE int idEventDef : : GetNumArgs ( ) const
{
2012-11-26 18:58:24 +00:00
return numargs ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetArgSize
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE size_t idEventDef : : GetArgSize ( ) const
{
2012-11-26 18:58:24 +00:00
return argsize ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetArgOffset
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE int idEventDef : : GetArgOffset ( int arg ) const
{
2012-11-26 18:58:24 +00:00
assert ( ( arg > = 0 ) & & ( arg < D_EVENT_MAXARGS ) ) ;
return argOffset [ arg ] ;
}
/*
= = = = = = = = = = = = = = = =
idEventDef : : GetEventNum
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
ID_INLINE int idEventDef : : GetEventNum ( ) const
{
2012-11-26 18:58:24 +00:00
return eventnum ;
}
# endif /* !__SYS_EVENT_H__ */