Skip to content

Commit 05e8131

Browse files
AbsolucyLemonInTheDarkSealed101
authored
[PORT] Stabilizes code that flicks overlays to view/all clients (#6631)
Co-authored-by: LemonInTheDark <[email protected]> Co-authored-by: Sealed101 <[email protected]>
1 parent 2776f58 commit 05e8131

File tree

14 files changed

+84
-59
lines changed

14 files changed

+84
-59
lines changed

code/__HELPERS/game.dm

+34-10
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,15 @@
139139
for(var/client/remove_from in hide_from)
140140
remove_from.images -= image_to_remove
141141

142-
143-
///Add an image to a list of clients and calls a proc to remove it after a duration
142+
/// Add an image to a list of clients and calls a proc to remove it after a duration
144143
/proc/flick_overlay_global(image/image_to_show, list/show_to, duration)
145144
if(!show_to || !length(show_to) || !image_to_show)
146145
return
147146
for(var/client/add_to in show_to)
148147
add_to.images += image_to_show
149148
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(remove_image_from_clients), image_to_show, show_to), duration, TIMER_CLIENT_TIME)
150149

151-
/// Flicks a certain overlay onto an atom, handling icon_state strings
150+
///Flicks a certain overlay onto an atom, handling icon_state strings
152151
/atom/proc/flick_overlay(image_to_show, list/show_to, duration, layer)
153152
var/image/passed_image = \
154153
istext(image_to_show) \
@@ -157,13 +156,38 @@
157156

158157
flick_overlay_global(passed_image, show_to, duration)
159158

160-
/// flicks an overlay to anyone who can view this atom
161-
/atom/proc/flick_overlay_view(image_to_show, duration)
162-
var/list/viewing = list()
163-
for(var/mob/viewer as anything in viewers(src))
164-
if(viewer.client)
165-
viewing += viewer.client
166-
flick_overlay(image_to_show, viewing, duration)
159+
/**
160+
* Helper atom that copies an appearance and exists for a period
161+
*/
162+
/atom/movable/flick_visual
163+
164+
/// Takes the passed in MA/icon_state, mirrors it onto ourselves, and displays that in world for duration seconds
165+
/// Returns the displayed object, you can animate it and all, but you don't own it, we'll delete it after the duration
166+
/atom/proc/flick_overlay_view(mutable_appearance/display, duration)
167+
if(!display)
168+
return null
169+
170+
var/mutable_appearance/passed_appearance = \
171+
istext(display) \
172+
? mutable_appearance(icon, display, layer) \
173+
: display
174+
175+
// If you don't give it a layer, we assume you want it to layer on top of this atom
176+
// Because this is vis_contents, we need to set the layer manually (you can just set it as you want on return if this is a problem)
177+
if(passed_appearance.layer == FLOAT_LAYER)
178+
passed_appearance.layer = layer + 0.1
179+
// This is faster then pooling. I promise
180+
var/atom/movable/flick_visual/visual = new()
181+
visual.appearance = passed_appearance
182+
visual.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
183+
// I hate /area
184+
var/atom/movable/lies_to_children = src
185+
lies_to_children.vis_contents += visual
186+
QDEL_IN_CLIENT_TIME(visual, duration)
187+
return visual
188+
189+
/area/flick_overlay_view(mutable_appearance/display, duration)
190+
return
167191

168192
///Get active players who are playing in the round
169193
/proc/get_active_player_count(alive_check = FALSE, afk_check = FALSE, human_check = FALSE)

code/controllers/subsystem/wardrobe.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ SUBSYSTEM_DEF(wardrobe)
310310
initial_callbacks[/obj/item/organ] = play_with
311311

312312
play_with = new /list(WARDROBE_CALLBACK_REMOVE)
313-
play_with[WARDROBE_CALLBACK_REMOVE] = CALLBACK(null, TYPE_PROC_REF(/obj/item/storage/box/survival,wardrobe_removal))
313+
play_with[WARDROBE_CALLBACK_REMOVE] = CALLBACK(null, TYPE_PROC_REF(/obj/item/storage/box/survival, wardrobe_removal))
314314
initial_callbacks[/obj/item/storage/box/survival] = play_with
315315

