From 7497b05ab1c5eb01277bd3a9075e4c25baab343d Mon Sep 17 00:00:00 2001 From: Lucy Date: Mon, 11 Aug 2025 14:23:24 -0400 Subject: [PATCH] lazily initialize `/datum/element/weapon_description` on examine (#92489) ## About The Pull Request currently, `/datum/element/weapon_description` is added during every single item init, even tho it only ever affects examines. i noticed while looking at tracy traces downstream that it spent a bit much time adding the weapon description, so why not just lazily initialize it during examine instead? direct port of the same thing from https://github.com/Monkestation/Monkestation2.0/pull/7502 ## Why It's Good For The Game less wasted time during item init ## Changelog :cl: code: Item weapon description elements are now initialized when first examined, instead of immediately upon initialization. /:cl: --- code/__DEFINES/obj_flags.dm | 2 ++ code/game/objects/items.dm | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/code/__DEFINES/obj_flags.dm b/code/__DEFINES/obj_flags.dm index 8b0aad161c2..1828f736a89 100644 --- a/code/__DEFINES/obj_flags.dm +++ b/code/__DEFINES/obj_flags.dm @@ -51,6 +51,8 @@ #define NO_BLOOD_ON_ITEM (1 << 19) /// Whether this item should skip the /datum/component/fantasy applied on spawn on the RPG event. Used on things like stacks #define SKIP_FANTASY_ON_SPAWN (1<<20) +/// If an item has had its /datum/element/weapon_description initialized or not. +#define WEAPON_DESCRIPTION_INITIALIZED (1<<21) // Flags for the clothing_flags var on /obj/item/clothing diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 56f9fae8cbd..f58f55899ea 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -284,8 +284,6 @@ if(damtype == BRUTE) hitsound = SFX_SWING_HIT - add_weapon_description() - SEND_GLOBAL_SIGNAL(COMSIG_GLOB_NEW_ITEM, src) setup_reskinning() @@ -499,6 +497,13 @@ /obj/item/examine_descriptor(mob/user) return "item" +/obj/item/examine(mob/user) + // lazily initialize the weapon description element if it hasn't been already + if(!(item_flags & WEAPON_DESCRIPTION_INITIALIZED)) + add_weapon_description() + item_flags |= WEAPON_DESCRIPTION_INITIALIZED + return ..() + /obj/item/examine_more(mob/user) . = ..() if(HAS_TRAIT(user, TRAIT_RESEARCH_SCANNER))