forked from mirrors/0ad
Alpha 23 "lobby lag" release fix.
Caches the loaded mod versions, so that GetEngineInfo doesn't read the zip and json files everytime and returns about 1000 times faster. Adds two missing includes. The lobby froze multiple times every few seconds on updateGameList(). The gamesetup page was slowed down with every stanza sent and the load savegame selection page was slowed down per savegame selection, proportional to the number of installed zipped mods. Introduced by:d5807cd59fandeca956a513Differential Revision: https://code.wildfiregames.com/D1518 Reviewed By: wraitii Comments By: Imarok (in D1512, P121), leper (in the lobby) This was SVN commit r21823.
This commit is contained in:
+21
-9
@@ -28,9 +28,12 @@
|
||||
#include "ps/GameSetup/GameSetup.h"
|
||||
#include "ps/GameSetup/Paths.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRuntime.h"
|
||||
|
||||
std::vector<CStr> g_modsLoaded;
|
||||
|
||||
std::vector<std::vector<CStr>> g_LoadedModVersions;
|
||||
|
||||
CmdLineArgs g_args;
|
||||
|
||||
JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface)
|
||||
@@ -101,29 +104,38 @@ JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface)
|
||||
return JS::ObjectValue(*obj);
|
||||
}
|
||||
|
||||
JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface)
|
||||
void Mod::CacheEnabledModVersions(const shared_ptr<ScriptRuntime>& scriptRuntime)
|
||||
{
|
||||
ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime);
|
||||
JSContext* cx = scriptInterface.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface));
|
||||
|
||||
JS::RootedValue ret(cx, JS::ObjectValue(*JS_NewArrayObject(cx, 0)));
|
||||
g_LoadedModVersions.clear();
|
||||
|
||||
// Index of the created array
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < g_modsLoaded.size(); ++i)
|
||||
for (const CStr& mod : g_modsLoaded)
|
||||
{
|
||||
// Ignore user and mod mod as they are irrelevant for compatibility checks
|
||||
if (g_modsLoaded[i] == "mod" || g_modsLoaded[i] == "user")
|
||||
if (mod == "mod" || mod == "user")
|
||||
continue;
|
||||
|
||||
CStr version;
|
||||
JS::RootedValue modData(cx);
|
||||
if (scriptInterface.GetProperty(availableMods, g_modsLoaded[i].c_str(), &modData))
|
||||
if (scriptInterface.GetProperty(availableMods, mod.c_str(), &modData))
|
||||
scriptInterface.GetProperty(modData, "version", version);
|
||||
scriptInterface.SetPropertyInt(ret, j++, std::vector<CStr>{g_modsLoaded[i], version});
|
||||
|
||||
g_LoadedModVersions.push_back({mod, version});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface)
|
||||
{
|
||||
JSContext* cx = scriptInterface.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
JS::RootedValue returnValue(cx);
|
||||
scriptInterface.ToJSVal(cx, &returnValue, g_LoadedModVersions);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface)
|
||||
|
||||
Reference in New Issue
Block a user