FreeWRL / FreeX3D 4.3.0
iglobal.c
1#include <internal.h> //needed for opengl_utils.h included in iglobal.h
2#include <iglobal.h>
3
4
5void display_init(struct tdisplay* d);
6void internalc_init(struct tinternalc* ic);
7void resources_init(struct tresources* t);
8void resources_clear(struct tresources* t);
9void threads_init(struct tthreads* t);
10
11#if !defined(FRONTEND_DOES_SNAPSHOTS)
12void Snapshot_init(struct tSnapshot *);
13#endif
14
15void EAI_C_CommonFunctions_init(struct tEAI_C_CommonFunctions*);
16void EAIEventsIn_init(struct tEAIEventsIn* t);
17void EAIHelpers_init(struct tEAIHelpers* t);
18
19#if !defined(EXCLUDE_EAI)
20void EAICore_init(struct tEAICore* t);
21#endif
22
23void SensInterps_init(struct tSensInterps *t);
24void ConsoleMessage_init(struct tConsoleMessage *t);
25void Mainloop_init(struct tMainloop *t);
26void Mainloop_clear(struct tMainloop *t);
27void ProdCon_init(struct tProdCon *t);
28void ProdCon_clear(struct tProdCon *t);
29
30#if defined (INCLUDE_NON_WEB3D_FORMATS)
31void ColladaParser_init(struct tColladaParser *t);
32#endif //INCLUDE_NON_WEB3D_FORMATS
33
34#if defined (INCLUDE_STL_FILES)
35void STL_Handler_init (struct tSTLHandler *t);
36#endif // INCLUDE_STL_FILES
37
38
39
40void Frustum_init(struct tFrustum *t);
41void LoadTextures_init(struct tLoadTextures *t);
42void OpenGL_Utils_init(struct tOpenGL_Utils *t);
43void OpenGL_Utils_clear(struct tOpenGL_Utils *t);
44#ifdef HAVE_OPENCL
45void OpenCL_Utils_init(struct tOpenCL_Utils *t);
46#endif
47//void RasterFont_init(struct tRasterFont *t);
48void RenderTextures_init(struct tRenderTextures *t);
49void Textures_init(struct tTextures *t);
50void Textures_clear(struct tTextures *t);
51
52void PluginSocket_init(struct tPluginSocket *t);
53void pluginUtils_init(struct tpluginUtils *t);
54void collision_init(struct tcollision *t);
55void collision_clear(struct tcollision *t);
56void Component_CubeMapTexturing_init(struct tComponent_CubeMapTexturing *t);
57void Component_CubeMapTexturing_clear(struct tComponent_CubeMapTexturing *t);
58void Component_EnvironSensor_init(struct tComponent_EnvironSensor *t);
59void Component_Geometry3D_init(struct tComponent_Geometry3D *t);
60void Component_Geometry3D_clear(struct tComponent_Geometry3D *t);
61void Component_Geospatial_init(struct tComponent_Geospatial *t);
62void Component_Geospatial_clear(struct tComponent_Geospatial *t);
63void Component_HAnim_init(struct tComponent_HAnim *t);
64void Component_HAnim_clear(struct tComponent_HAnim *t);
65void Component_Layering_init(struct tComponent_Layering *t);
66void Component_Layout_init(struct tComponent_Layout *t);
67void Component_NURBS_init(struct tComponent_NURBS *t);
68void Component_ParticleSystems_init(struct tComponent_ParticleSystems *t);
69void Component_ParticleSystems_clear(struct tComponent_ParticleSystems *t);
70void Component_ProgrammableShaders_init(struct tComponent_ProgrammableShaders *t);
71void Component_ProgrammableShaders_clear(struct tComponent_ProgrammableShaders *t);
72void Component_PTM_init(struct tComponent_PTM *t);
73void Component_PTM_clear(struct tComponent_PTM *t);
74void Component_RigidBodyPhysics_init(struct tComponent_RigidBodyPhysics *t);
75void Component_RigidBodyPhysics_clear(struct tComponent_RigidBodyPhysics *t);
76void Component_Followers_init(struct tComponent_Followers *t);
77void Component_Followers_clear(struct tComponent_Followers *t);
78
79void Component_KeyDevice_init(struct tComponent_KeyDevice *t);
80
81#ifdef OLDCODE
82OLDCODEvoid Component_Networking_init(struct tComponent_Networking *t);
83#endif
84
85void Component_Picking_init(struct tComponent_Picking *t);
86void Component_Rendering_init(struct tComponent_Rendering *t);
87void Component_Rendering_clear(struct tComponent_Rendering *t);
88void Component_Shape_init(struct tComponent_Shape *t);
89void Component_Sound_init(struct tComponent_Sound *t);
90void Component_Text_init(struct tComponent_Text *t);
91void Component_Text_clear(struct tComponent_Text *t);
92void Component_Layering_clear(struct tComponent_Layering *t);
93void Component_Layout_clear(struct tComponent_Layout *t);
94void Component_VolumeRendering_init(struct tComponent_VolumeRendering *t);
95void Component_VolumeRendering_clear(struct tComponent_VolumeRendering *t);
96
97void RenderFuncs_init(struct tRenderFuncs *t);
98void RenderFuncs_clear(struct tRenderFuncs *t);
99void StreamPoly_init(struct tStreamPoly *t);
100void Tess_init(struct tTess *t);
101void Viewer_init(struct tViewer *t);
102
103#if defined(STATUSBAR_HUD)
104void statusbar_init(struct tstatusbar *t);
105void statusbar_clear(struct tstatusbar *t);
106#endif
107
108void CParse_init(struct tCParse *t);
109void CParse_clear(struct tCParse *t);
110void CParseParser_init(struct tCParseParser *t);
111void CRoutes_init(struct tCRoutes *t);
112void CRoutes_clear(struct tCRoutes *t);
113void CScripts_init(struct tCScripts *t);
114#ifdef JAVASCRIPT_SM
115void JScript_init(struct tJScript *t);
116
117
118void jsUtils_init(struct tjsUtils *t);
119void jsVRMLBrowser_init(struct tjsVRMLBrowser *t);
120void jsVRMLClasses_init(struct tjsVRMLClasses *t);
121#endif //JAVASCRIPT_SM
122#ifdef JAVASCRIPT_DUK
123void JScript_duk_init(struct tJScript_duk *t);
124#endif //JAVASCRIPT_DUK
125void Bindable_init(struct tBindable *t);
126void Bindable_clear(struct tBindable *t);
127
128void X3DParser_init(struct tX3DParser *t);
129void X3DParser_clear(struct tX3DParser *t);
130
131void common_init(struct tcommon *t);
132void common_clear(struct tcommon *t);
133void CursorDraw_init(struct tCursorDraw *t);
134
135//static ttglobal iglobal; //<< for initial development witn single instance
136static int done_main_UI_thread_once = 0;
137pthread_key_t threadSpecificKey; //set like a global variable in the global scope in a .c file
138
139void iiglobal_sizeof_from_C(){
140printf("sizeof_iiblobal_fromC >>>>>>>>>>>>>>>>>>>>>>\n");
141printf(" tdisplay %d\n", (int)sizeof(struct tdisplay));
142printf(" tinternalc %d\n", (int)sizeof(struct tinternalc));
143printf(" tresources %d\n", (int)sizeof(struct tresources));
144printf(" tresources %d\n", (int)sizeof(struct tresources));
145printf(" tthreads %d\n", (int)sizeof(struct tthreads));
146
147#if !defined(FRONTEND_DOES_SNAPSHOTS)
148printf(" tSnapshot %d\n", (int)sizeof(struct tSnapshot));
149#endif
150
151printf(" tEAI_C_CommonFunctions %d\n", (int)sizeof(struct tEAI_C_CommonFunctions));
152printf(" tEAIEventsIn %d\n", (int)sizeof(struct tEAIEventsIn));
153printf(" tEAIHelpers %d\n", (int)sizeof(struct tEAIHelpers));
154
155#if !defined(EXCLUDE_EAI )
156printf(" tEAICore %d\n", (int)sizeof(struct tEAICore));
157#endif
158
159printf(" tSensInterps %d\n", (int)sizeof(struct tSensInterps));
160printf(" tConsoleMessage %d\n", (int)sizeof(struct tConsoleMessage));
161printf(" tMainloop %d\n", (int)sizeof(struct tMainloop));
162printf(" tMainloop %d\n", (int)sizeof(struct tMainloop));
163printf(" tProdCon %d\n", (int)sizeof(struct tProdCon));
164printf(" tProdCon %d\n", (int)sizeof(struct tProdCon));
165
166#if defined (INCLUDE_NON_WEB3D_FORMATS )
167printf(" tColladaParser %d\n", (int)sizeof(struct tColladaParser));
168#endif //INCLUDE_NON_WEB3D_FORMATS
169
170#if defined (INCLUDE_STL_FILES )
171printf(" tSTLHandler %d\n", (int)sizeof(struct tSTLHandler));
172#endif // INCLUDE_STL_FILES
173
174
175
176printf(" tFrustum %d\n", (int)sizeof(struct tFrustum));
177printf(" tLoadTextures %d\n", (int)sizeof(struct tLoadTextures));
178printf(" tOpenGL_Utils %d\n", (int)sizeof(struct tOpenGL_Utils));
179
180#ifdef HAVE_OPENCL
181printf(" tOpenCL_Utils %d\n", (int)sizeof(struct tOpenCL_Utils));
182#endif
183
184printf(" tRenderTextures %d\n", (int)sizeof(struct tRenderTextures));
185printf(" tTextures %d\n", (int)sizeof(struct tTextures));
186printf(" tPluginSocket %d\n", (int)sizeof(struct tPluginSocket));
187printf(" tpluginUtils %d\n", (int)sizeof(struct tpluginUtils));
188printf(" tcollision %d\n", (int)sizeof(struct tcollision));
189printf(" tComponent_CubeMapTexturing %d\n", (int)sizeof(struct tComponent_CubeMapTexturing));
190printf(" tComponent_EnvironSensor %d\n", (int)sizeof(struct tComponent_EnvironSensor));
191printf(" tComponent_Geometry3D %d\n", (int)sizeof(struct tComponent_Geometry3D));
192printf(" tComponent_Geospatial %d\n", (int)sizeof(struct tComponent_Geospatial));
193printf(" tComponent_HAnim %d\n", (int)sizeof(struct tComponent_HAnim));
194printf(" tComponent_Layering %d\n", (int)sizeof(struct tComponent_Layering));
195printf(" tComponent_Layout %d\n", (int)sizeof(struct tComponent_Layout));
196printf(" tComponent_NURBS %d\n", (int)sizeof(struct tComponent_NURBS));
197printf(" tComponent_ParticleSystems %d\n", (int)sizeof(struct tComponent_ParticleSystems));
198printf(" tComponent_ProgrammableShaders %d\n", (int)sizeof(struct tComponent_ProgrammableShaders));
199printf(" tComponent_PTM %d\n",(int)sizeof(struct tComponent_PTM));
200printf(" tComponent_RigidBodyPhysics %d\n", (int)sizeof(struct tComponent_RigidBodyPhysics));
201printf(" tComponent_Followers %d\n", (int)sizeof(struct tComponent_Followers));
202printf(" tComponent_KeyDevice %d\n", (int)sizeof(struct tComponent_KeyDevice));
203
204printf(" tComponent_Picking %d\n", (int)sizeof(struct tComponent_Picking));
205printf(" tComponent_Rendering %d\n", (int)sizeof(struct tComponent_Rendering));
206printf(" tComponent_Shape %d\n", (int)sizeof(struct tComponent_Shape));
207printf(" tComponent_Sound %d\n", (int)sizeof(struct tComponent_Sound));
208printf(" tComponent_Text %d\n", (int)sizeof(struct tComponent_Text));
209printf(" tComponent_VolumeRendering %d\n", (int)sizeof(struct tComponent_VolumeRendering));
210
211printf(" tRenderFuncs %d\n", (int)sizeof(struct tRenderFuncs));
212printf(" tStreamPoly %d\n", (int)sizeof(struct tStreamPoly));
213printf(" tTess %d\n", (int)sizeof(struct tTess));
214printf(" tViewer %d\n", (int)sizeof(struct tViewer));
215
216#if defined(STATUSBAR_HUD)
217printf(" tstatusbar %d\n", (int)sizeof(struct tstatusbar));
218#endif
219
220printf(" tCParse %d\n", (int)sizeof(struct tCParse));
221printf(" tCParseParser %d\n", (int)sizeof(struct tCParseParser));
222printf(" tCRoutes %d\n", (int)sizeof(struct tCRoutes));
223printf(" tCScripts %d\n", (int)sizeof(struct tCScripts));
224#ifdef JAVASCRIPT_SM
225printf(" tJScript %d\n", (int)sizeof(struct tJScript));
226
227
228printf(" tjsUtils %d\n", (int)sizeof(struct tjsUtils));
229printf(" tjsVRMLBrowser %d\n", (int)sizeof(struct tjsVRMLBrowser));
230printf(" tjsVRMLClasses %d\n", (int)sizeof(struct tjsVRMLClasses));
231#endif //JAVASCRIPT_SM
232#ifdef JAVASCRIPT_DUK
233printf(" tJScript_duk %d\n", (int)sizeof(struct tJScript_duk));
234#endif //JAVASCRIPT_DUK
235printf(" tBindable %d\n", (int)sizeof(struct tBindable));
236
237printf(" tX3DParser %d\n", (int)sizeof(struct tX3DParser));
238
239printf(" tcommon %d\n", (int)sizeof(struct tcommon));
240printf(" tCursorDraw %d\n", (int)sizeof(struct tCursorDraw));
241printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
242}
243
244
245ttglobal iglobal_constructor() //(mainthreadID,parserthreadID,texturethreadID...)
246{
247
248 //JAS printf ("calling iglobal_constructor\n");
249
250 //using Johns threadID method would:
251 //1. create global struct
252 // - malloc
253 // - initialize any that have initializers
254 //2. add 3 items to the thread2global[] list
255 //3. for each of those 3 items:
256 // - set thread2global[threadID] = global
257 // pthread_t uiThread;
258 ttglobal iglobal = MALLOCV(sizeof(struct iiglobal));
259 memset(iglobal,0,sizeof(struct iiglobal)); //set to zero/null by default
260#ifdef DISABLER
261 if(!done_main_UI_thread_once){
262 pthread_key_create(&threadSpecificKey, NULL);
263 done_main_UI_thread_once = 1; //this assumes the iglobal is created in the shared UI main thread
264 }
265 fwl_setCurrentHandle(iglobal,__FILE__,__LINE__); //probably redundant but no harm
266
267#if defined(WRAP_MALLOC) || defined(DEBUG_MALLOC)
268 iglobal->__memTable_ShouldRegisterAllocation = TRUE;
269 freewrlInitMemTable();
270#endif
271#endif
272 //call initializer for each sub-struct
273 display_init(&iglobal->display);
274 internalc_init(&iglobal->internalc);
275 resources_init(&iglobal->resources);
276 threads_init(&iglobal->threads);
277
278
279 #if !defined(FRONTEND_DOES_SNAPSHOTS)
280 Snapshot_init(&iglobal->Snapshot);
281 #endif
282
283 EAI_C_CommonFunctions_init(&iglobal->EAI_C_CommonFunctions);
284#if !defined(EXCLUDE_EAI)
285 EAIEventsIn_init(&iglobal->EAIEventsIn);
286 EAIHelpers_init(&iglobal->EAIHelpers);
287 EAICore_init(&iglobal->EAICore);
288#endif //EXCLUDE_EAI
289
290 SensInterps_init(&iglobal->SensInterps);
291 ConsoleMessage_init(&iglobal->ConsoleMessage);
292 Mainloop_init(&iglobal->Mainloop);
293 ProdCon_init(&iglobal->ProdCon);
294
295#if defined (INCLUDE_NON_WEB3D_FORMATS)
296 ColladaParser_init(&iglobal->ColladaParser);
297#endif //INCLUDE_NON_WEB3D_FORMATS
298
299#if defined (INCLUDE_STL_FILES)
300 STL_Handler_init (&iglobal->STLHandler);
301#endif // INCLUDE_STL_FILES
302
303 Frustum_init(&iglobal->Frustum);
304 LoadTextures_init(&iglobal->LoadTextures);
305 OpenGL_Utils_init(&iglobal->OpenGL_Utils);
306#ifdef HAVE_OPENCL
307 OpenCL_Utils_init(&iglobal->OpenCL_Utils);
308#endif
309
310 //RasterFont_init(&iglobal->RasterFont);
311 RenderTextures_init(&iglobal->RenderTextures);
312 Textures_init(&iglobal->Textures);
313 Component_PTM_init(&iglobal->Component_PTM);
314#ifndef DISABLER
315#ifndef NO_PLUGINSOCKET
316 PluginSocket_init(&iglobal->PluginSocket);
317#endif
318 pluginUtils_init(&iglobal->pluginUtils);
319#endif
320 collision_init(&iglobal->collision);
321 Component_CubeMapTexturing_init(&iglobal->Component_CubeMapTexturing);
322 Component_EnvironSensor_init(&iglobal->Component_EnvironSensor);
323 Component_Geometry3D_init(&iglobal->Component_Geometry3D);
324 Component_Geospatial_init(&iglobal->Component_Geospatial);
325 Component_HAnim_init(&iglobal->Component_HAnim);
326 Component_Layering_init(&iglobal->Component_Layering);
327 Component_Layout_init(&iglobal->Component_Layout);
328 Component_NURBS_init(&iglobal->Component_NURBS);
329 Component_ProgrammableShaders_init(&iglobal->Component_ProgrammableShaders);
330 Component_ParticleSystems_init(&iglobal->Component_ParticleSystems);
331 Component_RigidBodyPhysics_init(&iglobal->Component_RigidBodyPhysics);
332 Component_Followers_init(&iglobal->Component_Followers);
333 Component_KeyDevice_init(&iglobal->Component_KeyDevice);
334#ifdef OLDCODE
335OLDCODE Component_Networking_init(&iglobal->Component_Networking);
336#endif // OLDCODE
337 Component_Picking_init(&iglobal->Component_Picking);
338 Component_Rendering_init(&iglobal->Component_Rendering);
339 Component_Shape_init(&iglobal->Component_Shape);
340 Component_Sound_init(&iglobal->Component_Sound);
341 Component_Text_init(&iglobal->Component_Text);
342 Component_VolumeRendering_init(&iglobal->Component_VolumeRendering);
343 RenderFuncs_init(&iglobal->RenderFuncs);
344 StreamPoly_init(&iglobal->StreamPoly);
345 Tess_init(&iglobal->Tess);
346 Viewer_init(&iglobal->Viewer);
347#if defined(STATUSBAR_HUD)
348 statusbar_init(&iglobal->statusbar);
349#endif
350 CParse_init(&iglobal->CParse);
351 CParseParser_init(&iglobal->CParseParser);
352 CRoutes_init(&iglobal->CRoutes);
353 CScripts_init(&iglobal->CScripts);
354#ifdef JAVASCRIPT_SM
355 JScript_init(&iglobal->JScript);
356 jsUtils_init(&iglobal->jsUtils);
357 jsVRMLBrowser_init(&iglobal->jsVRMLBrowser);
358 jsVRMLClasses_init(&iglobal->jsVRMLClasses);
359#endif //JAVASCRIPT_SM
360#ifdef JAVASCRIPT_DUK
361 JScript_duk_init(&iglobal->JScript_duk);
362#endif //JAVASCRIPT_DUK
363 Bindable_init(&iglobal->Bindable);
364 X3DParser_init(&iglobal->X3DParser);
365 common_init(&iglobal->common);
366#ifndef DISABLER
367 CursorDraw_init(&iglobal->CursorDraw);
368
369 //uiThread = pthread_self();
370 //set_thread2global(iglobal, uiThread ,"UI thread");
371
372 if(!done_main_UI_thread_once){
373 pthread_key_create(&threadSpecificKey, NULL);
374 done_main_UI_thread_once = 1; //this assumes the iglobal is created in the shared UI main thread
375 }
376 fwl_setCurrentHandle(iglobal,__FILE__,__LINE__); //probably redundant but no harm
377#endif
378 return iglobal;
379}
380
381void __iglobal_fields_destructor(ttglobal tg);
382void remove_iglobal_from_table(ttglobal tg);
383void __iglobal_destructor(ttglobal tg);
384
385void iglobal_destructor(ttglobal tg)
386{
387 __iglobal_fields_destructor(tg);
388 __iglobal_destructor(tg);
389}
390
391void __iglobal_fields_destructor(ttglobal tg)
392{
393 /* you should have stopped any worker threads for this instance */
394 //call individual destructors in reverse order to constructor
395 FREE_IF_NZ(tg->CursorDraw.prv);
396 common_clear(&tg->common); FREE_IF_NZ(tg->common.prv);
397 X3DParser_clear(&tg->X3DParser); FREE_IF_NZ(tg->X3DParser.prv);
398 Bindable_clear(&tg->Bindable); FREE_IF_NZ(tg->Bindable.prv);
399
400#ifdef JAVASCRIPT_DUK
401 FREE_IF_NZ(tg->JScript_duk.prv);
402#endif //JAVASCRIPT_DUK
403#ifdef JAVASCRIPT_SM
404 FREE_IF_NZ(tg->jsVRMLClasses.prv);
405 FREE_IF_NZ(tg->jsVRMLBrowser.prv);
406 FREE_IF_NZ(tg->jsUtils.prv);
407
408 FREE_IF_NZ(tg->JScript.prv);
409#endif //JAVASCRIPT_SM
410 FREE_IF_NZ(tg->CScripts.prv);
411 CRoutes_clear(&tg->CRoutes); FREE_IF_NZ(tg->CRoutes.prv);
412 FREE_IF_NZ(tg->CParseParser.prv);
413 CParse_clear(&tg->CParse); FREE_IF_NZ(tg->CParse.prv);
414#if defined(STATUSBAR_HUD)
415 statusbar_clear(&tg->statusbar);
416#endif
417 FREE_IF_NZ(tg->statusbar.prv);
418 FREE_IF_NZ(tg->Viewer.prv);
419 FREE_IF_NZ(tg->Tess.prv);
420 Component_VolumeRendering_clear(&tg->Component_VolumeRendering); FREE_IF_NZ(tg->Component_VolumeRendering.prv);
421 FREE_IF_NZ(tg->StreamPoly.prv);
422 FREE_IF_NZ(tg->Component_Sound.prv);
423 RenderFuncs_clear(&tg->RenderFuncs); FREE_IF_NZ(tg->RenderFuncs.prv);
424 Component_Text_clear(&tg->Component_Text); FREE_IF_NZ(tg->Component_Text.prv);
425 FREE_IF_NZ(tg->Component_Shape.prv);
426 Component_Rendering_clear(&tg->Component_Rendering); FREE_IF_NZ(tg->Component_Rendering.prv);
427 FREE_IF_NZ(tg->Component_Picking.prv);
428#ifdef OLDCODE
429OLDCODE FREE_IF_NZ(tg->Component_Networking.prv);
430#endif
431 FREE_IF_NZ(tg->Component_KeyDevice.prv);
432 Component_Followers_clear(&tg->Component_Followers); FREE_IF_NZ(tg->Component_Followers.prv);
433 Component_RigidBodyPhysics_clear(&tg->Component_RigidBodyPhysics); FREE_IF_NZ(tg->Component_RigidBodyPhysics.prv);
434 Component_ProgrammableShaders_clear(&tg->Component_ProgrammableShaders); FREE_IF_NZ(tg->Component_ProgrammableShaders.prv);
435 Component_ParticleSystems_clear(&tg->Component_ParticleSystems); FREE_IF_NZ(tg->Component_ParticleSystems.prv);
436 FREE_IF_NZ(tg->Component_NURBS.prv);
437 Component_Layering_clear(&tg->Component_Layering); FREE_IF_NZ(tg->Component_Layering.prv);
438 Component_Layout_clear(&tg->Component_Layout); FREE_IF_NZ(tg->Component_Layout.prv);
439 Component_HAnim_clear(&tg->Component_HAnim); FREE_IF_NZ(tg->Component_HAnim.prv);
440 Component_Geospatial_clear(&tg->Component_Geospatial); FREE_IF_NZ(tg->Component_Geospatial.prv);
441 Component_Geometry3D_clear(&tg->Component_Geometry3D); FREE_IF_NZ(tg->Component_Geometry3D.prv);
442 FREE_IF_NZ(tg->Component_EnvironSensor.prv);
443 Component_CubeMapTexturing_clear(&tg->Component_CubeMapTexturing); FREE_IF_NZ(tg->Component_CubeMapTexturing.prv);
444 collision_clear(&tg->collision); FREE_IF_NZ(tg->collision.prv);
445 FREE_IF_NZ(tg->pluginUtils.prv);
446 FREE_IF_NZ(tg->PluginSocket.prv);
447 Component_PTM_clear(&tg->Component_PTM); FREE_IF_NZ(tg->Component_PTM.prv);
448 Textures_clear(&tg->Textures); FREE_IF_NZ(tg->Textures.prv);
449 FREE_IF_NZ(tg->RenderTextures.prv);
450 //FREE_IF_NZ(tg->RasterFont.prv);
451 OpenGL_Utils_clear(&tg->OpenGL_Utils); FREE_IF_NZ(tg->OpenGL_Utils.prv);
452 FREE_IF_NZ(tg->LoadTextures.prv);
453 FREE_IF_NZ(tg->Frustum.prv);
454
455#if defined (INCLUDE_NON_WEB3D_FORMATS)
456 FREE_IF_NZ(tg->ColladaParser.prv);
457#endif //INCLUDE_NON_WEB3D_FORMATS
458
459#if defined (INCLUDE_STL_FILES)
460 FREE_IF_NZ(tg->STLHandler.prv);
461#endif // INCLUDE_STL_FILES
462
463 ProdCon_clear(&tg->ProdCon); FREE_IF_NZ(tg->ProdCon.prv);
464 Mainloop_clear(&tg->Mainloop); FREE_IF_NZ(tg->Mainloop.prv);
465 FREE_IF_NZ(tg->ConsoleMessage.prv);
466 FREE_IF_NZ(tg->SensInterps.prv);
467 FREE_IF_NZ(tg->EAICore.prv);
468 FREE_IF_NZ(tg->EAIHelpers.prv);
469 FREE_IF_NZ(tg->EAIEventsIn.prv);
470 FREE_IF_NZ(tg->EAI_C_CommonFunctions.prv);
471 FREE_IF_NZ(tg->Snapshot.prv);
472
473 FREE_IF_NZ(tg->threads.prv);
474 resources_clear(&tg->resources); FREE_IF_NZ(tg->resources.prv);
475 FREE_IF_NZ(tg->internalc.prv);
476 FREE_IF_NZ(tg->display.prv);
477}
478
479void __iglobal_destructor(ttglobal tg)
480{
481 //destroy iglobal
482#ifndef DISABLER
483 FREE_IF_NZ(tg);
484#else
485 free(tg);
486#endif
487 //remove_iglobal_from_table(tg);
488 fwl_clearCurrentHandle(__FILE__,__LINE__);
489
490}
491
492
493
494void *fwl_getCurrentHandle(char *fi, int li){
495 ttglobal currentHandle = (ttglobal)pthread_getspecific(threadSpecificKey);
496 //printf ("fwl_getCurrentHandle returning %p at %s:%d\n",currentHandle,fi,li);
497 return (void*)currentHandle;
498}
499int fwl_setCurrentHandle(void *handle, char *fi, int li)
500{
501 //printf ("fwl_setCurrentHandle at to %p thread %p at %s:%d\n",handle,pthread_self(),fi,li);
502
503 pthread_setspecific(threadSpecificKey,handle);
504 return 1; /* let caller know its not in the table yet */
505}
506void fwl_clearCurrentHandle(char *fi, int li)
507{
508 void *currentHandle = NULL;
509 //printf ("fwl_clearCurrentHandle at %s:%d\n",fi,li);
510 pthread_setspecific(threadSpecificKey,currentHandle);
511
512}
513ttglobal gglobal(char *fi, int *li){
514 ttglobal tg = NULL;
515#ifdef DISABLER
516 if (done_main_UI_thread_once)
517#endif
518 tg = (ttglobal)pthread_getspecific(threadSpecificKey);
519 if(!tg)
520 {
521 printf("Ouch - no state for this thread -- hit a key to exit\n");
522#ifdef _MSC_VER
523 printf ("more info - thread %p\n\n",(void *)pthread_self().p);
524#else
525 printf ("more info - thread %p\n\n",(void *)pthread_self());
526#endif
527 getchar();
528 exit(-1);
529 }
530 return tg;
531}
532
533ttglobal gglobal0()
534{
535#ifdef DISABLER
536 if (!done_main_UI_thread_once)
537 {
538 return NULL;
539 }
540#endif
541 return (ttglobal)pthread_getspecific(threadSpecificKey);
542}