2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/libsrc/script/scrptsrv.h,v 1.5 1997/12/31 12:33:53 TOML Exp $
17 ///////////////////////////////////////////////////////////////////////////////
19 // Macros to build a script service
21 // Steps to defining your own script service:
23 // A script interface is similar to a COM interface, with the following
26 // 1) it cannot only be called from a script
27 // 2) arguments and return values must be of one of the base types in scrptbas.h,
29 // 3) Script functions by convention are always mixed-case style
30 // 4) In declarations of service methods, omit "THIS"
31 // 5) Implementations must derive from interface & implement using macros
33 // Note: because passive linking is used here, services in libraries may
34 // not get linked in if the service is the only thing in the module.
38 DECLARE_INTERFACE_(IAutoScriptService
, IUnknown
)
40 STDMETHOD_(void, Init
)() PURE
;
41 STDMETHOD_(void, End
)() PURE
;
44 #define DECLARE_SCRIPT_SERVICE_(iface_root) \
45 DECLARE_INTERFACE_( I##iface_root##ScriptService, IAutoScriptService)
47 #ifdef SCRIPT_MAIN_MODULE
49 #define DECLARE_SCRIPT_SERVICE(iface_root, lgiid) \
50 F_DECLARE_INTERFACE( I##iface_root##ScriptService); \
51 DEFINE_LG_GUID_UNCONDITIONAL(IID_I##iface_root##ScriptService, lgiid); \
52 extern IScriptMan * g_pScriptMan; \
53 I##iface_root##ScriptService & iface_root = *((I##iface_root##ScriptService *)g_pScriptMan->GetService(&IID_I##iface_root##ScriptService)); \
54 class c##iface_root##ServiceReleaser \
57 c##iface_root##ServiceReleaser() \
59 ((IUnknown *)(&iface_root))->Release(); \
61 } _g_##iface_root##ServiceReleaser; \
62 DECLARE_SCRIPT_SERVICE_(iface_root)
66 #define DECLARE_SCRIPT_SERVICE(iface_root, lgiid) \
67 F_DECLARE_INTERFACE( I##iface_root##ScriptService); \
68 const int kIID_I##iface_root##ScriptService = lgiid; \
69 DECLARE_SCRIPT_SERVICE_(iface_root)
73 template <class INTERFACE
, const GUID
* pIID_INTERFACE
>
74 class cScriptServiceImplBase
: public cCTUnaggregated
<INTERFACE
, pIID_INTERFACE
, kCTU_NoSelfDelete
>
76 STDMETHOD_(void, Init
)()
80 STDMETHOD_(void, End
)()
85 #define DECLARE_SCRIPT_SERVICE_IMPL(impl, iface_root) \
86 class impl : public cScriptServiceImplBase<I##iface_root##ScriptService, &IID_I##iface_root##ScriptService>
88 #define IMPLEMENT_SCRIPT_SERVICE_IMPL(impl, iface_root) \
89 DEFINE_LG_GUID_UNCONDITIONAL(IID_I##iface_root##ScriptService, kIID_I##iface_root##ScriptService); \
90 impl g_##impl##ScriptService; \
91 sScrSrvRegData g_##impl##ScrSrvRegData(&g_##impl##ScriptService, &IID_I##iface_root##ScriptService)
93 struct sScrSrvRegData
;
95 extern cDynArray
<sScrSrvRegData
*> g_ScrSrvRegData
;
99 sScrSrvRegData(IAutoScriptService
* pService
, const GUID
* pGuid
)
100 : pService(pService
), pGuid(pGuid
)
102 g_ScrSrvRegData
.Append(this);
105 IAutoScriptService
* pService
;
109 ///////////////////////////////////////////////////////////////////////////////
111 #endif /* !__SCRPTSRV_H */