316316
/datum/controller/subsystem/wardrobe/proc/load_outfits()

code/game/atoms.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
///overlays managed by [update_overlays][/atom/proc/update_overlays] to prevent removing overlays that weren't added by the same proc. Single items are stored on their own, not in a list.
6161
var/list/managed_overlays
6262

63-
/// Lazylist of all images (hopefully attached to us) to update when we change z levels
63+
/// Lazylist of all images (or atoms, I'm sorry) (hopefully attached to us) to update when we change z levels
6464
/// You will need to manage adding/removing from this yourself, but I'll do the updating for you
6565
var/list/image/update_on_z
6666

code/game/atoms_movable.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@
12021202

12031203
if(update_on_z)
12041204
// I so much wish this could be somewhere else. alas, no.
1205-
for(var/image/update in update_on_z)
1205+
for(var/image/update as anything in update_on_z)
12061206
SET_PLANE(update, PLANE_TO_TRUE(update.plane), new_turf)
12071207
if(update_overlays_on_z)
12081208
// This EVEN more so

code/game/machinery/scan_gate.dm

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@
207207
if(next_beep <= world.time)
208208
next_beep = world.time + (2 SECONDS)
209209
playsound(src, 'sound/machines/scanbuzz.ogg', 100, FALSE)
210-
var/image/alarm_image = image(icon, src, "alarm_light", layer+1)
211-
flick_overlay_view(alarm_image, 2 SECONDS)
210+
var/mutable_appearance/alarm_display = mutable_appearance(icon, "alarm_light")
211+
flick_overlay_view(alarm_display, 2 SECONDS)
212212
set_scanline("alarm", 2 SECONDS)
213213

214214
/obj/machinery/scanner_gate/can_interact(mob/user)

code/game/objects/items.dm

+11-11
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@
14611461
if(!istype(loc, /turf))
14621462
return
14631463
source = loc
1464-
var/image/pickup_animation = image(icon = src, loc = source, layer = layer + 0.1)
1464+
var/image/pickup_animation = image(icon = src)
14651465
SET_PLANE(pickup_animation, GAME_PLANE, source)
14661466
pickup_animation.transform.Scale(0.75)
14671467
pickup_animation.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
@@ -1482,13 +1482,13 @@
14821482
to_y += 10
14831483
pickup_animation.pixel_x += 6 * (prob(50) ? 1 : -1) //6 to the right or left, helps break up the straight upward move
14841484

1485-
flick_overlay_global(pickup_animation, GLOB.clients, 4)
1486-
var/matrix/animation_matrix = new(pickup_animation.transform)
1485+
var/atom/movable/flick_visual/pickup = source.flick_overlay_view(pickup_animation, 0.4 SECONDS)
1486+
var/matrix/animation_matrix = new(pickup.transform)
14871487
animation_matrix.Turn(pick(-30, 30))
14881488
animation_matrix.Scale(0.65)
14891489

1490-
animate(pickup_animation, alpha = 175, pixel_x = to_x, pixel_y = to_y, time = 3, transform = animation_matrix, easing = CUBIC_EASING)
1491-
animate(alpha = 0, transform = matrix().Scale(0.7), time = 1)
1490+
animate(pickup, alpha = 175, pixel_x = to_x, pixel_y = to_y, time = 0.3 SECONDS, transform = animation_matrix, easing = CUBIC_EASING)
1491+
animate(alpha = 0, transform = matrix().Scale(0.7), time = 0.1 SECONDS)
14921492

