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