mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 20:16:10 +08:00
More Source 2 / Dota shuffling.
- Remove tier1 interface/factory funcs that no longer exist. - Add/fix tier0 interface funcs. - Fix tier0 win64 link lib to have correct decorated names for Msg, Warning, etc. - Update Error() shim to act more closely to old behavior. - Moved CreateInterface impl to interfaces lib (appears to not be in tier1 anymore). - Removed exports log channels that aren't exported in S2.
This commit is contained in:
@ -12,12 +12,107 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/interface.h"
|
||||
|
||||
// All interfaces derive from this.
|
||||
class IBaseInterface
|
||||
{
|
||||
public:
|
||||
virtual ~IBaseInterface() {}
|
||||
};
|
||||
|
||||
typedef void* (*InstantiateInterfaceFn)();
|
||||
|
||||
// Used internally to register classes.
|
||||
class InterfaceReg
|
||||
{
|
||||
public:
|
||||
InterfaceReg(InstantiateInterfaceFn fn, const char *pName);
|
||||
|
||||
public:
|
||||
InstantiateInterfaceFn m_CreateFn;
|
||||
const char *m_pName;
|
||||
|
||||
InterfaceReg *m_pNext; // For the global list.
|
||||
};
|
||||
|
||||
// Use this to expose an interface that can have multiple instances.
|
||||
// e.g.:
|
||||
// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" )
|
||||
// This will expose a class called CInterfaceImp that implements IInterface (a pure class)
|
||||
// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" )
|
||||
//
|
||||
// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001")
|
||||
// so that each component can use these names/vtables to communicate
|
||||
//
|
||||
// A single class can support multiple interfaces through multiple inheritance
|
||||
//
|
||||
// Use this if you want to write the factory function.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName);
|
||||
#else
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
static void* __Create##className##_interface() {return static_cast<interfaceName *>( new className );} \
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName );
|
||||
#else
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static void* __Create##className##_interface() {return static_cast<interfaceName *>( new className );} \
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this to expose a singleton interface with a global variable you've created.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
static void* __Create##className##interfaceName##_interface() {return static_cast<interfaceName *>( &globalVarName );} \
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName);
|
||||
#else
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static void* __Create##className##interfaceName##_interface() {return static_cast<interfaceName *>( &globalVarName );} \
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this to expose a singleton interface. This creates the global variable for you automatically.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
static className __g_##className##_singleton; \
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
#else
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static className __g_##className##_singleton; \
|
||||
} \
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
#endif
|
||||
|
||||
// interface return status
|
||||
enum
|
||||
{
|
||||
IFACE_OK = 0,
|
||||
IFACE_FAILED
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface creation function
|
||||
// This function is automatically exported and allows you to access any interfaces exposed with the above macros.
|
||||
// if pReturnCode is set, it will return one of the following values (IFACE_OK, IFACE_FAILED)
|
||||
// extend this for other error conditions/code
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||
|
||||
DLL_EXPORT void* CreateInterface(const char *pName, int *pReturnCode);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Macros to declare interfaces appropriate for various tiers
|
||||
|
Reference in New Issue
Block a user