14931493
/obj/item/proc/do_drop_animation(atom/moving_from)
14941494
if(!istype(loc, /turf))
@@ -1535,9 +1535,9 @@
15351535
/atom/movable/proc/do_item_attack_animation(atom/attacked_atom, visual_effect_icon, obj/item/used_item)
15361536
var/image/attack_image
15371537
if(visual_effect_icon)
1538-
attack_image = image('icons/effects/effects.dmi', attacked_atom, visual_effect_icon, attacked_atom.layer + 0.1)
1538+
attack_image = image(icon = 'icons/effects/effects.dmi', icon_state = visual_effect_icon)
15391539
else if(used_item)
1540-
attack_image = image(icon = used_item, loc = attacked_atom, layer = attacked_atom.layer + 0.1)
1540+
attack_image = image(icon = used_item)
15411541
attack_image.plane = attacked_atom.plane + 1
15421542

15431543
// Scale the icon.
@@ -1564,12 +1564,12 @@
15641564
if(!attack_image)
15651565
return
15661566

1567-
flick_overlay_global(attack_image, GLOB.clients, 10)
1567+
var/atom/movable/flick_visual/attack = attacked_atom.flick_overlay_view(attack_image, 1 SECONDS)
15681568
var/matrix/copy_transform = new(transform)
15691569
// And animate the attack!
1570-
animate(attack_image, alpha = 175, transform = copy_transform.Scale(0.75), pixel_x = 0, pixel_y = 0, pixel_z = 0, time = 3)
1571-
animate(time = 1)
1572-
animate(alpha = 0, time = 3, easing = CIRCULAR_EASING|EASE_OUT)
1570+
animate(attack, alpha = 175, transform = copy_transform.Scale(0.75), pixel_x = 0, pixel_y = 0, pixel_z = 0, time = 0.3 SECONDS)
1571+
animate(time = 0.1 SECONDS)
1572+
animate(alpha = 0, time = 0.3 SECONDS, easing = CIRCULAR_EASING|EASE_OUT)
15731573

15741574
/// Common proc used by painting tools like spraycans and palettes that can access the entire 24 bits color space.
15751575
/obj/item/proc/pick_painting_tool_color(mob/user, default_color)

code/game/objects/items/devices/laserpointer.dm

+6-6
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@
167167

168168
//laser pointer image
169169
icon_state = "pointer_[pointer_icon_state]"
170-
var/image/I = image('icons/obj/weapons/guns/projectiles.dmi',targloc,pointer_icon_state,10)
170+
var/mutable_appearance/laser = mutable_appearance('icons/obj/weapons/guns/projectiles.dmi', pointer_icon_state, 10)
171171
var/list/modifiers = params2list(params)
172172
if(modifiers)
173173
if(LAZYACCESS(modifiers, ICON_X))
174-
I.pixel_x = (text2num(LAZYACCESS(modifiers, ICON_X)) - 16)
174+
laser.pixel_x = (text2num(LAZYACCESS(modifiers, ICON_X)) - 16)
175175
if(LAZYACCESS(modifiers, ICON_Y))
176-
I.pixel_y = (text2num(LAZYACCESS(modifiers, ICON_Y)) - 16)
176+
laser.pixel_y = (text2num(LAZYACCESS(modifiers, ICON_Y)) - 16)
177177
else
178-
I.pixel_x = target.pixel_x + rand(-5,5)
179-
I.pixel_y = target.pixel_y + rand(-5,5)
178+
laser.pixel_x = target.pixel_x + rand(-5,5)
179+
laser.pixel_y = target.pixel_y + rand(-5,5)
180180

181181
if(outmsg)
182182
to_chat(user, outmsg)
@@ -192,7 +192,7 @@
192192
to_chat(user, span_warning("[src]'s battery is overused, it needs time to recharge!"))
193193
recharge_locked = TRUE
194194

195-
targloc.flick_overlay_view(I, 10)
195+
targloc.flick_overlay_view(laser, 1 SECONDS)
196196
icon_state = "pointer"
197197

198198
/obj/item/laser_pointer/process(seconds_per_tick)

code/game/objects/structures/crates_lockers/closets/cardboardbox.dm

+10-9
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,19 @@
7575

