31 #include <system_threads.h>
35 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../vrml_parser/CRoutes.h"
39 #include "../main/headers.h"
40 #include "../vrml_parser/CParseGeneral.h"
41 #include "../main/Snapshot.h"
42 #include "../scenegraph/Collision.h"
43 #include "../scenegraph/quaternion.h"
44 #include "../scenegraph/Viewer.h"
45 #include "../input/EAIHeaders.h"
46 #include "../input/EAIHelpers.h"
47 #include "../input/SensInterps.h"
48 #include "../x3d_parser/Bindable.h"
64 void getField_ToJavascript (
int num,
int fromoffset) {
70 #ifdef SETFIELDVERBOSE
71 printf (
"getField_ToJavascript, from offset %d name %s type %d num=%d\n",
72 fromoffset,JSparamnames[fromoffset].name,JSparamnames[fromoffset].type,num);
77 switch (JSparamnames[fromoffset].type) {
78 case FIELDTYPE_SFBool:
79 case FIELDTYPE_SFFloat:
80 case FIELDTYPE_SFTime:
81 case FIELDTYPE_SFDouble:
82 case FIELDTYPE_SFInt32:
83 case FIELDTYPE_SFString:
84 setScriptECMAtype(num);
86 case FIELDTYPE_SFColor:
87 case FIELDTYPE_SFColorRGBA:
88 case FIELDTYPE_SFNode:
89 case FIELDTYPE_SFVec2f:
90 case FIELDTYPE_SFVec3f:
91 case FIELDTYPE_SFVec4f:
92 case FIELDTYPE_SFVec2d:
93 case FIELDTYPE_SFVec3d:
94 case FIELDTYPE_SFVec4d:
95 case FIELDTYPE_SFRotation:
96 setScriptMultiElementtype(num);
98 case FIELDTYPE_MFColor:
99 case FIELDTYPE_MFColorRGBA:
100 case FIELDTYPE_MFVec2f:
101 case FIELDTYPE_MFVec3f:
102 case FIELDTYPE_MFVec4f:
103 case FIELDTYPE_MFVec2d:
104 case FIELDTYPE_MFVec3d:
105 case FIELDTYPE_MFVec4d:
106 case FIELDTYPE_MFFloat:
107 case FIELDTYPE_MFTime:
108 case FIELDTYPE_MFInt32:
109 case FIELDTYPE_MFString:
110 case FIELDTYPE_MFNode:
111 case FIELDTYPE_MFRotation:
112 case FIELDTYPE_SFImage:
113 ignored = setMFElementtype(num);
116 printf(
"WARNING: sendScriptEventIn type %s not handled yet\n",
117 FIELDTYPES[JSparamnames[fromoffset].type]);
123 void getField_ToJavascript_B(
int shader_num,
int fieldOffset,
int type,
union anyVrml *any,
int len) {
125 #ifdef SETFIELDVERBOSE
128 printf (
"getField_ToJavascript, from offset %d type %d num=%d\n",
129 fieldOffset,JSparamnames[fieldOffset].type,shader_num);
136 case FIELDTYPE_SFBool:
137 case FIELDTYPE_SFFloat:
138 case FIELDTYPE_SFTime:
139 case FIELDTYPE_SFDouble:
140 case FIELDTYPE_SFInt32:
141 case FIELDTYPE_SFString:
143 set_one_ECMAtype(shader_num, fieldOffset, type, any, len);
145 case FIELDTYPE_SFColor:
146 case FIELDTYPE_SFColorRGBA:
147 case FIELDTYPE_SFNode:
148 case FIELDTYPE_SFVec2f:
149 case FIELDTYPE_SFVec3f:
150 case FIELDTYPE_SFVec4f:
151 case FIELDTYPE_SFVec2d:
152 case FIELDTYPE_SFVec3d:
153 case FIELDTYPE_SFVec4d:
154 case FIELDTYPE_SFRotation:
155 set_one_MultiElementType(shader_num, fieldOffset, any, len);
157 case FIELDTYPE_MFColor:
158 case FIELDTYPE_MFColorRGBA:
159 case FIELDTYPE_MFVec2f:
160 case FIELDTYPE_MFVec3f:
161 case FIELDTYPE_MFVec4f:
162 case FIELDTYPE_MFVec2d:
163 case FIELDTYPE_MFVec3d:
164 case FIELDTYPE_MFVec4d:
165 case FIELDTYPE_MFFloat:
166 case FIELDTYPE_MFTime:
167 case FIELDTYPE_MFInt32:
168 case FIELDTYPE_MFString:
169 case FIELDTYPE_MFNode:
170 case FIELDTYPE_MFRotation:
171 case FIELDTYPE_SFImage:
173 set_one_MFElementType(shader_num, fieldOffset, type, (
void *)any,len);
177 printf(
"WARNING: sendScriptEventIn type %s not handled yet\n",
200 int setMFElementtype (
int num) {
208 struct CRStruct *CRoutes = getCRoutes();
212 #ifdef SETFIELDVERBOSE
213 printf(
"------------BEGIN setMFElementtype ---------------\n");
217 fn = (
void *)CRoutes[num].routeFromNode;
218 fptr = CRoutes[num].fnptr;
222 pptr = offsetPointer_deref (
char *, fn, fptr);
224 len = CRoutes[num].len;
233 pptr = (
char *) mfp->p;
234 #ifdef SETFIELDVERBOSE
235 printf (
"setMFElementtype, len now %d, from %d\n",len,fn);
243 for (to_counter = 0; to_counter < CRoutes[num].tonode_count; to_counter++) {
246 to_ptr = &(CRoutes[num].tonodes[to_counter]);
247 myObj = X3D_SCRIPT(to_ptr->routeToNode)->__scriptObj;
249 #ifdef SETFIELDVERBOSE
250 printf (
"got a script event! index %d type %d\n",
251 num, CRoutes[num].direction_flag);
256 printf (
"\tdata length %d\n",len);
257 printf (
"and, sending it to %s as type %d\n",JSparamnames[to_ptr->foffset].name,
258 JSparamnames[to_ptr->foffset].type);
261 set_one_MFElementType(myObj->num, to_ptr->foffset, JSparamnames[to_ptr->foffset].type, (
void *)pptr,len);
265 #ifdef SETFIELDVERBOSE
266 printf(
"------------END setMFElementtype ---------------\n");
280 void setScriptMultiElementtype (
int num)
288 struct CRStruct *CRoutes = getCRoutes();
291 fn = (
void *)CRoutes[num].routeFromNode;
292 fptr = CRoutes[num].fnptr;
293 if (CRoutes[num].len == ROUTING_SFNODE) len = returnElementLength(FIELDTYPE_SFNode);
294 else if (CRoutes[num].len < 0) {
295 ConsoleMessage (
"setScriptMultiElementtype - len of %d unhandled\n",CRoutes[num].len);
298 len = CRoutes[num].len;
301 for (to_counter = 0; to_counter < CRoutes[num].tonode_count; to_counter++) {
304 to_ptr = &(CRoutes[num].tonodes[to_counter]);
305 myObj = X3D_SCRIPT(to_ptr->routeToNode)->__scriptObj;
308 tptr = to_ptr->foffset;
310 #ifdef SETFIELDVERBOSE
311 printf (
"got a script event! index %d type %d\n",
312 num, CRoutes[num].direction_flag);
313 printf (
"\tfrom %#x from ptr %#x\n\tto %#x toptr %#x\n",fn,fptr,myObj->num,tptr);
314 printf (
"\tdata length %d\n",len);
315 printf (
"setScriptMultiElementtype here script number %d tptr %d len %d\n",myObj->num, tptr,len);
318 fn = offsetPointer_deref(
void*,fn,fptr);
320 set_one_MultiElementType (myObj->num, tptr, fn, len);
330 void EAI_Convert_mem_to_ASCII (
int id,
char *reptype,
int type,
char *memptr,
char *buf) {
332 char utilBuf[EAIREADSIZE];
334 memset(utilBuf,
'\0',
sizeof(utilBuf));
336 errcount = UtilEAI_Convert_mem_to_ASCII (type,memptr, utilBuf);
338 sprintf (buf,
"%s\n%f\n%d\n%s",reptype,TickTime(),
id, utilBuf);
340 sprintf (buf,
"%s\n%f\n%d\n%s",reptype,TickTime(),
id,
"indeterminate....");
346 int UtilEAI_Convert_mem_to_ASCII (
int type,
char *memptr,
char *buf) {
369 eaiverbose = gglobal()->EAI_C_CommonFunctions.eaiverbose;
370 intptr = (
int *) memptr;
376 case FIELDTYPE_SFBool: {
378 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFBOOL - value %d; TRUE %d false %d\n",*intptr,TRUE,FALSE);
381 if (*intptr == 1) sprintf (buf,
"TRUE");
382 else sprintf (buf,
"FALSE");
386 case FIELDTYPE_SFDouble:
387 case FIELDTYPE_SFTime: {
389 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFTIME\n");
391 memcpy(&dval,memptr,
sizeof(
double));
392 sprintf (buf,
"%lf",dval);
396 case FIELDTYPE_SFInt32: {
398 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFINT32\n");
400 memcpy(&ival,memptr,
sizeof(
int));
401 sprintf (buf,
"%d",ival);
405 case FIELDTYPE_SFNode: {
407 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFNODE\n");
409 memcpy((
void *)&uval,(
void *)memptr,
sizeof(
void *));
410 sprintf (buf,
"%u",registerEAINodeForAccess(X3D_NODE(uval)));
414 case FIELDTYPE_SFFloat: {
416 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFFLOAT\n");
419 memcpy(fl,memptr,
sizeof(
float));
420 sprintf (buf,
"%f",fl[0]);
424 case FIELDTYPE_SFVec3f:
425 case FIELDTYPE_SFColor: {
427 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFCOLOR or EAI_SFVEC3F\n");
429 memcpy(fl,memptr,
sizeof(
float)*3);
430 sprintf (buf,
"%f %f %f",fl[0],fl[1],fl[2]);
434 case FIELDTYPE_SFVec3d: {
436 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFVEC3D\n");
438 memcpy(dl,memptr,
sizeof(
double)*3);
439 sprintf (buf,
"%lf %lf %lf",dl[0],dl[1],dl[2]);
443 case FIELDTYPE_SFVec2f: {
445 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFVEC2F\n");
447 memcpy(fl,memptr,
sizeof(
float)*2);
448 sprintf (buf,
"%f %f",fl[0],fl[1]);
452 case FIELDTYPE_SFColorRGBA:
453 case FIELDTYPE_SFRotation: {
455 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFROTATION\n");
458 memcpy(fl,memptr,
sizeof(
float)*4);
459 sprintf (buf,
"%f %f %f %f",fl[0],fl[1],fl[2],fl[3]);
463 case FIELDTYPE_SFImage:
464 case FIELDTYPE_SFString: {
468 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFSTRING\n");
473 xx= (uintptr_t *) memptr;
476 retSFString = (
char *)svptr->strptr;
477 sprintf (buf,
"\"%s\"",retSFString);
481 case FIELDTYPE_MFString: {
483 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFSTRING\n");
490 ptr = buf + strlen(buf);
492 for (row=0; row<(*MSptr).n; row++) {
494 if (strlen ((*MSptr).p[row]->strptr) == 0) {
495 sprintf (ptr,
"\"\" ");
497 sprintf (ptr,
"\"%s\" ",(*MSptr).p[row]->strptr);
500 ptr = buf + strlen (buf);
506 case FIELDTYPE_MFNode: {
510 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFNode, there are %d nodes at %p\n",(*MNptr).n,memptr);
513 ptr = buf + strlen(buf);
515 for (row=0; row<(*MNptr).n; row++) {
516 sprintf (ptr,
"%d ",registerEAINodeForAccess(X3D_NODE((*MNptr).p[row])));
517 ptr = buf + strlen (buf);
522 case FIELDTYPE_MFInt32: {
525 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFColor, there are %d nodes at %p\n",(*MCptr).n,memptr);
528 sprintf (buf,
"%d \n",(*MCptr).n);
529 ptr = buf + strlen(buf);
531 ip = (
int *) (*MCptr).p;
532 for (row=0; row<(*MCptr).n; row++) {
533 sprintf (ptr,
"%d \n",*ip);
536 ptr = buf + strlen (buf);
542 case FIELDTYPE_MFFloat:
543 case FIELDTYPE_MFVec2f:
544 case FIELDTYPE_MFVec3f:
545 case FIELDTYPE_MFRotation:
546 case FIELDTYPE_MFColorRGBA:
547 case FIELDTYPE_MFColor: {
549 if (type==FIELDTYPE_MFFloat) {numPerRow=1;}
550 else if (type==FIELDTYPE_MFVec2f) {numPerRow=2;}
551 else if (type==FIELDTYPE_MFRotation) {numPerRow=4;}
552 else if (type==FIELDTYPE_MFColorRGBA) {numPerRow=4;}
556 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFColor, there are %d nodes at %p\n",(*MCptr).n,memptr);
559 sprintf (buf,
"%d \n",(*MCptr).n);
560 ptr = buf + strlen(buf);
563 fp = (
float *) (*MCptr).p;
564 for (row=0; row<(*MCptr).n; row++) {
565 for (i=0; i<numPerRow; i++) {
570 sprintf (ptr,
"%f \n",fl[0]);
break;
572 sprintf (ptr,
"%f %f \n",fl[0],fl[1]);
break;
574 sprintf (ptr,
"%f %f %f \n",fl[0],fl[1],fl[2]);
break;
576 sprintf (ptr,
"%f %f %f %f \n",fl[0],fl[1],fl[2],fl[3]);
break;
579 ptr = buf + strlen (buf);
586 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI, type %d (%s) not handled yet\n",type,stringFieldtypeType (type));