void PyEntityFactory::InitPyClass() { bp::object meth = SrcPySystem()->Get("InitEntityClass", m_PyClass, false); if( meth.ptr() == Py_None ) return; // Not implemented, ignore SrcPySystem()->Run( meth ); }
//----------------------------------------------------------------------------- // Purpose: Called everytime the player respawns //----------------------------------------------------------------------------- void CHL2WarsPlayer::Spawn( void ) { SetModel( "models/error.mdl" ); // Default faction if we have no faction selected yet if( m_FactionName == NULL_STRING ) { const char *pFaction = GetDefaultFaction() ? GetDefaultFaction() : "rebels" ; ChangeFaction(pFaction); } BaseClass::Spawn(); UpdateCameraSettings(); m_Local.m_iHideHUD |= HIDEHUD_UNIT; SetStrategicMode( true ); // Hook spawn to a signal #ifdef ENABLE_PYTHON if( SrcPySystem()->IsPythonRunning() ) { // Setup dict for sending a signal boost::python::dict kwargs; kwargs["sender"] = boost::python::object(); kwargs["player"] = GetPyHandle(); boost::python::object signal = SrcPySystem()->Get( "playerspawned", "core.signals", true ); SrcPySystem()->CallSignal( signal, kwargs ); } #endif // ENABLE_PYTHON }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CUnitBase::DispatchOutOfAmmo( void ) { #ifdef ENABLE_PYTHON SrcPySystem()->Run<const char *>( SrcPySystem()->Get("DispatchEvent", GetPyInstance() ), "OnOutOfAmmo" ); #endif // ENABLE_PYTHON }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CUnitBase::DispatchBurstFinished( void ) { #ifdef ENABLE_PYTHON SrcPySystem()->Run<const char *>( SrcPySystem()->Get("DispatchEvent", GetPyInstance() ), "OnBurstFinished" ); #endif // ENABLE_PYTHON }
void FullClientUpdatePyNetworkClsByEdict( edict_t *pEdict ) { if( !SrcPySystem()->IsPythonRunning() ) { DevMsg("FullClientUpdatePyNetworkClsByEdict: Python is not running\n"); return; } Assert(g_SetupNetworkTablesOnHold == false); // Send messages about each server class PyServerClass *p = g_pPyServerClassHead; while( p ) { if( p->m_bFree ) { p = p->m_pPyNext; continue; } // Send message engine->ClientCommand( pEdict, "rpc %d %s %s\n", p->m_iType, p->m_pNetworkName, p->m_pNetworkedClass->m_pNetworkName); engine->ServerExecute(); // Send immediately to avoid an overflow when having too many p = p->m_pPyNext; } }
virtual void SetRotation( int iRotation ) { #if defined(_WIN32) #if defined(_DEBUG) Assert( SrcPySystem()->IsPythonRunning() ); Assert( GetCurrentThreadId() == g_hPythonThreadID ); #elif defined(PY_CHECKTHREADID) if( GetCurrentThreadId() != g_hPythonThreadID ) Error( "SetRotation: Client? %d. Thread ID is not the same as in which the python interpreter is initialized! %d != %d. Tell a developer.\n", CBaseEntity::IsClient(), g_hPythonThreadID, GetCurrentThreadId() ); #endif // _DEBUG/PY_CHECKTHREADID #endif // _WIN32 #if defined(_DEBUG) || defined(PY_CHECK_LOG_OVERRIDES) if( py_log_overrides.GetBool() ) Msg("Calling SetRotation( iRotation ) of Class: vgui::Image\n"); #endif // _DEBUG/PY_CHECK_LOG_OVERRIDES bp::override func_SetRotation = this->get_override( "SetRotation" ); if( func_SetRotation.ptr() != Py_None ) try { func_SetRotation( iRotation ); } catch(bp::error_already_set &) { PyErr_Print(); this->vgui::Image::SetRotation( iRotation ); } else this->vgui::Image::SetRotation( iRotation ); }
void FullClientUpdatePyNetworkClsByFilter( IRecipientFilter &filter ) { if( !SrcPySystem()->IsPythonRunning() ) return; Assert(g_SetupNetworkTablesOnHold == false); // Send messages about each server class PyServerClass *p = g_pPyServerClassHead; while( p ) { if( p->m_bFree ) { p = p->m_pPyNext; continue; } // Send message UserMessageBegin(filter, "PyNetworkCls"); WRITE_BYTE(p->m_iType); WRITE_STRING(p->m_pNetworkName); WRITE_STRING(p->m_pNetworkedClass->m_pNetworkName); MessageEnd(); p = p->m_pPyNext; } }
static bool SrcPyPathIsInGameFolder( const char *pPath ) { #if 0 if( SrcPySystem()->IsPathProtected() ) { // Verify the file is in the gamefolder char searchPaths[MAX_PATH]; filesystem->GetSearchPath( "MOD", true, searchPaths, sizeof( searchPaths ) ); V_StripTrailingSlash( searchPaths ); if( V_IsAbsolutePath( pPath ) ) { if( V_strnicmp( pPath, searchPaths, V_strlen( searchPaths ) ) != 0 ) return false; } else { char pFullPath[MAX_PATH]; char moddir[MAX_PATH]; filesystem->RelativePathToFullPath( ".", "MOD", moddir, sizeof( moddir ) ); V_MakeAbsolutePath( pFullPath, sizeof( pFullPath ), pPath, moddir ); if( V_strnicmp( pFullPath, searchPaths, V_strlen(searchPaths) ) != 0 ) return false; } } #endif // 0 return true; }
void FullClientUpdatePyNetworkCls( CBasePlayer *pPlayer ) { if( !SrcPySystem()->IsPythonRunning() ) return; CSingleUserRecipientFilter filter(pPlayer); filter.MakeReliable(); FullClientUpdatePyNetworkClsByFilter(filter); }
// Message handler for PyNetworkCls void __MsgFunc_PyNetworkCls( bf_read &msg ) { char clientClass[PYNETCLS_BUFSIZE]; char networkName[PYNETCLS_BUFSIZE]; int iType = msg.ReadByte(); msg.ReadString(clientClass, PYNETCLS_BUFSIZE); msg.ReadString(networkName, PYNETCLS_BUFSIZE); DbgStrPyMsg( "__MsgFunc_PyNetworkCls: Registering Python network class message %d %s %s\n", iType, clientClass, networkName ); // Get module path const char *pch = Q_strrchr( networkName, '.' ); if( !pch ) { Warning( "Invalid python class name %s\n", networkName ); return; } int n = pch - networkName + 1; char modulePath[PYNETCLS_BUFSIZE]; Q_strncpy( modulePath, networkName, n ); // Make sure the client class is imported SrcPySystem()->Import( modulePath ); // Read which client class we are modifying PyClientClassBase *p = FindPyClientClass( clientClass ); if( !p ) { Warning( "__MsgFunc_PyNetworkCls: Invalid networked class %s\n", clientClass ); return; } // Set type p->SetType( iType ); SetupClientClassRecv( p, iType ); // Read network class name Q_strncpy( p->m_strPyNetworkedClassName, networkName, PYNETCLS_BUFSIZE ); // Attach if a network class exists unsigned short lookup = m_NetworkClassDatabase.Find( networkName ); if ( lookup != m_NetworkClassDatabase.InvalidIndex() ) { m_NetworkClassDatabase.Element(lookup)->AttachClientClass( p ); } else { Warning( "__MsgFunc_PyNetworkCls: Invalid networked class %s\n", networkName ); } }
virtual void PostDataUpdate( DataUpdateType_t updateType ) { if( !m_hEnt.Get() ) return; if( m_hEnt->GetPyInstance().ptr() == Py_None ) { DevMsg("C_TEPyEvent can only be used with python entities!\n"); return; } try { SrcPySystem()->Run<int, int>( SrcPySystem()->Get("ReceiveEvent", m_hEnt->GetPyInstance(), true), m_iEvent, m_nData ); } catch( bp::error_already_set & ) { PyErr_Print(); } }
// Message handler for PyNetworkCls void __MsgFunc_PyNetworkCls( bf_read &msg ) { int iClassID; char networkName[PYNETCLS_BUFSIZE]; iClassID = msg.ReadWord(); msg.ReadString( networkName, PYNETCLS_BUFSIZE ); DbgStrPyMsg( "__MsgFunc_PyNetworkCls: Registering Python network class message %d %s\n", iClassID, networkName ); // Get module path const char *pch = V_strrchr( networkName, '.' ); if( !pch ) { Warning( "Invalid python class name %s\n", networkName ); return; } int n = pch - networkName + 1; char modulePath[PYNETCLS_BUFSIZE]; V_strncpy( modulePath, networkName, n ); // Make sure the client class is imported SrcPySystem()->Import( modulePath ); // Read which client class we are modifying PyClientClassBase *p = FindPyClientClassByID( iClassID ); if( !p ) { Warning( "__MsgFunc_PyNetworkCls: Invalid networked class %d\n", iClassID ); return; } // Read network class name V_strncpy( p->m_strPyNetworkedClassName, networkName, sizeof( p->m_strPyNetworkedClassName ) ); // Attach if a network class exists unsigned short lookup = m_NetworkClassDatabase.Find( networkName ); if ( lookup != m_NetworkClassDatabase.InvalidIndex() ) { m_NetworkClassDatabase.Element(lookup)->AttachClientClass( p ); } else { Warning( "__MsgFunc_PyNetworkCls: Invalid networked class %s\n", networkName ); } }
void UnregisterTickMethod( boost::python::object method ) { SrcPySystem()->UnregisterTickMethod(method); }
boost::python::list GetRegisteredTickMethods() { return SrcPySystem()->GetRegisteredTickMethods(); }
void UnregisterPerFrameMethod( boost::python::object method ) { SrcPySystem()->UnregisterPerFrameMethod(method); }
boost::python::list GetRegisteredPerFrameMethods() { return SrcPySystem()->GetRegisteredPerFrameMethods(); }
const char *UTIL_GetModuleNameFromIndex( int index ) { return SrcPySystem()->GetModuleNameFromIndex(index); }
int UTIL_GetModuleIndex( const char *module ) { return SrcPySystem()->GetModuleIndex(module); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void RegisterTickMethod( boost::python::object method, float ticksignal, bool looped, bool userealtime ) { SrcPySystem()->RegisterTickMethod(method, ticksignal, looped, userealtime); }
bool IsPerFrameMethodRegistered( boost::python::object method ) { return SrcPySystem()->IsPerFrameMethodRegistered( method ); }