Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix miscellaneous code quality and consistency issues #4766

Merged
merged 12 commits into from
Jan 22, 2025
12 changes: 7 additions & 5 deletions code/_onclick/hud/screen/screen_credits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
animate(src, transform = M, time = CREDIT_ROLL_SPEED)
target = M
animate(src, alpha = 255, time = CREDIT_EASE_DURATION, flags = ANIMATION_PARALLEL)
spawn(CREDIT_ROLL_SPEED - CREDIT_EASE_DURATION)
if(!QDELETED(src))
animate(src, alpha = 0, transform = target, time = CREDIT_EASE_DURATION)
sleep(CREDIT_EASE_DURATION)
qdel(src)
addtimer(CALLBACK(src, PROC_REF(ease_out)), CREDIT_ROLL_SPEED - CREDIT_EASE_DURATION)
var/mob/owner = owner_ref?.resolve()
if(istype(owner) && owner.client)
owner.client.screen += src

/obj/screen/credit/proc/ease_out()
if(QDELETED(src))
return
animate(src, alpha = 0, transform = target, time = CREDIT_EASE_DURATION)
QDEL_IN_CLIENT_TIME(src, CREDIT_EASE_DURATION)

/obj/screen/credit/Destroy()
var/client/P = parent
if(istype(P))
Expand Down
6 changes: 3 additions & 3 deletions code/controllers/subsystems/garbage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ SUBSYSTEM_DEF(garbage)
qdel(D, force)
#endif

