FreeWRL / FreeX3D 4.3.0
CScripts.h
1/*
2
3
4Class 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/* ************************************************************************** */
44void zeroScriptHandles (void);
45struct 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
73int ScriptFieldDecl_getMode(struct ScriptFieldDecl* sfd);
74int ScriptFieldDecl_getType(struct ScriptFieldDecl* sfd);
75const 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/* ************************** */
86struct VRMLLexer;
87struct ScriptFieldDecl* newScriptFieldDecl(struct VRMLLexer*, indexT, indexT, indexT);
88struct ScriptFieldInstanceInfo* newScriptFieldInstanceInfo(struct ScriptFieldDecl*, struct Shader_Script*);
89struct ScriptFieldDecl* scriptFieldDecl_copy(struct VRMLLexer*, struct ScriptFieldDecl*);
90void deleteScriptFieldDecl(struct ScriptFieldDecl*);
91
92/* Other members */
93/* ************* */
94
95/* Get "offset" data for routing */
96int scriptFieldDecl_getRoutingOffset(struct ScriptFieldDecl*);
97
98/* Set field value */
99void 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};
119struct ScriptFieldDecl* Shader_Script_getScriptField(struct Shader_Script* script, int ifield);
120int Shader_Script_getScriptFieldCount(struct Shader_Script* script);
121
122/* Constructor and destructor */
123/* ************************** */
124
125struct Shader_Script* new_Shader_Script(struct X3D_Node *);
126struct Shader_Script* new_Shader_ScriptB(struct X3D_Node *);
127
128void deleteScript();
129
130/* Other members */
131/* ************* */
132
133/* Initializes the script with its code */
134BOOL script_initCode(struct Shader_Script*, const char*);
135BOOL script_initCodeFromMFUri(struct Shader_Script*, const struct Multi_String*);
136char *shader_initCodeFromMFUri(const struct Multi_String* s);
137
138/* Add a new field */
139void script_addField(struct Shader_Script*, struct ScriptFieldDecl*);
140
141/* Get a field by name */
142struct ScriptFieldDecl* script_getField(struct Shader_Script*, indexT ind, indexT mod);
143struct 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
177struct ScriptFieldInstanceInfo* scriptFieldInstanceInfo_copy(struct ScriptFieldInstanceInfo*);
178void scriptFieldDecl_setFieldASCIIValue(struct ScriptFieldDecl *me, const char *val);
179
180
181/* setting script eventIns from routing table or EAI */
182void Set_one_MultiElementtype (int tn, int tptr, void *fn, unsigned len);
183void mark_script (int num);
184
185#define MAXJSVARIABLELENGTH 55 /* variable name length can be this long... */
187 int type, kind;
188 char name[MAXJSVARIABLELENGTH];
189 void *eventInFunction; /* compiled javascript function... if it is required */
190};
191struct CRjsnameStruct *getJSparamnames();
192int JSparamIndex (const char *name, const char *type, int mod);
193struct CRscriptStruct *getScriptControlIndex(int actualscript);
194
195int getFieldFromScript(struct Shader_Script * sp, char *fieldname, int *type, int *kind, int *iifield, union anyVrml **value, int **valueChanged);
196
197#endif /* __FREEWRL_CSCRIPTS_H__ */