7676
/// Does the MGS ! animation
7777
/atom/proc/do_alert_animation()
78-
var/image/alert_image = image('icons/obj/storage/closet.dmi', src, "cardboard_special", layer+1)
79-
SET_PLANE_EXPLICIT(alert_image, ABOVE_LIGHTING_PLANE, src)
80-
flick_overlay_view(alert_image, 0.8 SECONDS)
81-
alert_image.alpha = 0
82-
animate(alert_image, pixel_z = 32, alpha = 255, time = 0.5 SECONDS, easing = ELASTIC_EASING)
78+
var/mutable_appearance/alert = mutable_appearance('icons/obj/storage/closet.dmi', "cardboard_special")
79+
SET_PLANE_EXPLICIT(alert, ABOVE_LIGHTING_PLANE, src)
80+
var/atom/movable/flick_visual/exclamation = flick_overlay_view(alert, 1 SECONDS)
81+
exclamation.alpha = 0
82+
animate(exclamation, pixel_z = 32, alpha = 255, time = 0.5 SECONDS, easing = ELASTIC_EASING)
8383
// We use this list to update plane values on parent z change, which is why we need the timer too
8484
// I'm sorry :(
85-
LAZYADD(update_on_z, alert_image)
86-
addtimer(CALLBACK(src, PROC_REF(forget_alert_image), alert_image), 0.8 SECONDS)
85+
LAZYADD(update_on_z, exclamation)
86+
// Intentionally less time then the flick so we don't get weird shit
87+
addtimer(CALLBACK(src, PROC_REF(forget_alert), exclamation), 0.8 SECONDS, TIMER_CLIENT_TIME)
8788

88-
/atom/proc/forget_alert_image(image/alert_image)
89-
LAZYREMOVE(update_on_z, alert_image)
89+
/atom/proc/forget_alert(atom/movable/flick_visual/exclamation)
90+
LAZYREMOVE(update_on_z, exclamation)
9091

9192
/obj/structure/closet/cardboard/metal
9293
name = "large metal box"

code/game/turfs/closed/minerals.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@
731731
/turf/closed/mineral/gibtonite/proc/countdown(notify_admins = FALSE)
732732
set waitfor = FALSE
733733
while(istype(src, /turf/closed/mineral/gibtonite) && stage == GIBTONITE_ACTIVE && det_time > 0 && mineralAmt >= 1)
734-
flick_overlay_view(image('icons/turf/smoothrocks.dmi', src, "rock_Gibtonite_active"), 5) //makes the animation pulse one time per tick
734+
flick_overlay_view(mutable_appearance('icons/turf/smoothrocks.dmi', "rock_Gibtonite_active", ON_EDGED_TURF_LAYER + 0.1), 0.5 SECONDS) //makes the animation pulse one time per tick
735735
det_time--
736736
sleep(0.5 SECONDS)
737737
if(istype(src, /turf/closed/mineral/gibtonite))

code/modules/antagonists/heretic/magic/fire_blast.dm

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@
129129

130130
/datum/status_effect/fire_blasted/on_apply()
131131
if(owner.on_fire && animate_duration > 0 SECONDS)
132-
var/image/warning_sign = image(icon = 'icons/effects/effects.dmi', icon_state = "blessed", layer = BELOW_MOB_LAYER, loc = owner)
133-
owner.flick_overlay_view(warning_sign, initial(duration))
134-
warning_sign.alpha = 50
135-
animate(warning_sign, alpha = 255, time = animate_duration)
132+
var/mutable_appearance/warning_sign = mutable_appearance('icons/effects/effects.dmi', "blessed", BELOW_MOB_LAYER)
133+
var/atom/movable/flick_visual/warning = owner.flick_overlay_view(warning_sign, initial(duration))
134+
warning.alpha = 50
135+
animate(warning, alpha = 255, time = animate_duration)
136136

137137
return TRUE
138138

code/modules/hydroponics/hydroponics.dm

