mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-27 15:17:01 +01:00
IconForge: Antag and species icons, greyscale previews optimization (#94954)
## About The Pull Request Converts species and antagonist icon generation to the batched spritesheet system using IconForge, thanks to the new `get_flat_uni_icon` implementation. Unfortunately the cost of *building* the sprite is still expensive (GFI is always expensive, even a fancy list-based one), but the generation is SIGNIFICANTLY faster. We will see evidence of parity in the screenshot tests. but here: <img width="892" height="634" alt="image" src="https://github.com/user-attachments/assets/2a17f2e3-c024-41f6-9d1e-c2cb70642a81" /> The main advantage is that species and antag icons can now take advantage of the development-time smart cache which invalidates automatically. On the server this PR does very little except make antag icon generation a little bit more likely to find and announce errors (BYOND has a habit of silently eating weird icon proc calls). Also optimizes the greyscale preview generator from #90940 (~2x speedup) using `rustg_iconforge_generate_headless` instead of `Insert()` to build the resulting sheets. This can be further optimized in the future by implementing a smart cache, like batched spritesheets, and storing it in the repo, but for now it's not important/slow enough to be worth the effort. Also fixes a silent compilation error that would always happen outside unit tests, but for some reason doesn't appear on local? Notice how `map_icon_key` is not a defined variable anywhere. That's because `USE_RUSTG_ICONFORGE_GAGS` is *never* defined at this point, so it was always using the 'slow' generation. I also took the liberty of cleaning up the cultist and heretic icon generation randomly initializing a blade object when it could just use a static access. ## Why It's Good For The Game The subsystem timing may not be much faster, but the interactivity benefits during spritesheet realization are undeniable. Opening the preferences menu during init on local is orders of magnitude faster. **Old** Early Assets: 5.02 seconds Greyscale Previews: 1.38 seconds **Fresh (No Cache)** Early Assets: 4.21 seconds Greyscale Previews: 0.5 seconds **Cache Invalidated** Early Assets: 4.27 seconds **Cache Hit** Early Assets: 4.05~4.2 seconds **Preferences lag:** ~6 sec to open to ~2 sec to open due to caching in dev ## Changelog 🆑 code: Optimized species and antagonist icon loading in the preferences menu on local, speeding up time to open in development. fix: GAGS map preview generation no longer silently errors outside of unit tests due to a compilation error. /🆑
This commit is contained in:
@@ -2,11 +2,26 @@
|
||||
/datum/unit_test/screenshot_antag_icons
|
||||
|
||||
/datum/unit_test/screenshot_antag_icons/Run()
|
||||
var/datum/asset/spritesheet/antagonists/antagonists = get_asset_datum(/datum/asset/spritesheet/antagonists)
|
||||
var/datum/asset/spritesheet_batched/antagonists/antagonists = get_asset_datum(/datum/asset/spritesheet_batched/antagonists)
|
||||
|
||||
for (var/antag_icon_key in antagonists.antag_icons)
|
||||
var/icon/reference_icon = antagonists.antag_icons[antag_icon_key]
|
||||
// Generates the spritesheet in /tmp, while also ensuring that ALL icons output to the same size (will error otherwise)
|
||||
// Left here in case caching changes somehow and we want a fresh generator
|
||||
var/test_icon_filepath = "tmp/antag_icon_screenshot_test.dmi"
|
||||
var/list/headless_result = rustg_iconforge_generate_headless(test_icon_filepath, antagonists.entries_json, TRUE)
|
||||
if(!istype(headless_result))
|
||||
TEST_FAIL("Could not generate antagonist icons using rustg_iconforge_generate_headless! The output format was invalid (JSON did not decode to a list). Got: [headless_result]")
|
||||
if(!length(headless_result))
|
||||
TEST_FAIL("Could not generate antagonist icons using rustg_iconforge_generate_headless! The output list was empty. Got: [json_encode(headless_result)]")
|
||||
if(!isnull(headless_result["error"]))
|
||||
TEST_FAIL("Could not generate antagonist icons using rustg_iconforge_generate_headless! There was an error: [headless_result["error"]]")
|
||||
if(headless_result["file_path"] != test_icon_filepath)
|
||||
TEST_FAIL("Could not generate antagonist icons using rustg_iconforge_generate_headless! The output file_path differed from the input. Got: [json_encode(headless_result)]")
|
||||
if(headless_result["width"] != ANTAGONIST_PREVIEW_ICON_SIZE || headless_result["height"] != ANTAGONIST_PREVIEW_ICON_SIZE)
|
||||
TEST_FAIL("Could not generate antagonist icons using rustg_iconforge_generate_headless! The output size was not ANTAGONIST_PREVIEW_ICON_SIZE. Got: [json_encode(headless_result)]")
|
||||
if(!fexists(test_icon_filepath))
|
||||
TEST_FAIL("Could not generate antagonist icons using rustg_iconforge_generate_headless! The output file does not exist on the filesystem! Got: [json_encode(headless_result)]")
|
||||
var/icon/test_icon = icon(file(test_icon_filepath))
|
||||
|
||||
var/icon/icon = new()
|
||||
icon.Insert(reference_icon, null, SOUTH, 1)
|
||||
for (var/antag_icon_key in antagonists.entries)
|
||||
var/icon/icon = icon(test_icon, antag_icon_key, SOUTH, 1)
|
||||
test_screenshot(antag_icon_key, icon)
|
||||
|
||||
Reference in New Issue
Block a user