32 #include <libFreeWRL.h>
34 #include <resources.h>
38 #include "vrml_parser/Structs.h"
39 #include "main/headers.h"
40 #include "vrml_parser/CParseGeneral.h"
41 #include "scenegraph/Vector.h"
42 #include "vrml_parser/CFieldDecls.h"
43 #include "world_script/JScript.h"
44 #include "world_script/CScripts.h"
45 #include "world_script/fieldSet.h"
46 #include "vrml_parser/CParseParser.h"
47 #include "vrml_parser/CParseLexer.h"
48 #include "vrml_parser/CParse.h"
49 #include "input/InputFunctions.h"
50 #include "input/EAIHeaders.h"
51 #include "input/EAIHelpers.h"
53 #include "x3d_parser/X3DParser.h"
121 #ifndef __LIBFREEWRL_DECL_H__
122 #define __LIBFREEWRL_DECL_H__
125 #ifdef FREEWRL_THREAD_COLORIZED
128 #define PRINTF printf_with_colored_threads
129 extern int printf_with_colored_threads(
const char *format, ...);
130 #define FPRINTF fprintf_with_colored_threads
131 extern int fprintf_with_colored_threads(FILE *stream,
const char *format, ...);
135 #define PRINTF printf
136 #define FPRINTF fprintf
140 #define BOOL_STR(b) (b ? "TRUE" : "FALSE")
143 #if defined(FW_DEBUG)
144 # define DEBUG_(_expr) _expr
146 # define DEBUG_(_expr)
151 void fw_perror(FILE *f,
const char *format, ...);
153 #if defined(WRAP_MALLOC) || defined(DEBUG_MALLOC)
154 void freewrlFreeAllRegisteredAllocations();
155 bool freewrlIsRegisteringAllocation();
156 void freewrlSetShouldRegisterAllocation(
bool shouldRegisterAllocation);
157 void freewrlInitMemTable();
158 void freewrlDisposeMemTable();
163 #if defined(_MSC_VER)
168 int DEBUG_FPRINTF(
const char *fmt, ...);
169 #define DEBUG_MSG DEBUG_FPRINTF
170 #define TRACE_MSG DEBUG_FPRINTF
171 #define WARN_MSG DEBUG_FPRINTF
172 #define ERROR_MSG DEBUG_FPRINTF
173 #define PERROR_MSG DEBUG_FPRINTF
174 #define DEBUG_MEM DEBUG_FPRINTF
175 #define DEBUG_RENDER DEBUG_FPRINTF
176 #define DEBUG_TEX DEBUG_FPRINTF
177 #define DEBUG_X3DPARSER DEBUG_FPRINTF
178 #define DEBUG_SHADER DEBUG_FPRINTF
179 #define DEBUG_RES DEBUG_FPRINTF
180 #define DEBUG_CPARSER DEBUG_FPRINTF
200 #if !defined(MSVC_7) // _MSC_VER >= 1500
201 #define DEBUG_MSG(...) DEBUG_(FPRINTF(stdout, __VA_ARGS__))
202 #define TRACE_MSG(...) DEBUG_(FPRINTF(stdout, __VA_ARGS__))
203 #define WARN_MSG(...) DEBUG_(FPRINTF(stdout, __VA_ARGS__))
205 #define ERROR_MSG(...) FPRINTF(stderr, __VA_ARGS__)
206 #define PERROR_MSG(...) fw_perror(stderr, __VA_ARGS__)
208 #define DEBUG_FW(...) DEBUG_(PRINTF("FW: " __VA_ARGS__))
210 #define DEBUG_FW(...)
213 #define DEBUG_RES(...) DEBUG_(PRINTF("RES: " __VA_ARGS__))
215 #define DEBUG_RES(...)
219 #define DEBUG_TEX(...) DEBUG_(PRINTF("TEXTURE: " __VA_ARGS__))
221 #define DEBUG_TEX(...)
225 #define DEBUG_MEM(...) DEBUG_(PRINTF("MEM: " __VA_ARGS__))
227 #define DEBUG_MEM(...)
230 #ifdef CPARSERVERBOSE
231 #define DEBUG_CPARSER(...) DEBUG_(PRINTF("CPARSER: " __VA_ARGS__))
233 #define DEBUG_CPARSER(...)
237 #define DEBUG_CPROTO(...) DEBUG_(PRINTF("CPROTO: " __VA_ARGS__))
239 #define DEBUG_CPROTO(...)
242 #ifdef PLUGINSOCKETVERBOSE
243 #define DEBUG_PLUGINSOCKET(...) DEBUG_(PRINTF("PLUGINSOCKET: " __VA_ARGS__))
245 #define DEBUG_PLUGINSOCKET(...)
250 #define DEBUG_CR(...) DEBUG_(PRINTF("CR: " __VA_ARGS__))
252 #define DEBUG_CR(...)
256 #ifdef JSVRMLCLASSESVERBOSE
257 #define DEBUG_JSVRMLCLASSES(...) DEBUG_(PRINTF("JSVRMLCLASSES: " __VA_ARGS__))
259 #define DEBUG_JSVRMLCLASSES(...)
262 #ifdef JAVASCRIPTVERBOSE
263 #define DEBUG_JS(...) DEBUG_(PRINTF("JS: " __VA_ARGS__))
265 #define DEBUG_JS(...)
268 #ifdef SETFIELDVERBOSE
269 #define DEBUG_SETFIELD(...) DEBUG_(PRINTF("SETFIELD: " __VA_ARGS__))
271 #define DEBUG_SETFIELD(...)
275 #define DEBUG_RENDER(...) DEBUG_(PRINTF("RENDER: " __VA_ARGS__))
277 #define DEBUG_RENDER(...)
281 #define DEBUG_CHILD(...) DEBUG_(PRINTF("CHILD: " __VA_ARGS__))
283 #define DEBUG_CHILD(...)
288 #define DEBUG_SE(...) DEBUG_(PRINTF("SE: " __VA_ARGS__))
290 #define DEBUG_SE(...)
293 #ifdef STREAM_POLY_VERBOSE
294 #define DEBUG_STREAM_POLY(...) DEBUG_(PRINTF("STREAM_POLY: " __VA_ARGS__))
296 #define DEBUG_STREAM_POLY(...)
299 #ifdef OCCLUSIONVERBOSE
300 #define DEBUG_OCCLUSION(...) DEBUG_(PRINTF("OCCLUSION: " __VA_ARGS__))
302 #define DEBUG_OCCLUSION(...)
305 #ifdef FRUSTUMVERBOSE
306 #define DEBUG_FRUSTUM(...) DEBUG_(PRINTF("FRUSTUM: " __VA_ARGS__))
308 #define DEBUG_FRUSTUM(...)
312 #define DEBUG_SHADER(...) DEBUG_(PRINTF("SHADER: " __VA_ARGS__))
314 #define DEBUG_SHADER(...)
318 #define DEBUG_BIND(...) DEBUG_(PRINTF("BIND: " __VA_ARGS__))
320 #define DEBUG_BIND(...)
324 #ifdef X3DPARSERVERBOSE
325 #define DEBUG_X3DPARSER(...) DEBUG_(PRINTF("X3DPARSER: " __VA_ARGS__))
327 #define DEBUG_X3DPARSER(...)
331 #ifdef CAPABILITIESVERBOSE
332 #define DEBUG_CAPABILITIES(...) DEBUG_(PRINTF("CAPABILITIES: " __VA_ARGS__))
334 #define DEBUG_CAPABILITIES(...)
339 #define DEBUG_SENS(...) DEBUG_(PRINTF("SENS: " __VA_ARGS__))
341 #define DEBUG_SENS(...)
345 #define DEBUG_SOUND(...) DEBUG_(PRINTF("SOUND: " __VA_ARGS__))
347 #define DEBUG_SOUND(...)
351 #define DEBUG_FILL(...) DEBUG_(PRINTF("FILL: " __VA_ARGS__))
353 #define DEBUG_FILL(...)
357 #define DEBUG_TEXT(...) DEBUG_(PRINTF("TEXT: " __VA_ARGS__))
359 #define DEBUG_TEXT(...)
363 #define DEBUG_ARGS(...) DEBUG_(PRINTF("TEXT: " __VA_ARGS__))
365 #define DEBUG_ARGS(...)
368 #ifdef XEVENT_VERBOSE
369 #define DEBUG_XEV(...) DEBUG_(PRINTF("XEV: " __VA_ARGS__))
371 #define DEBUG_XEV(...)
375 void *mallocn_debug(
int line,
char *file,
void *node,
size_t size);
376 void *reallocn_debug(
int line,
char *file,
void *node,
void *pold,
size_t newsize);
377 void *mallocn(
void *node,
size_t size);
378 void *reallocn(
void *node,
void *pold,
size_t newsize);
383 #if defined(WRAP_MALLOC) || defined(DEBUG_MALLOC)
385 void *freewrlMalloc(
int line,
char *file,
size_t sz,
int zeroData);
386 void *freewrlRealloc(
int line,
char *file,
void *ptr,
size_t size);
387 void freewrlFree(
int line,
char *file,
void *a);
388 void *freewrlStrdup(
int line,
char *file,
char *str);
389 void *freewrlStrndup(
int line,
char *file,
const char *str,
size_t n);
390 #define MALLOCN(_node,_sz) (mallocn_debug(__LINE__,__FILE__,_node,_sz))
391 #define REALLOCN(_node,_oldp,_newsz) (reallocn_debug(__LINE__,__FILE__,_node,_oldp,_newsz))
392 # define MALLOCV(_sz) (freewrlMalloc(__LINE__, __FILE__, _sz, FALSE))
393 # define MALLOC(t,_sz) ((t)freewrlMalloc(__LINE__, __FILE__, _sz, FALSE))
394 # define CALLOC(_fill, _sz) freewrlMalloc(__LINE__, __FILE__, _fill * _sz, TRUE);
395 # define REALLOC(_a,_b) freewrlRealloc(__LINE__, __FILE__, _a, _b)
396 # define FREE(_ptr) freewrlFree(__LINE__, __FILE__, _ptr)
398 # define XALLOC(_type) (_type *) CALLOC(1, sizeof(_type))
399 # define XFREE(_ptr) {if (_ptr) { FREE(_ptr); _ptr = NULL; }}
401 # define STRDUP(_a) freewrlStrdup(__LINE__, __FILE__, _a)
403 # define STRNDUP(_a, _n) freewrlStrndup(__LINE__, __FILE__, _a, _n)
405 # define UNLINK(_fdd) do { \
406 TRACE_MSG("TRACE: unlink %s at %s:%d\n",_fdd,__FILE__,__LINE__); \
410 # define TEMPNAM(_dir,_pfx) tempnam(_dir, _pfx); do { \
411 TRACE_MSG("TRACE: tempnam %s/%s at %s:%d\n", _dir, _pfx, __FILE__, __LINE__); \
414 # define ASSERT(_ptr) do { if (!(_ptr)) { \
415 ERROR_MSG("ERROR: assert failed: %s (%s:%d)\n", #_ptr, __FILE__, __LINE__); } \
418 # define UNLINK unlink
419 # define TEMPNAM tempnam
422 # define ASSERT(_ptr) do { if (!(_ptr)) { \
423 ERROR_MSG("ERROR: assert failed: %s (%s:%d)\n", #_ptr, __FILE__, __LINE__); } \
429 #if defined(_MSC_VER)
430 # define TEMPNAM _tempnam
432 # define TEMPNAM tempnam
438 #define MALLOCN(_node,_sz) (mallocn(_node,_sz))
439 #define REALLOCN(_node,_oldp,_newsz) (reallocn(_node,_oldp,_newsz))
441 # define MALLOCV(_sz) (malloc(_sz))
442 # define MALLOC(t,_sz) ((_sz > 0) ? (t)malloc(_sz) : NULL)
443 # define REALLOC realloc
446 # define XALLOC(_type) (_type *) calloc(1, sizeof(_type))
447 # define XFREE(_ptr) {if (_ptr) { free(_ptr); _ptr = NULL; }}
449 # define STRDUP strdup
450 # define STRNDUP strndup
451 # define UNLINK unlink
452 # define TEMPNAM tempnam
454 # define ASSERT(_whatever)
460 #define FREE_IF_NZ(_ptr) {if (_ptr) { \
464 DEBUG_MEM("double free: %s:%d\n", __FILE__, __LINE__); \
471 #define PTR_REPLACE(_ptr,_newptr) do { \
472 if (_ptr != _newptr) { \
474 DEBUG_MSG("replacing ptr %p with %p\n", _ptr, _newptr); \
478 DEBUG_MSG("ptr newly assigned value %p\n", _newptr); \
482 DEBUG_MSG("replacing ptr with the same value (warning)\n"); \
485 #define PTR_REPLACE_DUP(_ptr,_newptr) do { \
486 if (_ptr != _newptr) { \
488 DEBUG_MSG("replacing ptr %p with %p\n", _ptr, _newptr); \
490 _ptr = STRDUP(_newptr); \
492 DEBUG_MSG("ptr newly assigned value %p\n", _newptr); \
493 _ptr = STRDUP(_newptr); \
496 DEBUG_MSG("replacing ptr with the same value (warning)\n"); \
500 void register_node_gc(
void *node,
void *p);
501 void unregister_node_gc(
void *node,
void *p);
502 void free_registered_node_gc(
void *node);
506 #if defined(_MSC_VER)
510 #define HAVE_BOOLEAN 1
516 #define HAVE_BOOLEAN 1
520 #define M_PI 3.14159265358979323846 //acos(-1.0)