35 #include "../../idlib/precompiled.h"
38 #include "../Game_local.h"
40 #define MAX_EVENTSPERFRAME 4096
52 static bool eventError =
false;
53 static char eventErrorMsg[ 128 ];
82 sprintf( eventErrorMsg,
"idEventDef::idEventDef : Too many args for '%s' event.",
name );
92 switch( formatspec[ i ] ) {
124 sprintf( eventErrorMsg,
"idEventDef::idEventDef : Invalid arg format '%s' string for '%s' event.", formatspec,
name );
141 sprintf( eventErrorMsg,
"idEvent '%s' defined twice with same name but differing format strings ('%s'!='%s').",
148 sprintf( eventErrorMsg,
"idEvent '%s' defined twice with same name but differing return types ('%c'!='%c').",
162 sprintf( eventErrorMsg,
"numEventDefs >= MAX_EVENTS" );
200 for( i = 0; i <
num; i++ ) {
248 const char *materialName;
254 ev = FreeEvents.
Next();
266 memset( ev->
data, 0, size );
272 for( i = 0; i < numargs; i++ ) {
274 if ( format[ i ] != arg->
type ) {
277 gameLocal.
Error(
"idEvent::Alloc : Wrong type passed in for arg # %d on '%s' event.", i, evdef->
GetName() );
283 switch( format[ i ] ) {
286 *
reinterpret_cast<int *
>( dataPtr ) = arg->
value;
291 *
reinterpret_cast<idVec3 *
>( dataPtr ) = *reinterpret_cast<const idVec3 *>( arg->
value );
308 *
reinterpret_cast<bool *
>( dataPtr ) =
true;
314 if ( reinterpret_cast<const trace_t *>( arg->
value )->c.material ) {
315 materialName =
reinterpret_cast<const trace_t *
>( arg->
value )->
c.material->GetName();
319 *
reinterpret_cast<bool *
>( dataPtr ) =
false;
324 gameLocal.
Error(
"idEvent::Alloc : Invalid arg format '%s' string for '%s' event.", format, evdef->
GetName() );
347 for( i = 0; i < numargs; i++ ) {
349 if ( format[ i ] != arg->
type ) {
352 gameLocal.
Error(
"idEvent::CopyArgs : Wrong type passed in for arg # %d on '%s' event.", i, evdef->
GetName() );
402 if ( obj->
IsType( idEntity::Type ) && ( ( (
idEntity*)(obj) )->timeGroup == TIME_GROUP2 ) ) {
403 event = FastEventQueue.
Next();
404 while( ( event !=
NULL ) && ( this->time >= event->
time ) ) {
420 event = EventQueue.
Next();
421 while( ( event !=
NULL ) && ( this->time >= event->
time ) ) {
445 for( event = EventQueue.
Next();
event !=
NULL;
event = next ) {
447 if ( event->
object == obj ) {
448 if ( !evdef || ( evdef == event->
eventdef ) ) {
455 for( event = FastEventQueue.
Next();
event !=
NULL;
event = next ) {
457 if ( event->
object == obj ) {
458 if ( !evdef || ( evdef == event->
eventdef ) ) {
484 EventPool[
i ].
Free();
500 const char *formatspec;
504 const char *materialName;
508 event = EventQueue.
Next();
516 ev =
event->eventdef;
519 for( i = 0; i < numargs; i++ ) {
522 switch( formatspec[ i ] ) {
525 args[
i ] = *
reinterpret_cast<int *
>( &data[
offset ] );
529 *
reinterpret_cast<idVec3 **
>( &args[
i ] ) = reinterpret_cast<idVec3 *>( &data[ offset ] );
533 *
reinterpret_cast<const char **
>( &args[
i ] ) = reinterpret_cast<const char *>( &data[ offset ] );
542 tracePtr =
reinterpret_cast<trace_t **
>( &args[
i ] );
543 if ( *reinterpret_cast<bool *>( &data[ offset ] ) ) {
544 *tracePtr =
reinterpret_cast<trace_t *
>( &data[ offset +
sizeof(
bool ) ] );
546 if ( ( *tracePtr )->c.material !=
NULL ) {
548 materialName =
reinterpret_cast<const char *
>( &data[ offset +
sizeof(
bool ) +
sizeof(
trace_t ) ] );
557 gameLocal.
Error(
"idEvent::ServiceEvents : Invalid arg format '%s' string for '%s' event.", formatspec, ev->
GetName() );
563 event->eventNode.Remove();
565 event->object->ProcessEventArgPtr( ev, args );
571 gameLocal.
Error(
"idEvent::ServiceEvents %d: %s left a value on the FPU stack\n", num, ev->
GetName() );
582 gameLocal.
Error(
"Event overflow. Possible infinite loop in script." );
593 void idEvent::ServiceFastEvents() {
600 const char *formatspec;
604 const char *materialName;
608 event = FastEventQueue.
Next();
616 ev =
event->eventdef;
619 for( i = 0; i < numargs; i++ ) {
622 switch( formatspec[ i ] ) {
625 args[
i ] = *
reinterpret_cast<int *
>( &data[
offset ] );
629 *
reinterpret_cast<idVec3 **
>( &args[
i ] ) = reinterpret_cast<idVec3 *>( &data[ offset ] );
633 *
reinterpret_cast<const char **
>( &args[
i ] ) = reinterpret_cast<const char *>( &data[ offset ] );
642 tracePtr =
reinterpret_cast<trace_t **
>( &args[
i ] );
643 if ( *reinterpret_cast<bool *>( &data[ offset ] ) ) {
644 *tracePtr =
reinterpret_cast<trace_t *
>( &data[ offset +
sizeof(
bool ) ] );
646 if ( ( *tracePtr )->c.material !=
NULL ) {
648 materialName =
reinterpret_cast<const char *
>( &data[ offset +
sizeof(
bool ) +
sizeof(
trace_t ) ] );
657 gameLocal.
Error(
"idEvent::ServiceFastEvents : Invalid arg format '%s' string for '%s' event.", formatspec, ev->
GetName() );
663 event->eventNode.Remove();
665 event->object->ProcessEventArgPtr( ev, args );
682 gameLocal.
Error(
"Event overflow. Possible infinite loop in script." );
700 #ifdef CREATE_EVENT_CODE
701 void CreateEventCallbackHandler();
702 CreateEventCallbackHandler();
758 event = EventQueue.
Next();
759 while( event !=
NULL ) {
765 format =
event->eventdef->GetArgFormat();
766 for ( i = 0, size = 0; i <
event->eventdef->GetNumArgs(); ++
i) {
767 dataPtr = &
event->data[
event->eventdef->GetArgOffset( i ) ];
768 switch( format[ i ] ) {
770 savefile->
WriteFloat( *reinterpret_cast<float *>( dataPtr ) );
771 size +=
sizeof(
float );
776 savefile->
WriteInt( *reinterpret_cast<int *>( dataPtr ) );
777 size +=
sizeof(
int );
780 savefile->
WriteVec3( *reinterpret_cast<idVec3 *>( dataPtr ) );
784 validTrace = *
reinterpret_cast<bool *
>( dataPtr );
786 size +=
sizeof(
bool );
793 str =
reinterpret_cast<char *
>( dataPtr +
sizeof(
bool ) +
sizeof(
trace_t ) );
803 event =
event->eventNode.Next();
810 event = FastEventQueue.
Next();
811 while( event !=
NULL ) {
819 event =
event->eventNode.Next();
839 for ( i = 0; i <
num; i++ ) {
844 event = FreeEvents.
Next();
846 event->eventNode.AddToEnd( EventQueue );
854 savefile->
Error(
"idEvent::Restore: unknown event '%s'", name.
c_str() );
861 savefile->
Error(
"idEvent::Restore: unknown class '%s' on event '%s'", name.
c_str(),
event->eventdef->GetName() );
869 savefile->
Error(
"idEvent::Restore: arg size (%d) doesn't match saved arg size(%d) on event '%s'", event->
eventdef->
GetArgSize(), argsize,
event->eventdef->GetName() );
873 format =
event->eventdef->GetArgFormat();
875 for ( j = 0, size = 0; j <
event->eventdef->GetNumArgs(); ++
j) {
876 dataPtr = &
event->data[
event->eventdef->GetArgOffset( j ) ];
877 switch( format[ j ] ) {
879 savefile->
ReadFloat( *reinterpret_cast<float *>( dataPtr ) );
880 size +=
sizeof(
float );
885 savefile->
ReadInt( *reinterpret_cast<int *>( dataPtr ) );
886 size +=
sizeof(
int );
889 savefile->
ReadVec3( *reinterpret_cast<idVec3 *>( dataPtr ) );
893 savefile->
ReadBool( *reinterpret_cast<bool *>( dataPtr ) );
894 size +=
sizeof(
bool );
895 if ( *reinterpret_cast<bool *>( dataPtr ) ) {
901 str =
reinterpret_cast<char *
>( dataPtr +
sizeof(
bool ) +
sizeof(
trace_t ) );
920 for ( i = 0; i <
num; i++ ) {
925 event = FreeEvents.
Next();
927 event->eventNode.AddToEnd( FastEventQueue );
935 savefile->
Error(
"idEvent::Restore: unknown event '%s'", name.
c_str() );
942 savefile->
Error(
"idEvent::Restore: unknown class '%s' on event '%s'", name.
c_str(),
event->eventdef->GetName() );
950 savefile->
Error(
"idEvent::Restore: arg size (%d) doesn't match saved arg size(%d) on event '%s'", event->
eventdef->
GetArgSize(), argsize,
event->eventdef->GetName() );
954 savefile->
Read( event->
data, argsize );
1012 #ifdef CREATE_EVENT_CODE
1018 void CreateEventCallbackHandler(
void ) {
1029 file->
Printf(
"// generated file - see CREATE_EVENT_CODE\n\n" );
1033 file->
Printf(
"\t/*******************************************************\n\n\t\t%d args\n\n\t*******************************************************/\n\n", i );
1035 for ( j = 0; j < ( 1 <<
i ); j++ ) {
1036 for( k = 0; k <
i; k++ ) {
1037 argString[ k ] = j & ( 1 << k ) ?
'f' :
'i';
1039 argString[
i ] =
'\0';
1044 for( k = 0; k <
i; k++ ) {
1045 if ( j & ( 1 << k ) ) {
1046 string1 +=
"const float";
1047 string2 +=
va(
"*( float * )&data[ %d ]", k );
1049 string1 +=
"const int";
1050 string2 +=
va(
"data[ %d ]", k );
1059 file->
Printf(
"\tcase %d :\n\t\ttypedef void ( idClass::*eventCallback_%s_t )( %s );\n", ( 1 << ( i +
D_EVENT_MAXARGS ) ) + j, argString, string1.
c_str() );
1060 file->
Printf(
"\t\t( this->*( eventCallback_%s_t )callback )( %s );\n\t\tbreak;\n\n", argString, string2.
c_str() );
int argOffset[D_EVENT_MAXARGS]
void WriteString(const char *string)
assert(prefInfo.fullscreenBtn)
static void Shutdown(void)
void WriteObject(const idClass *obj)
void Printf(const char *fmt,...) const id_attribute((format(printf
virtual bool FPU_StackIsEmpty(void)=0
type * GetEntity(void) const
GLenum GLsizei GLenum format
void SetOwner(type *object)
#define D_EVENT_ENTITY_NULL
void void void void void Error(const char *fmt,...) const id_attribute((format(printf
bool IsType(const idTypeInfo &c) const
bool IsListEmpty(void) const
void Write(const void *buffer, int len)
unsigned int formatspecIndex
static void RestoreTrace(idRestoreGame *savefile, trace_t &trace)
idFileSystem * fileSystem
idLinkList< idEvent > eventNode
void ReadBool(bool &value)
GLuint GLuint GLsizei GLenum type
void InsertBefore(idLinkList &node)
static void ClearEventList(void)
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
type * Alloc(const int num)
static idEventDef * eventDefList[MAX_EVENTS]
void WriteVec3(const idVec3 &vec)
static int NumEventCommands(void)
const idTypeInfo * typeinfo
size_t GetArgSize(void) const
void WriteBool(const bool value)
GLuint GLuint GLsizei count
static const idEventDef * FindEvent(const char *name)
const char * GetName(void) const
void ReadFloat(float &value)
void void Read(void *buffer, int len)
static void Save(idSaveGame *savefile)
void WriteFloat(const float value)
GLsizei GLsizei GLenum GLenum const GLvoid * data
static idTypeInfo * GetClass(const char *name)
virtual idFile * OpenFileWrite(const char *relativePath, const char *basePath="fs_savepath")=0
static void Copynz(char *dest, const char *src, int destsize)
idEventDef(const char *command, const char *formatspec=NULL, char returnType=0)
void Schedule(idClass *object, const idTypeInfo *cls, int time)
static const idEventDef * GetEventCommand(int eventnum)
void Error(const char *fmt,...) id_attribute((format(printf
#define MAX_EVENTSPERFRAME
int GetNumArgs(void) const
void WriteInt(const int value)
idDeclManager * declManager
void WriteMat3(const idMat3 &mat)
void ReadMat3(idMat3 &mat)
void AddToEnd(idLinkList &node)
static idDynamicBlockAlloc< byte, 16 *1024, 256 > eventDataAllocator
const idEventDef * eventdef
const char * GetArgFormat(void) const
static void Restore(idRestoreGame *savefile)
static void ServiceEvents(void)
void ReadVec3(idVec3 &vec)
const char * c_str(void) const
static void SaveTrace(idSaveGame *savefile, const trace_t &trace)
static void CopyArgs(const idEventDef *evdef, int numargs, va_list args, int data[D_EVENT_MAXARGS])
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
char * va(const char *fmt,...)
virtual void CloseFile(idFile *f)=0
static idEvent * Alloc(const idEventDef *evdef, int numargs, va_list args)
static void CancelEvents(const idClass *obj, const idEventDef *evdef=NULL)
void ReadString(idStr &string)
int sprintf(idStr &string, const char *fmt,...)
int GetArgOffset(int arg) const
virtual int Printf(const char *fmt,...) id_attribute((format(printf
void ReadObject(idClass *&obj)