Skip to content

Commit

Permalink
Reusable visual optimisation (#2286)
Browse files Browse the repository at this point in the history
reusable visual optimisation
  • Loading branch information
Halonexus authored Jul 27, 2024
1 parent 7f35c95 commit 52b8afb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
29 changes: 19 additions & 10 deletions code/datums/reusable_visual_pool.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@
RV.invisibility = 0
return RV

/datum/reusable_visual_pool/proc/ReturnToPool(obj/effect/reusable_visual/RV, called_from_timer = FALSE)
/datum/reusable_visual_pool/proc/ReturnToPool(obj/effect/reusable_visual/RV)
if(!istype(RV) || RV.pool != src || !RV.is_being_used)
return FALSE
if(!called_from_timer && RV.timer_id)
deltimer(RV.timer_id)
RV.timer_id = null
RV.delayed_return_count = 0
RV.is_being_used = FALSE
RV.invisibility = 101
RV.can_be_z_moved = FALSE
Expand All @@ -66,56 +64,67 @@
available_objects[available_count] = RV
return TRUE

#define SET_RV_RETURN_TIMER(RV, DURATION) ##RV.duration = DURATION; ##RV.timer_id = addtimer(CALLBACK(##RV.pool, TYPE_PROC_REF(/datum/reusable_visual_pool, ReturnToPool), ##RV, TRUE), ##RV.duration, TIMER_STOPPABLE);
/datum/reusable_visual_pool/proc/DelayedReturn(obj/effect/reusable_visual/RV, duration)
set waitfor = 0
RV.duration = duration
RV.delayed_return_count += 1
sleep(duration)
if(QDELETED(RV))
return
if(RV.delayed_return_count < 2)
ReturnToPool(RV)
else
RV.delayed_return_count -= 1

//Create procs like these for whatever effects
/datum/reusable_visual_pool/proc/NewSmashEffect(turf/location, duration = 3, color = null)
var/obj/effect/reusable_visual/RV = TakePoolElement()
SET_RV_RETURN_TIMER(RV, duration)
RV.name = "smash"
RV.icon_state = "smash"
RV.color = color
RV.loc = location
DelayedReturn(RV, duration)
return RV

/datum/reusable_visual_pool/proc/NewSparkles(turf/location, duration = 10, color = null)
var/obj/effect/reusable_visual/RV = TakePoolElement()
SET_RV_RETURN_TIMER(RV, duration)
RV.name = "sparkles"
RV.icon = 'icons/effects/effects.dmi'
RV.icon_state = "sparkles"
RV.color = color
RV.dir = pick(GLOB.cardinals)
RV.loc = location
DelayedReturn(RV, duration)
return RV

/datum/reusable_visual_pool/proc/NewCultSparks(turf/location, duration = 10)
var/obj/effect/reusable_visual/RV = TakePoolElement()
SET_RV_RETURN_TIMER(RV, duration)
RV.name = "cult sparks"
RV.icon = 'icons/effects/cult_effects.dmi'
RV.icon_state = "bloodsparkles"
RV.dir = pick(GLOB.cardinals)
RV.loc = location
DelayedReturn(RV, duration)
return RV

/datum/reusable_visual_pool/proc/NewCultIn(turf/location, direction = SOUTH)
var/obj/effect/reusable_visual/RV = TakePoolElement()
SET_RV_RETURN_TIMER(RV, 7)
RV.name = "cult in"
RV.icon = 'icons/effects/cult_effects.dmi'
RV.icon_state = "cultin"
RV.dir = direction
RV.loc = location
DelayedReturn(RV, 7)
return RV

/datum/reusable_visual_pool/proc/NewSmoke(turf/location, duration = 10, color = null)
var/obj/effect/reusable_visual/RV = TakePoolElement()
SET_RV_RETURN_TIMER(RV, duration)
RV.name = "smoke"
RV.icon = 'icons/effects/effects.dmi'
RV.icon_state = "smoke"
RV.color = color
RV.dir = pick(GLOB.cardinals)
RV.loc = location
animate(RV, alpha = 0, time = duration)
DelayedReturn(RV, duration)
return RV
9 changes: 3 additions & 6 deletions code/game/objects/effects/reusable_visual.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
invisibility = 101
///Reference to the pool that created this object. Do not edit this.
var/datum/reusable_visual_pool/pool
///How long the effect will be in use. 0 means until manually returned to pool. Only the pool datum should edit this.
///How long the effect will be in use. Only the pool datum should edit this.
var/duration = 0
///Only the pool datum should edit this.
var/timer_id = null
///Only the pool datum should edit this.
var/is_being_used = FALSE
///How many DelayedReturn procs are currently existing for this object, it will only be returned by the last remaining DelayedReturn proc.
var/delayed_return_count = 0

/obj/effect/reusable_visual/New(datum/reusable_visual_pool/creator_pool)
pool = creator_pool
return ..()

/obj/effect/reusable_visual/Destroy()
if(timer_id)
deltimer(timer_id)
timer_id = null
pool = null
return ..()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ GLOBAL_LIST_EMPTY(apostles)
(target_c.y + i <= world.maxy ? getline(locate(min(target_c.x + i, world.maxx), target_c.y + i, target_c.z), locate(max(target_c.x - i + 1, 1), target_c.y + i, target_c.z)) : list()) +\
(target_c.x - i > 0 ? getline(locate(target_c.x - i, min(target_c.y + i, world.maxy), target_c.z), locate(target_c.x - i, max(target_c.y - i + 1, 1), target_c.z)) : list())
for(var/turf/open/T in turf_list)
CHECK_TICK
if(faction_check != "apostle")
RVP.NewSparkles(T, 10, "#AAFFAA") // Indicating that it's a good thing
else
RVP.NewCultSparks(T, 10)
for(var/mob/living/L in T)
RVP.NewCultIn(T, L.dir)
addtimer(CALLBACK(src, PROC_REF(revive_target), L, i, faction_check))
CHECK_TICK
INVOKE_ASYNC(src, PROC_REF(revive_target), L, i, faction_check)
SLEEP_CHECK_DEATH(1.5)

/mob/living/simple_animal/hostile/abnormality/white_night/proc/revive_target(mob/living/L, attack_range = 1, faction_check = "apostle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,13 @@

/datum/reusable_visual_pool/proc/NewPaleEyeAttack(turf/location, duration = 5)
var/obj/effect/reusable_visual/RV = TakePoolElement()
SET_RV_RETURN_TIMER(RV, duration)
RV.name = "pale particles"
RV.icon = 'icons/effects/effects.dmi'
RV.icon_state = "ion_fade_flight"
RV.dir = pick(GLOB.cardinals)
RV.loc = location
animate(RV, alpha = 0, time = duration)
DelayedReturn(RV, duration)
return RV

/obj/effect/pale_eye
Expand Down

0 comments on commit 52b8afb

Please sign in to comment.