35#include "../vrml_parser/Structs.h"
36#include "../vrml_parser/CRoutes.h"
37#include "../main/headers.h"
39#include "../input/EAIHeaders.h"
40#include "../input/EAIHelpers.h"
41#include "../opengl/Frustum.h"
42#include "../opengl/OpenGL_Utils.h"
43#include "../opengl/Textures.h"
45#include "Component_Networking.h"
47#include "../scenegraph/RenderFuncs.h"
49#include <libFreeWRL.h>
56 #define TRACK_OSC_MSG 0
62#include "../vrml_parser/CParseGeneral.h"
63#include "../scenegraph/Vector.h"
64#include "../vrml_parser/CFieldDecls.h"
65#include "../world_script/JScript.h"
66#include "../world_script/CScripts.h"
67#include "../world_script/fieldSet.h"
68#include "../vrml_parser/CParseParser.h"
69#include "../vrml_parser/CParseLexer.h"
70#include "../vrml_parser/CParse.h"
78void error(
int num,
const char *m,
const char *path);
79void utilOSCcounts(
char *types ,
int *intCount,
int *fltCount,
int *strCount,
int *blobCount,
int *midiCount,
int *otherCount);
82#include "OSCcallbacks.c"
85#define MAX_OSC_SERVERS 32
86int serverPort[MAX_OSC_SERVERS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
87lo_server_thread oscThread[MAX_OSC_SERVERS] ;
89static uintptr_t *OSC_Nodes = NULL;
90static int num_OSC_Nodes = 0;
92int active_OSC_Nodes = FALSE;
94void utilOSCcounts(
char *types ,
int *intCount,
int *fltCount,
int *strCount,
int *blobCount,
int *midiCount,
int *otherCount) {
106 for (i=0 ; i < j ; i++) {
130void activate_OSCsensors() {
132 active_OSC_Nodes = TRUE ;
144 while (active_OSC_Nodes && curr_OSC_Node < num_OSC_Nodes) {
146 if (checkNode(realnode,__FILE__,__LINE__)) {
148 printf(
"activate_OSCsensors : %s,%d node=%p name=%s\n", __FILE__,__LINE__,realnode,realnode->description->strptr) ;
150 if (realnode->_status < 0) {
151 printf(
"activate_OSCsensors : %s,%d Moving %s to ready.\n", __FILE__,__LINE__,realnode->description->strptr) ;
152 realnode->_status = 0 ;
153 }
else if (realnode->_status == 0) {
154 printf(
"activate_OSCsensors : %s,%d\n", __FILE__,__LINE__) ;
155 printf(
"activate_OSCsensors : enabled=%d\n", realnode->enabled) ;
156 printf(
"activate_OSCsensors : gotEvents=%d\n", realnode->gotEvents) ;
157 printf(
"activate_OSCsensors : description=%s\n",realnode->description->strptr) ;
158 printf(
"activate_OSCsensors : protocol=%s\n", realnode->protocol->strptr) ;
159 printf(
"activate_OSCsensors : port=%d\n", realnode->port) ;
160 printf(
"activate_OSCsensors : filter=%s\n", realnode->filter->strptr) ;
161 printf(
"activate_OSCsensors : handler=%s\n", realnode->handler->strptr) ;
179 printf(
"activate_OSCsensors : talksTo=[ ");
180 for (i=0; i < realnode->talksTo.n; i++) {
181 printf(
"\"%s\" ",realnode->talksTo.p[i]->strptr);
185 myNode = parser_getNodeFromName(realnode->talksTo.p[i]->strptr);
186 if (myNode != NULL) {
187 printf(
"(%p) ",(
void *)myNode);
192 printf(
"] (%d nodes) (Need to fix %s,%d)\n",realnode->talksTo.n , __FILE__,__LINE__);
193 printf(
"activate_OSCsensors : listenfor=%s , expect %d parameters\n", realnode->listenfor->strptr , (
int)strlen(realnode->listenfor->strptr)) ;
194 printf(
"activate_OSCsensors : FIFOsize=%d\n", realnode->FIFOsize) ;
195 printf(
"activate_OSCsensors : _status=%d\n", realnode->_status) ;
197 if (realnode->FIFOsize > 0) {
199 utilOSCcounts(realnode->listenfor->strptr,&intCount,&fltCount,&strCount,&blobCount,&midiCount,&otherCount);
200 intCount = realnode->FIFOsize * (intCount + midiCount);
201 fltCount = realnode->FIFOsize * fltCount;
202 strCount = realnode->FIFOsize * (strCount + blobCount + otherCount);
203 printf(
"Allocate %d floats, %d ints for '%s'\n",fltCount,intCount,realnode->description->strptr);
205 realnode->_int32InpFIFO = (
void *) NewRingBuffer (intCount) ;
206 realnode->_floatInpFIFO = (
void *) NewRingBuffer (fltCount) ;
207 realnode->_stringInpFIFO = (
void *) NewRingBuffer (strCount) ;
212 int foundCurrentPort = -1 ;
213 for ( i=0 ; i < num_OSC_Nodes ; i++) {
214 if(realnode->port == serverPort[i]) {
219 if (foundCurrentPort < 0) {
220 foundCurrentPort = serverCount ;
221 serverPort[foundCurrentPort] = realnode->port ;
224 sprintf (buf,
"%d",realnode->port);
226 if (strcmp(
"TCP",realnode->protocol->strptr)==0) {
228 oscThread[foundCurrentPort] = lo_server_thread_new(buf, error);
229 }
else if (strcmp(
"UNIX",realnode->protocol->strptr)==0) {
231 oscThread[foundCurrentPort] = lo_server_thread_new(buf, error);
234 oscThread[foundCurrentPort] = lo_server_thread_new(buf, error);
236 lo_server_thread_start(oscThread[foundCurrentPort]);
239 printf(
"%d servers; current server is running in slot %d on port %d\n",serverCount,foundCurrentPort,serverPort[foundCurrentPort]) ;
244 int foundHandler = 0 ;
245 for (i=0 ; i < OSCfuncCount ; i++) {
246 printf(
"%d/%d : Check %s against %s\n",i,OSCfuncCount,realnode->handler->strptr,OSCfuncNames[i]);
247 if (0 == strcmp(realnode->handler->strptr,OSCfuncNames[i])) {foundHandler = i;}
249 if (OSCcallbacks[foundHandler] != NULL) {
250 printf(
"Going to hook '%s' to '%s' handler\n",realnode->description->strptr ,OSCfuncNames[foundHandler]) ;
251 lo_server_thread_add_method(oscThread[foundCurrentPort], realnode->filter->strptr, realnode->listenfor->strptr,
252 (OSCcallbacks[foundHandler]), realnode);
255 realnode->_status = 1 ;
257 active_OSC_Nodes = FALSE ;
265void error(
int num,
const char *msg,
const char *path)
267 printf(
"liblo server error %d in path %s: %s\n", num, path, msg);
270void add_OSCsensor(
struct X3D_Node * node) {
274 printf (
"error in registerOSCNode; somehow the node datastructure is zero \n");
278 if (node->_nodeType != NODE_OSC_Sensor)
return;
280 OSC_Nodes = (uintptr_t *) REALLOC (OSC_Nodes,
sizeof (uintptr_t *) * (num_OSC_Nodes+1));
284 *myptr = (uintptr_t) node;
288void remove_OSCsensor(
struct X3D_Node * node) {}
291void add_OSCsensor(
struct X3D_Node * node) {}
292void remove_OSCsensor(
struct X3D_Node * node) {}
296int loadstatus_Script(
struct X3D_Script *script);
297int getFieldFromNodeAndNameC(
struct X3D_Node* node,
const char *fieldname,
int *type,
int *kind,
int *iifield,
int *builtIn,
union anyVrml **value,
const char **cname);
307 if (node->__oldEnabled != node->enabled) {
308 node->__oldEnabled = node->enabled;
309 MARK_EVENT(X3D_NODE(node),offsetof (
struct X3D_LoadSensor, enabled));
311 if (!node->enabled)
return;
315 if (!renderstate()->render_sensitive)
return;
318 if NODE_NEEDS_COMPILING {
321 node->__finishedloading = 0;
322 node->progress = (float) 0.0;
323 node->__StartLoadTime = 0.0;
327 if (node->watchList.n<=0)
return;
330 if (node->__finishedloading == node->watchList.n)
return;
338 for (count = 0; count < node->watchList.n; count ++) {
340 cnode = node->watchList.p[count];
343 switch (cnode->_nodeType) {
344 case NODE_ImageTexture:
351 if (fwl_isTextureLoaded(tnode->__textureTableIndex)) {
361 if(inode->__loadstatus > INLINE_INITIAL_STATE && inode->__loadstatus < INLINE_STABLE)
363 if(inode->__loadstatus == INLINE_STABLE)
370 if(loadstatus_Script(X3D_SCRIPT(cnode)))
374 case NODE_ShaderProgram:
377 shader=(
struct Shader_Script *)(X3D_SHADERPROGRAM(cnode)->_shaderUserDefinedFields);
378 if(shader->loaded) nowFinished++;
381 case NODE_PackagedShader:
384 shader=(
struct Shader_Script *)(X3D_PACKAGEDSHADER(cnode)->_shaderUserDefinedFields);
385 if(shader->loaded) nowFinished++;
388 case NODE_ComposedShader:
391 shader=(
struct Shader_Script *)(X3D_COMPOSEDSHADER(cnode)->_shaderUserDefinedFields);
392 if(shader->loaded) nowFinished++;
399 shader=(
struct Shader_Script *)(X3D_EFFECT(cnode)->_shaderUserDefinedFields);
400 if(shader->loaded) nowFinished++;
404 case NODE_MovieTexture:
411 istate = loadstatus_AudioClip(anode);
425 if (nowFinished == node->watchList.n) {
427 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, isActive));
430 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, isLoaded));
432 node->progress = (float) 1.0;
433 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, progress));
435 node->loadTime = TickTime();
436 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, loadTime));
440 if ((nowLoading > 0) && (node->__loading == 0)) {
443 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, isActive));
446 node->__StartLoadTime = TickTime();
450 if (node->isActive == 1) {
451 node->progress = (float)(nowFinished)/(float)(node->watchList.n);
452 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, progress));
456 node->__loading = nowLoading;
457 node->__finishedloading = nowFinished;
460 if (node->timeOut > 0.0001) {
461 if (node->__StartLoadTime > 0.001) {
464 if ((TickTime() - node->__StartLoadTime) > node->timeOut) {
466 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, isLoaded));
469 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_LoadSensor, isActive));
472 node->__finishedloading = node->watchList.n;
480 int nc = (node->children).n;
492 printf(
"RENDER ANCHOR START %d (%d)\n",node, nc);
497 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
500 normalChildren(node->children);
503 printf(
"RENDER ANCHOR END %d\n",node);
505 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
509struct X3D_Node *broto_search_DEFname(
struct X3D_Proto *context,
const char *name);
510struct IMEXPORT *broto_search_IMPORTname(
struct X3D_Proto *context,
const char *name);
511struct IMEXPORT *broto_search_EXPORTname(
struct X3D_Proto *context,
const char *name);
513struct X3D_Node * broto_search_ALLnames(
struct X3D_Proto *context,
const char *name,
int *source){
525 node = broto_search_DEFname(context,name);
529 im = broto_search_IMPORTname(context,name);
534 nlinenode = broto_search_DEFname(context,im->inlinename);
535 if(nlinenode && nlinenode->_nodeType == NODE_Inline ){
536 struct X3D_Inline *nline = X3D_INLINE(nlinenode);
537 if(nline->__loadstatus == INLINE_IMPORTING || nline->__loadstatus == INLINE_STABLE){
539 struct IMEXPORT *ex = broto_search_EXPORTname(X3D_PROTO(nline),im->mxname);
548 node = broto_search_DEFname(X3D_PROTO(nline),ex->mxname);
566 struct X3D_Node* newnodef, *newnodet;
567 int source, type, kind, ifield, builtIn;
572 newnodef = route->from.node;
573 newnodet = route->to.node;
574 if(route->from.weak){
576 newnodef = broto_search_ALLnames(context,route->from.cnode,&source);
577 ic = newnodef != route->from.node;
578 changed = changed || ic;
580 route->from.weak = 3;
581 getFieldFromNodeAndNameC(newnodef,route->from.cfield,&type,&kind,&ifield,&builtIn, &value, &cname);
582 if(ifield < 0) ConsoleMessage(
"bad FROM field ROUTE %s.%s TO %s.%s\n",route->from.cnode,route->from.cfield,route->to.cnode,route->to.cfield);
583 route->from.ifield = ifield;
584 route->from.builtIn = builtIn;
585 route->from.ftype = type;
588 else route->from.weak = 1;
592 newnodet = broto_search_ALLnames(context,route->to.cnode,&source);
593 ic = newnodet != route->to.node;
594 changed = changed || ic;
597 getFieldFromNodeAndNameC(newnodet,route->to.cfield,&type,&kind,&ifield,&builtIn,&value,&cname);
599 ConsoleMessage(
"bad TO field ROUTE %s.%s TO %s.%s\n",route->from.cnode,route->from.cfield,route->to.cnode,route->to.cfield);
600 route->to.ifield = ifield;
601 route->to.builtIn = builtIn;
602 route->to.ftype = type;
605 else route->to.weak = 1;
608 if(route->lastCommand){
610 CRoutes_RemoveSimpleB(route->from.node,route->from.ifield,route->from.builtIn,route->to.node,route->to.ifield,route->to.builtIn,route->ft);
611 route->lastCommand = 0;
613 route->from.node = newnodef;
614 route->to.node = newnodet;
615 if(route->from.node && route->to.node && route->from.ifield > -1 && route->to.ifield > -1){
616 route->lastCommand = 1;
617 CRoutes_RegisterSimpleB(route->from.node,route->from.ifield,route->from.builtIn,route->to.node,route->to.ifield,route->to.builtIn,route->ft);
621void update_weakRoutes(
struct X3D_Proto *context){
631 if(context && context->__ROUTES){
637 for(k=0;k<vectorSize(context->__ROUTES);k++){
639 if(route->from.weak || route->to.weak){
640 update_weakRoute(context,route);
656 switch (node->__loadstatus) {
657 case INLINE_INITIAL_STATE:
659 if (node->url.n == 0) {
660 node->__loadstatus = INLINE_STABLE;
665 res = resource_create_multi(&(node->url));
666 res->media_type = resm_unknown;
667 node->__loadstatus = INLINE_REQUEST_RESOURCE;
668 node->__loadResource = res;
673 case INLINE_REQUEST_RESOURCE:
674 res = node->__loadResource;
675 resource_identify(node->_parentResource, res);
678 res->actions = resa_download | resa_load;
680 resitem_enqueue(ml_new(res));
682 node->__loadstatus = INLINE_FETCHING_RESOURCE;
685 case INLINE_FETCHING_RESOURCE:
686 res = node->__loadResource;
690 if (res->status == ress_loaded) {
692 res->ectx = (
void*)node;
693 res->whereToPlaceData = X3D_NODE(node);
694 res->offsetFromWhereToPlaceData = offsetof (
struct X3D_Inline, __children);
695 res->actions = resa_process;
696 node->__loadstatus = INLINE_PARSING;
698 node->__protoFlags = ciflag_set(node->__protoFlags,1,0);
699 res->complete = FALSE;
702 resitem_enqueue(ml_new(res));
704 }
else if ((res->status == ress_failed) || (res->status == ress_invalid)) {
707 node->__loadstatus = INLINE_STABLE;
713 res = node->__loadResource;
718 if (res->status == ress_parsed) {
720 node->__loadstatus = INLINE_IMPORTING;
726 case INLINE_IMPORTING:
728 context = hasContext(node->_executionContext);
730 update_weakRoutes(context);
731 node->__loadstatus = INLINE_STABLE;
736 node->__loadstatus = INLINE_UN_IMPORTING;
740 case INLINE_UN_IMPORTING:
742 context = hasContext(node->_executionContext);
744 update_weakRoutes(context);
745 node->__loadstatus = INLINE_UNLOADING;
747 case INLINE_UNLOADING:
772 unload_broto(X3D_PROTO(node));
773 node->__loadstatus = INLINE_INITIAL_STATE;
782 if(0)printf(
"in prep_inline\n");
785 if ((node->__loadstatus != INLINE_STABLE && node->load) || (node->__loadstatus != INLINE_INITIAL_STATE && !node->load)) {
793 if(0)printf(
"in compile_inline\n");
797 REINITIALIZE_SORTED_NODES_FIELD(node->__children,node->_sortedChildren);
800 int loadchanged, urlchanged;
805 loadchanged = urlchanged = 0;
806 loadchanged = node->load != node->__oldload;
807 urlchanged = node->url.n != node->__oldurl.n || node->url.p != node->__oldurl.p;
808 if(loadchanged || urlchanged){
810 node->__loadstatus = INLINE_UN_IMPORTING;
811 if(loadchanged) node->__oldload = node->load;
812 if(urlchanged) node->__oldurl = node->url;
818void prep_unitscale (
struct X3D_Proto *ec);
819void fin_unitscale (
struct X3D_Proto *ec);
828 RETURN_FROM_CHILD_IF_NOT_FOR_ME
829 prep_unitscale(X3D_PROTO(node));
830 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
833 normalChildren(node->_sortedChildren);
834 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
835 fin_unitscale(X3D_PROTO(node));