Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_TOOL_SCRIPTLOADER_H__
00009 #define __SP_TOOL_SCRIPTLOADER_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_SCRIPTLOADER
00015
00016
00017 #include "Base/spInputOutputString.hpp"
00018 #include "Base/spInputOutputFileSystem.hpp"
00019 #include "RenderSystem/spTextureBase.hpp"
00020 #include "SoundSystem/spSoundDevice.hpp"
00021 #include "SceneGraph/spSceneGraph.hpp"
00022
00023 #include <list>
00024 #include <vector>
00025
00026
00027 namespace sp
00028 {
00029 namespace tool
00030 {
00031
00032
00046 class SP_EXPORT ScriptLoader
00047 {
00048
00049 public:
00050
00051 ScriptLoader(scene::SceneGraph* ActiveSceneGraph = 0, audio::SoundDevice* ActiveSoundDevice = 0);
00052 virtual ~ScriptLoader();
00053
00054
00055
00057 virtual io::stringc getVersion() const;
00058
00064 bool loadScriptFile(const io::stringc &Filename);
00065
00066 void setConstant(const io::stringc &Name, const io::stringc &Value);
00067
00068
00069
00070 inline std::vector<video::Texture*> getTextureList() const
00071 {
00072 return Textures_.List;
00073 }
00074 inline std::vector<audio::Sound*> getSoundList() const
00075 {
00076 return Sounds_.List;
00077 }
00078 inline std::vector<scene::SceneNode*> getNodeList() const
00079 {
00080 return Nodes_.List;
00081 }
00082 inline std::vector<scene::Mesh*> getMeshList() const
00083 {
00084 return Meshes_.List;
00085 }
00086 inline std::vector<scene::Camera*> getCameraList() const
00087 {
00088 return Cameras_.List;
00089 }
00090 inline std::vector<scene::Light*> getLightList() const
00091 {
00092 return Lights_.List;
00093 }
00094 inline std::vector<scene::Billboard*> getBillboardList() const
00095 {
00096 return Billboards_.List;
00097 }
00098
00099 virtual void clearLists();
00100
00101 protected:
00102
00103
00104
00105 enum ECommandTypes
00106 {
00107 CMD_NONE = 0x00,
00108 CMD_DIRECT = 0x01,
00109 CMD_MACRO = 0x02,
00110 CMD_FORLOOP = 0x04,
00111 CMD_BLOCK = 0x08,
00112 CMD_ACCESS = 0x10,
00113 CMD_ALL = CMD_DIRECT | CMD_MACRO | CMD_FORLOOP | CMD_BLOCK | CMD_ACCESS
00114 };
00115
00116
00117
00118 struct SCommand
00119 {
00120 SCommand() : Type(CMD_NONE)
00121 {
00122 }
00123 ~SCommand()
00124 {
00125 }
00126
00127 ECommandTypes Type;
00128 io::stringc Name;
00129 };
00130
00131 struct SVector
00132 {
00133 dim::point2df vec2;
00134 dim::vector3df vec3;
00135 dim::vector4df vec4;
00136 video::color clr;
00137 };
00138
00139 struct SParameter
00140 {
00141 SParameter() : Used(false)
00142 {
00143 }
00144 ~SParameter()
00145 {
00146 }
00147
00148 bool Used;
00149 s32 Components;
00150 io::stringc Name;
00151 io::stringc StrValue;
00152 SVector VecValue;
00153 s32 IntValue;
00154 f32 FltValue;
00155 bool BitValue;
00156 };
00157
00158 struct SAnimationFrame
00159 {
00160 dim::vector3df Pos, Scl;
00161 dim::quaternion Rot;
00162 f32 Speed;
00163 };
00164
00165 struct SAnimation
00166 {
00167 bool Used;
00168 bool Splines;
00169 io::stringc Play;
00170 f32 Speed;
00171 f32 SplineExpansion;
00172 std::list<SAnimationFrame> Frames;
00173 };
00174
00175 struct SLoopRange
00176 {
00177 u32 FilePos, FileLine;
00178 u32 Index, MaxIndex;
00179 };
00180
00181 template <class T> struct SContainer
00182 {
00183 s32 EnumIndex;
00184 std::vector<T*> List;
00185 std::map<io::stringc, T*> Map;
00186 };
00187
00188
00189
00190 bool readScript();
00191
00192 io::stringc readNextLine();
00193 bool checkEOF() const;
00194 bool readLine();
00195
00196 void cropLineInside(s32 BeginPos, s32 EndPos);
00197 void cropLineOutside(s32 BeginPos, s32 EndPos);
00198
00199 s32 readString(io::stringc &Str, s32 BeginPos = 0) const;
00200
00201 SCommand readNextCommand(s32 AllowedCommands = CMD_ALL) const;
00202 bool readNextParameter(SParameter &Param, s32 BeginPos = 0);
00203 bool readNextParameterValue(SParameter &Param, io::stringc &CurLineContext);
00204
00205 io::stringc getLinesIndicate() const;
00206 void printErrorLI(const io::stringc &Message) const;
00207 void printWarningLI(const io::stringc &Message) const;
00208
00209 bool readCommandDirect();
00210 bool readCommandMacro();
00211 bool readCommandForLoop();
00212 bool readCommandBlock();
00213 bool readCommandAccess();
00214
00215 bool isParam(const io::stringc &Name);
00216
00217 virtual bool examineBlockNode();
00218 virtual bool examineBlockMesh();
00219 virtual bool examineBlockLight();
00220 virtual bool examineBlockCamera();
00221 virtual bool examineBlockBillboard();
00222 virtual bool examineBlockTerrain();
00223 virtual bool examineBlockTexture();
00224 virtual bool examineBlockSound();
00225 virtual bool examineBlockShader();
00226 virtual bool examineBlockAnim();
00227 virtual bool examineBlockFrame();
00228 virtual bool examineBlockSurface();
00229 virtual bool examineBlockVertex();
00230 virtual bool examineBlockTriangle();
00231
00232 bool examineBlockNode(scene::SceneNode* Obj);
00233 bool examineBlockMaterialNode(scene::MaterialNode* Obj);
00234
00235 void applyAnimation(scene::SceneNode* Obj);
00236 void applySurfaces(scene::Mesh* Obj);
00237
00238
00239
00240 io::FileSystem FileSys_;
00241 io::File* File_;
00242
00243 scene::SceneGraph* ActiveSceneGraph_;
00244 audio::SoundDevice* ActiveSoundDevice_;
00245
00246
00247 SContainer<video::Texture> Textures_;
00248 SContainer<audio::Sound> Sounds_;
00249 SContainer<scene::SceneNode> Nodes_;
00250 SContainer<scene::Mesh> Meshes_;
00251 SContainer<scene::Camera> Cameras_;
00252 SContainer<scene::Light> Lights_;
00253 SContainer<scene::Billboard> Billboards_;
00254
00255 std::map<std::string, io::stringc> UniformMap_;
00256 std::map<std::string, SParameter> VariableMap_;
00257 std::map<std::string, bool> InternalUniformMap_;
00258
00259
00260 io::stringc Line_, Trimed_;
00261 u32 CurLineNr_;
00262
00263 std::map<std::string, SLoopRange> LoopMap_;
00264
00265
00266 SCommand CurCommand_;
00267 std::map<std::string, SParameter> ParamMap_;
00268 SParameter CurParam_;
00269
00270 std::map<std::string, scene::SceneNode*> NodeMap_;
00271 std::map<std::string, video::Texture*> TextureMap_;
00272
00273
00274 io::stringc WorkDir_;
00275
00276 SAnimation CurAnim_;
00277
00278 video::MeshBuffer* CurSurface_;
00279 std::list<video::MeshBuffer*> CurSurfaceList_;
00280
00281 };
00282
00283
00284 }
00285
00286 }
00287
00288
00289 #endif
00290
00291 #endif
00292
00293
00294
00295