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

[MIRROR] Small optimization for Aura Healing #2928

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/controllers/subsystem/processing/aura.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// The subsystem used to tick auras ([/datum/component/aura_healing] and [/datum/component/damage_aura]).
PROCESSING_SUBSYSTEM_DEF(aura)
name = "Aura"
flags = SS_NO_INIT | SS_BACKGROUND | SS_KEEP_TIMING
wait = 0.3 SECONDS
5 changes: 0 additions & 5 deletions code/controllers/subsystem/processing/aura_healing.dm

This file was deleted.

40 changes: 23 additions & 17 deletions code/datums/components/aura_healing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// Can be applied to those only with a trait conditionally.
/datum/component/aura_healing
/// The range of which to heal
var/range
var/range = 5

/// Whether or not you must be a visible object of the parent
var/requires_visibility = TRUE
Expand Down Expand Up @@ -42,12 +42,13 @@
var/healing_color = COLOR_GREEN

/// A list of being healed to active alerts
var/list/current_alerts = list()
var/list/mob/living/current_alerts = list()

/// Cooldown between showing the heal effect
COOLDOWN_DECLARE(last_heal_effect_time)

/datum/component/aura_healing/Initialize(
range,
range = 5,
requires_visibility = TRUE,
brute_heal = 0,
burn_heal = 0,
Expand All @@ -63,7 +64,7 @@
if (!isatom(parent))
return COMPONENT_INCOMPATIBLE

START_PROCESSING(SSaura_healing, src)
START_PROCESSING(SSaura, src)

src.range = range
src.requires_visibility = requires_visibility
Expand All @@ -79,10 +80,10 @@
src.healing_color = healing_color

/datum/component/aura_healing/Destroy(force)
STOP_PROCESSING(SSaura_healing, src)
STOP_PROCESSING(SSaura, src)
var/alert_category = "aura_healing_[REF(src)]"

for(var/mob/living/alert_holder in current_alerts)
for(var/mob/living/alert_holder as anything in current_alerts)
alert_holder.clear_alert(alert_category)
current_alerts.Cut()

Expand All @@ -93,20 +94,25 @@
if (should_show_effect)
COOLDOWN_START(src, last_heal_effect_time, HEAL_EFFECT_COOLDOWN)

var/list/remove_alerts_from = current_alerts.Copy()

var/list/to_heal = list()
var/alert_category = "aura_healing_[REF(src)]"

for (var/mob/living/candidate in (requires_visibility ? view(range, parent) : range(range, parent)))
if (!isnull(limit_to_trait) && !HAS_TRAIT(candidate, limit_to_trait))
continue

remove_alerts_from -= candidate

if (!(candidate in current_alerts))
if(requires_visibility)
for(var/mob/living/candidate in view(range, parent))
if (!isnull(limit_to_trait) && !HAS_TRAIT(candidate, limit_to_trait))
continue
to_heal[candidate] = TRUE
else
for(var/mob/living/candidate in range(range, parent))
if (!isnull(limit_to_trait) && !HAS_TRAIT(candidate, limit_to_trait))
continue
to_heal[candidate] = TRUE

for (var/mob/living/candidate as anything in to_heal)
if (!current_alerts[candidate])
var/atom/movable/screen/alert/aura_healing/alert = candidate.throw_alert(alert_category, /atom/movable/screen/alert/aura_healing, new_master = parent)
alert.desc = "You are being healed by [parent]."
current_alerts += candidate
current_alerts[candidate] = TRUE

if (should_show_effect && candidate.health < candidate.maxHealth)
new /obj/effect/temp_visual/heal(get_turf(candidate), healing_color)
Expand Down Expand Up @@ -136,7 +142,7 @@

candidate.updatehealth()

for (var/mob/remove_alert_from as anything in remove_alerts_from)
for (var/mob/living/remove_alert_from as anything in current_alerts - to_heal)
remove_alert_from.clear_alert(alert_category)
current_alerts -= remove_alert_from

Expand Down
18 changes: 13 additions & 5 deletions code/datums/components/damage_aura.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// Will deal more damage the more people are present.
/datum/component/damage_aura
/// The range of which to damage
var/range
var/range = 5

/// Whether or not you must be a visible object of the parent
var/requires_visibility = TRUE
Expand Down Expand Up @@ -43,7 +43,7 @@
COOLDOWN_DECLARE(last_damage_effect_time)

/datum/component/damage_aura/Initialize(
range,
range = 5,
requires_visibility = TRUE,
brute_damage = 0,
burn_damage = 0,
Expand All @@ -59,7 +59,7 @@
if (!isatom(parent))
return COMPONENT_INCOMPATIBLE

START_PROCESSING(SSobj, src)
START_PROCESSING(SSaura, src)

src.range = range
src.requires_visibility = requires_visibility
Expand All @@ -75,7 +75,7 @@
src.current_owner = WEAKREF(current_owner)

/datum/component/damage_aura/Destroy(force)
STOP_PROCESSING(SSobj, src)
STOP_PROCESSING(SSaura, src)
return ..()

/// The requirements for the mob to be effected by the damage aura.
Expand All @@ -102,7 +102,15 @@
if (should_show_effect)
COOLDOWN_START(src, last_damage_effect_time, DAMAGE_EFFECT_COOLDOWN)

for (var/mob/living/candidate in (requires_visibility ? view(range, parent) : range(range, parent)))
var/list/to_damage = list()
if(requires_visibility)
for(var/mob/living/candidate in view(range, parent))
to_damage += candidate
else
for(var/mob/living/candidate in range(range, parent))
to_damage += candidate

for (var/mob/living/candidate as anything in to_damage)
var/mob/living/owner = current_owner?.resolve()
if (owner && owner == candidate)
owner_effect(owner, seconds_per_tick)
Expand Down
2 changes: 1 addition & 1 deletion tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@
#include "code\controllers\subsystem\processing\ai_basic_avoidance.dm"
#include "code\controllers\subsystem\processing\ai_behaviors.dm"
#include "code\controllers\subsystem\processing\antag_hud.dm"
#include "code\controllers\subsystem\processing\aura_healing.dm"
#include "code\controllers\subsystem\processing\aura.dm"
#include "code\controllers\subsystem\processing\clock_component.dm"
#include "code\controllers\subsystem\processing\conveyors.dm"
#include "code\controllers\subsystem\processing\digital_clock.dm"
Expand Down
Loading