void RegisterScriptedEntity( const char *className )
{
#ifdef CLIENT_DLL
	if ( GetClassMap().FindFactory( className ) )
	{
		return;
	}

	GetClassMap().Add( className, "CBaseScripted", sizeof( CBaseScripted ),
		&CCBaseScriptedFactory, true );
#else
	if ( EntityFactoryDictionary()->FindFactory( className ) )
	{
		return;
	}

	unsigned short lookup = m_EntityFactoryDatabase.Find( className );
	if ( lookup != m_EntityFactoryDatabase.InvalidIndex() )
	{
		return;
	}

	CEntityFactory<CBaseScripted> *pFactory = new CEntityFactory<CBaseScripted>( className );

	lookup = m_EntityFactoryDatabase.Insert( className, pFactory );
	Assert( lookup != m_EntityFactoryDatabase.InvalidIndex() );
#endif
}
Ejemplo n.º 2
0
PyEntityFactory::~PyEntityFactory()
{
	// Only remove if the there is a factory for this classname attached
	// to this instance of the factory (might already be replaced in python).
	if( GetClassMap().PyGetFactory( m_ClassName ) == this )
		GetClassMap().PyRemove( m_ClassName );
}
void RegisterScriptedWeapon( const char *className )
{
#ifdef CLIENT_DLL
	if ( GetClassMap().FindFactory( className ) )
	{
		return;
	}

	GetClassMap().Add( className, "CHL2MPScriptedWeapon", sizeof( CHL2MPScriptedWeapon ),
		&CCHL2MPScriptedWeaponFactory, true );
#else
	if ( EntityFactoryDictionary()->FindFactory( className ) )
	{
		return;
	}

	unsigned short lookup = m_WeaponFactoryDatabase.Find( className );
	if ( lookup != m_WeaponFactoryDatabase.InvalidIndex() )
	{
		return;
	}

	// Andrew; This fixes months worth of pain and anguish.
	CEntityFactory<CHL2MPScriptedWeapon> *pFactory = new CEntityFactory<CHL2MPScriptedWeapon>( className );

	lookup = m_WeaponFactoryDatabase.Insert( className, pFactory );
	Assert( lookup != m_WeaponFactoryDatabase.InvalidIndex() );
#endif
	// BUGBUG: When attempting to precache weapons registered during runtime,
	// they don't appear as valid registered entities.
	// static CPrecacheRegister precache_weapon_(&CPrecacheRegister::PrecacheFn_Other, className);
}
Ejemplo n.º 4
0
const char* Packet::getPacketClassname( PClassType eType )
{
	ClassMap& map = GetClassMap();
	ClassMap::iterator it = map.find( eType );
	if (it==map.end()) return "unknown";	// not found, perfectly valid (in use by registerPacketClass)
	return (*it).second.ClassName;
}
Ejemplo n.º 5
0
Packet* Packet::createPacket( PClassType eType ) 
{
	ClassMap& map = GetClassMap();
	ClassMap::iterator it = map.find( eType );
	if (it==map.end()) return NULL;	// not found, perfectly valid (in use by registerPacketClass)
	return (*it).second.StaticConstructor();
}
Ejemplo n.º 6
0
void Packet::registerPacketClass( PClassType eType, PacketCreateFuncType createFunc, const char* szClassName ) 
{
	UT_return_if_fail( !createPacket(eType) ); // if this fails, we have a duplicate eType registration
	ClassData cd;
	cd.StaticConstructor = createFunc;
	cd.ClassName = szClassName;
	GetClassMap()[eType] = cd;
}
Ejemplo n.º 7
0
boost::python::object PyGetClassByClassname( const char *class_name )
{
	if( !class_name )
		return bp::object();

	PyEntityFactory *pFactory = GetClassMap().PyGetFactoryByMapName( class_name );
	if( !pFactory )
		return bp::object();

	return pFactory->GetClass();
}
Ejemplo n.º 8
0
PyEntityFactory::PyEntityFactory( const char *pMapName, boost::python::object pyClass )
{
	m_ClassName[0] = 0;

	if( !pMapName )
	{
		PyErr_SetString(PyExc_ValueError, "EntityFactory must have a valid name");
		throw boost::python::error_already_set(); 
		return;
	}

	char *pClassName = boost::python::extract<char *>(pyClass.attr("__name__"));

	V_strncpy( m_ClassName, pClassName, sizeof( m_ClassName ) );
	m_PyClass = pyClass;

	// Remove any linked factory to this classname
	if( GetClassMap().PyGetFactory( m_ClassName ) )
		GetClassMap().PyRemove( m_ClassName );

	GetClassMap().PyAdd(pMapName, m_ClassName, 0, this);
}
void ResetEntityFactoryDatabase( void )
{
#ifdef CLIENT_DLL
#ifdef LUA_SDK
	GetClassMap().RemoveAllScripted();
#endif
#else
	for ( int i=m_EntityFactoryDatabase.First(); i != m_EntityFactoryDatabase.InvalidIndex(); i=m_EntityFactoryDatabase.Next( i ) )
	{
		delete m_EntityFactoryDatabase[ i ];
	}
	m_EntityFactoryDatabase.RemoveAll();
#endif
}