30 #include <system_threads.h>
34 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../main/headers.h"
39 #include "CParseGeneral.h"
40 #include "../scenegraph/Vector.h"
41 #include "../vrml_parser/CFieldDecls.h"
42 #include "../world_script/JScript.h"
43 #include "../world_script/CScripts.h"
44 #include "../world_script/fieldGet.h"
45 #include "../world_script/fieldSet.h"
46 #include "CParseParser.h"
47 #include "CParseLexer.h"
48 #include "../input/SensInterps.h"
49 #include "../scenegraph/Component_ProgrammableShaders.h"
50 #include "../input/EAIHeaders.h"
51 #include "../input/EAIHelpers.h"
53 #include "../opencl/OpenCL_Utils.h"
64 static bool canRouteOnGPUTo(
struct X3D_Node *me);
168 void (*interpptr)(
void *);
188 cl_kernel CL_Interpolator;
198 #define POSSIBLEINITIALROUTES 1000
207 #define LOCK_PREROUTETABLE pthread_mutex_lock(&p->preRouteLock);
208 #define UNLOCK_PREROUTETABLE pthread_mutex_unlock(&p->preRouteLock);
211 #define MUTEX_LOCK_ROUTING_UPDATES pthread_mutex_lock(&p->insertRouteLock);
212 #define MUTEX_FREE_LOCK_ROUTING_UPDATES pthread_mutex_unlock(&p->insertRouteLock);
221 int size_ClockEvents;
222 int CRoutes_Initiated;
225 int initialEventBeforeRoutesCount;
226 int preRouteTableSize;
228 pthread_mutex_t preRouteLock;
229 struct Vector* routesToRegister;
230 pthread_mutex_t insertRouteLock;
232 int thisIntTimeStamp;
237 struct Vector* ScriptControl;
246 void *CRoutes_constructor(){
247 void *v = MALLOCV(
sizeof(
struct pCRoutes));
248 memset(v,0,
sizeof(
struct pCRoutes));
251 void CRoutes_init(
struct tCRoutes *t){
254 t->CRoutesExtra = NULL;
256 t->max_script_found = -1;
257 t->max_script_found_and_initialized = -1;
259 t->MAXJSparamNames = 0;
262 t->prv = CRoutes_constructor();
266 p->size_ClockEvents = 1;
268 p->num_ClockEvents = 0;
269 p->CRoutes_Initiated = FALSE;
272 p->initialEventBeforeRoutesCount = 0;
273 p->preRouteTableSize = 0;
276 pthread_mutex_init(&(p->preRouteLock), NULL);
277 p->routesToRegister = NULL;
279 pthread_mutex_init(&(p->insertRouteLock), NULL);
281 p->thisIntTimeStamp = 1;
286 p->ScriptControl = newVector(
struct CRscriptControl*,0);
290 p->JSparamnames = NULL;
295 void lock_and_do_routes_register();
300 lock_and_do_routes_register();
302 p->CRoutes_Count = 0;
304 FREE_IF_NZ(p->CRoutes);
308 void CRoutes_clear(
struct tCRoutes *t){
312 FREE_IF_NZ(p->ClockEvents);
313 FREE_IF_NZ(p->preEvents);
323 int getCRouteCount(){
325 return p->CRoutes_Count;
327 int *getCRouteCounter(){
329 return &p->CRoutes_Count;
342 void markScriptResults(
struct X3D_Node * tn,
int tptr,
int route,
void * tonode) {
349 printf (
"markScriptResults: can update this node %p %d\n",tn,tptr);
354 printf (
"markScriptResults: skipping this node %p %d flag %d\n",tn,tptr,p->CRoutes[route].direction_flag);
358 MARK_EVENT (p->CRoutes[route].routeFromNode,p->CRoutes[route].fnptr);
361 if (p->CRoutes[route].interpptr != 0) {
363 tg->CRoutes.CRoutesExtra = p->CRoutes[route].extra;
365 printf (
"script propagate_events. index %d is an interpolator\n",route);
367 p->CRoutes[route].interpptr(tonode);
372 void AddRemoveSFNodeFieldChild(
387 if ((parent==NULL) || (child == NULL)) {
400 if ((ar == 0) || (ar == 1)) {
402 printf (
"we have to perform a \"set_child\" on this field\n");
406 if (*tn != NULL) remove_parent(*tn,parent);
410 ADD_PARENT(child,parent);
417 remove_parent(*tn,parent);
420 if ((*tn != NULL) && (child->referenceCount > 0)) {
421 ConsoleMessage (
".... ARSF, requested child to remove is %p %s ref %d as a child",child,stringNodeType(child->_nodeType),
422 child->referenceCount);
441 unsigned long upper_power_of_two(
unsigned long v)
454 void AddRemoveChildren (
463 void *newmal, *oldmal;
473 printf (
"\n start of AddRemoveChildren; parent is a %s at %p\n",stringNodeType(parent->_nodeType),parent);
474 printf (
"AddRemove Children parent %p tn %p, len %d ar %d\n",parent,tn,len,ar);
475 printf (
"called at %s:%d\n",file,line);
482 if ((parent==0) || (tn == 0)) {
493 printf (
"AddRemoveChildren, len %d, oldlen %d ar %d\n",len, oldlen, ar);
499 printf (
"we have to perform a \"set_children\" on this field\n");
506 for (counter=0; counter < oldlen; counter ++) remove_parent(tn->p[counter],parent);
509 if (oldlen > 0) {FREE_IF_NZ(tn->p);}
520 unsigned long p2new, p2old;
521 unsigned long old_len = (unsigned)(oldlen);
522 unsigned long new_len = (unsigned)(oldlen+len);
523 p2new = upper_power_of_two(new_len);
524 p2old = upper_power_of_two(old_len);
539 unsigned long po2 = upper_power_of_two(new_len);
543 printf(
"[%d]{%u}",oldlen,upper_power_of_two(old_len));
546 #if defined(DEBUG_MALLOC) && defined(DEBUG_MALLOC_LIST)
547 newmal = (
void*)freewrlMalloc(line, file, (po2)*
sizeof(
struct X3D_Node *), FALSE);
549 newmal = MALLOC (
void *, (po2)*
sizeof(
struct X3D_Node *));
553 if (newmal != NULL && oldlen > 0) memcpy (newmal,tn->p,oldlen*
sizeof(
void *));
570 tmpptr = offsetPointer_deref(
struct X3D_Node * *,newmal,
sizeof(
struct X3D_Node *) * oldlen);
573 for (counter = 0; counter < len; counter++) {
575 printf (
"AddRemove, count %d of %d, node %p parent %p\n",counter, len,nodelist[counter],parent);
577 if (tmpptr != NULL && nodelist[counter] != NULL) {
579 *tmpptr = nodelist[counter];
583 ADD_PARENT((
void *)nodelist[counter],(
void *)parent);
586 printf (
"AddRemoveChildren, Add, but new node is null; ignoring...\n");
606 for (c2 = 0; c2 < len; c2++) {
607 remptr = (
struct X3D_Node * *) tn->p;
610 for (counter = 0; counter < tn->n; counter ++) {
612 printf (
"remove, comparing %p with %p\n",*remptr, *remchild);
614 if ((*remptr == *remchild) && (!done)) {
616 printf (
"Found it! removing this child from this parent\n");
619 remove_parent(X3D_NODE(*remchild),parent);
631 finalLength = oldlen - num_removed;
633 printf (
"final length is %d, we have %d in original array\n", finalLength, tn->n);
634 remptr = (
struct X3D_Node * *) tn->p;
635 printf (
"so, the original array, with zeroed elements is: \n");
636 for (counter = 0; counter < tn->n; counter ++) {
637 printf (
"count %d of %d is %p\n",counter,tn->n, *remptr);
643 if (num_removed > 0) {
644 if (finalLength > 0) {
645 newmal = MALLOC (
void *, finalLength*
sizeof(
struct X3D_Node * *));
646 bzero (newmal, (
size_t)(finalLength*
sizeof(
struct X3D_Node * *)));
647 tmpptr = (
struct X3D_Node * *) newmal;
648 remptr = (
struct X3D_Node * *) tn->p;
651 for (counter = 0; counter < tn->n; counter ++) {
653 if (*remptr != NULL) {
673 printf (
"so, we have a final array length of %d\n",tn->n);
674 for (counter =0; counter <tn->n; counter ++) {
675 printf (
" element %d is %p\n",counter,tn->p[counter]);
692 void kill_clockEvents() {
696 p->num_ClockEvents = 0;
698 void do_ColorChaserTick(
void * ptr);
699 void do_ColorDamperTick(
void * ptr);
700 void do_CoordinateChaserTick(
void * ptr);
701 void do_CoordinateDamperTick(
void * ptr);
702 void do_OrientationChaserTick(
void * ptr);
703 void do_OrientationDamperTick(
void * ptr);
704 void do_PositionChaserTick(
void * ptr);
705 void do_ColorDamperTick(
void * ptr);
706 void do_PositionChaserTick(
void * ptr);
707 void do_PositionDamperTick(
void * ptr);
708 void do_PositionChaser2DTick(
void * ptr);
709 void do_PositionDamper2DTick(
void * ptr);
710 void do_ScalarChaserTick(
void * ptr);
711 void do_ScalarDamperTick(
void * ptr);
712 void do_TexCoordChaser2DTick(
void * ptr);
713 void do_TexCoordDamper2DTick(
void * ptr);
714 void do_CollisionSensorTick(
void * ptr);
716 void add_first(
struct X3D_Node * node) {
723 printf (
"error in add_first; somehow the node datastructure is zero \n");
727 clocktype = node->_nodeType;
745 case NODE_TimeSensor: myp = do_TimeSensorTick;
break;
746 case NODE_ProximitySensor: myp = do_ProximitySensorTick;
break;
747 case NODE_Collision: myp = do_CollisionTick;
break;
748 case NODE_MovieTexture: myp = do_MovieTextureTick;
break;
749 case NODE_AudioClip: myp = do_AudioTick;
break;
750 case NODE_VisibilitySensor: myp = do_VisibilitySensorTick;
break;
751 case NODE_TransformSensor: myp = do_TransformSensorTick;
break;
752 case NODE_GeoProximitySensor: myp = do_GeoProximitySensorTick;
break;
753 case NODE_ColorChaser: myp = do_ColorChaserTick;
break;
754 case NODE_ColorDamper: myp = do_ColorDamperTick;
break;
755 case NODE_CoordinateChaser: myp = do_CoordinateChaserTick;
break;
756 case NODE_CoordinateDamper: myp = do_CoordinateDamperTick;
break;
757 case NODE_OrientationChaser: myp = do_OrientationChaserTick;
break;
758 case NODE_OrientationDamper: myp = do_OrientationDamperTick;
break;
759 case NODE_PositionChaser: myp = do_PositionChaserTick;
break;
760 case NODE_PositionDamper: myp = do_PositionDamperTick;
break;
761 case NODE_PositionChaser2D: myp = do_PositionChaser2DTick;
break;
762 case NODE_PositionDamper2D: myp = do_PositionDamper2DTick;
break;
763 case NODE_ScalarChaser: myp = do_ScalarChaserTick;
break;
764 case NODE_ScalarDamper: myp = do_ScalarDamperTick;
break;
765 case NODE_TexCoordChaser2D: myp = do_TexCoordChaser2DTick;
break;
766 case NODE_TexCoordDamper2D: myp = do_TexCoordDamper2DTick;
break;
767 case NODE_LinePickSensor: myp = do_PickSensorTick;
break;
768 case NODE_PointPickSensor: myp = do_PickSensorTick;
break;
769 case NODE_PrimitivePickSensor: myp = do_PickSensorTick;
break;
770 case NODE_VolumePickSensor: myp = do_PickSensorTick;
break;
771 case NODE_CollisionSensor: myp = do_CollisionSensorTick;
break;
777 if (p->num_ClockEvents + 1 > p->size_ClockEvents){
786 memcpy(ce, p->ClockEvents, sizeof (
struct FirstStruct) * p->num_ClockEvents);
788 p->size_ClockEvents *= 2;
789 old_ce = p->ClockEvents;
795 if (p->ClockEvents == 0) {
796 printf (
"can not allocate memory for add_first call\n");
797 p->num_ClockEvents = 0;
801 for (count=0; count < p->num_ClockEvents; count ++) {
802 if (p->ClockEvents[count].tonode == node) {
809 for (count=0; count < p->num_ClockEvents; count ++) {
810 if (p->ClockEvents[count].tonode == NULL) {
812 p->ClockEvents[count].interpptr = myp;
813 p->ClockEvents[count].tonode = node;
820 p->ClockEvents[p->num_ClockEvents].interpptr = myp;
821 p->ClockEvents[p->num_ClockEvents].tonode = node;
823 p->num_ClockEvents++;
827 void delete_first(
struct X3D_Node *node) {
831 if (p->ClockEvents) {
832 for (count=0; count < p->num_ClockEvents; count ++) {
833 if (p->ClockEvents[count].tonode == node) {
834 p->ClockEvents[count].tonode = NULL;
853 void CRoutes_RegisterSimple(
860 void* interpolatorPointer;
865 switch (from->_nodeType) {
867 case NODE_ComposedShader:
869 case NODE_PackagedShader:
871 case NODE_ProgramShader:
872 dir = dir | FROM_SCRIPT;
break;
875 switch (to->_nodeType) {
877 case NODE_ComposedShader:
879 case NODE_PackagedShader:
881 case NODE_ProgramShader:
882 dir = dir | TO_SCRIPT;
break;
887 if (dir!=SCRIPT_TO_SCRIPT && dir!=TO_SCRIPT) {
889 if (to->_nodeType == NODE_StaticGroup) {
890 ConsoleMessage (
"ROUTE to a StaticGroup not allowed");
895 if (dir!=SCRIPT_TO_SCRIPT && dir!=FROM_SCRIPT) {
897 if (from->_nodeType == NODE_StaticGroup) {
898 ConsoleMessage (
"ROUTE from a StaticGroup not allowed");
904 if(dir!=SCRIPT_TO_SCRIPT && dir!=TO_SCRIPT)
905 interpolatorPointer=returnInterpolatorPointer(to->_nodeType);
907 interpolatorPointer=NULL;
908 CRoutes_Register(1, from, fromOfs, to,toOfs, type, interpolatorPointer, dir, NULL);
910 int usesBuiltin(
struct X3D_Node* node){
914 switch(node->_nodeType){
916 case NODE_ComposedShader:
918 case NODE_ShaderProgram :
919 case NODE_PackagedShader:
928 void CRoutes_RegisterSimpleB(
929 struct X3D_Node* from,
int fromIndex,
937 if(usesBuiltin(from))
938 fromOfs = NODE_OFFSETS[(from)->_nodeType][fromIndex*5 + 1];
941 toOfs = NODE_OFFSETS[(to)->_nodeType][toIndex*5 + 1];
942 CRoutes_RegisterSimple(from,fromOfs,to,toOfs,type);
953 void CRoutes_RemoveSimple(
959 void* interpolatorPointer;
961 interpolatorPointer=returnInterpolatorPointer(to->_nodeType);
963 CRoutes_Register(0, from, fromOfs, to, toOfs, type,
964 interpolatorPointer, 0, NULL);
967 void CRoutes_RemoveSimpleB(
struct X3D_Node* from,
int fromIndex,
968 struct X3D_Node* to,
int toIndex,
int len){
973 if(usesBuiltin(from))
974 fromOfs = NODE_OFFSETS[(from)->_nodeType][fromIndex*5 + 1];
977 toOfs = NODE_OFFSETS[(to)->_nodeType][toIndex*5 + 1];
979 CRoutes_RemoveSimple(from,fromOfs,to,toOfs,len);
991 void CRoutes_Register(
1006 cl_kernel CL_Interpolator = NULL;
1007 ConsoleMessage (
"CRoutes_Register, being run on :%s:\n",__DATE__);
1009 #endif //HAVE_OPENCL
1033 if (from->_nodeType == NODE_CoordinateInterpolator) {
1037 if (incr == 0) incr = -1;
1040 if (to->_nodeType == NODE_Coordinate) {
1042 if (canRouteOnGPUTo(to) ) {
1045 p = (ppOpenCL_Utils)tg->OpenCL_Utils.prv;
1047 px ->_GPU_Routes_out += incr;
1049 if (tg->OpenCL_Utils.OpenCL_Initialized) {
1050 printf (
"OpenCL initialized in routes\n");
1052 printf(
"OPENCL NOT INITIALIZED YET\n");
1055 while (!tg->OpenCL_Utils.OpenCL_Initialized) {
1057 printf (
"sleeping, waiting for CL to be initialized\n");
1062 CL_Interpolator = p->coordinateInterpolatorKernel;
1064 printf (
"CRoutes Register, have a CoordinateInterpolator to Coordinate, but dest node type not supported yet\n");
1065 px->_CPU_Routes_out+= incr;
1069 px->_CPU_Routes_out += incr;
1072 px->_CPU_Routes_out += incr;
1073 #endif //HAVE_OPENCL
1076 MUTEX_LOCK_ROUTING_UPDATES
1078 if (p->routesToRegister == NULL) {
1079 p->routesToRegister = newVector(
struct CR_RegStruct *, 16);
1084 newEntry->adrem = adrem;
1085 newEntry->from = from;
1086 newEntry->fromoffset = fromoffset;
1088 newEntry->toOfs = toOfs;
1089 newEntry->fieldType = type;
1090 newEntry->intptr = intptr;
1091 newEntry->scrdir = scrdir;
1092 newEntry->extra = extra;
1094 newEntry->CL_Interpolator = CL_Interpolator;
1097 vector_pushBack(
struct CR_RegStruct *, p->routesToRegister, newEntry);
1099 MUTEX_FREE_LOCK_ROUTING_UPDATES
1102 void free_routes_to_register(
struct Vector * routesToRegister){
1104 if(routesToRegister){
1107 for(i=0;i<vectorSize(routesToRegister);i++){
1108 r = vector_get(
struct CR_RegStruct*,routesToRegister,i);
1112 FREE_IF_NZ(routesToRegister);
1116 void print_routes_ready_to_register(FILE* fp)
1129 if(p->routesToRegister == NULL)
return;
1130 numRoutes = vectorSize(p->routesToRegister);
1131 fprintf(fp,
"Number of Routes Ready to Register %d\n",numRoutes);
1132 if (numRoutes < 1) {
1136 for (count = 0; count < (numRoutes); count++) {
1137 entry = vector_get(
struct CR_RegStruct *, p->routesToRegister, count);
1138 fromNode = entry->from;
1139 fromOffset = entry->fromoffset;
1141 toOffset = entry->toOfs;
1142 fromName = parser_getNameFromNode(fromNode);
1143 toName = parser_getNameFromNode(toNode);
1144 fprintf (fp,
" %p %s.%s TO %p %s.%s \n",fromNode,fromName,
1145 findFIELDNAMESfromNodeOffset0(fromNode,fromOffset),
1147 findFIELDNAMESfromNodeOffset0(toNode,toOffset)
1153 static void actually_do_CRoutes_Register() {
1154 int insert_here, check_here, shifter, isDuplicate;
1161 if (p->routesToRegister == NULL)
return;
1164 printf (
"actually_do_CRoutes_Register, vector size %d\n",vectorSize(p->routesToRegister));
1167 for (ind=0; ind<vectorSize(p->routesToRegister); ind++ ) {
1170 newEntry = vector_get(
struct CR_RegStruct *, p->routesToRegister, ind);
1173 printf (
"CRoutes_Register adrem %d from %u ",newEntry->adrem, newEntry->from);
1176 printf (
"off %u to %u intptr %p\n",
1177 newEntry->fromoffset, newEntry->to, newEntry->intptr);
1178 printf (
"CRoutes_Register, CRoutes_Count is %d\n",p->CRoutes_Count);
1182 if (!p->CRoutes_Initiated) {
1184 p->CRoutes_MAX = 25;
1185 p->CRoutes = MALLOC (
struct CRStruct *,
sizeof (*p->CRoutes) * p->CRoutes_MAX);
1187 p->CRoutes[0].routeFromNode = X3D_NODE(0);
1188 p->CRoutes[0].fnptr = 0;
1189 p->CRoutes[0].tonode_count = 0;
1190 p->CRoutes[0].tonodes = NULL;
1191 p->CRoutes[0].isActive = FALSE;
1192 p->CRoutes[0].interpptr = 0;
1193 p->CRoutes[0].intTimeStamp = 0;
1194 p->CRoutes[1].routeFromNode = X3D_NODE(-1);
1195 p->CRoutes[1].fnptr = 0x8FFFFFFF;
1196 p->CRoutes[1].tonode_count = 0;
1197 p->CRoutes[1].tonodes = NULL;
1198 p->CRoutes[1].isActive = FALSE;
1199 p->CRoutes[1].interpptr = 0;
1200 p->CRoutes[1].intTimeStamp = 0;
1201 p->CRoutes_Count = 2;
1202 p->CRoutes_Initiated = TRUE;
1205 p->CRoutes[0].CL_Interpolator = NULL;
1206 p->CRoutes[1].CL_Interpolator = NULL;
1213 while (newEntry->from > p->CRoutes[insert_here].routeFromNode) {
1215 printf (
"comparing %u to %u\n",newEntry->from, p->CRoutes[insert_here].routeFromNode);
1222 while ((newEntry->from == p->CRoutes[insert_here].routeFromNode) &&
1223 (newEntry->fromoffset > p->CRoutes[insert_here].fnptr)) {
1225 printf (
"same routeFromNode, different offset\n");
1235 printf (
"ok, CRoutes_Register - is this a duplicate? comparing from (%d %d), fnptr (%d %d) intptr (%d %d) and tonodes %d\n",
1236 p->CRoutes[insert_here].routeFromNode, newEntry->from,
1237 p->CRoutes[insert_here].fnptr, newEntry->fromoffset,
1238 p->CRoutes[insert_here].interpptr, newEntry->intptr,
1239 p->CRoutes[insert_here].tonodes);
1242 check_here = insert_here;
1244 while ((p->CRoutes[check_here].routeFromNode==newEntry->from) &&
1245 (p->CRoutes[check_here].fnptr==newEntry->fromoffset) &&
1246 (newEntry->adrem == 0 || p->CRoutes[check_here].interpptr==newEntry->intptr) &&
1247 (p->CRoutes[check_here].tonodes!=0)) {
1250 toof = newEntry->toOfs;
1252 if ((toN == (p->CRoutes[check_here].tonodes)->routeToNode) &&
1253 (toof == (p->CRoutes[check_here].tonodes)->foffset)) {
1257 printf (
"duplicate route; maybe this is a remove? \n");
1261 if (newEntry->adrem == 1) {
1263 printf (
"definite duplicate, returning\n");
1270 FREE_IF_NZ(p->CRoutes[check_here].tonodes);
1271 for (shifter = check_here; shifter < p->CRoutes_Count; shifter++) {
1273 printf (
"copying from %d to %d\n",shifter, shifter-1);
1275 memcpy ((
void *)&p->CRoutes[shifter],
1276 (
void *)&p->CRoutes[shifter+1],
1279 p->CRoutes_Count --;
1281 printf (
"routing table now %d\n",p->CRoutes_Count);
1282 for (shifter = 0; shifter < p->CRoutes_Count; shifter ++) {
1283 printf (
"%d: %u %u %u\n",shifter, p->CRoutes[shifter].routeFromNode, p->CRoutes[shifter].fnptr,
1284 p->CRoutes[shifter].interpptr);
1295 if (newEntry->adrem == 1 && !isDuplicate) {
1297 printf (
"CRoutes, inserting at %d\n",insert_here);
1301 for (shifter = p->CRoutes_Count; shifter > insert_here; shifter--) {
1302 memcpy ((
void *)&p->CRoutes[shifter], (
void *)&p->CRoutes[shifter-1],
sizeof(
struct CRStruct));
1304 printf (
"Copying from index %d to index %d\n",shifter, shifter-1);
1310 p->CRoutes[insert_here].routeFromNode = newEntry->from;
1311 p->CRoutes[insert_here].fnptr = newEntry->fromoffset;
1312 p->CRoutes[insert_here].isActive = FALSE;
1313 p->CRoutes[insert_here].tonode_count = 0;
1314 p->CRoutes[insert_here].tonodes = NULL;
1315 p->CRoutes[insert_here].len = returnRoutingElementLength(newEntry->fieldType);
1316 p->CRoutes[insert_here].interpptr = (void (*)(
void*))newEntry->intptr;
1317 p->CRoutes[insert_here].direction_flag = newEntry->scrdir;
1318 p->CRoutes[insert_here].extra = newEntry->extra;
1319 p->CRoutes[insert_here].intTimeStamp = 0;
1321 p->CRoutes[insert_here].CL_Interpolator = newEntry->CL_Interpolator;
1325 if ((p->CRoutes[insert_here].tonodes =
1327 fprintf(stderr,
"CRoutes_Register: calloc failed to allocate memory.\n");
1329 p->CRoutes[insert_here].tonode_count = 1;
1332 to_ptr = &(p->CRoutes[insert_here].tonodes[0]);
1333 to_ptr->routeToNode = newEntry->to;
1334 to_ptr->foffset = newEntry->toOfs;
1338 if (p->CRoutes_Count >= (p->CRoutes_MAX-2)) {
1340 p->CRoutes_MAX += 50;
1341 p->CRoutes =(
struct CRStruct *) REALLOC (p->CRoutes, sizeof (*p->CRoutes) * p->CRoutes_MAX);
1344 p->CRoutes_Count ++;
1347 printf (
"routing table now %d\n",p->CRoutes_Count);
1348 for (shifter = 0; shifter < p->CRoutes_Count; shifter ++) {
1349 printf (
"%d: from: %p offset: %u Interpolator %p direction %d, len %d extra %p : ",shifter,
1350 p->CRoutes[shifter].routeFromNode, p->CRoutes[shifter].fnptr,
1351 p->CRoutes[shifter].interpptr, p->CRoutes[shifter].direction_flag, p->CRoutes[shifter].len, p->CRoutes[shifter].extra);
1352 for (insert_here = 0; insert_here < p->CRoutes[shifter].tonode_count; insert_here++) {
1353 printf (
" to: %p %u",p->CRoutes[shifter].tonodes[insert_here].routeToNode,
1354 p->CRoutes[shifter].tonodes[insert_here].foffset);
1362 free_routes_to_register(p->routesToRegister);
1363 p->routesToRegister = NULL;
1365 printf (
"routing table now %d\n",p->CRoutes_Count);
1366 for (shifter = 0; shifter < p->CRoutes_Count; shifter ++) {
1367 printf (
"%3d from: %p offset: %u Interp %p dir %d, len %d extra %p :\n",shifter,
1368 p->CRoutes[shifter].routeFromNode, p->CRoutes[shifter].fnptr,
1369 p->CRoutes[shifter].interpptr, p->CRoutes[shifter].direction_flag, p->CRoutes[shifter].len, p->CRoutes[shifter].extra);
1370 for (insert_here = 0; insert_here < p->CRoutes[shifter].tonode_count; insert_here++) {
1371 printf (
" to: %p %u\n",p->CRoutes[shifter].tonodes[insert_here].routeToNode,
1372 p->CRoutes[shifter].tonodes[insert_here].foffset);
1378 void lock_and_do_routes_register()
1381 MUTEX_LOCK_ROUTING_UPDATES
1382 actually_do_CRoutes_Register();
1383 MUTEX_FREE_LOCK_ROUTING_UPDATES
1387 #ifdef DEBUG_VALIDNODE
1389 void mark_event_check (
struct X3D_Node *from,
int totalptr,
char *fn,
int line) {
1390 printf (
"mark_event_check: at %s:%d\n",fn,line);
1391 if (X3D_NODE_CHECK(from)) {
1393 printf (
"mark_event_check, routing from a %s\n",stringNodeType(from->_nodeType));
1396 printf (
"mark_event_check, not a real node %d\n",from);
1398 mark_event(from,totalptr);
1399 printf (
"mark_event_check: finished at %s:%d\n",fn,line);
1411 void mark_event (
struct X3D_Node *from,
int totalptr) {
1415 if(from == 0)
return;
1418 X3D_NODE_CHECK(from);
1421 if (!p->CRoutes_Initiated) {
1424 if (p->initialEventBeforeRoutesCount >= p->preRouteTableSize) {
1425 p->preRouteTableSize += POSSIBLEINITIALROUTES;
1426 p->preEvents=REALLOC (p->preEvents,
1429 p->preEvents[p->initialEventBeforeRoutesCount].from = from;
1430 p->preEvents[p->initialEventBeforeRoutesCount].totalptr = totalptr;
1431 p->initialEventBeforeRoutesCount++;
1432 UNLOCK_PREROUTETABLE
1440 printf (
"\nmark_event, from %s (%u) fromoffset %u\n", stringNodeType(from->_nodeType),from, totalptr);
1445 while (from > p->CRoutes[findit].routeFromNode) {
1447 printf (
"mark_event, skipping past %x %x, index %d\n",from, p->CRoutes[findit].routeFromNode, findit);
1454 while ((from == p->CRoutes[findit].routeFromNode) &&
1455 (totalptr != p->CRoutes[findit].fnptr)) findit ++;
1459 printf (
"ep, (%#x %#x) (%#x %#x) at %d \n",
1460 from,p->CRoutes[findit].routeFromNode, totalptr,
1461 p->CRoutes[findit].fnptr,findit);
1466 while ((from == p->CRoutes[findit].routeFromNode) &&
1467 (totalptr == p->CRoutes[findit].fnptr)) {
1469 printf (
"found event at %d\n",findit);
1471 if (p->CRoutes[findit].intTimeStamp!=p->thisIntTimeStamp) {
1472 p->CRoutes[findit].isActive=TRUE;
1473 p->CRoutes[findit].intTimeStamp=p->thisIntTimeStamp;
1477 else printf (
"routing loop broken, findit %d\n",findit);
1483 printf (
"done mark_event\n");
1488 void mark_event_B (
struct X3D_Node *lastFrom,
int lastptr,
struct X3D_Node *from,
int totalptr) {
1492 if(from == 0)
return;
1495 X3D_NODE_CHECK(from);
1498 if (!p->CRoutes_Initiated) {
1501 if (p->initialEventBeforeRoutesCount >= p->preRouteTableSize) {
1502 p->preRouteTableSize += POSSIBLEINITIALROUTES;
1503 p->preEvents=REALLOC (p->preEvents,
1506 p->preEvents[p->initialEventBeforeRoutesCount].from = from;
1507 p->preEvents[p->initialEventBeforeRoutesCount].totalptr = totalptr;
1508 p->initialEventBeforeRoutesCount++;
1509 UNLOCK_PREROUTETABLE
1517 printf (
"\nmark_event, from %s (%u) fromoffset %u\n", stringNodeType(from->_nodeType),from, totalptr);
1522 while (from > p->CRoutes[findit].routeFromNode) {
1524 printf (
"mark_event, skipping past %x %x, index %d\n",from, p->CRoutes[findit].routeFromNode, findit);
1531 while ((from == p->CRoutes[findit].routeFromNode) &&
1532 (totalptr != p->CRoutes[findit].fnptr)) findit ++;
1536 printf (
"ep, (%#x %#x) (%#x %#x) at %d \n",
1537 from,p->CRoutes[findit].routeFromNode, totalptr,
1538 p->CRoutes[findit].fnptr,findit);
1543 while ((from == p->CRoutes[findit].routeFromNode) &&
1544 (totalptr == p->CRoutes[findit].fnptr)) {
1547 printf (
"found event at %d\n",findit);
1549 isCycle = (p->CRoutes[findit].tonodes[0].routeToNode == lastFrom &&
1550 p->CRoutes[findit].tonodes[0].foffset == lastptr);
1552 if (p->CRoutes[findit].intTimeStamp!=p->thisIntTimeStamp) {
1553 p->CRoutes[findit].isActive=TRUE;
1554 p->CRoutes[findit].intTimeStamp=p->thisIntTimeStamp;
1558 else printf (
"routing loop broken, findit %d\n",findit);
1564 printf (
"done mark_event\n");
1581 return vector_get(
struct CRscriptStruct*,p->ScriptControl,actualscript);
1584 void setScriptControlIndex(
int actualscript,
struct CRscriptStruct *sc){
1586 vector_set(
struct CRscriptStruct*,p->ScriptControl,actualscript,sc);
1588 int isScriptControlOK(
int actualscript)
1592 cs = vector_get(
struct CRscriptStruct*,p->ScriptControl,actualscript);
1594 return cs->scriptOK;
1596 int isScriptControlInitialized(
int actualscript)
1602 if(actualscript < p->JSMaxScript){
1603 cs = vector_get(
struct CRscriptStruct*,p->ScriptControl,actualscript);
1605 if(cs->_initialized) ret = TRUE;
1610 int loadstatus_Script(
struct X3D_Script *script){
1613 if(script->__scriptObj){
1614 struct Shader_Script * shader=X3D_SCRIPT(script)->__scriptObj;
1615 istate = isScriptControlInitialized(shader->num);
1620 void initializeAnyScripts()
1638 if( tg->CRoutes.max_script_found != tg->CRoutes.max_script_found_and_initialized)
1642 for (i=tg->CRoutes.max_script_found_and_initialized+1; i <= tg->CRoutes.max_script_found; i++)
1645 JSCreateScriptContext(i);
1646 JSInitializeScriptAndFields(i);
1647 ScriptControl = getScriptControlIndex(i);
1648 if (ScriptControl->scriptOK)
1649 jsActualrunScript(i,
"initialize()");
1653 tg->CRoutes.max_script_found_and_initialized = tg->CRoutes.max_script_found;
1666 void CRoutes_js_new (
int num,
int scriptType) {
1674 cs->thisScriptType = scriptType;
1677 if (num > tg->CRoutes.max_script_found) tg->CRoutes.max_script_found = num;
1689 void mark_script (
int num) {
1698 getScriptControlIndex(num)->scr_act = TRUE;
1703 int runQueuedDirectOutputs();
1713 int JSparamNameIndex,
int type,
int extra,
int len) {
1725 int touched_flag=FALSE;
1756 if(shader->num > -1 && shader->loaded){
1757 actualscript = shader->num;
1764 if(!isScriptControlInitialized(actualscript)){
1769 if (actualscript > tg->CRoutes.max_script_found_and_initialized) {
1775 if(!isScriptControlOK(actualscript)){
1804 touched_flag = get_valueChanged_flag((
int)JSparamNameIndex,actualscript);
1807 if (touched_flag!= 0) {
1820 js_setField_javascriptEventOut_B(any,type, len, extra,
1836 resetScriptTouchedFlag ((
int) actualscript, (
int) JSparamNameIndex);
1858 printf (
"%f finished gatherScriptEventOuts loop\n",TickTime());
1863 void JSparamnamesShutdown(){
1867 FREE_IF_NZ(p->JSparamnames);
1868 tg->CRoutes.jsnameindex = -1;
1869 tg->CRoutes.MAXJSparamNames = 0;
1872 void kill_javascript(
void) {
1878 printf (
"calling kill_javascript()\n");
1879 zeroScriptHandles();
1880 if (jsIsRunning() != 0) {
1881 for (i=0; i<=tg->CRoutes.max_script_found_and_initialized; i++) {
1883 ScriptControl = getScriptControlIndex(i);
1885 if (ScriptControl->cx != 0) {
1886 JSDeleteScriptContext(i);
1888 setScriptControlIndex(i,NULL);
1893 tg->CRoutes.max_script_found = -1;
1894 tg->CRoutes.max_script_found_and_initialized = -1;
1896 JSparamnamesShutdown();
1902 printf (
"done kill_javascript\n");
1906 void cleanupDie(
int num,
const char *msg) {
1914 sc->thisScriptType = NOSCRIPT;
1915 sc->eventsProcessed = NULL;
1918 sc->_initialized = FALSE;
1919 sc->scriptOK = FALSE;
1920 sc->scriptText = NULL;
1921 sc->paramList = NULL;
1968 void JSMaxAlloc2(
int num){
1971 if(!p->ScriptControl)
1974 if(p->ScriptControl->allocn <= num){
1977 istart = p->ScriptControl->allocn;
1978 iend = upper_power_of_two(num+1);
1979 p->ScriptControl->data = REALLOC(p->ScriptControl->data,iend*
sizeof(
struct CRscriptStruct *));
1980 p->ScriptControl->allocn = iend;
1981 p->JSMaxScript = p->ScriptControl->allocn;
1985 for(i=istart;i<iend;i++)
1989 int unInitializeScript(
struct X3D_Node *node){
1991 if(node && node->_nodeType == NODE_Script){
1999 count = sscript->num;
2000 ScriptControl = getScriptControlIndex(count);
2001 if (ScriptControl->cx != 0)
2002 JSDeleteScriptContext(count);
2003 setScriptControlIndex(count,NULL);
2004 FREE_IF_NZ(ScriptControl);
2015 #ifdef JAVASCRIPTVERBOSE
2016 printf(
"JSinit: script %d\n",num);
2020 if (script->num >= p->JSMaxScript) {
2021 JSMaxAlloc2(script->num);
2023 cs = newScriptControl();
2024 setScriptControlIndex(script->num,cs);
2026 cs->script = script;
2031 void SaveScriptText(
int num,
const char *text) {
2037 if (num >= p->JSMaxScript) {
2038 ConsoleMessage (
"SaveScriptText: warning, script %d initialization out of order",num);
2041 ScriptControl = getScriptControlIndex(num);
2042 FREE_IF_NZ(ScriptControl->scriptText);
2043 ScriptControl->scriptText = STRDUP(text);
2046 jsClearScriptControlEntries(num);
2048 if (((
int)num) > tg->CRoutes.max_script_found) tg->CRoutes.max_script_found = num;
2057 return p->JSparamnames;
2062 p->JSparamnames = JSparamnames;
2073 int JSparamIndex (
const char *name,
const char *type) {
2081 printf (
"start of JSparamIndex, name %s, type %s\n",name,type);
2082 printf (
"start of JSparamIndex, lengths name %d, type %d\n",
2083 strlen(name),strlen(type));
2086 ty = findFieldInFIELDTYPES(type);
2089 printf (
"JSparamIndex, type %d, %s\n",ty,type);
2097 for (ctr=0; ctr<=tg->CRoutes.jsnameindex; ctr++) {
2098 if (ty==JSparamnames[ctr].type) {
2099 if ((strlen(JSparamnames[ctr].name) == len) &&
2100 (strncmp(name,JSparamnames[ctr].name,len)==0)) {
2102 printf (
"JSparamIndex, duplicate, returning %d\n",ctr);
2112 tg->CRoutes.jsnameindex ++;
2115 if (tg->CRoutes.jsnameindex >= tg->CRoutes.MAXJSparamNames) {
2117 tg->CRoutes.MAXJSparamNames += 100;
2118 setJSparamnames( (
struct CRjsnameStruct*)REALLOC (JSparamnames,
sizeof(*JSparamnames) * tg->CRoutes.MAXJSparamNames));
2119 JSparamnames = getJSparamnames();
2122 if (len > MAXJSVARIABLELENGTH-2) len = MAXJSVARIABLELENGTH-2;
2123 strncpy (JSparamnames[tg->CRoutes.jsnameindex].name,name,len);
2124 JSparamnames[tg->CRoutes.jsnameindex].name[len] = 0;
2125 JSparamnames[tg->CRoutes.jsnameindex].type = ty;
2126 JSparamnames[tg->CRoutes.jsnameindex].eventInFunction = NULL;
2128 printf (
"JSparamIndex, returning %d\n",tg->JScript.jsnameindex);
2131 return tg->CRoutes.jsnameindex;
2147 char * BOOL_STRING(
int inp) {
if (inp)
return "true ";
else return "false ";}
2161 union anyVrml* get_anyVrml(
struct X3D_Node* node,
int offset,
int *type,
int *mode)
2165 int fromMode, fromType, fromOffset;
2167 fromType = INT_ID_UNDEFINED;
2168 fromMode = INT_ID_UNDEFINED;
2169 fromOffset = offset;
2172 switch(node->_nodeType)
2174 case NODE_ShaderProgram:
2175 case NODE_ComposedShader:
2176 case NODE_PackagedShader:
2182 switch(fromNode->_nodeType)
2184 case NODE_Script: shader =(
struct Shader_Script *)(X3D_SCRIPT(fromNode)->__scriptObj);
break;
2185 case NODE_ComposedShader: shader =(
struct Shader_Script *)(X3D_COMPOSEDSHADER(fromNode)->_shaderUserDefinedFields);
break;
2186 case NODE_Effect: shader =(
struct Shader_Script *)(X3D_EFFECT(fromNode)->_shaderUserDefinedFields);
break;
2187 case NODE_ShaderProgram: shader =(
struct Shader_Script *)(X3D_SHADERPROGRAM(fromNode)->_shaderUserDefinedFields);
break;
2188 case NODE_PackagedShader: shader =(
struct Shader_Script *)(X3D_PACKAGEDSHADER(fromNode)->_shaderUserDefinedFields);
break;
2190 sfield= vector_get(
struct ScriptFieldDecl*, shader->fields, fromOffset);
2191 fromAny = &sfield->value;
2192 fromType = sfield->fieldDecl->fieldType;
2193 fromMode = sfield->fieldDecl->PKWmode;
2202 pfield= vector_get(
struct ProtoFieldDecl*, pstruct->iface, fromOffset);
2203 fromAny = &pfield->defaultVal;
2204 fromType = pfield->type;
2205 fromMode = pfield->mode;
2210 const int * offsets;
2212 fromAny = (
union anyVrml*)offsetPointer_deref(
void *,fromNode , fromOffset);
2214 offsets = NODE_OFFSETS[fromNode->_nodeType];
2215 while(*offsets > -1)
2218 if(offsets[1]==fromOffset)
2220 fromType = offsets[2];
2221 fromMode = PKW_from_KW(offsets[3]);
2234 void cleanFieldIfManaged(
int type,
int mode,BOOL isPublic,
struct X3D_Node* parent,
int offset)
2248 if(isManagedField(mode,type,isPublic))
2250 int n,k,haveSomething,fromType,fromMode;
2253 any = get_anyVrml(parent,offset,&fromType,&fromMode);
2254 haveSomething = (type==FIELDTYPE_SFNode && any->sfnode) || (type==FIELDTYPE_MFNode && any->mfnode.n);
2255 haveSomething = haveSomething && parent;
2257 if(type==FIELDTYPE_SFNode){
2258 plist = &any->sfnode;
2261 plist = any->mfnode.p;
2267 remove_parent(sfn,parent);
2269 sfn->referenceCount--;
2271 if(type==FIELDTYPE_MFNode) {
2279 void add_mfparents(
struct X3D_Node* newParent,
union anyVrml* mfnode,
int mftype)
2282 if(mftype != FIELDTYPE_MFNode)
return;
2283 for(i=0;i<mfnode->mfnode.n;i++)
2285 add_parent(mfnode->mfnode.p[i],newParent,__FILE__,__LINE__);
2300 char *findFIELDNAMES0(
struct X3D_Node *node,
int offset);
2303 const char *stringMode(
int pkwmode,
int cute){
2304 const char **strmode;
2305 const char *cutemode[] = {
"init",
"in",
"out",
"inOut" };
2306 const char *fullmode[] = {
"initializeOnly",
"inputOnly",
"outputOnly",
"inputOutput"};
2308 if(cute) strmode = cutemode;
2312 case PKW_initializeOnly:
2314 case PKW_inputOutput:
2318 case PKW_outputOnly:
2325 void print_field_value(FILE *fp,
int typeIndex,
union anyVrml* value);
2327 void propagate_events_B() {
2332 union anyVrml *fromAny, *toAny;
2333 struct X3D_Node *fromNode, *toNode, *lastFromNode;
2334 int fromOffset, toOffset, lastFromOffset, last_markme;
2339 int len, isize, type, sftype, isMF, itime, nRoutesDone, modeFrom, modeTo, debugRoutes;
2347 printf (
"\npropagate_events start\n");
2350 type = INT_ID_UNDEFINED;
2353 p->thisIntTimeStamp ++;
2354 lastFromOffset = -1;
2355 lastFromNode = NULL;
2356 last_markme = FALSE;
2360 printf(
"current time=%d routecount=%d\n",p->thisIntTimeStamp,p->CRoutes_Count);
2365 for (counter = 1; counter < p->CRoutes_Count-1; counter++) {
2368 fromNode = p->CRoutes[counter].routeFromNode;
2369 fromOffset = p->CRoutes[counter].fnptr;
2370 itime = p->CRoutes[counter].intTimeStamp;
2371 switch(fromNode->_nodeType)
2373 case NODE_ShaderProgram:
2374 case NODE_ComposedShader:
2376 case NODE_PackagedShader:
2382 switch(fromNode->_nodeType)
2384 case NODE_Script: shader =(
struct Shader_Script *)(X3D_SCRIPT(fromNode)->__scriptObj);
break;
2385 case NODE_ComposedShader: shader =(
struct Shader_Script *)(X3D_COMPOSEDSHADER(fromNode)->_shaderUserDefinedFields);
break;
2386 case NODE_Effect: shader =(
struct Shader_Script *)(X3D_EFFECT(fromNode)->_shaderUserDefinedFields);
break;
2387 case NODE_ShaderProgram: shader =(
struct Shader_Script *)(X3D_SHADERPROGRAM(fromNode)->_shaderUserDefinedFields);
break;
2388 case NODE_PackagedShader: shader =(
struct Shader_Script *)(X3D_PACKAGEDSHADER(fromNode)->_shaderUserDefinedFields);
break;
2390 sfield= vector_get(
struct ScriptFieldDecl*, shader->fields, fromOffset);
2391 fromAny = &sfield->value;
2393 type = sfield->fieldDecl->fieldType;
2395 sftype = type - isMF;
2398 isize = sizeofSForMF(sftype);
2399 if(isMF) len =
sizeof(int) +
sizeof(
void*);
2401 modeFrom = sfield->fieldDecl->PKWmode;
2404 if(fromNode->_nodeType == NODE_Script){
2408 markme = last_markme;
2409 if(!(fromNode==lastFromNode && fromOffset==lastFromOffset)){
2411 int JSparamNameIndex = sfield->fieldDecl->JSparamNameIndex;
2412 markme = gatherScriptEventOut_B(fromAny,shader,JSparamNameIndex,type,0,len);
2415 if (p->CRoutes[counter].intTimeStamp!=p->thisIntTimeStamp) {
2416 p->CRoutes[counter].isActive=TRUE;
2417 p->CRoutes[counter].intTimeStamp=p->thisIntTimeStamp;
2420 last_markme = markme;
2432 pfield= vector_get(
struct ProtoFieldDecl*, pstruct->iface, fromOffset);
2433 fromAny = &pfield->defaultVal;
2434 type = pfield->type;
2435 modeFrom = pfield->mode;
2440 const int * offsets;
2442 fromAny = (
union anyVrml*)offsetPointer_deref(
void *,fromNode , fromOffset);
2444 offsets = NODE_OFFSETS[fromNode->_nodeType];
2445 while(*offsets > -1)
2448 if(offsets[1]==fromOffset)
2451 modeFrom = PKW_from_KW(offsets[3]);
2462 sftype = type - isMF;
2465 isize = sizeofSForMF(sftype);
2466 if(isMF) len =
sizeof(int) +
sizeof(
void*);
2471 for (to_counter = 0; to_counter < p->CRoutes[counter].tonode_count; to_counter++) {
2472 modeTo = PKW_inputOnly;
2473 to_ptr = &(p->CRoutes[counter].tonodes[to_counter]);
2474 if (to_ptr == NULL) {
2475 printf(
"WARNING: tonode at %u is NULL in propagate_events.\n",
2481 printf(
"propagate_events: counter %d to_counter %u act %s from %u off %u to %u off %u oint %u dir %d\n",
2482 counter, to_counter, BOOL_STRING(p->CRoutes[counter].isActive),
2483 p->CRoutes[counter].routeFromNode, p->CRoutes[counter].fnptr,
2484 to_ptr->routeToNode, to_ptr->foffset, p->CRoutes[counter].interpptr,
2485 p->CRoutes[counter].direction_flag);
2488 if (p->CRoutes[counter].isActive == TRUE) {
2490 p->CRoutes[counter].isActive = FALSE;
2498 toNode = to_ptr->routeToNode;
2499 toOffset = to_ptr->foffset;
2503 if (toNode != NULL) {
2504 switch(toNode->_nodeType)
2506 case NODE_ShaderProgram:
2507 case NODE_ComposedShader:
2508 case NODE_PackagedShader:
2514 switch(toNode->_nodeType)
2516 case NODE_Script: shader =(
struct Shader_Script *)(X3D_SCRIPT(toNode)->__scriptObj);
break;
2517 case NODE_ComposedShader: shader =(
struct Shader_Script *)(X3D_COMPOSEDSHADER(toNode)->_shaderUserDefinedFields);
break;
2518 case NODE_Effect: shader =(
struct Shader_Script *)(X3D_EFFECT(toNode)->_shaderUserDefinedFields);
break;
2519 case NODE_ShaderProgram: shader =(
struct Shader_Script *)(X3D_SHADERPROGRAM(toNode)->_shaderUserDefinedFields);
break;
2520 case NODE_PackagedShader: shader =(
struct Shader_Script *)(X3D_PACKAGEDSHADER(toNode)->_shaderUserDefinedFields);
break;
2522 sfield= vector_get(
struct ScriptFieldDecl*, shader->fields, toOffset);
2523 toAny = &sfield->value;
2524 modeTo = sfield->fieldDecl->PKWmode;
2532 pfield= vector_get(
struct ProtoFieldDecl*, pstruct->iface, toOffset);
2533 toAny = &pfield->defaultVal;
2534 modeTo = pfield->mode;
2538 toAny = (
union anyVrml*)offsetPointer_deref(
void *,toNode , toOffset);
2541 const int *offsets = NODE_OFFSETS[toNode->_nodeType];
2542 while(*offsets > -1)
2545 if(offsets[1]==fromOffset)
2547 modeTo = PKW_from_KW(offsets[3]);
2568 if (toNode != NULL) {
2569 cleanFieldIfManaged(type,modeTo,1,toNode,toOffset);
2571 shallow_copy_field(type,fromAny,toAny);
2574 registerParentIfManagedField(type,modeTo,1, toAny, toNode);
2581 mark_event_B(fromNode,fromOffset, toNode, toOffset);
2586 char *fromName, *toName, *fromFieldName, *toFieldName, *fromModeName, *toModeName, *fromNodeType, *toNodeType;
2587 char fromNameP[100], toNameP[100];
2588 sprintf(fromNameP,
"%p",fromNode);
2589 sprintf(toNameP,
"%p",toNode);
2590 fromName = parser_getNameFromNode(fromNode);
2591 if(!fromName) fromName = &fromNameP[0];
2592 toName = parser_getNameFromNode(toNode);
2593 if(!toName) toName = &toNameP[0];
2594 fromFieldName = findFIELDNAMES0(fromNode,fromOffset);
2595 toFieldName = findFIELDNAMES0(toNode,toOffset);
2596 if(!toName) toName = &toNameP[0];
2597 fromNodeType = (
char *)stringNodeType(fromNode->_nodeType);
2598 if(fromNode->_nodeType == NODE_Proto)
2599 fromNodeType = ((
struct ProtoDefinition*)(X3D_PROTO(fromNode)->__protoDef))->protoName;
2600 toNodeType = (
char *)stringNodeType(toNode->_nodeType);
2601 if(toNode->_nodeType == NODE_Proto)
2602 toNodeType = ((
struct ProtoDefinition*)(X3D_PROTO(toNode)->__protoDef))->protoName;
2603 fromModeName = (
char *)stringMode(modeFrom,1);
2604 toModeName = (
char *)stringMode(modeTo, 1);
2605 printf(
" %s %s.%s %s TO %s %s.%s %s %d ",fromNodeType,fromName,fromFieldName,fromModeName,
2606 toNodeType,toName,toFieldName,toModeName,itime);
2607 print_field_value(stdout,type,toAny);
2615 if (toNode != NULL) {
2616 switch(toNode->_nodeType)
2623 shader =(
struct Shader_Script *)(X3D_SCRIPT(toNode)->__scriptObj);
2639 sfield= vector_get(
struct ScriptFieldDecl*, shader->fields, toOffset);
2642 if(isScriptControlInitialized(shader->num) && isScriptControlOK(shader->num))
2644 int JSparamNameIndex = sfield->fieldDecl->JSparamNameIndex;
2646 mark_script(shader->num);
2649 getField_ToJavascript_B(shader->num, JSparamNameIndex, type, (
union anyVrml* ) toAny->mfnode.p, toAny->mfnode.n);
2651 getField_ToJavascript_B(shader->num, JSparamNameIndex, type, toAny, len);
2659 case NODE_ShaderProgram:
2660 case NODE_ComposedShader:
2662 case NODE_PackagedShader:
2666 getField_ToShader(toNode, toOffset, toAny, type);
2676 if (p->CRoutes[counter].interpptr != 0)
2681 printf(
"propagate_events: index %d is an interpolator\n",counter);
2685 tg->CRoutes.CRoutesExtra = p->CRoutes[counter].extra;
2687 p->CRoutes[counter].interpptr((
void *)(toNode));
2701 update_node(toNode);
2705 lastFromNode = fromNode;
2706 lastFromOffset = fromOffset;
2710 havinterp = havinterp || runQueuedDirectOutputs();
2713 }
while (havinterp==TRUE);
2716 for (counter =0; counter <= tg->CRoutes.max_script_found_and_initialized; counter++) {
2720 sc->scr_act = FALSE;
2721 js_cleanup_script_context(counter);
2732 printf (
"done propagate_events\n\n");
2735 void propagate_events()
2737 propagate_events_B();
2750 void printStatsEvents(){
2751 ConsoleMessage(
"%25s %d\n",
"ClockEvent count", ((
ppCRoutes)gglobal()->CRoutes.prv)->num_ClockEvents);
2753 void usehit_clear();
2762 ne = p->num_ClockEvents;
2763 for (counter =0; counter < ne; counter ++) {
2764 ce = p->ClockEvents[counter];
2766 ce.interpptr(ce.tonode);
2784 if (p->routesToRegister != NULL) {
2785 MUTEX_LOCK_ROUTING_UPDATES
2786 actually_do_CRoutes_Register();
2787 MUTEX_FREE_LOCK_ROUTING_UPDATES
2793 if (p->preEvents != NULL) {
2794 if (p->CRoutes_Initiated) {
2798 printf (
"doing preEvents, we have %d events \n",p->initialEventBeforeRoutesCount);
2801 for (counter = 0; counter < p->initialEventBeforeRoutesCount; counter ++) {
2802 MARK_EVENT(p->preEvents[counter].from, p->preEvents[counter].totalptr);
2804 p->initialEventBeforeRoutesCount = 0;
2805 p->preRouteTableSize = 0;
2806 FREE_IF_NZ(p->preEvents);
2807 UNLOCK_PREROUTETABLE
2819 ne = p->num_ClockEvents;
2820 for (counter =0; counter < ne; counter ++) {
2821 ce = p->ClockEvents[counter];
2823 ce.interpptr(ce.tonode);
2845 int getRoutesCount(
void) {
2848 return p->CRoutes_Count;
2851 void getSpecificRoute (
int routeNo,
struct X3D_Node **fromNode,
int *fromOffset,
2852 struct X3D_Node **toNode,
int *toOffset) {
2857 if ((routeNo <1) || (routeNo >= p->CRoutes_Count)) {
2858 *fromNode = NULL; *fromOffset = 0; *toNode = NULL; *toOffset = 0;
2864 *fromNode = p->CRoutes[routeNo].routeFromNode;
2865 *fromOffset = p->CRoutes[routeNo].fnptr;
2867 if (p->CRoutes[routeNo].tonode_count != 1) {
2868 printf (
"huh? tonode count %d\n",p->CRoutes[routeNo].tonode_count);
2869 *toNode = 0; *toOffset = 0;
2874 to_ptr = &(p->CRoutes[routeNo].tonodes[0]);
2875 *toNode = to_ptr->routeToNode;
2876 *toOffset = to_ptr->foffset;
2890 void kill_routing (
void) {
2895 if (p->CRoutes_Initiated) {
2896 p->CRoutes_Initiated = FALSE;
2897 p->CRoutes_Count = 0;
2899 FREE_IF_NZ (p->CRoutes);
2901 printf (
"kill_routing done\n");
2906 void Multimemcpy (
struct X3D_Node *toNode,
struct X3D_Node *fromNode,
void *tn,
void *fn,
size_t multitype) {
2914 void *fromptr, *toptr;
2919 printf (
"Multimemcpy, copying structures from %p (%s) to %p (%s) %p %p type %d\n",
2920 fromNode, stringNodeType(fromNode->_nodeType),
2921 toNode, stringNodeType(toNode->_nodeType),
2937 fromptr = (
void *)mv3ffn->p;
2940 fromcount = mv3ffn->n;
2944 tocount = mv3ftn->n;
2945 printf (
"Multimemcpy, fromcount %d\n",fromcount);
2949 switch (multitype) {
2950 case ROUTING_SFNODE: structlen =
sizeof (
void *);
break;
2951 case ROUTING_MFNODE: structlen =
sizeof (
void *);
break;
2952 case ROUTING_SFIMAGE: structlen =
sizeof (
void *);
break;
2953 case ROUTING_MFSTRING: structlen =
sizeof (
void *);
break;
2954 case ROUTING_MFFLOAT: structlen =
sizeof (float);
break;
2955 case ROUTING_MFROTATION: structlen =
sizeof (
struct SFRotation);
break;
2956 case ROUTING_MFINT32: structlen =
sizeof (int);
break;
2957 case ROUTING_MFCOLOR: structlen =
sizeof (
struct SFColor);
break;
2958 case ROUTING_MFVEC2F: structlen =
sizeof (
struct SFVec2f);
break;
2959 case ROUTING_MFVEC3F: structlen =
sizeof (
struct SFColor);
break;
2960 case ROUTING_MFVEC3D: structlen =
sizeof (
struct SFVec3d);
break;
2961 case ROUTING_MFDOUBLE: structlen =
sizeof (double);
break;
2962 case ROUTING_MFMATRIX4F: structlen =
sizeof (
struct SFMatrix4f);
break;
2963 case ROUTING_MFMATRIX4D: structlen =
sizeof (
struct SFMatrix4d);
break;
2964 case ROUTING_MFVEC2D: structlen =
sizeof (
struct SFVec2d);
break;
2965 case ROUTING_MFVEC4F: structlen =
sizeof (
struct SFVec4f);
break;
2966 case ROUTING_MFVEC4D: structlen =
sizeof (
struct SFVec4d);
break;
2967 case ROUTING_MFMATRIX3F: structlen =
sizeof (
struct SFMatrix3f);
break;
2968 case ROUTING_MFMATRIX3D: structlen =
sizeof (
struct SFMatrix3d);
break;
2970 case ROUTING_SFSTRING: {
2983 memcpy (&fStr,fn,
sizeof (
void *));
2984 memcpy (&tStr,tn,
sizeof (
void *));
2989 verify_Uni_String(tStr, fStr->strptr);
3003 if(multitype==ROUTING_SFNODE){
3005 memcpy (tn,fn,structlen);
3010 int nele = fromcount;
3011 FREE_IF_NZ (mv3ftn->p);
3013 if( multitype == ROUTING_MFNODE ) nele = (int) upper_power_of_two(nele);
3014 mv3ftn->p = MALLOC (
struct SFVec3f *, structlen*nele);
3015 toptr = (
void *)mv3ftn->p;
3018 mv3ftn->n = fromcount;
3021 printf (
"Multimemcpy, fromcount %d tocount %d fromptr %p toptr %p\n",fromcount,tocount,fromptr,toptr);
3025 memcpy (toptr,fromptr,structlen * fromcount);
3034 if (toNode != NULL) {
3035 if (multitype==ROUTING_SFNODE) {
3036 unsigned int fnvalue;
3037 unsigned int *fnlocation;
3039 fnlocation = (
unsigned int*)fn;
3040 fnvalue= *fnlocation;
3041 sfnodeptr = (
struct X3D_Node*)fnvalue;
3043 printf (
"got a ROUTING_SFNODE, adding %u to %u\n",(
unsigned int) fn, (
unsigned int) toNode);
3045 ADD_PARENT(X3D_NODE(sfnodeptr),toNode);
3047 if (multitype==ROUTING_MFNODE) {
3052 printf (
"fromcount %d tocount %d\n",fromcount, tocount);
3053 printf (
"ROUTING - have to add parents... \n");
3056 for (count = 0; count < mv3ffn->n; count++) {
3058 printf (
"node in place %d is %u ",count,arrptr[count]);
3059 printf (
"%s ",stringNodeType(arrptr[count]->_nodeType));
3063 ADD_PARENT(arrptr[count],toNode);
3075 static bool canRouteOnGPUTo(
struct X3D_Node *me) {
3078 if (me == NULL)
return FALSE;
3079 printf (
"canRouteOnGPUTo = %s\n",stringNodeType(me->_nodeType));
3080 for (i=0; i< vectorSize(me->_parentVector); i++) {
3082 printf (
"parent %d is a %s\n",i,stringNodeType(par->_nodeType));
3083 switch (par->_nodeType) {
3084 case NODE_TriangleSet :
3085 case NODE_IndexedTriangleSet:
3088 default:
return FALSE;
3095 #endif //HAVE_OPENCL