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.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
|
|
|
|
Base class for all C++ objects. Provides fast run-time type checking and run-time
|
|
|
|
instancing of objects.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "../Game_local.h"
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
|
|
|
idTypeInfo
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
// this is the head of a singly linked list of all the idTypes
|
2012-11-28 15:47:07 +00:00
|
|
|
static idTypeInfo* typelist = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
static idHierarchy<idTypeInfo> classHierarchy;
|
|
|
|
static int eventCallbackMemory = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idTypeInfo::idClassType()
|
|
|
|
|
|
|
|
Constructor for class. Should only be called from CLASS_DECLARATION macro.
|
|
|
|
Handles linking class definition into class hierarchy. This should only happen
|
|
|
|
at startup as idTypeInfos are statically defined. Since static variables can be
|
|
|
|
initialized in any order, the constructor must handle the case that subclasses
|
|
|
|
are initialized before superclasses.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo::idTypeInfo( const char* classname, const char* superclass, idEventFunc<idClass>* eventCallbacks, idClass * ( *CreateInstance )(),
|
|
|
|
void ( idClass::*Spawn )(), void ( idClass::*Save )( idSaveGame* savefile ) const, void ( idClass::*Restore )( idRestoreGame* savefile ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo* type;
|
|
|
|
idTypeInfo** insert;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
this->classname = classname;
|
|
|
|
this->superclass = superclass;
|
|
|
|
this->eventCallbacks = eventCallbacks;
|
|
|
|
this->eventMap = NULL;
|
|
|
|
this->Spawn = Spawn;
|
|
|
|
this->Save = Save;
|
|
|
|
this->Restore = Restore;
|
|
|
|
this->CreateInstance = CreateInstance;
|
|
|
|
this->super = idClass::GetClass( superclass );
|
|
|
|
this->freeEventMap = false;
|
|
|
|
typeNum = 0;
|
|
|
|
lastChild = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check if any subclasses were initialized before their superclass
|
2012-11-28 15:47:07 +00:00
|
|
|
for( type = typelist; type != NULL; type = type->next )
|
|
|
|
{
|
|
|
|
if( ( type->super == NULL ) && !idStr::Cmp( type->superclass, this->classname ) &&
|
|
|
|
idStr::Cmp( type->classname, "idClass" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
type->super = this;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Insert sorted
|
2012-11-28 15:47:07 +00:00
|
|
|
for( insert = &typelist; *insert; insert = &( *insert )->next )
|
|
|
|
{
|
|
|
|
assert( idStr::Cmp( classname, ( *insert )->classname ) );
|
|
|
|
if( idStr::Cmp( classname, ( *insert )->classname ) < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
next = *insert;
|
|
|
|
*insert = this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !*insert )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
*insert = this;
|
|
|
|
next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idTypeInfo::~idTypeInfo
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo::~idTypeInfo()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idTypeInfo::Init
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
Initializes the event callback table for the class. Creates a
|
2012-11-26 18:58:24 +00:00
|
|
|
table for fast lookups of event functions. Should only be called once.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idTypeInfo::Init()
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
|
|
|
idEventFunc<idClass>* def;
|
2012-11-26 18:58:24 +00:00
|
|
|
int ev;
|
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
bool* set;
|
2012-11-26 18:58:24 +00:00
|
|
|
int num;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( eventMap )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we've already been initialized by a subclass
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// make sure our superclass is initialized first
|
2012-11-28 15:47:07 +00:00
|
|
|
if( super && !super->eventMap )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
super->Init();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// add to our node hierarchy
|
2012-11-28 15:47:07 +00:00
|
|
|
if( super )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node.ParentTo( super->node );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node.ParentTo( classHierarchy );
|
|
|
|
}
|
|
|
|
node.SetOwner( this );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// keep track of the number of children below each class
|
2012-11-28 15:47:07 +00:00
|
|
|
for( c = super; c != NULL; c = c->super )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
c->lastChild++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if we're not adding any new event callbacks, we can just use our superclass's table
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( !eventCallbacks || !eventCallbacks->event ) && super )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
eventMap = super->eventMap;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// set a flag so we know to delete the eventMap table
|
|
|
|
freeEventMap = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Allocate our new table. It has to have as many entries as there
|
|
|
|
// are events. NOTE: could save some space by keeping track of the maximum
|
|
|
|
// event that the class responds to and doing range checking.
|
|
|
|
num = idEventDef::NumEventCommands();
|
2012-11-28 15:47:07 +00:00
|
|
|
eventMap = new( TAG_SYSTEM ) eventCallback_t[ num ];
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( eventMap, 0, sizeof( eventCallback_t ) * num );
|
|
|
|
eventCallbackMemory += sizeof( eventCallback_t ) * num;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// allocate temporary memory for flags so that the subclass's event callbacks
|
|
|
|
// override the superclass's event callback
|
2012-11-28 15:47:07 +00:00
|
|
|
set = new( TAG_SYSTEM ) bool[ num ];
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( set, 0, sizeof( bool ) * num );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// go through the inheritence order and copies the event callback function into
|
|
|
|
// a list indexed by the event number. This allows fast lookups of
|
|
|
|
// event functions.
|
2012-11-28 15:47:07 +00:00
|
|
|
for( c = this; c != NULL; c = c->super )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
def = c->eventCallbacks;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !def )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// go through each entry until we hit the NULL terminator
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; def[ i ].event != NULL; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ev = def[ i ].event->GetEventNum();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( set[ ev ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
set[ ev ] = true;
|
|
|
|
eventMap[ ev ] = def[ i ].function;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delete[] set;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idTypeInfo::Shutdown
|
|
|
|
|
|
|
|
Should only be called when DLL or EXE is being shutdown.
|
2012-11-28 15:47:07 +00:00
|
|
|
Although it cleans up any allocated memory, it doesn't bother to remove itself
|
2012-11-26 18:58:24 +00:00
|
|
|
from the class list since the program is shutting down.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idTypeInfo::Shutdown()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// free up the memory used for event lookups
|
2012-11-28 15:47:07 +00:00
|
|
|
if( eventMap )
|
|
|
|
{
|
|
|
|
if( freeEventMap )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete[] eventMap;
|
|
|
|
}
|
|
|
|
eventMap = NULL;
|
|
|
|
}
|
|
|
|
typeNum = 0;
|
|
|
|
lastChild = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
|
|
|
idClass
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
const idEventDef EV_Remove( "<immediateremove>", NULL );
|
|
|
|
const idEventDef EV_SafeRemove( "remove", NULL );
|
|
|
|
|
|
|
|
ABSTRACT_DECLARATION( NULL, idClass )
|
2012-11-28 15:47:07 +00:00
|
|
|
EVENT( EV_Remove, idClass::Event_Remove )
|
|
|
|
EVENT( EV_SafeRemove, idClass::Event_SafeRemove )
|
2012-11-26 18:58:24 +00:00
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
// alphabetical order
|
2012-11-28 15:47:07 +00:00
|
|
|
idList<idTypeInfo*, TAG_IDCLASS> idClass::types;
|
2012-11-26 18:58:24 +00:00
|
|
|
// typenum order
|
2012-11-28 15:47:07 +00:00
|
|
|
idList<idTypeInfo*, TAG_IDCLASS> idClass::typenums;
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
bool idClass::initialized = false;
|
|
|
|
int idClass::typeNumBits = 0;
|
|
|
|
int idClass::memused = 0;
|
|
|
|
int idClass::numobjects = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::CallSpawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::CallSpawn()
|
|
|
|
{
|
|
|
|
idTypeInfo* type;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = GetType();
|
|
|
|
CallSpawnFunc( type );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::CallSpawnFunc
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
classSpawnFunc_t idClass::CallSpawnFunc( idTypeInfo* cls )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
classSpawnFunc_t func;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( cls->super )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
func = CallSpawnFunc( cls->super );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( func == cls->Spawn )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// don't call the same function twice in a row.
|
|
|
|
// this can happen when subclasses don't have their own spawn function.
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
( this->*cls->Spawn )();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return cls->Spawn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::FindUninitializedMemory
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::FindUninitializedMemory()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#ifdef ID_DEBUG_UNINITIALIZED_MEMORY
|
2012-12-11 22:04:53 +00:00
|
|
|
// DG: use int instead of long for 64bit compatibility
|
|
|
|
unsigned int* ptr = ( ( unsigned int* )this ) - 1;
|
|
|
|
// DG end
|
2012-11-26 18:58:24 +00:00
|
|
|
int size = *ptr;
|
|
|
|
assert( ( size & 3 ) == 0 );
|
|
|
|
size >>= 2;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < size; i++ )
|
|
|
|
{
|
|
|
|
if( ptr[i] == 0xcdcdcdcd )
|
|
|
|
{
|
|
|
|
const char* varName = GetTypeVariableName( GetClassname(), i << 2 );
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Warning( "type '%s' has uninitialized variable %s (offset %d)", GetClassname(), varName, i << 2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::~idClass
|
|
|
|
|
|
|
|
Destructor for object. Cancels any events that depend on this object.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClass::~idClass()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEvent::CancelEvents( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::DisplayInfo_f
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::DisplayInfo_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "Class memory status: %i bytes allocated in %i objects\n", memused, numobjects );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ListClasses_f
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::ListClasses_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo* type;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "%-24s %-24s %-6s %-6s\n", "Classname", "Superclass", "Type", "Subclasses" );
|
|
|
|
gameLocal.Printf( "----------------------------------------------------------------------\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < types.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
type = types[ i ];
|
|
|
|
gameLocal.Printf( "%-24s %-24s %6d %6d\n", type->classname, type->superclass, type->typeNum, type->lastChild - type->typeNum );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "...%d classes", types.Num() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::CreateInstance
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClass* idClass::CreateInstance( const char* name )
|
|
|
|
{
|
|
|
|
const idTypeInfo* type;
|
|
|
|
idClass* obj;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = idClass::GetClass( name );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !type )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
obj = type->CreateInstance();
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::Init
|
|
|
|
|
|
|
|
Should be called after all idTypeInfos are initialized, so must be called
|
|
|
|
manually upon game code initialization. Tells all the idTypeInfos to initialize
|
|
|
|
their event callback table for the associated class. This should only be called
|
|
|
|
once during the execution of the program or DLL.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::Init()
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
2012-11-26 18:58:24 +00:00
|
|
|
int num;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "Initializing class hierarchy\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( initialized )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "...already initialized\n" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// init the event callback tables for all the classes
|
2012-11-28 15:47:07 +00:00
|
|
|
for( c = typelist; c != NULL; c = c->next )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
c->Init();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// number the types according to the class hierarchy so we can quickly determine if a class
|
|
|
|
// is a subclass of another
|
|
|
|
num = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( c = classHierarchy.GetNext(); c != NULL; c = c->node.GetNext(), num++ )
|
|
|
|
{
|
|
|
|
c->typeNum = num;
|
2012-11-26 18:58:24 +00:00
|
|
|
c->lastChild += num;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// number of bits needed to send types over network
|
|
|
|
typeNumBits = idMath::BitsForInteger( num );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// create a list of the types so we can do quick lookups
|
|
|
|
// one list in alphabetical order, one in typenum order
|
|
|
|
types.SetGranularity( 1 );
|
|
|
|
types.SetNum( num );
|
|
|
|
typenums.SetGranularity( 1 );
|
|
|
|
typenums.SetNum( num );
|
|
|
|
num = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( c = typelist; c != NULL; c = c->next, num++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
types[ num ] = c;
|
|
|
|
typenums[ c->typeNum ] = c;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
initialized = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "...%i classes, %i bytes for event callbacks\n", types.Num(), eventCallbackMemory );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::Shutdown
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::Shutdown()
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
|
|
|
|
|
|
|
for( c = typelist; c != NULL; c = c->next )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
c->Shutdown();
|
|
|
|
}
|
|
|
|
types.Clear();
|
|
|
|
typenums.Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
initialized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::new
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void* idClass::operator new( size_t s )
|
|
|
|
{
|
|
|
|
int* p;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
s += sizeof( int );
|
2012-11-28 15:47:07 +00:00
|
|
|
p = ( int* )Mem_Alloc( s, TAG_IDCLASS );
|
2012-11-26 18:58:24 +00:00
|
|
|
*p = s;
|
|
|
|
memused += s;
|
|
|
|
numobjects++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return p + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::delete
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::operator delete( void* ptr )
|
|
|
|
{
|
|
|
|
int* p;
|
|
|
|
|
|
|
|
if( ptr )
|
|
|
|
{
|
|
|
|
p = ( ( int* )ptr ) - 1;
|
2012-11-26 18:58:24 +00:00
|
|
|
memused -= *p;
|
|
|
|
numobjects--;
|
2012-11-28 15:47:07 +00:00
|
|
|
Mem_Free( p );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::GetClass
|
|
|
|
|
|
|
|
Returns the idTypeInfo for the name of the class passed in. This is a static function
|
|
|
|
so it must be called as idClass::GetClass( classname )
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo* idClass::GetClass( const char* name )
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
2012-11-26 18:58:24 +00:00
|
|
|
int order;
|
|
|
|
int mid;
|
|
|
|
int min;
|
|
|
|
int max;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !initialized )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// idClass::Init hasn't been called yet, so do a slow lookup
|
2012-11-28 15:47:07 +00:00
|
|
|
for( c = typelist; c != NULL; c = c->next )
|
|
|
|
{
|
|
|
|
if( !idStr::Cmp( c->classname, name ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// do a binary search through the list of types
|
|
|
|
min = 0;
|
|
|
|
max = types.Num() - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( min <= max )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
mid = ( min + max ) / 2;
|
|
|
|
c = types[ mid ];
|
|
|
|
order = idStr::Cmp( c->classname, name );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !order )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return c;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( order > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
max = mid - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
min = mid + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::GetType
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo* idClass::GetType( const int typeNum )
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
|
|
|
|
|
|
|
if( !initialized )
|
|
|
|
{
|
|
|
|
for( c = typelist; c != NULL; c = c->next )
|
|
|
|
{
|
|
|
|
if( c->typeNum == typeNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( ( typeNum >= 0 ) && ( typeNum < types.Num() ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return typenums[ typeNum ];
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::GetClassname
|
|
|
|
|
|
|
|
Returns the text classname of the object.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idClass::GetClassname() const
|
|
|
|
{
|
|
|
|
idTypeInfo* type;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = GetType();
|
|
|
|
return type->classname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::GetSuperclass
|
|
|
|
|
|
|
|
Returns the text classname of the superclass.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idClass::GetSuperclass() const
|
|
|
|
{
|
|
|
|
idTypeInfo* cls;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
cls = GetType();
|
|
|
|
return cls->superclass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::CancelEvents
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::CancelEvents( const idEventDef* ev )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEvent::CancelEvents( this, ev );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventArgs
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventArgs( const idEventDef* ev, int time, int numargs, ... )
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
|
|
|
idEvent* event;
|
2012-11-26 18:58:24 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
assert( ev );
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idEvent::initialized )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
c = GetType();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !c->eventMap[ ev->GetEventNum() ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we don't respond to this event, so ignore it
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bool isReplicated = true;
|
|
|
|
// If this is an entity with skipReplication, we want to process the event normally even on clients.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IsType( idEntity::Type ) )
|
|
|
|
{
|
|
|
|
idEntity* thisEnt = static_cast< idEntity* >( this );
|
|
|
|
if( thisEnt->fl.skipReplication )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
isReplicated = false;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// we service events on the client to avoid any bad code filling up the event pool
|
|
|
|
// we don't want them processed usually, unless when the map is (re)loading.
|
|
|
|
// we allow threads to run fine, though.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( common->IsClient() && isReplicated && ( gameLocal.GameState() != GAMESTATE_STARTUP ) && !IsType( idThread::Type ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
va_start( args, numargs );
|
|
|
|
event = idEvent::Alloc( ev, numargs, args );
|
|
|
|
va_end( args );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
event->Schedule( this, c, time );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 1, &arg1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 2, &arg1, &arg2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2, idEventArg arg3 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 3, &arg1, &arg2, &arg3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 4, &arg1, &arg2, &arg3, &arg4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 5, &arg1, &arg2, &arg3, &arg4, &arg5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6, idEventArg arg7 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventMS
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventMS( const idEventDef* ev, int time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6, idEventArg arg7, idEventArg arg8 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, time, 8, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 1, &arg1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 2, &arg1, &arg2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2, idEventArg arg3 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 3, &arg1, &arg2, &arg3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 4, &arg1, &arg2, &arg3, &arg4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 5, &arg1, &arg2, &arg3, &arg4, &arg5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6, idEventArg arg7 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::PostEventSec
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::PostEventSec( const idEventDef* ev, float time, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6, idEventArg arg7, idEventArg arg8 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return PostEventArgs( ev, SEC2MS( time ), 8, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEventArgs
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEventArgs( const idEventDef* ev, int numargs, ... )
|
|
|
|
{
|
|
|
|
idTypeInfo* c;
|
2012-11-26 18:58:24 +00:00
|
|
|
int num;
|
2012-12-07 17:29:47 +00:00
|
|
|
// RB: 64 bit fix, changed int to intptr_t
|
|
|
|
intptr_t data[ D_EVENT_MAXARGS ];
|
|
|
|
// RB end
|
2012-11-26 18:58:24 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
assert( ev );
|
|
|
|
assert( idEvent::initialized );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
c = GetType();
|
|
|
|
num = ev->GetEventNum();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !c->eventMap[ num ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we don't respond to this event, so ignore it
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
va_start( args, numargs );
|
|
|
|
idEvent::CopyArgs( ev, numargs, args, data );
|
|
|
|
va_end( args );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ProcessEventArgPtr( ev, data );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 1, &arg1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 2, &arg1, &arg2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2, idEventArg arg3 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 3, &arg1, &arg2, &arg3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 4, &arg1, &arg2, &arg3, &arg4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 5, &arg1, &arg2, &arg3, &arg4, &arg5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6, idEventArg arg7 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 7, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEvent
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClass::ProcessEvent( const idEventDef* ev, idEventArg arg1, idEventArg arg2, idEventArg arg3, idEventArg arg4, idEventArg arg5, idEventArg arg6, idEventArg arg7, idEventArg arg8 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ProcessEventArgs( ev, 8, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::ProcessEventArgPtr
|
|
|
|
================
|
|
|
|
*/
|
2012-12-07 17:29:47 +00:00
|
|
|
// RB: 64 bit fixes, changed int to intptr_t
|
|
|
|
bool idClass::ProcessEventArgPtr( const idEventDef* ev, intptr_t* data )
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
2012-12-07 17:29:47 +00:00
|
|
|
// RB end
|
2012-11-28 15:47:07 +00:00
|
|
|
idTypeInfo* c;
|
2012-11-26 18:58:24 +00:00
|
|
|
int num;
|
|
|
|
eventCallback_t callback;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( ev );
|
|
|
|
assert( idEvent::initialized );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetTimeState ts;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( IsType( idEntity::Type ) )
|
|
|
|
{
|
|
|
|
idEntity* ent = ( idEntity* )this;
|
2012-11-26 18:58:24 +00:00
|
|
|
ts.PushState( ent->timeGroup );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( g_debugTriggers.GetBool() && ( ev == &EV_Activate ) && IsType( idEntity::Type ) )
|
|
|
|
{
|
|
|
|
const idEntity* ent = *reinterpret_cast<idEntity**>( data );
|
|
|
|
gameLocal.Printf( "%d: '%s' activated by '%s'\n", gameLocal.framenum, static_cast<idEntity*>( this )->GetName(), ent ? ent->GetName() : "NULL" );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
c = GetType();
|
|
|
|
num = ev->GetEventNum();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !c->eventMap[ num ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we don't respond to this event, so ignore it
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
callback = c->eventMap[ num ];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-12-07 17:29:47 +00:00
|
|
|
// RB: I tried first to get CPU_EASYARGS switch running with x86_64
|
|
|
|
// but it caused many crashes with the Doom scripts.
|
|
|
|
// The new Callbacks.cpp was generated with intptr_t and it works fine.
|
2012-11-26 18:58:24 +00:00
|
|
|
#if !CPU_EASYARGS
|
2012-12-07 17:29:47 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
/*
|
2013-12-31 01:23:16 +00:00
|
|
|
on ppc architecture, floats are passed in a separate set of registers
|
2012-11-28 15:47:07 +00:00
|
|
|
the function prototypes must have matching float declaration
|
|
|
|
|
|
|
|
http://developer.apple.com/documentation/DeveloperTools/Conceptual/MachORuntime/2rt_powerpc_abi/chapter_9_section_5.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch( ev->GetFormatspecIndex() )
|
|
|
|
{
|
|
|
|
case 1 << D_EVENT_MAXARGS :
|
|
|
|
( this->*callback )();
|
|
|
|
break;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// generated file - see CREATE_EVENT_CODE
|
|
|
|
#include "Callbacks.cpp"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
default:
|
|
|
|
gameLocal.Warning( "Invalid formatspec on event '%s'", ev->GetName() );
|
|
|
|
break;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
#else
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( D_EVENT_MAXARGS == 8 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-12-07 17:29:47 +00:00
|
|
|
// RB: 64 bit fixes, changed int to intptr_t
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( ev->GetNumArgs() )
|
|
|
|
{
|
|
|
|
case 0 :
|
|
|
|
( this->*callback )();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_1_t )( const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_1_t )callback )( data[ 0 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_2_t )( const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_2_t )callback )( data[ 0 ], data[ 1 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_3_t )( const intptr_t, const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_3_t )callback )( data[ 0 ], data[ 1 ], data[ 2 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_4_t )( const intptr_t, const intptr_t, const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_4_t )callback )( data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_5_t )( const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_5_t )callback )( data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_6_t )( const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_6_t )callback )( data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_7_t )( const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_7_t )callback )( data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8 :
|
2012-12-07 17:29:47 +00:00
|
|
|
typedef void ( idClass::*eventCallback_8_t )( const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t, const intptr_t );
|
2012-11-28 15:47:07 +00:00
|
|
|
( this->*( eventCallback_8_t )callback )( data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
gameLocal.Warning( "Invalid formatspec on event '%s'", ev->GetName() );
|
|
|
|
break;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-12-07 17:29:47 +00:00
|
|
|
// RB end
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
#endif
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::Event_Remove
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::Event_Remove()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClass::Event_SafeRemove
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClass::Event_SafeRemove()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Forces the remove to be done at a safe time
|
|
|
|
PostEventMS( &EV_Remove, 0 );
|
|
|
|
}
|