00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef __SP_TOOL_SCRIPTFRAMEWORK_H__
00009 #define __SP_TOOL_SCRIPTFRAMEWORK_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 <map>
00025 #include <vector>
00026 
00027 
00028 namespace sp
00029 {
00030 namespace tool
00031 {
00032 
00033 
00035 class SP_EXPORT ScriptFramework
00036 {
00037     
00038     public:
00039         
00040         ScriptFramework(scene::SceneGraph* ActiveSceneGraph = 0, audio::SoundDevice* ActiveSoundDevice = 0);
00041         virtual ~ScriptFramework();
00042         
00043         
00044         
00046         virtual io::stringc getVersion() const;
00047         
00053         bool loadScriptFile(const io::stringc &Filename);
00054         
00055         virtual void updateFramework();
00056         
00057         virtual void clearLists();
00058         
00059         
00060         
00061         inline std::vector<video::Texture*> getTextureList() const
00062         {
00063             return Textures_.List;
00064         }
00065         inline std::vector<audio::Sound*> getSoundList() const
00066         {
00067             return Sounds_.List;
00068         }
00069         inline std::vector<scene::SceneNode*> getNodeList() const
00070         {
00071             return Nodes_.List;
00072         }
00073         inline std::vector<scene::Mesh*> getMeshList() const
00074         {
00075             return Meshes_.List;
00076         }
00077         inline std::vector<scene::Camera*> getCameraList() const
00078         {
00079             return Cameras_.List;
00080         }
00081         inline std::vector<scene::Light*> getLightList() const
00082         {
00083             return Lights_.List;
00084         }
00085         inline std::vector<scene::Billboard*> getBillboardList() const
00086         {
00087             return Billboards_.List;
00088         }
00089         
00090     protected:
00091         
00092         
00093         
00094         static const c8* ERRORMSG_WRONGTOKEN;
00095         
00096         
00097         
00098         enum ETokens
00099         {
00100             TOKEN_UNKNOWN,
00101             TOKEN_STRING,       
00102             TOKEN_INTEGER,      
00103             TOKEN_FLOAT,        
00104             TOKEN_SEMICOLON,    
00105             TOKEN_POINT,        
00106             TOKEN_COMMA,        
00107             TOKEN_DOUBLEPOINT,  
00108             TOKEN_QUOTE,        
00109             TOKEN_COMMENT,      
00110             TOKEN_COMMENT_MS,   
00111             TOKEN_COMMENT_ME,   
00112             TOKEN_SLASH,        
00113             TOKEN_BACKSLASH,    
00114             TOKEN_STAR,         
00115             TOKEN_PLUS,         
00116             TOKEN_MINUS,        
00117             TOKEN_EQUAL,        
00118             TOKEN_HASHKEY,      
00119             TOKEN_QUESTION,     
00120             TOKEN_BLANK,        
00121             TOKEN_BRACKET_SS,   
00122             TOKEN_BRACKET_SE,   
00123             TOKEN_BRACKET_CS,   
00124             TOKEN_BRACKET_CE,   
00125             TOKEN_BRACKET_NS,   
00126             TOKEN_BRACKET_NE,   
00127         };
00128         
00129         enum EKeywords
00130         {
00131             KEYWORD_UNKNOWN,
00132             KEYWORD_COMMAND,            
00133             KEYWORD_VECTOR_BEGIN,       
00134             KEYWORD_VECTOR_END,         
00135             KEYWORD_VARIABLE,           
00136             KEYWORD_CLASS,              
00137             KEYWORD_BLOCK,              
00138             KEYWORD_MEMBER,             
00139             KEYWORD_ACCESS,             
00140             KEYWORD_ATTRIBUTE,          
00141             KEYWORD_CONSTRUCT_END,      
00142             KEYWORD_STRING,             
00143             KEYWORD_INTEGER,            
00144             KEYWORD_FLOAT,              
00145             KEYWORD_BOOLEAN,            
00146             KEYWORD_LOOP_BEGIN,         
00147             KEYWORD_LOOP_END,           
00148             KEYWORD_LOOP_FROM,          
00149             KEYWORD_LOOP_TO,            
00150             KEYWORD_LOOP_STEP,          
00151             KEYWORD_OPERATOR,           
00152         };
00153         
00154         
00155         
00156         struct SValue
00157         {
00158             SValue()
00159                 : Integer(0), Float(0.0f)
00160             {
00161             }
00162             SValue(s32 Value)
00163                 : Integer(Value), Float(static_cast<f32>(Value)), Str(Value)
00164             {
00165             }
00166             SValue(f32 Value)
00167                 : Integer(static_cast<s32>(Value)), Float(Value), Str(Value)
00168             {
00169             }
00170             SValue(const io::stringc &String)
00171                 : Integer(String.val<s32>()), Float(String.val<f32>()), Str(String)
00172             {
00173             }
00174             SValue(s32 ValueInt, f32 ValueFlt, const io::stringc &String)
00175                 : Integer(ValueInt), Float(ValueFlt), Str(String)
00176             {
00177             }
00178             ~SValue()
00179             {
00180             }
00181             
00182             
00183             SValue& operator += (const SValue &other)
00184             {
00185                 Integer += other.Integer;
00186                 Float   += other.Float;
00187                 Str     += other.Str;
00188                 return *this;
00189             }
00190             SValue& operator -= (const SValue &other)
00191             {
00192                 Integer -= other.Integer;
00193                 Float   -= other.Float;
00194                 return *this;
00195             }
00196             SValue& operator *= (const SValue &other)
00197             {
00198                 Integer *= other.Integer;
00199                 Float   *= other.Float;
00200                 return *this;
00201             }
00202             SValue& operator /= (const SValue &other)
00203             {
00204                 if (other.Integer)
00205                     Integer /= other.Integer;
00206                 Float /= other.Float;
00207                 return *this;
00208             }
00209             
00210             
00211             void Operator(const SValue &other, c8 Op)
00212             {
00213                 switch (Op)
00214                 {
00215                     case '+': *this += other; break;
00216                     case '-': *this -= other; break;
00217                     case '*': *this *= other; break;
00218                     case '/': *this /= other; break;
00219                 }
00220             }
00221             
00222             
00223             s32 Integer;
00224             f32 Float;
00225             io::stringc Str;
00226         };
00227         
00228         struct SVector
00229         {
00230             dim::point2df vec2() const;
00231             dim::vector3df vec3() const;
00232             dim::vector4df vec4() const;
00233             video::color clr() const;
00234             
00235             std::vector<SValue> List;
00236         };
00237         
00238         template <class T> struct SContainer
00239         {
00240             s32 EnumIndex;
00241             std::vector<T*> List;
00242             std::map<io::stringc, T*> Map;
00243         };
00244         
00245         
00246         
00247         c8 readNextChar();
00248         void decrementFilePos();
00249         
00250         ETokens readNextToken(bool OnlySingleChar = false);
00251         
00252         EKeywords readNextKeyword();
00253         
00254         bool readScript();
00255         bool readCommand();
00256         bool readVector();
00257         bool readClass();
00258         bool readBlock();
00259         bool readLoopBegin();
00260         bool readLoopEnd();
00261         bool readVariable();
00262         bool readValue(SValue &Value);
00263         
00264         bool printError(const io::stringc &Message);
00265         void printWarning(const io::stringc &Message);
00266         
00267         bool getAccessMember(const io::stringc &Name);
00268         
00269         
00270         
00271         io::FileSystem FileSys_;
00272         io::File* File_;
00273         
00274         scene::SceneGraph* ActiveSceneGraph_;
00275         audio::SoundDevice* ActiveSoundDevice_;
00276         
00277         
00278         SContainer<video::Texture>      Textures_;
00279         SContainer<audio::Sound>        Sounds_;
00280         SContainer<scene::SceneNode>    Nodes_;
00281         SContainer<scene::Mesh>         Meshes_;
00282         SContainer<scene::Camera>       Cameras_;
00283         SContainer<scene::Light>        Lights_;
00284         SContainer<scene::Billboard>    Billboards_;
00285         
00286         
00287         io::stringc CurLine_;
00288         u32 CurColumnNr_;
00289         u32 CurLineNr_;
00290         std::list<io::stringc> LineList_;
00291         
00292         c8 CurChar_;
00293         
00294         ETokens CurToken_;
00295         io::stringc StrToken_;
00296         s32 IntToken_;
00297         f32 FltToken_;
00298         
00299         EKeywords CurKeyword_;
00300         io::stringc StrKeyword_, Str2Keyword_;
00301         c8 OperatorType_;
00302         
00303         
00304         io::stringc WorkDir_;
00305         
00306 };
00307 
00308 
00309 } 
00310 
00311 } 
00312 
00313 
00314 #endif
00315 
00316 #endif
00317 
00318 
00319 
00320