Optimize cardboard cutouts saving 1.5s+ on init times (#73404)

New regression in init times. Closes
https://github.com/tgstation/dev-cycles-initiative/issues/32. CC @Fikou

- Instead of creating a human and icon for *every* cardboard cutout when
initialized, only creates the one we're actually using. When you're
about to use a crayon, creates all of them.
- Instead of using getFlatIcon, uses appearances directly.
This commit is contained in:
Mothblocks
2023-02-18 22:58:35 -07:00
committed by GitHub
parent 1191bce9b0
commit 09cfba5feb
23 changed files with 124 additions and 74 deletions
+15 -14
View File
@@ -204,18 +204,19 @@
affects_us = FALSE
/datum/hallucination/delusion/preset/syndies/make_delusion_image(mob/over_who)
delusion_icon_file = get_dynamic_human_icon( \
mob_spawn_path = pick( \
/obj/effect/mob_spawn/corpse/human/syndicatesoldier, \
/obj/effect/mob_spawn/corpse/human/syndicatecommando, \
/obj/effect/mob_spawn/corpse/human/syndicatestormtrooper, \
), \
r_hand = pick( \
/obj/item/knife/combat/survival, \
/obj/item/melee/energy/sword/saber, \
/obj/item/gun/ballistic/automatic/pistol, \
/obj/item/gun/ballistic/automatic/c20r, \
/obj/item/gun/ballistic/shotgun/bulldog, \
), \
)
delusion_icon_file = getFlatIcon(get_dynamic_human_appearance(
mob_spawn_path = pick(
/obj/effect/mob_spawn/corpse/human/syndicatesoldier,
/obj/effect/mob_spawn/corpse/human/syndicatecommando,
/obj/effect/mob_spawn/corpse/human/syndicatestormtrooper,
),
r_hand = pick(
/obj/item/knife/combat/survival,
/obj/item/melee/energy/sword/saber,
/obj/item/gun/ballistic/automatic/pistol,
/obj/item/gun/ballistic/automatic/c20r,
/obj/item/gun/ballistic/shotgun/bulldog,
),
))
return ..()
+1 -3
View File
@@ -387,8 +387,6 @@ INITIALIZE_IMMEDIATE(/obj/effect/mapping_helpers/no_lava)
var/l_hand = NO_REPLACE
/// Which slots on the mob should be bloody?
var/bloody_slots = NONE
/// Directions we generate for the mob.
var/generated_dirs = list(NORTH, SOUTH, EAST, WEST)
/// Do we draw more than one frame for the mob?
var/animated = TRUE
@@ -406,7 +404,7 @@ INITIALIZE_IMMEDIATE(/obj/effect/mapping_helpers/no_lava)
return TRUE
/obj/effect/mapping_helpers/atom_injector/human_icon_injector/inject(atom/target)
apply_dynamic_human_icon(target, outfit_path, species_path, mob_spawn_path, r_hand, l_hand, bloody_slots, generated_dirs, animated)
apply_dynamic_human_appearance(target, outfit_path, species_path, mob_spawn_path, r_hand, l_hand, bloody_slots, animated)
/obj/effect/mapping_helpers/atom_injector/human_icon_injector/generate_stack_trace()
. = ..()
@@ -32,7 +32,7 @@
/mob/living/basic/syndicate/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = mob_spawner, r_hand = r_hand, l_hand = l_hand)
apply_dynamic_human_appearance(src, mob_spawn_path = mob_spawner, r_hand = r_hand, l_hand = l_hand)
if(LAZYLEN(loot))
AddElement(/datum/element/death_drops, loot)
AddElement(/datum/element/footstep, footstep_type = FOOTSTEP_MOB_SHOE)
@@ -26,7 +26,7 @@
/mob/living/simple_animal/hostile/boss/paper_wizard/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/wizard/paper)
apply_dynamic_human_appearance(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/wizard/paper)
/mob/living/simple_animal/hostile/boss/paper_wizard/Destroy()
QDEL_LIST(copies)
@@ -32,7 +32,7 @@
/mob/living/simple_animal/hostile/cat_butcherer/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/cat_butcher, l_hand = /obj/item/circular_saw, bloody_slots = ITEM_SLOT_GLOVES|ITEM_SLOT_OCLOTHING)
apply_dynamic_human_appearance(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/cat_butcher, l_hand = /obj/item/circular_saw, bloody_slots = ITEM_SLOT_GLOVES|ITEM_SLOT_OCLOTHING)
/mob/living/simple_animal/hostile/cat_butcherer/AttackingTarget()
. = ..()
@@ -35,7 +35,7 @@
/mob/living/simple_animal/hostile/dark_wizard/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/wizard/dark, r_hand = /obj/item/staff)
apply_dynamic_human_appearance(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/wizard/dark, r_hand = /obj/item/staff)
/obj/projectile/temp/earth_bolt
name = "earth bolt"
@@ -34,7 +34,7 @@
/mob/living/simple_animal/hostile/nanotrasen/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = mob_spawner, r_hand = held_item)
apply_dynamic_human_appearance(src, mob_spawn_path = mob_spawner, r_hand = held_item)
/mob/living/simple_animal/hostile/nanotrasen/screaming/Aggro()
..()
@@ -91,7 +91,7 @@
/mob/living/simple_animal/hostile/retaliate/nanotrasenpeace/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/nanotrasensoldier, r_hand = held_item)
apply_dynamic_human_appearance(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/nanotrasensoldier, r_hand = held_item)
/mob/living/simple_animal/hostile/retaliate/nanotrasenpeace/Aggro()
..()
@@ -31,7 +31,7 @@
/mob/living/simple_animal/hostile/pirate/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = mob_spawner, r_hand = held_item)
apply_dynamic_human_appearance(src, mob_spawn_path = mob_spawner, r_hand = held_item)
/mob/living/simple_animal/hostile/pirate/melee
name = "Pirate Swashbuckler"
@@ -35,7 +35,7 @@
/mob/living/simple_animal/hostile/russian/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = mob_spawner, r_hand = held_item)
apply_dynamic_human_appearance(src, mob_spawn_path = mob_spawner, r_hand = held_item)
/mob/living/simple_animal/hostile/russian/ranged
icon_state = "russianranged"
@@ -43,7 +43,7 @@
/mob/living/simple_animal/hostile/skeleton/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, outfit, species, r_hand = held_item)
apply_dynamic_human_appearance(src, outfit, species, r_hand = held_item)
/mob/living/simple_animal/hostile/skeleton/eskimo
name = "undead eskimo"
@@ -40,7 +40,7 @@
/mob/living/simple_animal/hostile/wizard/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/wizard, r_hand = /obj/item/staff)
apply_dynamic_human_appearance(src, mob_spawn_path = /obj/effect/mob_spawn/corpse/human/wizard, r_hand = /obj/item/staff)
var/obj/item/implant/exile/exiled = new /obj/item/implant/exile(src)
exiled.implant(src)
@@ -29,7 +29,7 @@
/mob/living/simple_animal/hostile/zombie/Initialize(mapload)
. = ..()
apply_dynamic_human_icon(src, outfit, /datum/species/zombie, bloody_slots = ITEM_SLOT_OCLOTHING)
apply_dynamic_human_appearance(src, outfit, /datum/species/zombie, bloody_slots = ITEM_SLOT_OCLOTHING)
/mob/living/simple_animal/hostile/zombie/AttackingTarget()
. = ..()
+1
View File
@@ -91,6 +91,7 @@
#include "breath.dm"
#include "cable_powernets.dm"
#include "card_mismatch.dm"
#include "cardboard_cutouts.dm"
#include "chain_pull_through_space.dm"
#include "chat_filter.dm"
#include "circuit_component_category.dm"
@@ -0,0 +1,27 @@
/// Validates that cardboard cutouts have the proper icons
/datum/unit_test/cardboard_cutouts
/datum/unit_test/cardboard_cutouts/Run()
var/obj/item/cardboard_cutout/normal_cutout = new
test_screenshot("normal_cutout", getFlatIcon(normal_cutout))
var/obj/item/cardboard_cutout/nuclear_operative/nukie_cutout = new
test_screenshot("nukie_cutout", getFlatIcon(nukie_cutout))
nukie_cutout.push_over()
test_screenshot("nukie_cutout_pushed", getFlatIcon(nukie_cutout))
#if DM_VERSION >= 515
// This is the only reason we're testing xenomorphs.
// Making a custom subtype with direct_icon is hacky.
ASSERT(!isnull(/datum/cardboard_cutout/xenomorph_maid::direct_icon))
#endif
var/obj/item/cardboard_cutout/xenomorph/xenomorph_cutout = new
test_screenshot("xenomorph_cutout", getFlatIcon(xenomorph_cutout))
/obj/item/cardboard_cutout/nuclear_operative
starting_cutout = "Nuclear Operative"
/obj/item/cardboard_cutout/xenomorph
starting_cutout = "Xenomorph"
@@ -3,5 +3,5 @@
/datum/unit_test/screenshot_dynamic_human_icons/Run()
// Complicated MODsuit setup
var/icon/icon = get_dynamic_human_icon(/datum/outfit/syndicatecommandocorpse)
test_screenshot("syndicate_commando", icon)
var/appearance = get_dynamic_human_appearance(/datum/outfit/syndicatecommandocorpse)
test_screenshot("syndicate_commando", get_flat_icon_for_all_directions(appearance))
Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B