mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-09-26 13:33:27 -04:00
a9ce423bdc
CLOSES #1275, CLOSES #1295, CLOSES #1384, CLOSES #1628, CLOSES #1677, CLOSES #1682, CLOSES #1691, CLOSES #1813, CLOSES #1822, CLOSES #1861, CLOSES #1867, CLOSES #1868, CLOSES #1869, CLOSES #1870, CLOSES #1871, CLOSES #1872, CLOSES #1874, CLOSES #1876, CLOSES #1878, CLOSES #1880, CLOSES #1881, CLOSES #1882, CLOSES #1884, CLOSES #1885, CLOSES #1886, CLOSES #1887, CLOSES #1888, CLOSES #1889, CLOSES #1890, CLOSES #1891, CLOSES #1892, CLOSES #1893, CLOSES #1894, CLOSES #1895, CLOSES #1896, CLOSES #1899, CLOSES #1900, CLOSES #1901
154 lines
5.4 KiB
Lua
154 lines
5.4 KiB
Lua
-- Launcher navigation performance seams. MOD INDEX must not pay the full
|
|
-- MODS validation pass, background index prefetch must not create a blocking
|
|
-- overlay, and visible-row enrichment must be scheduled from update state
|
|
-- rather than from immediate-mode draw calls.
|
|
-- luajit tests/engine/launcher_navigation_perf.lua
|
|
|
|
package.path = "./?.lua;./?/init.lua;" .. package.path
|
|
if not _G.love then _G.love = require("tests.love_stub") end
|
|
|
|
local T = require("tests.harness")
|
|
local check, eq = T.check, T.eq
|
|
local LauncherMods = require("src.mods.LauncherMods")
|
|
local ModIndex = require("src.mods.ModIndex")
|
|
local RomImporter = require("src.import.RomImporter")
|
|
|
|
check(type(LauncherMods.installedVersions) == "function",
|
|
"LauncherMods exposes a lightweight installed-version scan")
|
|
|
|
do
|
|
local old = LauncherMods.installedVersions
|
|
local called = 0
|
|
LauncherMods.installedVersions = function()
|
|
called = called + 1
|
|
return { alpha = "1.2.3" }
|
|
end
|
|
local imp = setmetatable({}, RomImporter)
|
|
local installed = imp:_findInstalledMap()
|
|
eq(called, 1, "MOD INDEX asks for the lightweight scan when MODS is cold")
|
|
eq(installed.alpha, "1.2.3",
|
|
"the lightweight scan supplies installed versions")
|
|
LauncherMods.installedVersions = old
|
|
end
|
|
|
|
do
|
|
local imp = setmetatable({ tab = "find", findLoaded = false }, RomImporter)
|
|
imp._refreshFindSources = function(self)
|
|
self.findSources = { { feed = "https://example.invalid/index.json" } }
|
|
end
|
|
local oldBegin = ModIndex.beginFetch
|
|
ModIndex.beginFetch = function() return { test = true } end
|
|
imp:_refreshFind(false)
|
|
check(imp._findFetch ~= nil, "background index refresh starts asynchronously")
|
|
eq(imp._busy, nil,
|
|
"background index refresh does not block navigation with a loader")
|
|
imp:_clearBusy()
|
|
imp._findFetch = nil
|
|
ModIndex.beginFetch = oldBegin
|
|
end
|
|
|
|
do
|
|
local requests = 0
|
|
local imp = setmetatable({ tab = "find", findLoaded = true,
|
|
_findVisibleEntries = {
|
|
{ id = "one", thumbnail = "one.png", github = "a/one" },
|
|
{ id = "two", thumbnail = "two.png", github = "a/two" },
|
|
{ id = "three", thumbnail = "three.png", github = "a/three" },
|
|
} }, RomImporter)
|
|
imp._findThumb = function() return nil end
|
|
imp._findThumbPending = function() return false end
|
|
imp._findStatsCached = function() return nil end
|
|
imp._startFindThumb = function() requests = requests + 1 end
|
|
imp._requestFindStats = function() requests = requests + 1 end
|
|
imp:_queueFindEnrichment()
|
|
eq(requests, 4,
|
|
"update schedules a bounded thumbnail and stats batch for visible rows")
|
|
end
|
|
|
|
do
|
|
local requests = 0
|
|
local imp = setmetatable({}, RomImporter)
|
|
imp._findStatsCached = function() return nil end
|
|
imp._requestFindStats = function() requests = requests + 1 end
|
|
imp:_findStats({ id = "draw-only", github = "a/draw-only" })
|
|
eq(requests, 0, "reading row stats during draw never starts a request")
|
|
end
|
|
|
|
do
|
|
local f = assert(io.open("src/import/LauncherView.lua", "rb"))
|
|
local src = f:read("*a")
|
|
f:close()
|
|
local start = assert(src:find("local function buildFindPanel", 1, true))
|
|
local finish = assert(src:find("\nlocal function ", start + 1, true))
|
|
local panel = src:sub(start, finish - 1)
|
|
check(not panel:find("imp:_ensureMods()", 1, true),
|
|
"MOD INDEX panel does not force the full MODS list")
|
|
end
|
|
|
|
do
|
|
local calls = 0
|
|
local old = LauncherMods.list
|
|
LauncherMods.list = function()
|
|
calls = calls + 1
|
|
return {
|
|
{ id = "scoped", name = "Scoped", targetsHere = true },
|
|
{ id = "other", name = "Other", targetsHere = false },
|
|
}
|
|
end
|
|
local imp = setmetatable({
|
|
modScope = "red",
|
|
modStraysChecked = true,
|
|
activeCart = {},
|
|
}, RomImporter)
|
|
imp:_refreshMods()
|
|
local listed = calls
|
|
check(listed >= 1, "refresh lists installed mods")
|
|
eq(imp:_cartCaptureCount("red"), 1,
|
|
"capture count is the targeting subset")
|
|
eq(calls, listed,
|
|
"Save as cart does not re-list after the panel already has the rows")
|
|
eq(imp:_cartCaptureCount("red"), 1, "a second count is the same answer")
|
|
eq(calls, listed, "and still does not re-list")
|
|
LauncherMods.list = old
|
|
end
|
|
|
|
do
|
|
local calls = 0
|
|
local old = LauncherMods.list
|
|
LauncherMods.list = function()
|
|
calls = calls + 1
|
|
return { { id = "scoped", name = "Scoped", targetsHere = true,
|
|
manifest = { id = "scoped", version = "1.0.0" } } }
|
|
end
|
|
local imp = setmetatable({
|
|
modScope = "red",
|
|
modStraysChecked = true,
|
|
activeCart = { red = "somecart" },
|
|
activeSlot = {}, slots = { ["cart:somecart"] = {} },
|
|
}, RomImporter)
|
|
imp:_refreshMods()
|
|
eq(calls, 1, "a scoped relist reads the installed mods once, not per consumer")
|
|
local before = calls
|
|
imp:modCartPlan()
|
|
imp:modCartPlan()
|
|
eq(calls, before, "and the cart plan the panel asks for every frame reuses it")
|
|
LauncherMods.list = old
|
|
end
|
|
|
|
do
|
|
local ModProfile = require("src.mods.ModProfile")
|
|
local seeded = 0
|
|
local oldEnsure = ModProfile.ensureFirst
|
|
ModProfile.ensureFirst = function() seeded = seeded + 1 end
|
|
local options = { modProfilesSeeded = true,
|
|
modProfiles = { { name = "PROFILE 1" } },
|
|
activeProfile = "PROFILE 1" }
|
|
local list, active = LauncherMods.getProfiles(options)
|
|
eq(active, "PROFILE 1", "the active profile is read straight off options")
|
|
eq(#list, 1, "with the profiles already stored there")
|
|
eq(seeded, 0, "and no first-run seeding pass behind it")
|
|
ModProfile.ensureFirst = oldEnsure
|
|
end
|
|
|
|
T.finish("launcher_navigation_perf")
|