FreeWRL/FreeX3D  3.0.0
CScripts.h
1 /*
2 
3 
4 Class to wrap a java script for CParser
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_CSCRIPTS_H__
29 #define __FREEWRL_CSCRIPTS_H__
30 
31 /* ************************************************************************** */
32 /* ************************ Java function name to JSScript mapping ********* */
33 /* ************************************************************************** */
34 /* Some stuff for routing */
35 #define FROM_SCRIPT 1
36 #define TO_SCRIPT 2
37 #define SCRIPT_TO_SCRIPT 3
38 
39 
40 
41 /* ************************************************************************** */
42 /* ************************ Methods used by X3D Parser ********************* */
43 /* ************************************************************************** */
44 void zeroScriptHandles (void);
45 struct X3D_Script * protoScript_copy (struct X3D_Script *me);
46 
47 
48 /* ************************************************************************** */
49 /* ****************************** ScriptFieldDecl *************************** */
50 /* ************************************************************************** */
51 
52 /* Struct */
53 /* ****** */
54 
56 {
57  /* subclass of FieldDecl,
58  for 'dynamic fields': fields added by scene-author to qualifying node types such as Script, Proto, ShaderScript
59  */
60  struct FieldDecl* fieldDecl;
61 
62  /* Stringified value, if required by a parser. */
63  char* ASCIIvalue;
64 
65  /* For fields */
66  int valueChanged; //dug9_2014 eventOut flag, added for JScript_duk.c / duktape, which will use this valueChanged,anyVrml instead of jsNative.h > sfNative.valueChanged,anyVrml
67  union anyVrml value;
68  BOOL valueSet; /* Has the value been set? used during parsing and construction*/
69  int eventInSet; //used by SFNode setter, and runQueuedDirectOutputs
70  struct Shader_Script* script; //dug9_2014 added here for duktape proxy
71 };
72 
73 int ScriptFieldDecl_getMode(struct ScriptFieldDecl* sfd);
74 int ScriptFieldDecl_getType(struct ScriptFieldDecl* sfd);
75 const char* ScriptFieldDecl_getName(struct ScriptFieldDecl* sfd);
76 
77 
78 /* Structure that holds information regarding script fields that are targets in PROTO IS statements */
80  struct ScriptFieldDecl* decl;
81  struct Shader_Script* script; /* dug9_2014: Q by putting *script into ScriptFieldDecl, can *ScriptFieldInstanceInfo be replaced by *ScriptFieldDecl? */
82 };
83 
84 /* Constructor and destructor */
85 /* ************************** */
86 struct VRMLLexer;
87 struct ScriptFieldDecl* newScriptFieldDecl(struct VRMLLexer*, indexT, indexT, indexT);
88 struct ScriptFieldInstanceInfo* newScriptFieldInstanceInfo(struct ScriptFieldDecl*, struct Shader_Script*);
89 struct ScriptFieldDecl* scriptFieldDecl_copy(struct VRMLLexer*, struct ScriptFieldDecl*);
90 void deleteScriptFieldDecl(struct ScriptFieldDecl*);
91 
92 /* Other members */
93 /* ************* */
94 
95 /* Get "offset" data for routing */
96 int scriptFieldDecl_getRoutingOffset(struct ScriptFieldDecl*);
97 
98 /* Set field value */
99 void scriptFieldDecl_setFieldValue(struct ScriptFieldDecl*, union anyVrml);
100 
101 /* Forwards to inherited methods */
102 #define scriptFieldDecl_isField(me, nam, mod) \
103  fieldDecl_isField((me)->fieldDecl, nam, mod)
104 
105 /* ************************************************************************** */
106 /* ********************************** Script ******************************** */
107 /* ************************************************************************** */
108 
109 /* Struct */
110 /* ****** */
111 
113 {
114  struct X3D_Node *ShaderScriptNode; /* NODE_Script, NODE_ComposedShader, etc */
115  int num; /* The script handle if a script, -1 if a shader */
116  BOOL loaded; /* Has the code been loaded into this script? */
117  struct Vector* fields;
118 };
119 struct ScriptFieldDecl* Shader_Script_getScriptField(struct Shader_Script* script, int ifield);
120 int Shader_Script_getScriptFieldCount();
121 
122 /* Constructor and destructor */
123 /* ************************** */
124 
125 struct Shader_Script* new_Shader_Script(struct X3D_Node *);
126 struct Shader_Script* new_Shader_ScriptB(struct X3D_Node *);
127 
128 void deleteScript();
129 
130 /* Other members */
131 /* ************* */
132 
133 /* Initializes the script with its code */
134 BOOL script_initCode(struct Shader_Script*, const char*);
135 BOOL script_initCodeFromMFUri(struct Shader_Script*, const struct Multi_String*);
136 char *shader_initCodeFromMFUri(const struct Multi_String* s);
137 
138 /* Add a new field */
139 void script_addField(struct Shader_Script*, struct ScriptFieldDecl*);
140 
141 /* Get a field by name */
142 struct ScriptFieldDecl* script_getField(struct Shader_Script*, indexT ind, indexT mod);
143 struct ScriptFieldDecl* script_getField_viaCharName (struct Shader_Script* me, const char *name);
144 
145 
147  struct ScriptParamList *next;
148  indexT kind;
149  indexT type;
150  char *field;
151  union anyVrml value;
152 };
153 
155  /* type */
156  int thisScriptType;
157 
158  /* Javascript parameters */
159  int _initialized; /* this script initialized yet? */
160  void *cx; /* JSContext */
161  void *glob; /* JSGlobals */
162  void *eventsProcessed; /* eventsProcessed() compiled function parameter >=185 JSObject* <185 JSScript* */
163 
164  char *scriptText;
165  struct ScriptParamList *paramList;
166  int scriptOK; /* set to TRUE if the script loads ok */
167  struct Shader_Script* script; //dug9_2014 added here for duktape proxy which will use script->field[i].valueChanged and anyVrml Value instead of scriptparamlist here
168  int scr_act; //non-zero -something sent this script an eventin
169 };
170 //extern struct CRscriptStruct *ScriptControl;
171 //struct CRscriptStruct *getScriptControl();
172 //void setScriptControl(struct CRscriptStruct *ScriptControl);
173 
174 
175 /* function protos */
176 
177 struct ScriptFieldInstanceInfo* scriptFieldInstanceInfo_copy(struct ScriptFieldInstanceInfo*);
178 void scriptFieldDecl_setFieldASCIIValue(struct ScriptFieldDecl *me, const char *val);
179 
180 
181 /* setting script eventIns from routing table or EAI */
182 void Set_one_MultiElementtype (int tn, int tptr, void *fn, unsigned len);
183 void mark_script (int num);
184 
185 #define MAXJSVARIABLELENGTH 55 /* variable name length can be this long... */
187  int type;
188  char name[MAXJSVARIABLELENGTH];
189  void *eventInFunction; /* compiled javascript function... if it is required */
190 };
191 struct CRjsnameStruct *getJSparamnames();
192 int JSparamIndex (const char *name, const char *type);
193 struct CRscriptStruct *getScriptControlIndex(int actualscript);
194 
195 
196 
197 #endif /* __FREEWRL_CSCRIPTS_H__ */
Definition: Vector.h:36