2022-01-18 01:21:24 +01:00
|
|
|
//===========================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: A higher level link library for general use in the game and SDK.
|
|
|
|
//
|
|
|
|
//===========================================================================//
|
2022-01-17 03:28:16 +01:00
|
|
|
|
2022-01-18 01:21:24 +01:00
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include "vpc/interfaces.h"
|
2023-08-22 01:11:49 +02:00
|
|
|
#include "tier1/interface.h"
|
2022-01-17 03:28:16 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
// Purpose: register a new factory
|
|
|
|
// Input : createFn -
|
|
|
|
// *pName -
|
2022-04-09 00:59:42 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
void CFactorySystem::AddFactory(InstantiateInterfaceFn createFn, const char* pName) const
|
2022-04-09 00:59:42 +02:00
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
InterfaceReg(createFn, pName);
|
2022-04-09 00:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
// Purpose: get a factory by name
|
|
|
|
// Input : *pName -
|
2022-01-17 03:28:16 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
void* CFactorySystem::GetFactory(const char* pName) const
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
for (InterfaceReg* it = *s_ppInterfaceRegs;
|
|
|
|
it; it = it->m_pNext) // Loop till we go out of scope.
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
if (V_strcmp(it->m_pName, pName) == NULL)
|
|
|
|
return it->m_CreateFn();
|
2022-04-09 00:59:42 +02:00
|
|
|
}
|
2022-01-17 03:28:16 +01:00
|
|
|
|
2023-08-22 01:11:49 +02:00
|
|
|
// No dice.
|
|
|
|
return nullptr;
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
// Purpose: get the factory system's interface version
|
|
|
|
// Input : *pName -
|
2022-01-17 03:28:16 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
const char* CFactorySystem::GetVersion(void) const
|
2022-01-17 03:28:16 +01:00
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
return FACTORY_INTERFACE_VERSION;
|
2022-01-17 03:28:16 +01:00
|
|
|
}
|
|
|
|
|
2022-08-21 00:59:55 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
// Purpose:
|
2022-08-21 00:59:55 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
void* CreateInterface(const char* pName, int* pReturnCode)
|
2022-08-21 00:59:55 +02:00
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
return CreateInterfaceInternal(pName, pReturnCode);
|
2022-08-21 00:59:55 +02:00
|
|
|
}
|
|
|
|
|
2022-08-21 01:02:07 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
// Purpose:
|
2022-08-21 01:02:07 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
2023-08-22 01:11:49 +02:00
|
|
|
IFactorySystem* GetFactorySystem()
|
2022-08-21 00:59:55 +02:00
|
|
|
{
|
2023-08-22 01:11:49 +02:00
|
|
|
return g_pFactorySystem;
|
2022-08-21 00:59:55 +02:00
|
|
|
}
|
|
|
|
|
2023-08-22 01:11:49 +02:00
|
|
|
CFactorySystem* g_pFactorySystem = new CFactorySystem();
|