소스 검색

Added globalVars VariantMap to AngelScript API which can be used to share data between script modules or persist data through script reloads.

Lasse Öörni 10 년 전
부모
커밋
6f01d1cac9
4개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      Docs/Reference.dox
  2. 2 0
      Source/Urho3D/Script/Script.cpp
  3. 3 0
      Source/Urho3D/Script/Script.h
  4. 1 0
      Source/Urho3D/Script/ScriptAPI.cpp

+ 3 - 1
Docs/Reference.dox

@@ -636,7 +636,9 @@ There are some complexities of the scripting system one has to watch out for:
 
 - When the resource request for a particular ScriptFile is initially made, the script file and the files it includes are compiled into an AngelScript script module. Each script module has its own class hierarchy that is not usable from other script modules, unless the classes are declared shared. See AngelScript documentation for more details.
 
-- If a ScriptFile resource is reloaded, all the script objects created from it will be destroyed, then recreated. They will lose any stored state as their constructors and Start() methods will be run again. This is rarely useful when running an actual game, but may be helpful during development.
+- If a ScriptFile resource is reloaded, all the script objects created from it will be destroyed, then recreated. They will lose any stored state as their constructors and Start() methods will be run again. This is rarely useful when running an actual game, but may be helpful during development. 
+
+A global VariantMap, globalVars, can be accessed by all scripts to store shared data or to preserve data through script file reloads.
 
 \section Scripting_Modifications AngelScript modifications
 

+ 2 - 0
Source/Urho3D/Script/Script.cpp

@@ -65,6 +65,8 @@ class ScriptResourceRouter : public ResourceRouter
     }
 };
 
+VariantMap Script::globalVars;
+
 Script::Script(Context* context) :
     Object(context),
     scriptEngine_(0),

+ 3 - 0
Source/Urho3D/Script/Script.h

@@ -102,6 +102,9 @@ public:
     /// Return the script module create/delete mutex.
     Mutex& GetModuleMutex() { return moduleMutex_; }
 
+    /// Variant map for global variables that can persist through a script program reload.
+    static VariantMap globalVars;
+
 private:
     /// Increase script nesting level.
     void IncScriptNestingLevel() { ++scriptNestingLevel_; }

+ 1 - 0
Source/Urho3D/Script/ScriptAPI.cpp

@@ -276,6 +276,7 @@ static void RegisterScript(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Script", "void set_executeConsoleCommands(bool)", asMETHOD(Script, SetExecuteConsoleCommands), asCALL_THISCALL);
     engine->RegisterObjectMethod("Script", "bool get_executeConsoleCommands() const", asMETHOD(Script, GetExecuteConsoleCommands), asCALL_THISCALL);
     engine->RegisterGlobalFunction("Script@+ get_script()", asFUNCTION(GetScript), asCALL_CDECL);
+    engine->RegisterGlobalProperty("VariantMap globalVars", &Script::globalVars);
 }
 
 static void RegisterScriptObject(asIScriptEngine* engine)