FreeWRL/FreeX3D  3.0.0
CRoutes.h
1 /*
2 
3 
4 VRML-parsing routines in C.
5 
6 */
7 
8 /****************************************************************************
9  This file is part of the FreeWRL/FreeX3D Distribution.
10 
11  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12 
13  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14  it under the terms of the GNU Lesser Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25 ****************************************************************************/
26 
27 
28 #ifndef __FREEWRL_CROUTES_H__
29 #define __FREEWRL_CROUTES_H__
30 
31 /* grab the OpenCL defines here - not many will use it,but the CRStruct needs it */
32 /* we could do the include in all the referencing files, which would be cleaner... */
33 #ifdef HAVE_OPENCL
34 #include "../opencl/OpenCL_Utils.h"
35 #endif
36 
37 /* C routes */
38 typedef struct _CRnodeStruct {
39  struct X3D_Node *routeToNode;
40  int foffset;
41 } CRnodeStruct;
42 
43 
44 struct CRStruct {
45  struct X3D_Node* routeFromNode;
46  int fnptr;
47  int tonode_count;
48  CRnodeStruct *tonodes;
49  int isActive;
50  int len;
51  void (*interpptr)(void *); /* pointer to an interpolator to run */
52  int direction_flag; /* if non-zero indicates script in/out,
53  proto in/out */
54  void *extra; /* used to pass a parameter (eg, 1 = addChildren..) */
55  int intTimeStamp; /* used for ROUTE loop breaking */
56 #ifdef HAVE_OPENCL
57  cl_kernel CL_Interpolator;
58 #endif //HAVE_OPENCL
59 
60 };
61 
62 struct brouteEnd{
63  int weak; //0-normal strong node* end 1=weak and not loaded 2=weak and loaded(so node* available now, but may vanish back to 1)
64  char *cnode; // char* node name if its a weak reference -used for routing to IMPORT nodes, which show up late, and can leave
65  char *cfield; // char* field name ditto
66  struct X3D_Node* node; //if its a strong reference
67  //int builtin; //flag 1 = builtin node, 0= script, proto with user fields (Q. what about routing to Script.url?)
68  //int Ofs; //integer offset for builtin field, in bytes from node*
69  int ifield; //integer routable field index - for scripts,protos the index of user field, for builtins the index into OFFESTS[] array
70  int ftype; //field type
71 };
72 
73 struct brotoRoute
74 {
75  struct brouteEnd from;
76  struct brouteEnd to;
77  int lastCommand; //0-none or delete 1-add
78  int ft;
79  //struct X3D_Node* fromNode;
80  //int fromOfs;
81  //struct X3D_Node* toNode;
82  //int toOfs;
83 };
84 
85 #define REINITIALIZE_SORTED_NODES_FIELD(aaa,bbb) \
86  /* has this changed size? */ \
87  {\
88  int nc = aaa.n; \
89  if (nc != bbb.n) {\
90  \
91  FREE_IF_NZ(bbb.p); \
92  bbb.p = MALLOC(void *, sizeof (struct X3DNode *) * nc); \
93  } \
94  \
95  /* copy the nodes over; we will sort the sorted list */ \
96  memcpy(bbb.p, aaa.p, sizeof (struct X3DNode *) * nc); \
97  bbb.n = nc; \
98  }
99 
100 
101 struct CRStruct *getCRoutes();
102 
103 /* function protos */
104 void getSpecificRoute (int routeNo, struct X3D_Node **fromNode, int *fromOffset, struct X3D_Node **toNode, int *toOffset);
105 
106 void do_first(void);
107 void delete_first(struct X3D_Node *);
108 
109 unsigned long upper_power_of_two(unsigned long v);
110 
111 void mark_event (struct X3D_Node *from, int fromoffset);
112 void mark_event_check (struct X3D_Node *from, int fromoffset,char *fn, int line);
113 void Multimemcpy (struct X3D_Node *toNode, struct X3D_Node *fromNode, void *tn, void *fn, size_t multitype);
114 
115 void CRoutes_js_new (int num,int scriptType);
116 
117 void AddRemoveSFNodeFieldChild(
118  struct X3D_Node *parent,
119  struct X3D_Node **tn, //target SFNode field
120  struct X3D_Node *node, //node to set,add or remove from parent
121  int ar, //0=set,1=add,2=remove
122  char *file,
123  int line);
124 
125 void initializeAnyScripts();
126 void cleanupDie(int num, const char *msg);
127 
128 #endif /* __FREEWRL_CROUTES_H__ */