convert line ends
[canaan.git] / prj / cam / libsrc / script / scrptmm.h
blob0985d6928c43d8051ab1b99456af47738f7031d5
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/libsrc/script/scrptmm.h,v 1.13 1998/07/30 20:57:30 TOML Exp $
8 //
9 //
12 #ifndef __SCRPTMM_H
13 #define __SCRPTMM_H
15 #include <multparm.h>
17 #ifndef SCRIPT
18 #error ("scrptmm.h only valid for use in scripts, not in app");
19 #endif
21 ///////////////////////////////////////////////////////////////////////////////
23 // Script DLL main module magic (please ignore)
26 #ifdef SCRIPT_MAIN_MODULE
28 // @TBD (toml 12-05-97): Rework this after real DLL/Library issues
29 // have been solved
31 #include <allocovr.h>
32 #include <scrptmem.h>
34 cScriptModuleAlloc g_Malloc;
35 IAllocator * g_pMalloc;
36 tScriptPrintFunc g_pPrint;
37 EXTERN IMalloc * g_pAppAlloc = NULL;
40 EXTERN int LGAPI HeapInit()
42 Assert_(g_pMalloc);
43 return !!g_pMalloc;
46 EXTERN void LGAPI HeapTerm()
50 extern "C"
53 void *(*f_malloc)(size_t size) = malloc;
54 void *(*f_realloc)(void *p, size_t size) = realloc;
55 void (*f_free)(void *p) = free;
56 size_t (*f_msize)(void *p) = _msize;
57 void *(*f_malloc_db)(size_t size, const char *, int) = malloc_db;
58 void *(*f_realloc_db)(void *p, size_t size, const char *, int) = realloc_db;
59 void (*f_free_db)(void *p, const char *, int) = free_db;
61 void *MallocSpew(size_t size, const char *file, int line)
63 void *p;
64 p = (*f_malloc_db)(size, file, line);
66 return(p);
70 #include <pool.h>
72 // Create a pool of fixed sized objects
74 EXTERN HPOOL LGAPI PoolCreate(size_t s)
76 Assert_(g_pMalloc);
77 return (HPOOL)s;
81 // Allocate an item from the pool
83 EXTERN void * LGAPI PoolAlloc(HPOOL hPool)
85 Assert_(g_pMalloc);
86 return malloc((size_t)hPool);
90 // Free an item from the pool
92 EXTERN void LGAPI PoolFree(HPOOL pPool, void *pData)
94 Assert_(g_pMalloc);
95 free(pData);
99 // Destroy the pool
101 EXTERN void LGAPI PoolDestroy(HPOOL pPool)
105 #endif
107 ///////////////////////////////////////////////////////////////////////////////
109 // Main module data and entry point
112 #ifdef SCRIPT_MAIN_MODULE
114 #define DLL_PROCESS_ATTACH 1
115 #define DLL_THREAD_ATTACH 2
116 #define DLL_THREAD_DETACH 3
117 #define DLL_PROCESS_DETACH 0
119 #pragma comment(linker, "/entry:_ScriptDllMainCRTStartup")
121 EXTERN BOOL __stdcall _CRT_INIT(
122 HANDLE hDllHandle,
123 DWORD dwReason,
124 void * lpreserved
127 static HANDLE g_hDll;
128 static void * g_pStartupReserved;
130 BOOL __stdcall _ScriptDllMainCRTStartup(
131 HANDLE hDllHandle,
132 DWORD dwReason,
133 void * lpreserved
136 BOOL retcode;
138 switch (dwReason)
140 case DLL_PROCESS_ATTACH:
141 g_hDll = hDllHandle;
142 g_pStartupReserved = lpreserved;
143 retcode = TRUE;
144 break;
146 case DLL_THREAD_ATTACH:
147 case DLL_THREAD_DETACH:
148 case DLL_PROCESS_DETACH:
149 retcode = _CRT_INIT(hDllHandle, dwReason, lpreserved);
150 if (dwReason == DLL_PROCESS_DETACH) {
152 /* --<<= --/-/-/-/-/-/-/ <<< ((( ((( /\ ))) ))) >>> \-\-\-\-\-\-\-- =>>-- *\
154 The extra memory tracking layer has been removed for EEE since it
155 caused a heap trash which has been difficult to track, associated
156 with dropping any script module. We die right here with an invalid
157 block on the free list.
159 (Mat 5/24/98)
161 \* --<<= --\-\-\-\-\-\-\ <<< ((( ((( \/ ))) ))) >>> /-/-/-/-/-/-/-- =>>-- */
164 #ifndef NO_ATTACH_ALLOC
165 g_Malloc.Remove(); // restores g_pMalloc
166 #endif
167 SafeRelease(g_pMalloc);
169 break;
172 return retcode;
175 cMultiParm::uScratch cMultiParm::gm_scratch;
177 void cMultiParm::VecToTempString() const
179 sprintf(gm_scratch.szBuf, "%f, %f, %f", pVec->x, pVec->y, pVec->z);
182 #include <hshsttem.h>
183 template cStrHashSet<cScript::sScrMsgMapEntry *>;
185 #include <initguid.h>
186 #include <scrguid.h>
187 #include <allcguid.h>
189 cScriptModule g_ScriptModule;
190 IScriptMan * g_pScriptMan;
192 EXTERN
193 __LGEXPORT
194 BOOL LGAPI ScriptModuleInit(const char * pszName,
195 IScriptMan * pScriptMan,
196 tScriptPrintFunc pPrint,
197 IUnknown * pMalloc,
198 IScriptModule ** ppModule)
200 pMalloc->QueryInterface(IID_IDebugMalloc, (void **) &g_pMalloc);
201 if (!g_pMalloc)
202 pMalloc->QueryInterface(IID_IMalloc, (void **) &g_pMalloc); // ! (toml 06-14-98)
204 g_pScriptMan = pScriptMan;
205 g_pAppAlloc = g_pMalloc;
206 #ifndef NO_ATTACH_ALLOC
207 g_Malloc.cScriptModuleAlloc::cScriptModuleAlloc(); // force
208 g_Malloc.Attach((IMalloc **)&g_pMalloc);
209 #endif
211 _CRT_INIT(g_hDll, DLL_PROCESS_ATTACH, g_pStartupReserved);
213 g_ScriptModule.SetName(pszName);
214 g_pPrint = pPrint;
216 // We don't AddRef as the module is initialized with a reference.
217 *ppModule = &g_ScriptModule;
219 return TRUE;
222 #endif
224 ///////////////////////////////////////////////////////////////////////////////
225 #endif /* !__SCRPTMM_H */