// Should be treated as a replacement for the 'del' keyword.
// Datums passed to this will be given a chance to clean up references to allow the GC to collect them.
/// Should be treated as a replacement for the 'del' keyword.
/// Datums passed to this will be given a chance to clean up references to allow the GC to collect them.
/// Non-datums passed to this will be hard-deleted.
/proc/qdel(datum/D, force=FALSE)
if(isnull(D))
return
if(!istype(D))
PRINT_STACK_TRACE("qdel() can only handle /datum (sub)types, was passed: [log_info_line(D)]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want qdel() on non-instances to error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

images :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this response. Images harddel'd prior to this PR so I'm not sure what the purpose of these changes is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? images still get qdel'd though. you literally added code in the footprints pr that qdel_list'd a list of images. and it should be fine to qdel an image, but this code makes that throw a useless error. istype(/image, /datum) is false, it will throw a pointless error if you try to qdel an image, and if you do this you can't do QDEL_IN(image, X). the only real case where it should error is if we pass a primitive like text or a number, which shouldn't get del'd anyway, and if you want i can add a CRASH for that but it seems unnecessary

Copy link
Contributor

@MistakeNot4892 MistakeNot4892 Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation.
The qdel list in footprints is a mistake (per Discord) - I'm not sure we should be implicitly supporting the qdel of images/lists, since they're better left to the GC. No strong feelings on the matter though. The CRASH on an invalid qdel param has been useful in the past for me however.

del(D)
return
var/datum/qdel_item/I = SSgarbage.items[D.type]
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystems/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ SUBSYSTEM_DEF(mapping)
. = list()
for(var/template_type in subtypesof(/datum/map_template))
var/datum/map_template/template = template_type
if(!TYPE_IS_ABSTRACT(template) && initial(template.template_parent_type) != template_type && initial(template.name))
if(!TYPE_IS_ABSTRACT(template))
. += new template_type(type) // send name as a param to catch people doing illegal ad hoc creation

/datum/controller/subsystem/mapping/proc/get_template(var/template_name)
Expand Down
15 changes: 8 additions & 7 deletions code/controllers/subsystems/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ SUBSYSTEM_DEF(shuttle)

/datum/controller/subsystem/shuttle/proc/initialize_shuttle(var/shuttle_type, var/map_hash, var/list/add_args)
var/datum/shuttle/shuttle = shuttle_type
if(initial(shuttle.category) != shuttle_type)
var/list/shuttle_args = list(map_hash)
if(length(add_args))
shuttle_args += add_args
shuttle = new shuttle(arglist(shuttle_args))
shuttle_areas |= shuttle.shuttle_area
return shuttle
if(TYPE_IS_ABSTRACT(shuttle))
return null
var/list/shuttle_args = list(map_hash)
if(length(add_args))
shuttle_args += add_args
shuttle = new shuttle(arglist(shuttle_args))
shuttle_areas |= shuttle.shuttle_area
return shuttle

/datum/controller/subsystem/shuttle/proc/hook_up_motherships(shuttles_list)
for(var/datum/shuttle/S in shuttles_list)
Expand Down
2 changes: 0 additions & 2 deletions code/datums/traits/maluses/amputations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
if(trait_type == type)
continue
var/decl/trait/malus/amputation/trait = check_traits[trait_type]
if(!trait.name)
continue // remove when abstract decl handling from dev is merged
for(var/limb in trait.apply_to_limbs)
if(limb in ban_traits_relating_to_limbs)
LAZYDISTINCTADD(incompatible_with, trait_type)
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/effects/chem/water.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
break

sleep(delay)
sleep(10)
qdel(src)
QDEL_IN(src, 1 SECOND)

/obj/effect/effect/water/Move(turf/newloc)
if(newloc.density)
Expand Down
18 changes: 6 additions & 12 deletions code/game/objects/effects/mines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@
if(ismob(obj))
var/mob/mob = obj
mob.add_genetic_condition(pick(decls_repository.get_decls_of_type(/decl/genetic_condition/disability)))
spawn(0)
qdel(src)
qdel(src)

/obj/effect/mine/proc/triggerstun(obj)
if(ismob(obj))
var/mob/M = obj
SET_STATUS_MAX(M, STAT_STUN, 30)
spark_at(src, cardinal_only = TRUE)
spawn(0)
qdel(src)
qdel(src)

/obj/effect/mine/proc/triggern2o(obj)
//example: n2o triggerproc
Expand All @@ -53,30 +51,26 @@
if(target.simulated && !target.blocks_air)
target.assume_gas(/decl/material/gas/nitrous_oxide, 30)

spawn(0)
qdel(src)
qdel(src)

/obj/effect/mine/proc/triggerflame(obj)
for (var/turf/target in range(1,src))
if(target.simulated && !target.blocks_air)
target.assume_gas(/decl/material/gas/hydrogen, 30)
target.hotspot_expose(1000, CELL_VOLUME)

spawn(0)
qdel(src)
qdel(src)

/obj/effect/mine/proc/triggerkick(obj)
spark_at(src, cardinal_only = TRUE)
if(ismob(obj))
var/mob/victim = obj
qdel(victim.client)
spawn(0)
qdel(src)
qdel(src)

/obj/effect/mine/proc/explode(obj)
explosion(loc, 0, 1, 2, 3)
spawn(0)
qdel(src)
qdel(src)

/obj/effect/mine/dnascramble
name = "Radiation Mine"
Expand Down
10 changes: 8 additions & 2 deletions code/game/objects/effects/temporary.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
layer = ABOVE_HUMAN_LAYER
mouse_opacity = MOUSE_OPACITY_UNCLICKABLE
simulated = FALSE
var/duration = 10 //in deciseconds
var/duration = 1 SECOND //in deciseconds

/obj/effect/temp_visual/Initialize(mapload, set_dir)
if(set_dir)
Expand All @@ -17,9 +17,15 @@
icon = 'icons/effects/effects.dmi'
icon_state = "empdisable"

/obj/effect/temp_visual/emppulse
name = "electromagnetic pulse"
icon = 'icons/effects/effects.dmi'
icon_state = "emppulse"
duration = 2 SECONDS

/obj/effect/temp_visual/bloodsplatter
icon = 'icons/effects/bloodspatter.dmi'
duration = 5
duration = 0.5 SECONDS
layer = LYING_HUMAN_LAYER
var/splatter_type = "splatter"

Expand Down
8 changes: 1 addition & 7 deletions code/game/objects/empulse.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
log_and_message_admins("EMP with size ([heavy_range], [light_range]) in area [epicenter.loc.name] ")

if(heavy_range > 1)
var/obj/effect/overlay/pulse = new/obj/effect/overlay(epicenter)
pulse.icon = 'icons/effects/effects.dmi'
pulse.icon_state = "emppulse"
pulse.SetName("electromagnetic pulse")
pulse.anchored = TRUE
spawn(20)
qdel(pulse)
new /obj/effect/temp_visual/emppulse(epicenter)

if(heavy_range > light_range)
light_range = heavy_range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
/obj/item/grenade/anti_photon/proc/finish()
set_light(10, 10, rgb(rand(64,255), rand(64,255), rand(64,255)))
playsound(loc, 'sound/effects/bang.ogg', 50, 1, 5)
sleep(1 SECOND)
qdel(src)
QDEL_IN(src, 1 SECOND)
6 changes: 2 additions & 4 deletions code/game/objects/items/weapons/weaponry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@

/obj/item/energy_net/dropped()
..()
spawn(10)
if(src) qdel(src)
QDEL_IN(src, 1 SECOND)

/obj/item/energy_net/throw_impact(atom/hit_atom)
..()
Expand All @@ -85,8 +84,7 @@
qdel(src)

// If we miss or hit an obstacle, we still want to delete the net.
spawn(10)
if(src) qdel(src)
QDEL_IN(src, 1 SECOND)

/obj/effect/energy_net
name = "energy net"
Expand Down
5 changes: 2 additions & 3 deletions code/game/world_topic_commands.dm
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,5 @@
uid = "topic_command_prometheus_metrics"

/decl/topic_command/secure/prometheus_metrics/use()
if(!global.prometheus_metrics)
return "Metrics not ready"
return global.prometheus_metrics.collect()
var/static/decl/prometheus_metrics/prometheus_metrics = IMPLIED_DECL
return prometheus_metrics.collect()
57 changes: 28 additions & 29 deletions code/modules/admin/secrets/investigation/attack_logs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,66 +69,65 @@
. = filters_per_client[user.client]
if(!.)
. = list()
for(var/af_type in subtypesof(/attack_filter))
var/attack_filter/af = af_type
if(initial(af.category) == af_type)
for(var/datum/attack_filter/af_type as anything in subtypesof(/datum/attack_filter))
if(TYPE_IS_ABSTRACT(af_type))
continue
. += new af_type(src)
filters_per_client[user.client] = .

/datum/admin_secret_item/investigation/attack_logs/proc/get_filter_html(user)
. = list()
for(var/filter in get_user_filters(user))
var/attack_filter/af = filter
var/datum/attack_filter/af = filter
. += af.get_html()
. = jointext(.," | ")

/datum/admin_secret_item/investigation/attack_logs/proc/filter_log(user, var/datum/attack_log/al)
for(var/filter in get_user_filters(user))
var/attack_filter/af = filter
var/datum/attack_filter/af = filter
if(af.filter_attack(al))
return TRUE
return FALSE

/datum/admin_secret_item/investigation/attack_logs/proc/reset_user_filters(user)
for(var/filter in get_user_filters(user))
var/attack_filter/af = filter
var/datum/attack_filter/af = filter
af.reset()

/attack_filter
var/category = /attack_filter
/datum/attack_filter
abstract_type = /datum/attack_filter
var/datum/admin_secret_item/investigation/attack_logs/holder

/attack_filter/New(var/holder)
/datum/attack_filter/New(var/holder)
..()
src.holder = holder

/attack_filter/Topic(href, href_list)
/datum/attack_filter/Topic(href, href_list)
if(..())
return TRUE
if(OnTopic(href_list))
holder.execute(usr)
return TRUE

/attack_filter/proc/get_html()
/datum/attack_filter/proc/get_html()
return

/attack_filter/proc/reset()
/datum/attack_filter/proc/reset()
return

/attack_filter/proc/filter_attack(var/datum/attack_log/al)
/datum/attack_filter/proc/filter_attack(var/datum/attack_log/al)
return FALSE

/attack_filter/proc/OnTopic(href_list)
/datum/attack_filter/proc/OnTopic(href_list)
return FALSE

/*
* Filter logs with one or more missing clients
*/
/attack_filter/no_client
/datum/attack_filter/no_client
var/filter_missing_clients = TRUE

/attack_filter/no_client/get_html()
/datum/attack_filter/no_client/get_html()
. = list()
. += "Must have clients: "
if(filter_missing_clients)
Expand All @@ -137,18 +136,18 @@
. += "<a href='byond://?src=\ref[src];yes=1'>Yes</a><span class='linkOn'>No</span>"
. = jointext(.,null)

/attack_filter/no_client/OnTopic(href_list)
/datum/attack_filter/no_client/OnTopic(href_list)
if(href_list["yes"] && !filter_missing_clients)
filter_missing_clients = TRUE
return TRUE
if(href_list["no"] && filter_missing_clients)
filter_missing_clients = FALSE
return TRUE

/attack_filter/no_client/reset()
/datum/attack_filter/no_client/reset()
filter_missing_clients = initial(filter_missing_clients)

/attack_filter/no_client/filter_attack(var/datum/attack_log/al)
/datum/attack_filter/no_client/filter_attack(var/datum/attack_log/al)
if(!filter_missing_clients)
return FALSE
if(al.attacker && al.attacker.client.ckey == NO_CLIENT_CKEY)
Expand All @@ -160,19 +159,19 @@
/*
Either subject must be the selected client
*/
/attack_filter/must_be_given_ckey
/datum/attack_filter/must_be_given_ckey
var/ckey_filter
var/check_attacker = TRUE
var/check_victim = TRUE
var/description = "Either ckey is"

/attack_filter/must_be_given_ckey/reset()
/datum/attack_filter/must_be_given_ckey/reset()
ckey_filter = null

/attack_filter/must_be_given_ckey/get_html()
/datum/attack_filter/must_be_given_ckey/get_html()
return "[description]: <a href='byond://?src=\ref[src];select_ckey=1'>[ckey_filter ? ckey_filter : "*ANY*"]</a>"

/attack_filter/must_be_given_ckey/OnTopic(href_list)
/datum/attack_filter/must_be_given_ckey/OnTopic(href_list)
if(!href_list["select_ckey"])
return
var/ckey = input("Select ckey to filter on","Select ckey", ckey_filter) as null|anything in get_ckeys()
Expand All @@ -183,7 +182,7 @@
ckey_filter = ckey
return TRUE

/attack_filter/must_be_given_ckey/proc/get_ckeys()
/datum/attack_filter/must_be_given_ckey/proc/get_ckeys()
. = list()
for(var/log in attack_log_repository.attack_logs_)
var/datum/attack_log/al = log
Expand All @@ -194,7 +193,7 @@
. = sortTim(., /proc/cmp_text_asc)
. += "*ANY*"

/attack_filter/must_be_given_ckey/filter_attack(var/datum/attack_log/al)
/datum/attack_filter/must_be_given_ckey/filter_attack(var/datum/attack_log/al)
if(!ckey_filter)
return FALSE
if(check_attacker && al.attacker && al.attacker.client.ckey == ckey_filter)
Expand All @@ -206,19 +205,19 @@
/*
Attacker must be the selected client
*/
/attack_filter/must_be_given_ckey/attacker
/datum/attack_filter/must_be_given_ckey/attacker
description = "Attacker ckey is"
check_victim = FALSE

/attack_filter/must_be_given_ckey/attacker/filter_attack(al)
/datum/attack_filter/must_be_given_ckey/attacker/filter_attack(al)
return ..(al, TRUE, FALSE)

/*
Victim must be the selected client
*/
/attack_filter/must_be_given_ckey/victim
/datum/attack_filter/must_be_given_ckey/victim
description = "Victim ckey is"
check_attacker = FALSE

/attack_filter/must_be_given_ckey/victim/filter_attack(al)
/datum/attack_filter/must_be_given_ckey/victim/filter_attack(al)
return ..(al, FALSE, TRUE)
Loading