yzwalkman

——用数绘画

导航

Ogre源代码浅析——脚本及其解析(七)

    ScriptCompilerManager是进行脚本解析的关键类型对象(参见:http://www.cnblogs.com/yzwalkman/archive/2012/12/30/2839013.html “脚本及其解析(一)”)。ScriptCompilerManager在其构造函数中将会创建ScriptCompiler对象实例,并将对象指针赋给其mScriptCompiler成员变量。前面所说解析过程的三个阶段即是由此mScriptCompiler对象完成的。对于ScriptCompiler来说,除了前面涉及的各函数过程外,还有两块内容值得关注。一是,如下的枚举变量定义:

  1 enum
  2     {
  3         ID_MATERIAL = 3,
  4         ID_VERTEX_PROGRAM,
  5         ID_GEOMETRY_PROGRAM,
  6         ID_FRAGMENT_PROGRAM,
  7         ID_TECHNIQUE,
  8         ID_PASS,
  9         ID_TEXTURE_UNIT,
 10         ID_VERTEX_PROGRAM_REF,
 11         ID_GEOMETRY_PROGRAM_REF,
 12         ID_FRAGMENT_PROGRAM_REF,
 13         ID_SHADOW_CASTER_VERTEX_PROGRAM_REF,
 14         ID_SHADOW_CASTER_FRAGMENT_PROGRAM_REF,
 15         ID_SHADOW_RECEIVER_VERTEX_PROGRAM_REF,
 16         ID_SHADOW_RECEIVER_FRAGMENT_PROGRAM_REF,
 17         ID_SHADOW_CASTER_MATERIAL,
 18         ID_SHADOW_RECEIVER_MATERIAL,
 19         
 20         ID_LOD_VALUES,
 21         ID_LOD_STRATEGY,
 22         ID_LOD_DISTANCES,
 23         ID_RECEIVE_SHADOWS,
 24         ID_TRANSPARENCY_CASTS_SHADOWS,
 25         ID_SET_TEXTURE_ALIAS,
 26 
 27         ID_SOURCE,
 28         ID_SYNTAX,
 29         ID_DEFAULT_PARAMS,
 30         ID_PARAM_INDEXED,
 31         ID_PARAM_NAMED,
 32         ID_PARAM_INDEXED_AUTO,
 33         ID_PARAM_NAMED_AUTO,
 34 
 35         ID_SCHEME,
 36         ID_LOD_INDEX,
 37         ID_GPU_VENDOR_RULE,
 38         ID_GPU_DEVICE_RULE,
 39         ID_INCLUDE, 
 40         ID_EXCLUDE, 
 41 
 42         ID_AMBIENT,
 43         ID_DIFFUSE,
 44         ID_SPECULAR,
 45         ID_EMISSIVE,
 46             ID_VERTEXCOLOUR,
 47         ID_SCENE_BLEND,
 48             ID_COLOUR_BLEND,
 49             ID_ONE,
 50             ID_ZERO,
 51             ID_DEST_COLOUR,
 52             ID_SRC_COLOUR,
 53             ID_ONE_MINUS_DEST_COLOUR,
 54             ID_ONE_MINUS_SRC_COLOUR,
 55             ID_DEST_ALPHA,
 56             ID_SRC_ALPHA,
 57             ID_ONE_MINUS_DEST_ALPHA,
 58             ID_ONE_MINUS_SRC_ALPHA,
 59         ID_SEPARATE_SCENE_BLEND,
 60         ID_SCENE_BLEND_OP,
 61             ID_REVERSE_SUBTRACT,
 62             ID_MIN,
 63             ID_MAX,
 64         ID_SEPARATE_SCENE_BLEND_OP,
 65         ID_DEPTH_CHECK,
 66         ID_DEPTH_WRITE,
 67         ID_DEPTH_FUNC,
 68         ID_DEPTH_BIAS,
 69         ID_ITERATION_DEPTH_BIAS,
 70             ID_ALWAYS_FAIL,
 71             ID_ALWAYS_PASS,
 72             ID_LESS_EQUAL,
 73             ID_LESS,
 74             ID_EQUAL,
 75             ID_NOT_EQUAL,
 76             ID_GREATER_EQUAL,
 77             ID_GREATER,
 78         ID_ALPHA_REJECTION,
 79         ID_ALPHA_TO_COVERAGE,
 80         ID_LIGHT_SCISSOR,
 81         ID_LIGHT_CLIP_PLANES,
 82         ID_TRANSPARENT_SORTING,
 83         ID_ILLUMINATION_STAGE,
 84             ID_DECAL,
 85         ID_CULL_HARDWARE,
 86             ID_CLOCKWISE,
 87             ID_ANTICLOCKWISE,
 88         ID_CULL_SOFTWARE,
 89             ID_BACK,
 90             ID_FRONT,
 91         ID_NORMALISE_NORMALS,
 92         ID_LIGHTING,
 93         ID_SHADING,
 94             ID_FLAT, 
 95             ID_GOURAUD,
 96             ID_PHONG,
 97         ID_POLYGON_MODE,
 98             ID_SOLID,
 99             ID_WIREFRAME,
100             ID_POINTS,
101         ID_POLYGON_MODE_OVERRIDEABLE,
102         ID_FOG_OVERRIDE,
103             ID_NONE,
104             ID_LINEAR,
105             ID_EXP,
106             ID_EXP2,
107         ID_COLOUR_WRITE,
108         ID_MAX_LIGHTS,
109         ID_START_LIGHT,
110         ID_ITERATION,
111             ID_ONCE,
112             ID_ONCE_PER_LIGHT,
113             ID_PER_LIGHT,
114             ID_PER_N_LIGHTS,
115             ID_POINT,
116             ID_SPOT,
117             ID_DIRECTIONAL,
118         ID_LIGHT_MASK,
119         ID_POINT_SIZE,
120         ID_POINT_SPRITES,
121         ID_POINT_SIZE_ATTENUATION,
122         ID_POINT_SIZE_MIN,
123         ID_POINT_SIZE_MAX,
124 
125         ID_TEXTURE_ALIAS,
126         ID_TEXTURE,
127             ID_1D,
128             ID_2D,
129             ID_3D,
130             ID_CUBIC,
131             ID_UNLIMITED,
132             ID_ALPHA,
133             ID_GAMMA,
134         ID_ANIM_TEXTURE,
135         ID_CUBIC_TEXTURE,
136             ID_SEPARATE_UV,
137             ID_COMBINED_UVW,
138         ID_TEX_COORD_SET,
139         ID_TEX_ADDRESS_MODE,
140             ID_WRAP,
141             ID_CLAMP,
142             ID_BORDER,
143             ID_MIRROR,
144         ID_TEX_BORDER_COLOUR,
145         ID_FILTERING,
146             ID_BILINEAR,
147             ID_TRILINEAR,
148             ID_ANISOTROPIC,
149         ID_MAX_ANISOTROPY,
150         ID_MIPMAP_BIAS,
151         ID_COLOUR_OP,
152             ID_REPLACE,
153             ID_ADD,
154             ID_MODULATE,
155             ID_ALPHA_BLEND,
156         ID_COLOUR_OP_EX,
157             ID_SOURCE1,
158             ID_SOURCE2,
159             ID_MODULATE_X2,
160             ID_MODULATE_X4,
161             ID_ADD_SIGNED,
162             ID_ADD_SMOOTH,
163             ID_SUBTRACT,
164             ID_BLEND_DIFFUSE_COLOUR,
165             ID_BLEND_DIFFUSE_ALPHA,
166             ID_BLEND_TEXTURE_ALPHA,
167             ID_BLEND_CURRENT_ALPHA,
168             ID_BLEND_MANUAL,
169             ID_DOT_PRODUCT,
170             ID_SRC_CURRENT,
171             ID_SRC_TEXTURE,
172             ID_SRC_DIFFUSE,
173             ID_SRC_SPECULAR,
174             ID_SRC_MANUAL,
175         ID_COLOUR_OP_MULTIPASS_FALLBACK,
176         ID_ALPHA_OP_EX,
177         ID_ENV_MAP,
178             ID_SPHERICAL,
179             ID_PLANAR,
180             ID_CUBIC_REFLECTION,
181             ID_CUBIC_NORMAL,
182         ID_SCROLL,
183         ID_SCROLL_ANIM,
184         ID_ROTATE,
185         ID_ROTATE_ANIM,
186         ID_SCALE,
187         ID_WAVE_XFORM,
188             ID_SCROLL_X,
189             ID_SCROLL_Y,
190             ID_SCALE_X,
191             ID_SCALE_Y,
192             ID_SINE,
193             ID_TRIANGLE,
194             ID_SQUARE,
195             ID_SAWTOOTH,
196             ID_INVERSE_SAWTOOTH,
197         ID_TRANSFORM,
198         ID_BINDING_TYPE,
199             ID_VERTEX,
200             ID_FRAGMENT,
201         ID_CONTENT_TYPE,
202             ID_NAMED,
203             ID_SHADOW,
204         ID_TEXTURE_SOURCE,
205         ID_SHARED_PARAMS,
206         ID_SHARED_PARAM_NAMED,
207         ID_SHARED_PARAMS_REF,
208 
209         ID_PARTICLE_SYSTEM,
210         ID_EMITTER,
211         ID_AFFECTOR,
212 
213         ID_COMPOSITOR,
214             ID_TARGET,
215             ID_TARGET_OUTPUT,
216 
217             ID_INPUT,
218                 ID_PREVIOUS,
219                 ID_TARGET_WIDTH,
220                 ID_TARGET_HEIGHT,
221                 ID_TARGET_WIDTH_SCALED,
222                 ID_TARGET_HEIGHT_SCALED,
223             ID_COMPOSITOR_LOGIC,
224             ID_TEXTURE_REF,
225             ID_SCOPE_LOCAL,
226             ID_SCOPE_CHAIN,
227             ID_SCOPE_GLOBAL,
228             ID_POOLED,
229             //ID_GAMMA, - already registered for material
230             ID_NO_FSAA,
231             ID_DEPTH_POOL,
232             ID_ONLY_INITIAL,
233             ID_VISIBILITY_MASK,
234             ID_LOD_BIAS,
235             ID_MATERIAL_SCHEME,
236             ID_SHADOWS_ENABLED,
237 
238             ID_CLEAR,
239             ID_STENCIL,
240             ID_RENDER_SCENE,
241             ID_RENDER_QUAD,
242             ID_IDENTIFIER,
243             ID_FIRST_RENDER_QUEUE,
244             ID_LAST_RENDER_QUEUE,
245             ID_QUAD_NORMALS,
246                 ID_CAMERA_FAR_CORNERS_VIEW_SPACE,
247                 ID_CAMERA_FAR_CORNERS_WORLD_SPACE,
248 
249             ID_BUFFERS,
250                 ID_COLOUR,
251                 ID_DEPTH,
252             ID_COLOUR_VALUE,
253             ID_DEPTH_VALUE,
254             ID_STENCIL_VALUE,
255 
256             ID_CHECK,
257             ID_COMP_FUNC,
258             ID_REF_VALUE,
259             ID_MASK,
260             ID_FAIL_OP,
261                 ID_KEEP,
262                 ID_INCREMENT,
263                 ID_DECREMENT,
264                 ID_INCREMENT_WRAP,
265                 ID_DECREMENT_WRAP,
266                 ID_INVERT,
267             ID_DEPTH_FAIL_OP,
268             ID_PASS_OP,
269             ID_TWO_SIDED,
270 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
271         ID_RT_SHADER_SYSTEM,
272 #endif
273         ID_END_BUILTIN_IDS
274     };

    此枚举变量中的各个值,对应着在Ogre脚本文件中出现的所有的关键字。 二是,ScriptCompiler相关的成员变量mIds,定义如下:

1 typedef HashMap<String,uint32> IdMap;        
2 ...
3 IdMap mIds;

    对mIds的初始化,是在ScriptCompiler类的initWordMap函数中完成的:

  1     void ScriptCompiler::initWordMap()
  2     {
  3         mIds["on"] = ID_ON;
  4         mIds["off"] = ID_OFF;
  5         mIds["true"] = ID_TRUE;
  6         mIds["false"] = ID_FALSE;
  7         mIds["yes"] = ID_YES;
  8         mIds["no"] = ID_NO;
  9 
 10         // Material ids
 11         mIds["material"] = ID_MATERIAL;
 12         mIds["vertex_program"] = ID_VERTEX_PROGRAM;
 13         mIds["geometry_program"] = ID_GEOMETRY_PROGRAM;
 14         mIds["fragment_program"] = ID_FRAGMENT_PROGRAM;
 15         mIds["technique"] = ID_TECHNIQUE;
 16         mIds["pass"] = ID_PASS;
 17         mIds["texture_unit"] = ID_TEXTURE_UNIT;
 18         mIds["vertex_program_ref"] = ID_VERTEX_PROGRAM_REF;
 19         mIds["geometry_program_ref"] = ID_GEOMETRY_PROGRAM_REF;
 20         mIds["fragment_program_ref"] = ID_FRAGMENT_PROGRAM_REF;
 21         mIds["shadow_caster_vertex_program_ref"] = ID_SHADOW_CASTER_VERTEX_PROGRAM_REF;
 22         mIds["shadow_caster_fragment_program_ref"] = ID_SHADOW_CASTER_FRAGMENT_PROGRAM_REF;
 23         mIds["shadow_receiver_vertex_program_ref"] = ID_SHADOW_RECEIVER_VERTEX_PROGRAM_REF;
 24         mIds["shadow_receiver_fragment_program_ref"] = ID_SHADOW_RECEIVER_FRAGMENT_PROGRAM_REF;
 25 
 26         mIds["lod_values"] = ID_LOD_VALUES;
 27         mIds["lod_strategy"] = ID_LOD_STRATEGY;
 28         mIds["lod_distances"] = ID_LOD_DISTANCES;
 29         mIds["receive_shadows"] = ID_RECEIVE_SHADOWS;
 30         mIds["transparency_casts_shadows"] = ID_TRANSPARENCY_CASTS_SHADOWS;
 31         mIds["set_texture_alias"] = ID_SET_TEXTURE_ALIAS;
 32 
 33         mIds["source"] = ID_SOURCE;
 34         mIds["syntax"] = ID_SYNTAX;
 35         mIds["default_params"] = ID_DEFAULT_PARAMS;
 36         mIds["param_indexed"] = ID_PARAM_INDEXED;
 37         mIds["param_named"] = ID_PARAM_NAMED;
 38         mIds["param_indexed_auto"] = ID_PARAM_INDEXED_AUTO;
 39         mIds["param_named_auto"] = ID_PARAM_NAMED_AUTO;
 40 
 41         mIds["scheme"] = ID_SCHEME;
 42         mIds["lod_index"] = ID_LOD_INDEX;
 43         mIds["shadow_caster_material"] = ID_SHADOW_CASTER_MATERIAL;
 44         mIds["shadow_receiver_material"] = ID_SHADOW_RECEIVER_MATERIAL;
 45         mIds["gpu_vendor_rule"] = ID_GPU_VENDOR_RULE;
 46         mIds["gpu_device_rule"] = ID_GPU_DEVICE_RULE;
 47         mIds["include"] = ID_INCLUDE;
 48         mIds["exclude"] = ID_EXCLUDE;
 49 
 50         mIds["ambient"] = ID_AMBIENT;
 51         mIds["diffuse"] = ID_DIFFUSE;
 52         mIds["specular"] = ID_SPECULAR;
 53         mIds["emissive"] = ID_EMISSIVE;
 54         mIds["vertexcolour"] = ID_VERTEXCOLOUR;
 55         mIds["scene_blend"] = ID_SCENE_BLEND;
 56         mIds["colour_blend"] = ID_COLOUR_BLEND;
 57         mIds["one"] = ID_ONE;
 58         mIds["zero"] = ID_ZERO;
 59         mIds["dest_colour"] = ID_DEST_COLOUR;
 60         mIds["src_colour"] = ID_SRC_COLOUR;
 61         mIds["one_minus_src_colour"] = ID_ONE_MINUS_SRC_COLOUR;
 62         mIds["one_minus_dest_colour"] = ID_ONE_MINUS_DEST_COLOUR;
 63         mIds["dest_alpha"] = ID_DEST_ALPHA;
 64         mIds["src_alpha"] = ID_SRC_ALPHA;
 65         mIds["one_minus_dest_alpha"] = ID_ONE_MINUS_DEST_ALPHA;
 66         mIds["one_minus_src_alpha"] = ID_ONE_MINUS_SRC_ALPHA;
 67         mIds["separate_scene_blend"] = ID_SEPARATE_SCENE_BLEND;
 68         mIds["scene_blend_op"] = ID_SCENE_BLEND_OP;
 69         mIds["reverse_subtract"] = ID_REVERSE_SUBTRACT;
 70         mIds["min"] = ID_MIN;
 71         mIds["max"] = ID_MAX;
 72         mIds["separate_scene_blend_op"] = ID_SEPARATE_SCENE_BLEND_OP;
 73         mIds["depth_check"] = ID_DEPTH_CHECK;
 74         mIds["depth_write"] = ID_DEPTH_WRITE;
 75         mIds["depth_func"] = ID_DEPTH_FUNC;
 76         mIds["depth_bias"] = ID_DEPTH_BIAS;
 77         mIds["iteration_depth_bias"] = ID_ITERATION_DEPTH_BIAS;
 78         mIds["always_fail"] = ID_ALWAYS_FAIL;
 79         mIds["always_pass"] = ID_ALWAYS_PASS;
 80         mIds["less_equal"] = ID_LESS_EQUAL;
 81         mIds["less"] = ID_LESS;
 82         mIds["equal"] = ID_EQUAL;
 83         mIds["not_equal"] = ID_NOT_EQUAL;
 84         mIds["greater_equal"] = ID_GREATER_EQUAL;
 85         mIds["greater"] = ID_GREATER;
 86         mIds["alpha_rejection"] = ID_ALPHA_REJECTION;
 87         mIds["alpha_to_coverage"] = ID_ALPHA_TO_COVERAGE;
 88         mIds["light_scissor"] = ID_LIGHT_SCISSOR;
 89         mIds["light_clip_planes"] = ID_LIGHT_CLIP_PLANES;
 90         mIds["transparent_sorting"] = ID_TRANSPARENT_SORTING;
 91         mIds["illumination_stage"] = ID_ILLUMINATION_STAGE;
 92         mIds["decal"] = ID_DECAL;
 93         mIds["cull_hardware"] = ID_CULL_HARDWARE;
 94         mIds["clockwise"] = ID_CLOCKWISE;
 95         mIds["anticlockwise"] = ID_ANTICLOCKWISE;
 96         mIds["cull_software"] = ID_CULL_SOFTWARE;
 97         mIds["back"] = ID_BACK;
 98         mIds["front"] = ID_FRONT;
 99         mIds["normalise_normals"] = ID_NORMALISE_NORMALS;
100         mIds["lighting"] = ID_LIGHTING;
101         mIds["shading"] = ID_SHADING;
102         mIds["flat"] = ID_FLAT;
103         mIds["gouraud"] = ID_GOURAUD;
104         mIds["phong"] = ID_PHONG;
105         mIds["polygon_mode"] = ID_POLYGON_MODE;
106         mIds["solid"] = ID_SOLID;
107         mIds["wireframe"] = ID_WIREFRAME;
108         mIds["points"] = ID_POINTS;
109         mIds["polygon_mode_overrideable"] = ID_POLYGON_MODE_OVERRIDEABLE;
110         mIds["fog_override"] = ID_FOG_OVERRIDE;
111         mIds["none"] = ID_NONE;
112         mIds["linear"] = ID_LINEAR;
113         mIds["exp"] = ID_EXP;
114         mIds["exp2"] = ID_EXP2;
115         mIds["colour_write"] = ID_COLOUR_WRITE;
116         mIds["max_lights"] = ID_MAX_LIGHTS;
117         mIds["start_light"] = ID_START_LIGHT;
118         mIds["iteration"] = ID_ITERATION;
119         mIds["once"] = ID_ONCE;
120         mIds["once_per_light"] = ID_ONCE_PER_LIGHT;
121         mIds["per_n_lights"] = ID_PER_N_LIGHTS;
122         mIds["per_light"] = ID_PER_LIGHT;
123         mIds["point"] = ID_POINT;
124         mIds["spot"] = ID_SPOT;
125         mIds["directional"] = ID_DIRECTIONAL;
126         mIds["light_mask"] = ID_LIGHT_MASK;
127         mIds["point_size"] = ID_POINT_SIZE;
128         mIds["point_sprites"] = ID_POINT_SPRITES;
129         mIds["point_size_min"] = ID_POINT_SIZE_MIN;
130         mIds["point_size_max"] = ID_POINT_SIZE_MAX;
131         mIds["point_size_attenuation"] = ID_POINT_SIZE_ATTENUATION;
132 
133         mIds["texture_alias"] = ID_TEXTURE_ALIAS;
134         mIds["texture"] = ID_TEXTURE;
135         mIds["1d"] = ID_1D;
136         mIds["2d"] = ID_2D;
137         mIds["3d"] = ID_3D;
138         mIds["cubic"] = ID_CUBIC;
139         mIds["unlimited"] = ID_UNLIMITED;
140         mIds["alpha"] = ID_ALPHA;
141         mIds["gamma"] = ID_GAMMA;
142         mIds["anim_texture"] = ID_ANIM_TEXTURE;
143         mIds["cubic_texture"] = ID_CUBIC_TEXTURE;
144         mIds["separateUV"] = ID_SEPARATE_UV;
145         mIds["combinedUVW"] = ID_COMBINED_UVW;
146         mIds["tex_coord_set"] = ID_TEX_COORD_SET;
147         mIds["tex_address_mode"] = ID_TEX_ADDRESS_MODE;
148         mIds["wrap"] = ID_WRAP;
149         mIds["clamp"] = ID_CLAMP;
150         mIds["mirror"] = ID_MIRROR;
151         mIds["border"] = ID_BORDER;
152         mIds["tex_border_colour"] = ID_TEX_BORDER_COLOUR;
153         mIds["filtering"] = ID_FILTERING;
154         mIds["bilinear"] = ID_BILINEAR;
155         mIds["trilinear"] = ID_TRILINEAR;
156         mIds["anisotropic"] = ID_ANISOTROPIC;
157         mIds["max_anisotropy"] = ID_MAX_ANISOTROPY;
158         mIds["mipmap_bias"] = ID_MIPMAP_BIAS;
159         mIds["colour_op"] = ID_COLOUR_OP;
160         mIds["replace"] = ID_REPLACE;
161         mIds["add"] = ID_ADD;
162         mIds["modulate"] = ID_MODULATE;
163         mIds["alpha_blend"] = ID_ALPHA_BLEND;
164         mIds["colour_op_ex"] = ID_COLOUR_OP_EX;
165         mIds["source1"] = ID_SOURCE1;
166         mIds["source2"] = ID_SOURCE2;
167         mIds["modulate"] = ID_MODULATE;
168         mIds["modulate_x2"] = ID_MODULATE_X2;
169         mIds["modulate_x4"] = ID_MODULATE_X4;
170         mIds["add"] = ID_ADD;
171         mIds["add_signed"] = ID_ADD_SIGNED;
172         mIds["add_smooth"] = ID_ADD_SMOOTH;
173         mIds["subtract"] = ID_SUBTRACT;
174         mIds["blend_diffuse_alpha"] = ID_BLEND_DIFFUSE_ALPHA;
175         mIds["blend_texture_alpha"] = ID_BLEND_TEXTURE_ALPHA;
176         mIds["blend_current_alpha"] = ID_BLEND_CURRENT_ALPHA;
177         mIds["blend_manual"] = ID_BLEND_MANUAL;
178         mIds["dotproduct"] = ID_DOT_PRODUCT;
179         mIds["blend_diffuse_colour"] = ID_BLEND_DIFFUSE_COLOUR;
180         mIds["src_current"] = ID_SRC_CURRENT;
181         mIds["src_texture"] = ID_SRC_TEXTURE;
182         mIds["src_diffuse"] = ID_SRC_DIFFUSE;
183         mIds["src_specular"] = ID_SRC_SPECULAR;
184         mIds["src_manual"] = ID_SRC_MANUAL;
185         mIds["colour_op_multipass_fallback"] = ID_COLOUR_OP_MULTIPASS_FALLBACK;
186         mIds["alpha_op_ex"] = ID_ALPHA_OP_EX;
187         mIds["env_map"] = ID_ENV_MAP;
188         mIds["spherical"] = ID_SPHERICAL;
189         mIds["planar"] = ID_PLANAR;
190         mIds["cubic_reflection"] = ID_CUBIC_REFLECTION;
191         mIds["cubic_normal"] = ID_CUBIC_NORMAL;
192         mIds["scroll"] = ID_SCROLL;
193         mIds["scroll_anim"] = ID_SCROLL_ANIM;
194         mIds["rotate"] = ID_ROTATE;
195         mIds["rotate_anim"] = ID_ROTATE_ANIM;
196         mIds["scale"] = ID_SCALE;
197         mIds["wave_xform"] = ID_WAVE_XFORM;
198         mIds["scroll_x"] = ID_SCROLL_X;
199         mIds["scroll_y"] = ID_SCROLL_Y;
200         mIds["scale_x"] = ID_SCALE_X;
201         mIds["scale_y"] = ID_SCALE_Y;
202         mIds["sine"] = ID_SINE;
203         mIds["triangle"] = ID_TRIANGLE;
204         mIds["sawtooth"] = ID_SAWTOOTH;
205         mIds["square"] = ID_SQUARE;
206         mIds["inverse_sawtooth"] = ID_INVERSE_SAWTOOTH;
207         mIds["transform"] = ID_TRANSFORM;
208         mIds["binding_type"] = ID_BINDING_TYPE;
209         mIds["vertex"] = ID_VERTEX;
210         mIds["fragment"] = ID_FRAGMENT;
211         mIds["content_type"] = ID_CONTENT_TYPE;
212         mIds["named"] = ID_NAMED;
213         mIds["shadow"] = ID_SHADOW;
214         mIds["texture_source"] = ID_TEXTURE_SOURCE;
215         mIds["shared_params"] = ID_SHARED_PARAMS;
216         mIds["shared_param_named"] = ID_SHARED_PARAM_NAMED;
217         mIds["shared_params_ref"] = ID_SHARED_PARAMS_REF;
218 
219         // Particle system
220         mIds["particle_system"] = ID_PARTICLE_SYSTEM;
221         mIds["emitter"] = ID_EMITTER;
222         mIds["affector"] = ID_AFFECTOR;
223 
224         // Compositor
225         mIds["compositor"] = ID_COMPOSITOR;
226         mIds["target"] = ID_TARGET;
227         mIds["target_output"] = ID_TARGET_OUTPUT;
228 
229         mIds["input"] = ID_INPUT;
230         mIds["none"] = ID_NONE;
231         mIds["previous"] = ID_PREVIOUS;
232         mIds["target_width"] = ID_TARGET_WIDTH;
233         mIds["target_height"] = ID_TARGET_HEIGHT;
234         mIds["target_width_scaled"] = ID_TARGET_WIDTH_SCALED;
235         mIds["target_height_scaled"] = ID_TARGET_HEIGHT_SCALED;
236         mIds["pooled"] = ID_POOLED;
237         //mIds["gamma"] = ID_GAMMA; - already registered
238         mIds["no_fsaa"] = ID_NO_FSAA;
239         mIds["depth_pool"] = ID_DEPTH_POOL;
240 
241         mIds["texture_ref"] = ID_TEXTURE_REF;
242         mIds["local_scope"] = ID_SCOPE_LOCAL;
243         mIds["chain_scope"] = ID_SCOPE_CHAIN;
244         mIds["global_scope"] = ID_SCOPE_GLOBAL;
245         mIds["compositor_logic"] = ID_COMPOSITOR_LOGIC;
246             
247         mIds["only_initial"] = ID_ONLY_INITIAL;
248         mIds["visibility_mask"] = ID_VISIBILITY_MASK;
249         mIds["lod_bias"] = ID_LOD_BIAS;
250         mIds["material_scheme"] = ID_MATERIAL_SCHEME;
251         mIds["shadows"] = ID_SHADOWS_ENABLED;
252 
253         mIds["clear"] = ID_CLEAR;
254         mIds["stencil"] = ID_STENCIL;
255         mIds["render_scene"] = ID_RENDER_SCENE;
256         mIds["render_quad"] = ID_RENDER_QUAD;
257         mIds["identifier"] = ID_IDENTIFIER;
258         mIds["first_render_queue"] = ID_FIRST_RENDER_QUEUE;
259         mIds["last_render_queue"] = ID_LAST_RENDER_QUEUE;
260         mIds["quad_normals"] = ID_QUAD_NORMALS;
261         mIds["camera_far_corners_view_space"] = ID_CAMERA_FAR_CORNERS_VIEW_SPACE;
262         mIds["camera_far_corners_world_space"] = ID_CAMERA_FAR_CORNERS_WORLD_SPACE;
263 
264         mIds["buffers"] = ID_BUFFERS;
265         mIds["colour"] = ID_COLOUR;
266         mIds["depth"] = ID_DEPTH;
267         mIds["colour_value"] = ID_COLOUR_VALUE;
268         mIds["depth_value"] = ID_DEPTH_VALUE;
269         mIds["stencil_value"] = ID_STENCIL_VALUE;
270 
271         mIds["check"] = ID_CHECK;
272         mIds["comp_func"] = ID_COMP_FUNC;
273         mIds["ref_value"] = ID_REF_VALUE;
274         mIds["mask"] = ID_MASK;
275         mIds["fail_op"] = ID_FAIL_OP;
276         mIds["keep"] = ID_KEEP;
277         mIds["increment"] = ID_INCREMENT;
278         mIds["decrement"] = ID_DECREMENT;
279         mIds["increment_wrap"] = ID_INCREMENT_WRAP;
280         mIds["decrement_wrap"] = ID_DECREMENT_WRAP;
281         mIds["invert"] = ID_INVERT;
282         mIds["depth_fail_op"] = ID_DEPTH_FAIL_OP;
283         mIds["pass_op"] = ID_PASS_OP;
284         mIds["two_sided"] = ID_TWO_SIDED;
285 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
286         mIds["rtshader_system"] = ID_RT_SHADER_SYSTEM;
287 #endif
288     }

    可以看到,mIds容器主要用于将脚本文件中的关键字映射到相关的枚举变量上,并保存这种对应关系。

    脚本文件的解析,在完成了之前的三个阶段后,Ogre将会根据解析所得的脚本文件类型和结构来创建脚本数据对象,读取相应的脚本数据。为此,Ogre还引入了ScriptTranslator类型,并定义了以下类型MaterialTranslator、TechniqueTranslator、PassTranslator、TextureUnitTranslator、TextureSourceTranslator、GpuProgramTranslator、SharedParamsTranslator、ParticleSystemTranslator、ParticleEmitterTranslator、ParticleAffectorTranslator、CompositorTranslator、CompositionTechniqueTranslator、CompositionTargetPassTranslator和CompositionPassTranslator作为ScriptTranslator类的派生类。这些ScriptTranslator类对象实例由ScriptTranslatorManager来管理。ScriptTranslatorManager作为ScriptCompilerManager的成员变量被保存,其在ScriptCompilerManager中相应的成员变量的定义为:

1         // Stores a map from object types to the translators that handle them
2         vector<ScriptTranslatorManager*>::type mManagers;
3 
4         // A pointer to the built-in ScriptTranslatorManager
5         ScriptTranslatorManager *mBuiltinTranslatorManager;

    Ogre并不是直接对ScriptTranslatorManager进行实例化并加以保存;而是以ScriptTranslatorManager为基类,定义一个派生类——BuiltinScriptTranslatorManager,然后将创建的BuiltinScriptTranslatorManager的对象指针保存在ScriptCompilerManager中,BuiltinScriptTranslatorManager定义如下:

 1     class _OgreExport BuiltinScriptTranslatorManager : public ScriptTranslatorManager
 2     {
 3     private:
 4         MaterialTranslator mMaterialTranslator;
 5         TechniqueTranslator mTechniqueTranslator;
 6         PassTranslator mPassTranslator;
 7         TextureUnitTranslator mTextureUnitTranslator;
 8         TextureSourceTranslator mTextureSourceTranslator;
 9         GpuProgramTranslator mGpuProgramTranslator;
10         SharedParamsTranslator mSharedParamsTranslator;
11         ParticleSystemTranslator mParticleSystemTranslator;
12         ParticleEmitterTranslator mParticleEmitterTranslator;
13         ParticleAffectorTranslator mParticleAffectorTranslator;
14         CompositorTranslator mCompositorTranslator;
15         CompositionTechniqueTranslator mCompositionTechniqueTranslator;
16         CompositionTargetPassTranslator mCompositionTargetPassTranslator;
17         CompositionPassTranslator mCompositionPassTranslator;
18     public:
19         BuiltinScriptTranslatorManager();
20         /// Returns the number of translators being managed
21         virtual size_t getNumTranslators() const;
22         /// Returns a manager for the given object abstract node, or null if it is not supported
23         virtual ScriptTranslator *getTranslator(const AbstractNodePtr &node);
24     };

    可以看到,BuiltinScriptTranslatorManager一旦被创建,之前所说的各ScriptTranslator派生类对象将被自动创建。通过BuiltinScriptTranslatorManager就可以方便地引用当前需要的ScriptTranslator对象来对脚本数据进行解读。

    ScriptCompilerManager在其构造函数中创建ScriptCompiler对象实例之后,紧接着会创建BuiltinScriptTranslatorManager对象实例,并将对象指针保存在mBuiltinTranslatorManager中,同时在mManagers容器内作一个备份。

    通过ScriptCompiler实例对象和BuiltinScriptTranslatorManager实例对象的创建,ScriptCompilerManager为保存在脚本对象中的脚本数据的解析,作好了准备。

 

 

 

posted on 2013-01-20 16:35  yzwalkman  阅读(1203)  评论(0编辑  收藏  举报