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"
64void 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 case FIELDTYPE_SFImage:
97 case FIELDTYPE_SFMatrix3f:
98 case FIELDTYPE_SFMatrix4f:
99 case FIELDTYPE_SFMatrix3d:
100 case FIELDTYPE_SFMatrix4d:
101 setScriptMultiElementtype(num);
103 case FIELDTYPE_MFFloat:
104 case FIELDTYPE_MFBool:
105 case FIELDTYPE_MFInt32:
106 case FIELDTYPE_MFTime:
107 case FIELDTYPE_MFDouble:
108 case FIELDTYPE_MFColor:
109 case FIELDTYPE_MFColorRGBA:
110 case FIELDTYPE_MFVec2f:
111 case FIELDTYPE_MFVec3f:
112 case FIELDTYPE_MFVec4f:
113 case FIELDTYPE_MFVec2d:
114 case FIELDTYPE_MFVec3d:
115 case FIELDTYPE_MFVec4d:
116 case FIELDTYPE_MFString:
117 case FIELDTYPE_MFNode:
118 case FIELDTYPE_MFRotation:
119 case FIELDTYPE_MFImage:
120 case FIELDTYPE_MFMatrix3f:
121 case FIELDTYPE_MFMatrix4f:
122 case FIELDTYPE_MFMatrix3d:
123 case FIELDTYPE_MFMatrix4d:
124 ignored = setMFElementtype(num);
127 printf(
"WARNING: sendScriptEventIn type %s not handled yet\n",
128 FIELDTYPES[JSparamnames[fromoffset].type]);
134void getField_ToJavascript_B(
int shader_num,
int fieldOffset,
int type,
union anyVrml *any,
int len) {
136 #ifdef SETFIELDVERBOSE
139 printf (
"getField_ToJavascript, from offset %d type %d num=%d\n",
140 fieldOffset,JSparamnames[fieldOffset].type,shader_num);
147 case FIELDTYPE_SFBool:
148 case FIELDTYPE_SFFloat:
149 case FIELDTYPE_SFTime:
150 case FIELDTYPE_SFDouble:
151 case FIELDTYPE_SFInt32:
152 case FIELDTYPE_SFString:
154 set_one_ECMAtype(shader_num, fieldOffset, type, any, len);
156 case FIELDTYPE_SFColor:
157 case FIELDTYPE_SFColorRGBA:
158 case FIELDTYPE_SFNode:
159 case FIELDTYPE_SFVec2f:
160 case FIELDTYPE_SFVec3f:
161 case FIELDTYPE_SFVec4f:
162 case FIELDTYPE_SFVec2d:
163 case FIELDTYPE_SFVec3d:
164 case FIELDTYPE_SFVec4d:
165 case FIELDTYPE_SFMatrix3f:
166 case FIELDTYPE_SFMatrix4f:
167 case FIELDTYPE_SFMatrix3d:
168 case FIELDTYPE_SFMatrix4d:
169 case FIELDTYPE_SFRotation:
170 case FIELDTYPE_SFImage:
171 set_one_MultiElementType(shader_num, fieldOffset, any, len);
173 case FIELDTYPE_MFFloat:
174 case FIELDTYPE_MFInt32:
175 case FIELDTYPE_MFBool:
176 case FIELDTYPE_MFTime:
177 case FIELDTYPE_MFDouble:
178 case FIELDTYPE_MFColor:
179 case FIELDTYPE_MFColorRGBA:
180 case FIELDTYPE_MFVec2f:
181 case FIELDTYPE_MFVec3f:
182 case FIELDTYPE_MFVec4f:
183 case FIELDTYPE_MFVec2d:
184 case FIELDTYPE_MFVec3d:
185 case FIELDTYPE_MFVec4d:
186 case FIELDTYPE_MFString:
187 case FIELDTYPE_MFNode:
188 case FIELDTYPE_MFRotation:
189 case FIELDTYPE_MFImage:
190 case FIELDTYPE_MFMatrix3f:
191 case FIELDTYPE_MFMatrix4f:
192 case FIELDTYPE_MFMatrix3d:
193 case FIELDTYPE_MFMatrix4d:
195 set_one_MFElementType(shader_num, fieldOffset, type, (
void *)any,len);
199 printf(
"WARNING: sendScriptEventIn type %s not handled yet\n",
222int setMFElementtype (
int num) {
227 CRnodeStruct *to_ptr = NULL;
230 struct CRStruct *CRoutes = getCRoutes();
234 #ifdef SETFIELDVERBOSE
235 printf(
"------------BEGIN setMFElementtype ---------------\n");
239 fn = (
void *)CRoutes[num].routeFromNode;
240 fptr = CRoutes[num].fnptr;
244 pptr = offsetPointer_deref (
char *, fn, fptr);
246 len = CRoutes[num].len;
255 pptr = (
char *) mfp->p;
256 #ifdef SETFIELDVERBOSE
257 printf (
"setMFElementtype, len now %d, from %d\n",len,fn);
265 for (to_counter = 0; to_counter < CRoutes[num].tonode_count; to_counter++) {
268 to_ptr = &(CRoutes[num].tonodes[to_counter]);
269 myObj = X3D_SCRIPT(to_ptr->routeToNode)->__scriptObj;
271 #ifdef SETFIELDVERBOSE
272 printf (
"got a script event! index %d type %d\n",
273 num, CRoutes[num].direction_flag);
278 printf (
"\tdata length %d\n",len);
279 printf (
"and, sending it to %s as type %d\n",JSparamnames[to_ptr->foffset].name,
280 JSparamnames[to_ptr->foffset].type);
283 set_one_MFElementType(myObj->num, to_ptr->foffset, JSparamnames[to_ptr->foffset].type, (
void *)pptr,len);
287 #ifdef SETFIELDVERBOSE
288 printf(
"------------END setMFElementtype ---------------\n");
302void setScriptMultiElementtype (
int num)
309 CRnodeStruct *to_ptr = NULL;
310 struct CRStruct *CRoutes = getCRoutes();
313 fn = (
void *)CRoutes[num].routeFromNode;
314 fptr = CRoutes[num].fnptr;
315 if (CRoutes[num].len == ROUTING_SFNODE) len = returnElementLength(FIELDTYPE_SFNode);
316 else if (CRoutes[num].len < 0) {
317 ConsoleMessage (
"setScriptMultiElementtype - len of %d unhandled\n",CRoutes[num].len);
320 len = CRoutes[num].len;
323 for (to_counter = 0; to_counter < CRoutes[num].tonode_count; to_counter++) {
326 to_ptr = &(CRoutes[num].tonodes[to_counter]);
327 myObj = X3D_SCRIPT(to_ptr->routeToNode)->__scriptObj;
330 tptr = to_ptr->foffset;
332 #ifdef SETFIELDVERBOSE
333 printf (
"got a script event! index %d type %d\n",
334 num, CRoutes[num].direction_flag);
335 printf (
"\tfrom %#x from ptr %#x\n\tto %#x toptr %#x\n",fn,fptr,myObj->num,tptr);
336 printf (
"\tdata length %d\n",len);
337 printf (
"setScriptMultiElementtype here script number %d tptr %d len %d\n",myObj->num, tptr,len);
340 fn = offsetPointer_deref(
void*,fn,fptr);
342 set_one_MultiElementType (myObj->num, tptr, fn, len);
352void EAI_Convert_mem_to_ASCII (
int id,
char *reptype,
int type,
char *memptr,
char *buf) {
354 char utilBuf[EAIREADSIZE];
356 memset(utilBuf,
'\0',
sizeof(utilBuf));
358 errcount = UtilEAI_Convert_mem_to_ASCII (type,memptr, utilBuf);
360 sprintf (buf,
"%s\n%f\n%d\n%s",reptype,TickTime(),
id, utilBuf);
362 sprintf (buf,
"%s\n%f\n%d\n%s",reptype,TickTime(),
id,
"indeterminate....");
368int UtilEAI_Convert_mem_to_ASCII (
int type,
char *memptr,
char *buf) {
391 eaiverbose = gglobal()->EAI_C_CommonFunctions.eaiverbose;
392 intptr = (
int *) memptr;
398 case FIELDTYPE_SFBool: {
400 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFBOOL - value %d; TRUE %d false %d\n",*intptr,TRUE,FALSE);
403 if (*intptr == 1) sprintf (buf,
"TRUE");
404 else sprintf (buf,
"FALSE");
408 case FIELDTYPE_SFDouble:
409 case FIELDTYPE_SFTime: {
411 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFTIME\n");
413 memcpy(&dval,memptr,
sizeof(
double));
414 sprintf (buf,
"%lf",dval);
418 case FIELDTYPE_SFInt32: {
420 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFINT32\n");
422 memcpy(&ival,memptr,
sizeof(
int));
423 sprintf (buf,
"%d",ival);
427 case FIELDTYPE_SFNode: {
429 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFNODE\n");
431 memcpy((
void *)&uval,(
void *)memptr,
sizeof(
void *));
432 sprintf (buf,
"%u",registerEAINodeForAccess(X3D_NODE(uval)));
436 case FIELDTYPE_SFFloat: {
438 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFFLOAT\n");
441 memcpy(fl,memptr,
sizeof(
float));
442 sprintf (buf,
"%f",fl[0]);
446 case FIELDTYPE_SFVec3f:
447 case FIELDTYPE_SFColor: {
449 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFCOLOR or EAI_SFVEC3F\n");
451 memcpy(fl,memptr,
sizeof(
float)*3);
452 sprintf (buf,
"%f %f %f",fl[0],fl[1],fl[2]);
456 case FIELDTYPE_SFVec3d: {
458 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFVEC3D\n");
460 memcpy(dl,memptr,
sizeof(
double)*3);
461 sprintf (buf,
"%lf %lf %lf",dl[0],dl[1],dl[2]);
465 case FIELDTYPE_SFVec2f: {
467 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFVEC2F\n");
469 memcpy(fl,memptr,
sizeof(
float)*2);
470 sprintf (buf,
"%f %f",fl[0],fl[1]);
474 case FIELDTYPE_SFColorRGBA:
475 case FIELDTYPE_SFRotation: {
477 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFROTATION\n");
480 memcpy(fl,memptr,
sizeof(
float)*4);
481 sprintf (buf,
"%f %f %f %f",fl[0],fl[1],fl[2],fl[3]);
485 case FIELDTYPE_SFImage:
486 case FIELDTYPE_SFString: {
490 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_SFSTRING\n");
495 xx= (uintptr_t *) memptr;
498 retSFString = (
char *)svptr->strptr;
499 sprintf (buf,
"\"%s\"",retSFString);
503 case FIELDTYPE_MFString: {
505 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFSTRING\n");
512 ptr = buf + strlen(buf);
514 for (row=0; row<(*MSptr).n; row++) {
516 if (strlen ((*MSptr).p[row]->strptr) == 0) {
517 sprintf (ptr,
"\"\" ");
519 sprintf (ptr,
"\"%s\" ",(*MSptr).p[row]->strptr);
522 ptr = buf + strlen (buf);
528 case FIELDTYPE_MFNode: {
532 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFNode, there are %d nodes at %p\n",(*MNptr).n,memptr);
535 ptr = buf + strlen(buf);
537 for (row=0; row<(*MNptr).n; row++) {
538 sprintf (ptr,
"%d ",registerEAINodeForAccess(X3D_NODE((*MNptr).p[row])));
539 ptr = buf + strlen (buf);
544 case FIELDTYPE_MFInt32: {
547 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFColor, there are %d nodes at %p\n",(*MCptr).n,memptr);
550 sprintf (buf,
"%d \n",(*MCptr).n);
551 ptr = buf + strlen(buf);
553 ip = (
int *) (*MCptr).p;
554 for (row=0; row<(*MCptr).n; row++) {
555 sprintf (ptr,
"%d \n",*ip);
558 ptr = buf + strlen (buf);
564 case FIELDTYPE_MFFloat:
565 case FIELDTYPE_MFVec2f:
566 case FIELDTYPE_MFVec3f:
567 case FIELDTYPE_MFRotation:
568 case FIELDTYPE_MFColorRGBA:
569 case FIELDTYPE_MFColor: {
571 if (type==FIELDTYPE_MFFloat) {numPerRow=1;}
572 else if (type==FIELDTYPE_MFVec2f) {numPerRow=2;}
573 else if (type==FIELDTYPE_MFRotation) {numPerRow=4;}
574 else if (type==FIELDTYPE_MFColorRGBA) {numPerRow=4;}
578 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI_MFColor, there are %d nodes at %p\n",(*MCptr).n,memptr);
581 sprintf (buf,
"%d \n",(*MCptr).n);
582 ptr = buf + strlen(buf);
585 fp = (
float *) (*MCptr).p;
586 for (row=0; row<(*MCptr).n; row++) {
587 for (i=0; i<numPerRow; i++) {
592 sprintf (ptr,
"%f \n",fl[0]);
break;
594 sprintf (ptr,
"%f %f \n",fl[0],fl[1]);
break;
596 sprintf (ptr,
"%f %f %f \n",fl[0],fl[1],fl[2]);
break;
598 sprintf (ptr,
"%f %f %f %f \n",fl[0],fl[1],fl[2],fl[3]);
break;
601 ptr = buf + strlen (buf);
608 printf (
"UtilEAI_Convert_mem_to_ASCII: EAI, type %d (%s) not handled yet\n",type,stringFieldtypeType (type));