00001 // ///////////////////////////////////////////////////////////////////////////// 00002 // 00003 // Name: ScriptManager.h 00004 // Author: Michael Bartsch (ZCCdark203) 00005 // 00006 // Desc : Declaration of the ScriptManager class. 00007 // 00008 // License: Copyright (C) 2009 Michael Bartsch and Contributors 00009 // 00010 // This program is free software: you can redistribute it 00011 // and/or modify it under the terms of the zlib/libpng License. 00012 // See main.cpp for conditions of distribution and use. 00013 // 00014 // ///////////////////////////////////////////////////////////////////////////// 00015 00016 #ifndef __SCRIPTMANAGER_H__ 00017 #define __SCRIPTMANAGER_H__ 00018 00019 // Include files 00020 #include "../dependencies.h" 00021 #include "../core/ReferenceCounted.h" 00022 00023 #ifdef __COMPILE_WITH_ANGELSCRIPT__ 00024 00025 #include "Script.h" 00026 00027 // Forward declarations. 00028 class Script; 00029 00030 00031 // ScriptManager class 00034 class ScriptManager : public ReferenceCounted 00035 { 00036 friend class Script; 00037 00038 public: 00039 00040 // Initialisation and deinitialisation 00042 ScriptManager(); 00044 ~ScriptManager(); 00045 00047 void init(); 00049 void clear(); 00050 00051 // Reference counting 00054 void grab(); 00057 void drop(); 00058 00059 // Methods 00062 asIScriptEngine* getEngine() const; 00063 00067 bool addScript(Script *script); 00068 00073 bool addScriptSection(const std::string &name, const std::string §ion); 00074 00079 Script* createScript(const std::string &name, bool grab = true); 00084 Script* createScriptFromFile(const std::string &fileName, bool grab = true); 00089 Script* createScriptFromFile(IReadFile *file, bool grab = true); 00090 00093 Script* getScript(const u32 id); 00096 Script* getScript(const std::string &name); 00097 00099 void removeScripts(); 00101 void removeScriptSections(); 00105 bool removeScript(Script *script); 00109 bool removeScript(const u32 id); 00113 bool removeScript(const std::string &name); 00116 bool removeScriptSection(const std::string &name); 00117 00118 private: 00119 00120 // Private methods. 00121 void addScriptSectionsToScript(Script *script); 00122 00123 // Private members 00124 asIScriptEngine *pEngine; 00125 00126 std::vector<Script*> mScripts; 00127 std::map<std::string, std::string> mScriptSections; 00128 }; 00129 00130 00131 // AngelScript functions 00133 extern void MessageCallback(const asSMessageInfo *msg, void *param); 00134 00135 #endif // __COMPILE_WITH_ANGELSCRIPT__ 00136 00137 #endif