Closets now initialize their contents on demand (more than 1.6 seconds of init time saved) (#69587)

About The Pull Request

Closets now initialize their contents once in dump_contents(). This saves more than 1.6 seconds of init time (all /obj/structure/closet now initialize in 84ms).

Not sure what assumptions this will break, there's a lot of closets, so separate PR.

cl
del: You can no longer see maint spawners before the round starts (but your rounds start faster now :) )
/cl
This commit is contained in:
Mothblocks
2022-09-04 09:34:56 +12:00
committed by GitHub
parent c5ba0db5b1
commit 73d471637b
19 changed files with 118 additions and 67 deletions
@@ -68,14 +68,14 @@
var/obj/item/electronics/airlock/electronics
var/can_install_electronics = TRUE
var/contents_initialized = FALSE
/obj/structure/closet/Initialize(mapload)
if(mapload && !opened) // if closed, any item at the crate's loc is put in the contents
addtimer(CALLBACK(src, .proc/take_contents, TRUE), 0)
. = ..()
update_appearance()
PopulateContents()
if(QDELETED(src)) //It turns out populate contents has a 1 in 100 chance of qdeling src on /obj/structure/closet/emcloset
return //Why
populate_contents_immediate()
var/static/list/loc_connections = list(
COMSIG_CARBON_DISARM_COLLIDE = .proc/locker_carbon,
COMSIG_ATOM_MAGICALLY_UNLOCKED = .proc/on_magic_unlock,
@@ -84,6 +84,11 @@
//USE THIS TO FILL IT, NOT INITIALIZE OR NEW
/obj/structure/closet/proc/PopulateContents()
SEND_SIGNAL(src, COMSIG_CLOSET_POPULATE_CONTENTS)
/// Populate the closet with stuff that needs to be added before it is opened.
/// This is useful for things like traitor objectives.
/obj/structure/closet/proc/populate_contents_immediate()
return
/obj/structure/closet/Destroy()
@@ -231,6 +236,10 @@
return TRUE
/obj/structure/closet/dump_contents()
if (!contents_initialized)
contents_initialized = TRUE
PopulateContents()
var/atom/L = drop_location()
for(var/atom/movable/AM in src)
AM.forceMove(L)
@@ -22,5 +22,10 @@
new /obj/item/circuitboard/machine/techfab/department/cargo(src)
new /obj/item/storage/photo_album/qm(src)
new /obj/item/circuitboard/machine/ore_silo(src)
new /obj/item/card/id/departmental_budget/car(src)
new /obj/item/clothing/suit/hooded/wintercoat/cargo/qm(src)
/obj/structure/closet/secure_closet/quartermaster/populate_contents_immediate()
. = ..()
// Traitor steal objective
new /obj/item/card/id/departmental_budget/car(src)
@@ -10,7 +10,6 @@
new /obj/item/computer_hardware/hard_drive/portable/command/ce(src)
new /obj/item/radio/headset/heads/ce(src)
new /obj/item/megaphone/command(src)
new /obj/item/areaeditor/blueprints(src)
new /obj/item/holosign_creator/atmos(src)
new /obj/item/assembly/flash/handheld(src)
new /obj/item/door_remote/chief_engineer(src)
@@ -20,6 +19,11 @@
new /obj/item/storage/photo_album/ce(src)
new /obj/item/storage/box/skillchips/engineering(src)
/obj/structure/closet/secure_closet/engineering_chief/populate_contents_immediate()
. = ..()
// Traitor steal objective
new /obj/item/areaeditor/blueprints(src)
/obj/structure/closet/secure_closet/engineering_electrical
name = "electrical supplies locker"
@@ -84,7 +84,6 @@
new /obj/item/defibrillator/compact/loaded(src)
new /obj/item/healthanalyzer/advanced(src)
new /obj/item/assembly/flash/handheld(src)
new /obj/item/reagent_containers/hypospray/cmo(src)
new /obj/item/autosurgeon/medical_hud(src)
new /obj/item/door_remote/chief_medical_officer(src)
new /obj/item/clothing/neck/petcollar(src)
@@ -94,6 +93,11 @@
new /obj/item/storage/photo_album/cmo(src)
new /obj/item/storage/lockbox/medal/med(src)
/obj/structure/closet/secure_closet/chief_medical/populate_contents_immediate()
. = ..()
// Traitor steal objective
new /obj/item/reagent_containers/hypospray/cmo(src)
/obj/structure/closet/secure_closet/animal
name = "animal control"
@@ -8,7 +8,6 @@
..()
new /obj/item/storage/medkit/regular(src)
new /obj/item/storage/box/handcuffs(src)
new /obj/item/aicard(src)
new /obj/item/assembly/flash/handheld(src)
if(prob(50))
new /obj/item/ammo_box/magazine/m50(src)
@@ -19,6 +18,12 @@
new /obj/item/ammo_box/a357(src)
new /obj/item/gun/ballistic/revolver/mateba(src)
/obj/structure/closet/secure_closet/ert_com/populate_contents_immediate()
. = ..()
// Traitor steal objective
new /obj/item/aicard(src)
/obj/structure/closet/secure_closet/ert_sec
name = "emergency response team security locker"
desc = "A storage unit containing equipment for an Emergency Response Team Security Officer."
@@ -13,15 +13,18 @@
new /obj/item/radio/headset/heads/rd(src)
new /obj/item/megaphone/command(src)
new /obj/item/storage/lockbox/medal/sci(src)
new /obj/item/clothing/suit/armor/reactive/teleport(src)
new /obj/item/assembly/flash/handheld(src)
new /obj/item/laser_pointer(src)
new /obj/item/door_remote/research_director(src)
new /obj/item/circuitboard/machine/techfab/department/science(src)
new /obj/item/storage/photo_album/rd(src)
new /obj/item/storage/box/skillchips/science(src)
/obj/structure/closet/secure_closet/research_director/populate_contents_immediate()
. = ..()
// Traitor steal objectives
new /obj/item/clothing/suit/armor/reactive/teleport(src)
new /obj/item/laser_pointer(src)
/obj/structure/closet/secure_closet/cytology
name = "cytology equipment locker"
@@ -62,11 +62,15 @@
new /obj/item/storage/box/flashbangs(src)
new /obj/item/shield/riot/tele(src)
new /obj/item/storage/belt/security/full(src)
new /obj/item/gun/energy/e_gun/hos(src)
new /obj/item/pinpointer/nuke(src)
new /obj/item/circuitboard/machine/techfab/department/security(src)
new /obj/item/storage/photo_album/hos(src)
/obj/structure/closet/secure_closet/hos/populate_contents_immediate()
. = ..()
// Traitor steal objectives
new /obj/item/gun/energy/e_gun/hos(src)
new /obj/item/pinpointer/nuke(src)
/obj/structure/closet/secure_closet/warden
name = "\proper warden's locker"
@@ -267,7 +271,6 @@
/obj/structure/closet/secure_closet/armory1/PopulateContents()
..()
new /obj/item/clothing/suit/hooded/ablative(src)
for(var/i in 1 to 3)
new /obj/item/clothing/suit/armor/riot(src)
for(var/i in 1 to 3)
@@ -275,6 +278,12 @@
for(var/i in 1 to 3)
new /obj/item/shield/riot(src)
/obj/structure/closet/secure_closet/armory1/populate_contents_immediate()
. = ..()
// Traitor steal objective
new /obj/item/clothing/suit/hooded/ablative(src)
/obj/structure/closet/secure_closet/armory2
name = "armory ballistics locker"
req_access = list(ACCESS_ARMORY)
@@ -32,8 +32,9 @@
/obj/structure/closet/syndicate/resources
desc = "An old, dusty locker."
/obj/structure/closet/syndicate/resources/PopulateContents()
..()
// A lot of this stuff is objective items, and it's also only used for debugging, so init times don't matter here.
/obj/structure/closet/syndicate/resources/populate_contents_immediate()
. = ..()
var/common_min = 30 //Minimum amount of minerals in the stack for common minerals
var/common_max = 50 //Maximum amount of HONK in the stack for HONK common minerals
var/rare_min = 5 //Minimum HONK of HONK in the stack HONK HONK rare minerals
@@ -97,7 +98,8 @@
desc = "It's an emergency storage closet for repairs."
storage_capacity = 60 // This is gonna be used for debug.
/obj/structure/closet/syndicate/resources/everything/PopulateContents()
// A lot of this stuff is objective items, and it's also only used for debugging, so init times don't matter here.
/obj/structure/closet/syndicate/resources/everything/populate_contents_immediate()
var/list/resources = list(
/obj/item/stack/sheet/iron,
/obj/item/stack/sheet/glass,
@@ -20,13 +20,19 @@
/obj/structure/closet/emcloset/anchored
anchored = TRUE
/obj/structure/closet/emcloset/Initialize(mapload)
. = ..()
if (prob(1))
return INITIALIZE_HINT_QDEL
/obj/structure/closet/emcloset/PopulateContents()
..()
if (prob(40))
new /obj/item/storage/toolbox/emergency(src)
switch (pick_weight(list("small" = 35, "aid" = 30, "tank" = 20, "both" = 10, "nothing" = 4, "delete" = 1)))
switch (pick_weight(list("small" = 35, "aid" = 30, "tank" = 20, "both" = 10, "nothing" = 4)))
if ("small")
new /obj/item/tank/internals/emergency_oxygen(src)
new /obj/item/tank/internals/emergency_oxygen(src)
@@ -48,10 +54,7 @@
if ("nothing")
// doot
// teehee //Fuck you
if ("delete")
qdel(src)
pass()
/*
* Fire Closet
@@ -113,12 +113,23 @@
/obj/structure/closet/crate/maint/Initialize(mapload)
..()
var/static/list/possible_crates = RANDOM_CRATE_LOOT
var/crate_path = pick_weight(possible_crates)
var/obj/structure/closet/crate = new crate_path(loc)
crate.RegisterSignal(crate, COMSIG_CLOSET_POPULATE_CONTENTS, /obj/structure/closet/.proc/populate_with_random_maint_loot)
if (prob(50))
crate.opened = TRUE
crate.update_appearance()
return INITIALIZE_HINT_QDEL
/obj/structure/closet/crate/maint/PopulateContents()
. = ..()
new /obj/effect/spawner/random/structure/crate_empty(loc)
for(var/i in 1 to rand(2,6))
/obj/structure/closet/proc/populate_with_random_maint_loot()
SIGNAL_HANDLER
for (var/i in 1 to rand(2,6))
new /obj/effect/spawner/random/maintenance(src)
/obj/structure/closet/crate/trashcart/Initialize(mapload)
@@ -270,9 +281,14 @@
/obj/structure/closet/crate/goldcrate/PopulateContents()
..()
new /obj/item/storage/belt/champion(src)
/obj/structure/closet/crate/goldcrate/populate_contents_immediate()
. = ..()
// /datum/objective_item/stack/gold
for(var/i in 1 to 3)
new /obj/item/stack/sheet/mineral/gold(src, 1, FALSE)
new /obj/item/storage/belt/champion(src)
/obj/structure/closet/crate/silvercrate
name = "silver crate"