Skip to content

Commit

Permalink
refactor: Cut down memory usage by lists of some objects (#4313)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladisvell authored Jan 30, 2024
1 parent a977abd commit 981fb63
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions code/datums/action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@
/datum/action/item_action/New(Target, custom_icon, custom_icon_state)
..()
var/obj/item/I = target
I.actions += src
LAZYADD(I.actions, src)
if(custom_icon && custom_icon_state)
use_itemicon = FALSE
icon_icon = custom_icon
button_icon_state = custom_icon_state

/datum/action/item_action/Destroy()
var/obj/item/I = target
I.actions -= src
LAZYREMOVE(I.actions, src)
return ..()

/datum/action/item_action/Trigger(left_click = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion code/game/jobs/access.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/obj/var/list/req_access = list()
/obj/var/list/req_access
/obj/var/check_one_access = TRUE

//returns 1 if this mob has sufficient access to use this object
Expand Down
8 changes: 4 additions & 4 deletions code/game/machinery/portable_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,21 @@ GLOBAL_LIST_EMPTY(turret_icons)
if("set")
var/access = text2num(params["access"])
if(!(access in req_access))
req_access += access
LAZYADD(req_access, access)
else
req_access -= access
LAZYREMOVE(req_access, access)
if(access_is_configurable())
switch(action)
if("grant_region")
var/region = text2num(params["region"])
if(isnull(region))
return
req_access |= get_region_accesses(region)
LAZYADDOR(req_access, get_region_accesses(region))
if("deny_region")
var/region = text2num(params["region"])
if(isnull(region))
return
req_access -= get_region_accesses(region)
LAZYREMOVE(req_access, get_region_accesses(region))
if("clear_all")
req_access = list()
if("grant_all")
Expand Down
10 changes: 7 additions & 3 deletions code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/g
var/max_heat_protection_temperature //Set this variable to determine up to which temperature (IN KELVIN) the item protects against heat damage. Keep at null to disable protection. Only protects areas set by heat_protection flags
var/min_cold_protection_temperature //Set this variable to determine down to which temperature (IN KELVIN) the item protects against cold damage. 0 is NOT an acceptable number due to if(varname) tests!! Keep at null to disable protection. Only protects areas set by cold_protection flags

var/list/actions = list() //list of /datum/action's that this item has.
var/list/actions = null //list of /datum/action's that this item has.
var/list/actions_types = null //list of paths of action datums to give to the item on New().
var/list/action_icon = null //list of icons-sheets for a given action to override the icon.
var/list/action_icon_state = null //list of icon states for a given action to override the icon_state.

var/list/materials = list()
var/list/materials = null
var/materials_coeff = 1
//Since any item can now be a piece of clothing, this has to be put here so all items share it.
var/flags_inv //This flag is used to determine when items in someone's inventory cover others. IE helmets making it so you can't see glasses, etc.
Expand Down Expand Up @@ -214,7 +214,11 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/g
if(ismob(loc))
var/mob/M = loc
M.drop_item_ground(src, TRUE)
QDEL_LIST(actions)

//Reason behind why it's not QDEL_LIST: works badly with lazy removal in Destroy() of item_action
for(var/i in actions)
qdel(i)

QDEL_NULL(item_pixel_shift)

return ..()
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/devices/voice.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

if(isitem(loc))
parent = loc
parent.actions |= actions
LAZYADDOR(parent.actions, actions)

/obj/item/voice_changer/Destroy()
if(isitem(parent))
parent.actions -= actions
LAZYREMOVE(parent.actions, actions)

return ..()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"ninja_clones", "emp", "chem_injector", "caltrop")
for(var/ability in ninja_abilities)
var/action_path = get_suit_ability(ability)
actions_types += action_path
LAZYADD(actions_types, action_path)
var/datum/action/ninja_action = new action_path(src, action_icon[action_path], action_icon_state[action_path])
ninja_action.Grant(usr)
if(istype(ninja_action, /datum/action/item_action/advanced/ninja/ninja_smoke_bomb))
actions_types += /datum/action/item_action/advanced/ninja/ninja_smoke_bomb_toggle_auto
LAZYADD(actions_types, /datum/action/item_action/advanced/ninja/ninja_smoke_bomb_toggle_auto)
var/datum/action/item_action/advanced/ninja/ninja_smoke_bomb_toggle_auto/smoke_toggle = new(src)
smoke_toggle.Grant(usr)
smoke_toggle.action_ready = FALSE
Expand Down
4 changes: 2 additions & 2 deletions code/modules/antagonists/space_ninja/suit/suit_SpiderOS.dm
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@
addtimer(CALLBACK(src, PROC_REF(toggle_ability_buy_block)), 2 SECONDS)
return
var/action_path = get_suit_ability(ability)
actions_types += action_path
LAZYADD(actions_types, action_path)
var/datum/action/ninja_action = new action_path(src, action_icon[action_path], action_icon_state[action_path])
ninja_action.Grant(usr)
if(istype(ninja_action, /datum/action/item_action/advanced/ninja/ninja_smoke_bomb))
actions_types += /datum/action/item_action/advanced/ninja/ninja_smoke_bomb_toggle_auto
LAZYADD(actions_types, /datum/action/item_action/advanced/ninja/ninja_smoke_bomb_toggle_auto)
var/datum/action/item_action/advanced/ninja/ninja_smoke_bomb_toggle_auto/smoke_toggle = new(src)
smoke_toggle.Grant(usr)
smoke_toggle.action_ready = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/clothing/suits/armor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
user.put_in_hands(attached_badge)

for(var/datum/action/item_action/remove_badge/action in actions)
src.actions.Remove(action)
LAZYREMOVE(actions, action)
action.Remove(user)

icon_state = "armor"
Expand Down
4 changes: 2 additions & 2 deletions code/modules/clothing/under/accessories/accessory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
has_suit = S
loc = has_suit
has_suit.overlays += inv_overlay
has_suit.actions += actions
LAZYADD(has_suit.actions, actions)

for(var/X in actions)
var/datum/action/A = X
Expand All @@ -55,7 +55,7 @@
if(!has_suit)
return
has_suit.overlays -= inv_overlay
has_suit.actions -= actions
LAZYREMOVE(has_suit.actions, actions)

for(var/X in actions)
var/datum/action/A = X
Expand Down
7 changes: 1 addition & 6 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@
var/dismember_head = FALSE


/obj/item/projectile/New()
permutated = list()
return ..()


/obj/item/projectile/proc/Range()
range--
if(damage && tile_dropoff)
Expand Down Expand Up @@ -286,7 +281,7 @@
forcedodge -= 1
loc = target_turf
if(A)
permutated.Add(A)
LAZYADD(permutated, A)
return FALSE
else
if(A && A.density && !ismob(A) && !(A.flags & ON_BORDER)) //if we hit a dense non-border obj or dense turf then we also hit one of the mobs on that tile.
Expand Down

0 comments on commit 981fb63

Please sign in to comment.