+2-2
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,9 @@
828828
// Beakers, bottles, buckets, etc.
829829
if(reagent_source.is_drainable())
830830
playsound(loc, 'sound/effects/slosh.ogg', 25, TRUE)
831-
var/image/splash_animation = image('icons/effects/effects.dmi', src, "splash_hydroponics")
831+
var/mutable_appearance/splash_animation = mutable_appearance('icons/effects/effects.dmi', "splash_hydroponics")
832832
splash_animation.color = mix_color_from_reagents(reagent_source.reagents.reagent_list)
833-
flick_overlay_global(splash_animation, GLOB.clients, 1.1 SECONDS)
833+
flick_overlay_view(splash_animation, 1.1 SECONDS)
834834

835835
if(visi_msg)
836836
visible_message(span_notice("[visi_msg]."))

code/modules/mob/living/living_defense.dm

+5-5
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,13 @@
570570
*/
571571
/mob/living/proc/do_slap_animation(atom/slapped)
572572
do_attack_animation(slapped, no_effect=TRUE)
573-
var/image/gloveimg = image('icons/effects/effects.dmi', slapped, "slapglove", slapped.layer + 0.1)
574-
gloveimg.pixel_y = 10 // should line up with head
575-
gloveimg.pixel_x = 10
576-
flick_overlay_global(gloveimg, GLOB.clients, 10)
573+
var/mutable_appearance/glove_appearance = mutable_appearance('icons/effects/effects.dmi', "slapglove")
574+
glove_appearance.pixel_y = 10 // should line up with head
575+
glove_appearance.pixel_x = 10
576+
var/atom/movable/flick_visual/glove = slapped.flick_overlay_view(glove_appearance, 1 SECONDS)
577577

578578
// And animate the attack!
579-
animate(gloveimg, alpha = 175, transform = matrix() * 0.75, pixel_x = 0, pixel_y = 10, pixel_z = 0, time = 3)
579+
animate(glove, alpha = 175, transform = matrix() * 0.75, pixel_x = 0, pixel_y = 10, pixel_z = 0, time = 3)
580580
animate(time = 1)
581581
animate(alpha = 0, time = 3, easing = CIRCULAR_EASING|EASE_OUT)
582582

code/modules/reagents/reagent_containers.dm

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@
180180

181181
playsound(target, 'sound/effects/slosh.ogg', 25, TRUE)
182182

183-
var/image/splash_animation = image('icons/effects/effects.dmi', target, "splash")
183+
var/mutable_appearance/splash_animation = mutable_appearance('icons/effects/effects.dmi', "splash")
184184
if(isturf(target))
185-
splash_animation = image('icons/effects/effects.dmi', target, "splash_floor")
185+
splash_animation.icon_state = "splash_floor"
186186
splash_animation.color = mix_color_from_reagents(reagents.reagent_list)
187-
flick_overlay_global(splash_animation, GLOB.clients, 1.0 SECONDS)
187+
target.flick_overlay_view(splash_animation, 1 SECONDS)
188188

189189
for(var/datum/reagent/reagent as anything in reagents.reagent_list)
190190
reagent_text += "[reagent] ([num2text(reagent.volume)]),"
@@ -301,11 +301,11 @@
301301

302302
playsound(target, 'sound/effects/slosh.ogg', 25, TRUE)
303303

304-
var/image/splash_animation = image('icons/effects/effects.dmi', target, "splash")
304+
var/mutable_appearance/splash_animation = mutable_appearance('icons/effects/effects.dmi', "splash")
305305
if(isturf(target))
306-
splash_animation = image('icons/effects/effects.dmi', target, "splash_floor")
306+
splash_animation.icon_state = "splash_floor"
307307
splash_animation.color = mix_color_from_reagents(reagents.reagent_list)
308-
flick_overlay_global(splash_animation, GLOB.clients, 1.0 SECONDS)
308+
target.flick_overlay_view(splash_animation, 1.0 SECONDS)
309309

310310
reagents.clear_reagents()
311311

icons/turf/smoothrocks.dmi

17 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)