- Timestamp:
- 05/24/18 20:08:56 (7 years ago)
- Location:
- ps/trunk/source/ps
- Files:
-
- 5 edited
-
GameSetup/GameSetup.cpp (modified) (2 diffs)
-
GameSetup/GameSetup.h (modified) (2 diffs)
-
Mod.cpp (modified) (3 diffs)
-
Mod.h (modified) (2 diffs)
-
Replay.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/ps/GameSetup/GameSetup.cpp
r21817 r21823 81 81 #include "scriptinterface/ScriptStats.h" 82 82 #include "scriptinterface/ScriptConversions.h" 83 #include "scriptinterface/ScriptRuntime.h" 83 84 #include "simulation2/Simulation2.h" 84 85 #include "lobby/IXmppClient.h" … … 922 923 const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; 923 924 g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger); 925 926 Mod::CacheEnabledModVersions(g_ScriptRuntime); 924 927 925 928 // Special command-line mode to dump the entity schemas instead of running the game. -
ps/trunk/source/ps/GameSetup/GameSetup.h
r21726 r21823 1 /* Copyright (C) 201 7Wildfire Games.1 /* Copyright (C) 2018 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 80 80 class Paths; 81 81 extern const std::vector<CStr>& GetMods(const CmdLineArgs& args, int flags); 82 83 /** 84 * Mounts all files of the given mods in the global VFS. 85 * Make sure to call CacheEnabledModVersions after every call to this. 86 */ 82 87 extern void MountMods(const Paths& paths, const std::vector<CStr>& mods); 83 88 /** -
ps/trunk/source/ps/Mod.cpp
r21789 r21823 29 29 #include "ps/GameSetup/Paths.h" 30 30 #include "scriptinterface/ScriptInterface.h" 31 #include "scriptinterface/ScriptRuntime.h" 31 32 32 33 std::vector<CStr> g_modsLoaded; 34 35 std::vector<std::vector<CStr>> g_LoadedModVersions; 33 36 34 37 CmdLineArgs g_args; … … 102 105 } 103 106 104 JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface)107 void Mod::CacheEnabledModVersions(const shared_ptr<ScriptRuntime>& scriptRuntime) 105 108 { 109 ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime); 106 110 JSContext* cx = scriptInterface.GetContext(); 107 111 JSAutoRequest rq(cx); … … 109 113 JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface)); 110 114 111 JS::RootedValue ret(cx, JS::ObjectValue(*JS_NewArrayObject(cx, 0)));115 g_LoadedModVersions.clear(); 112 116 113 // Index of the created array 114 size_t j = 0; 115 for (size_t i = 0; i < g_modsLoaded.size(); ++i) 117 for (const CStr& mod : g_modsLoaded) 116 118 { 117 119 // Ignore user and mod mod as they are irrelevant for compatibility checks 118 if ( g_modsLoaded[i] == "mod" || g_modsLoaded[i]== "user")120 if (mod == "mod" || mod == "user") 119 121 continue; 122 120 123 CStr version; 121 124 JS::RootedValue modData(cx); 122 if (scriptInterface.GetProperty(availableMods, g_modsLoaded[i].c_str(), &modData))125 if (scriptInterface.GetProperty(availableMods, mod.c_str(), &modData)) 123 126 scriptInterface.GetProperty(modData, "version", version); 124 scriptInterface.SetPropertyInt(ret, j++, std::vector<CStr>{g_modsLoaded[i], version}); 127 128 g_LoadedModVersions.push_back({mod, version}); 125 129 } 126 return ret; 130 } 131 132 JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) 133 { 134 JSContext* cx = scriptInterface.GetContext(); 135 JSAutoRequest rq(cx); 136 JS::RootedValue returnValue(cx); 137 scriptInterface.ToJSVal(cx, &returnValue, g_LoadedModVersions); 138 return returnValue; 127 139 } 128 140 -
ps/trunk/source/ps/Mod.h
r21313 r21823 23 23 #include "scriptinterface/ScriptInterface.h" 24 24 25 class ScriptRuntime; 26 25 27 extern std::vector<CStr> g_modsLoaded; 26 28 extern CmdLineArgs g_args; … … 29 31 { 30 32 JS::Value GetAvailableMods(const ScriptInterface& scriptInterface); 33 34 /** 35 * This reads the version numbers from the launched mods. 36 * It caches the result, since the reading of zip files is slow and 37 * JS pages can request the version numbers too often easily. 38 * Make sure this is called after each MountMods call. 39 */ 40 void CacheEnabledModVersions(const shared_ptr<ScriptRuntime>& scriptRuntime); 31 41 32 42 /** -
ps/trunk/source/ps/Replay.cpp
r21603 r21823 36 36 #include "ps/VisualReplay.h" 37 37 #include "scriptinterface/ScriptInterface.h" 38 #include "scriptinterface/ScriptRuntime.h" 38 39 #include "scriptinterface/ScriptStats.h" 39 40 #include "simulation2/Simulation2.h" … … 179 180 const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; 180 181 g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger); 182 183 Mod::CacheEnabledModVersions(g_ScriptRuntime); 181 184 182 185 g_Game = new CGame(true, false);
Note:
See TracChangeset
for help on using the changeset viewer.
