FreeWRL/FreeX3D  3.0.0
iglobal.h
1 /*
2 The globals have 'private' and 'public' facilities
3 1. if the variables are used only in one source file, they go
4  in a ppFileName struct in Filename.c
5 2. if the variables are used in other source files (via extern) then either:
6 2a. add getter and setter functions and keep private, or
7 2b. add directly to iiglobal struct in iglobal.h, in the struct tFileName sub-struct
8 2bi. in this case if its a pointer to a complex type, put as void* in iglobal and
9  add casting to the code (so iglobal.h doesn't have to #include a bunch of headers)
10 
11 Variable initialization:
12 1. for private: in a //private section in FileName_init(..) p->variable = const value
13 2. for public: in a //public section in FileName_init(..) t->variable = const value
14 
15 Variable use:
16 1. for private: ppFileName p = (ppFileName)gglobal()->FileName.prv;
17 -- p->variable = ...
18 2. for public: gglobal()->FileName.variable = ...
19 
20 */
21 
22 #ifndef INSTANCEGLOBAL
23 //#include "display.h" //for opengl_utils.h which is for rdr_caps
24 //#include "opengl/OpenGL_Utils.h" //for rdr_caps
25 #include "list.h"
26 #ifdef DISABLER
27 #include "dbl_list.h"
28 #endif
29 #include <system.h>
30 //#include <libFreeWRL.h>
31 #include <pthread.h>
32 #include <threads.h> //for threads
33 //#define GLenum int
34 //#define GLuint unsigned int
35 //#include "vrml_parser/Structs.h" //for SFColor
36 //#include "x3d_parser/X3DParser.h" //for PARENTSTACKSIZE
37 //#include "ui/common.h" // for ppcommon
38 
39 
40 
41 typedef struct iiglobal //InstanceGlobal
42 {
43  struct tdisplay{
44  void *params; //freewrl_params_t
45  int _global_gl_err; //GLenum
46  bool display_initialized;// = FALSE;
47  int screenWidth;// = 0; /* screen */
48  int screenHeight;// = 0;
49  char *window_title;// = NULL;
50  int shutterGlasses;// = 0; /* stereo shutter glasses */
51  void *rdr_caps; //s_renderer_capabilities_t
52  void *prv;
53  }display;
54  struct tinternalc {
55  bool global_strictParsing;// = FALSE;
56  bool global_plugin_print;// = FALSE;
57  bool global_occlusion_disable;// = FALSE;
58  unsigned user_request_texture_size;// = 0;
59  bool global_print_opengl_errors;// = FALSE;
60  bool global_trace_threads;// = FALSE;
61  void *prv;
62  } internalc;
63  //struct tio_http {
64  // void *prv;
65  //} io_http;
66  struct tresources {
67  //resource_item_t *root_res; // = NULL;
68  void *root_res;
69  void *prv;
70  } resources;
71  struct tthreads {
72  pthread_t disposeThread;
73  pthread_t mainThread; /* main (default) thread */
74  pthread_t DispThrd; /*DEF_THREAD(DispThrd); display thread */
75  pthread_t PCthread; /* DEF_THREAD(PCthread)parser thread */
76  pthread_t loadThread; /* DEF_THREAD(pthread_t loadThread)texture thread */
77  /* Synchronize / exclusion root_res and below */
78  pthread_mutex_t mutex_resource_tree; // = PTHREAD_MUTEX_INITIALIZER;
79 
80  /* Synchronize / exclusion : resource queue for parser */
81  pthread_mutex_t mutex_resource_list; // = PTHREAD_MUTEX_INITIALIZER;
82  pthread_cond_t resource_list_condition; // = PTHREAD_COND_INITIALIZER;
83 
84  pthread_mutex_t mutex_frontend_list; // = PTHREAD_MUTEX_INITIALIZER;
85 
86  /* Synchronize / exclusion (main<=>texture) */
87  pthread_mutex_t mutex_texture_list; // = PTHREAD_MUTEX_INITIALIZER;
88  pthread_cond_t texture_list_condition; // = PTHREAD_COND_INITIALIZER;
89  bool ResourceThreadRunning;
90  bool TextureThreadRunning;
91  bool ResourceThreadWaiting;
92  bool TextureThreadWaiting;
93  bool flushing;
94  int MainLoopQuit;
95  void *prv;
96  } threads;
97 
98  struct tSnapshot {
99  bool doSnapshot;
100  bool doPrintshot;
101  int snapGoodCount;
102  void *prv;
103  } Snapshot;
105  int eaiverbose;// = FALSE;
106  void *prv;
107  } EAI_C_CommonFunctions;
108  struct tEAIEventsIn{
109  void *prv;
110  } EAIEventsIn;
111  struct tEAIHelpers{
112  char *outBuffer;
113  int outBufferLen;
114  void *prv;
115  } EAIHelpers;
116  struct tEAICore{
117  /* EAI input buffer */
118  char *EAIbuffer;
119  int EAIbufcount; /* pointer into buffer*/
120  int EAIbufpos;
121  int EAIbufsize; /* current size in bytes of input buffer*/
122  void *prv;
123  } EAICore;
124  struct tSensInterps{
125  void *prv;
126  } SensInterps;
128  int consMsgCount;
129  int Console_writeToHud;
130  void *prv;
131  } ConsoleMessage;
132  struct tMainloop{
133  float gl_linewidth;
134  /* what kind of file was just parsed? */
135  int currentFileVersion;
136  double TickTime;
137  double lastTime;
138  double BrowserFPS;// = 100.0; /* calculated FPS */
139  double BrowserSpeed;// = 0.0; /* calculated movement speed */
140  const char *BrowserDescription;
141  int HaveSensitive;// = FALSE;
142  int AllowNavDrag;
143  int trisThisLoop;
144  int clipPlane;// = 0;
145  int SHIFT; //state of shift key up = 0, down = 1
146  int CTRL; //state of ctrl key up = 0, down = 1
147  //int currentX[20], currentY[20]; /* current mouse position.*/
148  void *prv;
149  char *tmpFileLocation;
150  char *url;
151  char *scene_name; //null or take from url
152  char *scene_suff; //null or wrl or x3d
153  int scene_profile; //from parser (or capabilities handler) used in js scene.profile
154  int *scene_components;
155  char *replaceWorldRequest;
156  void *replaceWorldRequestMulti; //will be struct multi-string
157  void *_vportstack; //Stack for viewports
158  void *_stagestack; //stack for stage ID
159  void *_framebufferstack; //stack for backbuffers, usually GL_BACK, or can be FBO
160  int screenOrientation2;
161  int pickray_x;
162  int pickray_y;
163  float fieldOfView; //set in setup_projection, used in volumeRendering
164  } Mainloop;
165  struct tProdCon{
166  struct Vector *viewpointNodes;// = NULL;
167  int currboundvpno;//=0;
168  /* bind nodes in display loop, NOT in parsing threadthread */
169  struct X3D_Node *setViewpointBindInRender;// = NULL;
170  struct X3D_Node *setFogBindInRender;// = NULL;
171  struct X3D_Node *setBackgroundBindInRender;// = NULL;
172  struct X3D_Node *setNavigationBindInRender;// = NULL;
173  void *savedParser; //struct VRMLParser* savedParser;
174  void *prv;
175  } ProdCon;
176  #if defined (INCLUDE_NON_WEB3D_FORMATS)
177  struct tColladaParser{
178  void *prv;
179  }ColladaParser;
180  #endif //INCLUDE_NON_WEB3D_FORMATS
181 
182  #if defined (INCLUDE_STL_FILES)
183  struct tSTLHandler {
184  void *prv;
185  }STLHandler;
186  #endif // INCLUDE_STL_FILES
187 
188 
189  struct tFrustum{
190  int OccFailed;//. = FALSE;
191  void *prv;
192  } Frustum;
194  /* is the texture thread up and running yet? */
195  //int TextureThreadInitialized;// = FALSE;
196  void *prv;
197  }LoadTextures;
199  /* is this 24 bit depth? 16? 8?? Assume 24, unless set on opening */
200  int displayDepth;// = 24;
201  //static float cc_red = 0.0f, cc_green = 0.0f, cc_blue = 0.0f, cc_alpha = 1.0f;
202  int cc_changed;// = FALSE;
203  void *prv;
204  }OpenGL_Utils;
205 
206 #ifdef HAVE_OPENCL
207  struct tOpenCL_Utils{
208  bool OpenCL_Initialized; // = FALSE;
209  bool OpenCL_OK; // = FALSE
210  void *prv;
211  }OpenCL_Utils;
212 #endif //HAVE_OPENCL
213 
214 #ifdef STATUSBAR_STD
215  struct tRasterFont{
216  void *prv;
217  }RasterFont;
218 #endif
220  //struct multiTexParams textureParameterStack[MAX_MULTITEXTURE];
221  void *textureParameterStack;
222  void *prv;
223  }RenderTextures;
224  struct tTextures{
225  /* for texture remapping in TextureCoordinate nodes */
226  //GLuint *global_tcin;
227  unsigned int *global_tcin;
228  int global_tcin_count;
229  void *global_tcin_lastParent;
230  //GLuint defaultBlankTexture;
231  unsigned int defaultBlankTexture;
232  void *prv;
233  }Textures;
235  void *prv;
236  }PluginSocket;
237  struct tpluginUtils{
238  void *prv;
239  }pluginUtils;
240  struct tcollision{
241  void *prv;
242  }collision;
244  void *prv;
245  }Component_CubeMapTexturing;
247  void *prv;
248  }Component_EnvironSensor;
250  void *prv;
251  }Component_Geometry3D;
253  void *prv;
254  }Component_Geospatial;
256  void *prv;
257  }Component_HAnim;
259  void *prv;
260  }Component_Layering;
262  void *prv;
263  }Component_Layout;
265  void *prv;
266  }Component_NURBS;
268  void *prv;
269  }Component_ParticleSystems;
271  void *prv;
272  }Component_ProgrammableShaders;
274  void *prv;
275  }Component_RigidBodyPhysics;
277  void *prv;
278  }Component_Followers;
280  void *prv;
281  }Component_KeyDevice;
282 
283 #ifdef OLDCODE
284 iOLDCODE struct tComponent_Networking{
285 iOLDCODE void *ReWireNamenames;
286 iOLDCODE int ReWireNametableSize;
287 iOLDCODE void *ReWireDevices;
288 iOLDCODE int ReWireDevicetableSize;
289 iOLDCODE void *prv;
290 iOLDCODE }Component_Networking;
291 #endif // OLDCODE
292 
294  void *prv;
295  }Component_Picking;
297  void *prv;
298  }Component_Rendering;
300  void *prv;
301  }Component_Shape;
303  int sound_from_audioclip;// = 0;
304  /* is the sound engine started yet? */
305  int SoundEngineStarted;// = FALSE;
306  void *prv;
307  }Component_Sound;
309  void *prv;
310  }Component_Text;
312  void *prv;
313  }Component_VRML1;
315  void *prv;
316  }Component_VolumeRendering;
317  struct tRenderFuncs{
318  #ifdef OLDCODE
319  OLDCODE char *OSX_last_world_url_for_reload;
320  OLDCODE char *OSX_replace_world_from_console;
321  #endif //OLDCODE
322 
323  /* Any action for the Browser to do? */
324  int BrowserAction;// = FALSE;
325  double hitPointDist; /* distance in ray: 0 = r1, 1 = r2, 2 = 2*r2-r1... */
326  /* used to save rayhit and hyperhit for later use by C functions */
327  //struct SFColor hyp_save_posn, hyp_save_norm, ray_save_posn;
328  float hyp_save_posn[3];
329  float hyp_save_norm[3];
330  float ray_save_posn[3]; //getRayHit() > last intersection of pickray/bearing with geometry, transformed into the coordinates of the geometry
331  void *hypersensitive;//= 0;
332  int hyperhit;// = 0;
333  //struct point_XYZ hp;
334  void *hp;
335  void *rayHit;
336  //void *rayHitHyper;
337  //struct point_XYZ t_r1,t_r2,t_r3; /* transformed ray */
338  //void *t_r123; /* transformed ray */
339  int lightingOn; /* do we need to restore lighting in Shape? */
340  int have_transparency;//=FALSE;/* did any Shape have transparent material? */
341  /* material node usage depends on texture depth; if rgb (depth1) we blend color field
342  and diffusecolor with texture, else, we dont bother with material colors */
343  int last_texture_type;// = NOTEXTURE;
344  /* texture stuff - see code. Need array because of MultiTextures */
345  //GLuint boundTextureStack[10];//MAX_MULTITEXTURE];
346  unsigned int boundTextureStack[10];//MAX_MULTITEXTURE];
347  int textureStackTop;
348  void *texturenode;
349  void *shapenode;
350  void *prv;
351  }RenderFuncs;
352  struct tStreamPoly{
353  void *prv;
354  }StreamPoly;
355  struct tTess{
356  int *global_IFS_Coords;
357  int global_IFS_Coord_count;//=0;
358  //GLUtriangulatorObj *global_tessobj;
359  void *global_tessobj;
360  void *prv;
361  }Tess;
362  struct tViewer{
363  int stereotype;
364  void *prv;
365  }Viewer;
366  struct tstatusbar{
367  void *prv;
368  }statusbar;
369  struct tCParse{
370  void* globalParser;
371  void *prv;
372  }CParse;
374  void *prv;
375  }CParseParser;
376  struct tCRoutes{
377  /* EAI needs the extra parameter, so we put it globally when a RegisteredListener is clicked. */
378  void *CRoutesExtra;// = 0;
379  //jsval JSglobal_return_val;
380  void *JSSFpointer;
381  int max_script_found;// = -1; /* the maximum script number found */
382  int max_script_found_and_initialized;// = -1; /* the maximum script number found */
383  int jsnameindex; //= -1;
384  int MAXJSparamNames;// = 0;
385 
386  void *prv;
387  }CRoutes;
388  struct tCScripts{
389  void *prv;
390  }CScripts;
391  struct tJScript{
392  void * JSglobal_return_val;
393  void *prv;
394  }JScript;
395  struct tjsUtils{
396  void *prv;
397  }jsUtils;
399  /* for setting field values to the output of a CreateVrml style of call */
400  /* it is kept at zero, unless it has been used. Then it is reset to zero */
401  void * JSCreate_global_return_val;
402  void *prv;
403  }jsVRMLBrowser;
405  void *prv;
406  }jsVRMLClasses;
407  struct tBindable{
408  //struct sNaviInfo naviinfo;
409  // struct Vector *background_stack;
410  // struct Vector *viewpoint_stack;
411  // struct Vector *navigation_stack;
412  // struct Vector *fog_stack;
413  void *naviinfo;
414  //void *background_stack;
415  //void *viewpoint_stack;
416  //void *navigation_stack;
417  //void *fog_stack;
418  int activeLayer;
419  void *bstacks;
420  void *prv;
421  }Bindable;
422  struct tX3DParser{
423  int parentIndex;// = -1;
424  //struct X3D_Node *parentStack[PARENTSTACKSIZE];
425  char *CDATA_Text;// = NULL;
426  int CDATA_Text_curlen;// = 0;
427  void *prv;
428  }X3DParser;
429  struct tcommon{
430  void *prv;
431  }common;
432  struct tCursorDraw{
433  void *prv;
434  }CursorDraw;
435 #ifdef DISABLER
436 #if defined(WRAP_MALLOC) || defined(DEBUG_MALLOC)
437  pthread_mutex_t __memTableGlobalLock;
438  bool __memTable_CheckInit;
439  bool __memTable_ShouldRegisterAllocation;
440  dbl_list_t *__memTable;
441 #endif
442 #endif
443 } * ttglobal;
444 #define INSTANCEGLOBAL 1
445 #endif
446 ttglobal iglobal_constructor();
447 void iglobal_destructor(ttglobal);
448 //void set_thread2global(ttglobal fwl, pthread_t any , char *desc);
449 void resetGGlobal();
450 ttglobal gglobal(); //gets based on threadID, errors out if no threadID
451 //ppcommon gglobal_common(); // lets the front end get the myMenuStatus without hassle. dug9 Mar2014: poll for the values with get_status, get_... in common.c
452 ttglobal gglobal0(); //will return null if thread not yet initialized
453 //ttglobal gglobalH(void *handle); //use window handle
454 //ttglobal gglobalH0(void *handle); //test if window handle is in the table yet
Definition: Vector.h:36