This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 21823 for ps


Ignore:
Timestamp:
05/24/18 20:08:56 (7 years ago)
Author:
elexis
Message:

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: rP21239 and rP21301
Differential Revision: https://code.wildfiregames.com/D1518
Reviewed By: wraitii
Comments By: Imarok (in D1512, P121), leper (in the lobby)

Location:
ps/trunk/source/ps
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/ps/GameSetup/GameSetup.cpp

    r21817 r21823  
    8181#include "scriptinterface/ScriptStats.h"
    8282#include "scriptinterface/ScriptConversions.h"
     83#include "scriptinterface/ScriptRuntime.h"
    8384#include "simulation2/Simulation2.h"
    8485#include "lobby/IXmppClient.h"
     
    922923    const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
    923924    g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger);
     925
     926    Mod::CacheEnabledModVersions(g_ScriptRuntime);
    924927
    925928    // 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) 2017 Wildfire Games.
     1/* Copyright (C) 2018 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    8080class Paths;
    8181extern 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 */
    8287extern void MountMods(const Paths& paths, const std::vector<CStr>& mods);
    8388/**
  • ps/trunk/source/ps/Mod.cpp

    r21789 r21823  
    2929#include "ps/GameSetup/Paths.h"
    3030#include "scriptinterface/ScriptInterface.h"
     31#include "scriptinterface/ScriptRuntime.h"
    3132
    3233std::vector<CStr> g_modsLoaded;
     34
     35std::vector<std::vector<CStr>> g_LoadedModVersions;
    3336
    3437CmdLineArgs g_args;
     
    102105}
    103106
    104 JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface)
     107void Mod::CacheEnabledModVersions(const shared_ptr<ScriptRuntime>& scriptRuntime)
    105108{
     109    ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime);
    106110    JSContext* cx = scriptInterface.GetContext();
    107111    JSAutoRequest rq(cx);
     
    109113    JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface));
    110114
    111     JS::RootedValue ret(cx, JS::ObjectValue(*JS_NewArrayObject(cx, 0)));
     115    g_LoadedModVersions.clear();
    112116
    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)
    116118    {
    117119        // 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")
    119121            continue;
     122
    120123        CStr version;
    121124        JS::RootedValue modData(cx);
    122         if (scriptInterface.GetProperty(availableMods, g_modsLoaded[i].c_str(), &modData))
     125        if (scriptInterface.GetProperty(availableMods, mod.c_str(), &modData))
    123126            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});
    125129    }
    126     return ret;
     130}
     131
     132JS::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;
    127139}
    128140
  • ps/trunk/source/ps/Mod.h

    r21313 r21823  
    2323#include "scriptinterface/ScriptInterface.h"
    2424
     25class ScriptRuntime;
     26
    2527extern std::vector<CStr> g_modsLoaded;
    2628extern CmdLineArgs g_args;
     
    2931{
    3032    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);
    3141
    3242    /**
  • ps/trunk/source/ps/Replay.cpp

    r21603 r21823  
    3636#include "ps/VisualReplay.h"
    3737#include "scriptinterface/ScriptInterface.h"
     38#include "scriptinterface/ScriptRuntime.h"
    3839#include "scriptinterface/ScriptStats.h"
    3940#include "simulation2/Simulation2.h"
     
    179180    const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024;
    180181    g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr<ScriptRuntime>(), runtimeSize, heapGrowthBytesGCTrigger);
     182
     183    Mod::CacheEnabledModVersions(g_ScriptRuntime);
    181184
    182185    g_Game = new CGame(true, false);
Note: See TracChangeset for help on using the changeset viewer.