[MIRROR] Stabilizes code that flicks overlays to view/all clients [MDB IGNORE] (#22601)

* Stabilizes code that flicks overlays to view/all clients (#76937)

## About The Pull Request

Rather then using images and displaying them with client.images, we can
instead simply make an object, give it the passed in image/MA's
appearance, and then vis_contents it where we want.

If you want to animate things, you can just use the atom we return from
the proc call.

This ends up costing about 25% of the best case scenario (one guy
online)
It will save more time with more users, but it also allows us to avoid
the hypersuffering that is passing GLOB.clients into the flick proc. So
I think I'm happy enough with this.

For context, here's average per call cost for flick_overlay_view() right
now.
It winds between 5e-5 and 1e-4. With these changes we should pretty
consistently hit the low end of this, because none of our work really
varies all that much.

![flick_avg](https://github.com/tgstation/tgstation/assets/58055496/3483e022-9cc5-490a-be5e-eb79f4e2110b)

(I was using sswardrobe for this, but it ends up being a lot slower so
like, why yaknow)
```
/atom/movable/flick_visual
        New: 3.65625ms
        Provide: 7.4375ms
        Qdel: 9.4375ms
        Stash: 9.46875ms
```

## Why It's Good For The Game

Using our tools should not make your code eat cpu time for no reason.
Hearers is expensive, iterating clients is expensive, let's not be
expensive.

* Stabilizes code that flicks overlays to view/all clients

* Not every client needs to see this

* and these could be using SECONDS

* grr DM

* Convert these modular files to seconds too

* Update dance_machine.dm

---------

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-07-20 18:59:09 -04:00
committed by GitHub
co-authored by LemonInTheDark Giz
parent d9c9533383
commit 8782f19258
23 changed files with 118 additions and 94 deletions
+11 -11
View File
@@ -1436,7 +1436,7 @@
if(!istype(loc, /turf))
return
source = loc
var/image/pickup_animation = image(icon = src, loc = source, layer = layer + 0.1)
var/image/pickup_animation = image(icon = src)
SET_PLANE(pickup_animation, GAME_PLANE, source)
pickup_animation.transform.Scale(0.75)
pickup_animation.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
@@ -1457,13 +1457,13 @@
to_y += 10
pickup_animation.pixel_x += 6 * (prob(50) ? 1 : -1) //6 to the right or left, helps break up the straight upward move
flick_overlay_global(pickup_animation, GLOB.clients, 4)
var/matrix/animation_matrix = new(pickup_animation.transform)
var/atom/movable/flick_visual/pickup = source.flick_overlay_view(pickup_animation, 0.4 SECONDS)
var/matrix/animation_matrix = new(pickup.transform)
animation_matrix.Turn(pick(-30, 30))
animation_matrix.Scale(0.65)
animate(pickup_animation, alpha = 175, pixel_x = to_x, pixel_y = to_y, time = 3, transform = animation_matrix, easing = CUBIC_EASING)
animate(alpha = 0, transform = matrix().Scale(0.7), time = 1)
animate(pickup, alpha = 175, pixel_x = to_x, pixel_y = to_y, time = 0.3 SECONDS, transform = animation_matrix, easing = CUBIC_EASING)
animate(alpha = 0, transform = matrix().Scale(0.7), time = 0.1 SECONDS)
/obj/item/proc/do_drop_animation(atom/moving_from)
if(!istype(loc, /turf))
@@ -1510,9 +1510,9 @@
/atom/movable/proc/do_item_attack_animation(atom/attacked_atom, visual_effect_icon, obj/item/used_item)
var/image/attack_image
if(visual_effect_icon)
attack_image = image('icons/effects/effects.dmi', attacked_atom, visual_effect_icon, attacked_atom.layer + 0.1)
attack_image = image(icon = 'icons/effects/effects.dmi', icon_state = visual_effect_icon)
else if(used_item)
attack_image = image(icon = used_item, loc = attacked_atom, layer = attacked_atom.layer + 0.1)
attack_image = image(icon = used_item)
attack_image.plane = attacked_atom.plane + 1
// Scale the icon.
@@ -1539,12 +1539,12 @@
if(!attack_image)
return
flick_overlay_global(attack_image, GLOB.clients, 10)
var/atom/movable/flick_visual/attack = attacked_atom.flick_overlay_view(attack_image, 1 SECONDS)
var/matrix/copy_transform = new(transform)
// And animate the attack!
animate(attack_image, alpha = 175, transform = copy_transform.Scale(0.75), pixel_x = 0, pixel_y = 0, pixel_z = 0, time = 3)
animate(time = 1)
animate(alpha = 0, time = 3, easing = CIRCULAR_EASING|EASE_OUT)
animate(attack, alpha = 175, transform = copy_transform.Scale(0.75), pixel_x = 0, pixel_y = 0, pixel_z = 0, time = 0.3 SECONDS)
animate(time = 0.1 SECONDS)
animate(alpha = 0, time = 0.3 SECONDS, easing = CIRCULAR_EASING|EASE_OUT)
/// Common proc used by painting tools like spraycans and palettes that can access the entire 24 bits color space.
/obj/item/proc/pick_painting_tool_color(mob/user, default_color)
@@ -165,16 +165,16 @@
//laser pointer image
icon_state = "pointer_[pointer_icon_state]"
var/image/I = image('icons/obj/weapons/guns/projectiles.dmi',targloc,pointer_icon_state,10)
var/mutable_appearance/laser = mutable_appearance('icons/obj/weapons/guns/projectiles.dmi', pointer_icon_state, 10)
var/list/modifiers = params2list(params)
if(modifiers)
if(LAZYACCESS(modifiers, ICON_X))
I.pixel_x = (text2num(LAZYACCESS(modifiers, ICON_X)) - 16)
laser.pixel_x = (text2num(LAZYACCESS(modifiers, ICON_X)) - 16)
if(LAZYACCESS(modifiers, ICON_Y))
I.pixel_y = (text2num(LAZYACCESS(modifiers, ICON_Y)) - 16)
laser.pixel_y = (text2num(LAZYACCESS(modifiers, ICON_Y)) - 16)
else
I.pixel_x = target.pixel_x + rand(-5,5)
I.pixel_y = target.pixel_y + rand(-5,5)
laser.pixel_x = target.pixel_x + rand(-5,5)
laser.pixel_y = target.pixel_y + rand(-5,5)
if(outmsg)
to_chat(user, outmsg)
@@ -190,7 +190,7 @@
to_chat(user, span_warning("[src]'s battery is overused, it needs time to recharge!"))
recharge_locked = TRUE
targloc.flick_overlay_view(I, 10)
targloc.flick_overlay_view(laser, 1 SECONDS)
icon_state = "pointer"
/obj/item/laser_pointer/process(seconds_per_tick)
@@ -81,18 +81,19 @@
/// Does the MGS ! animation
/atom/proc/do_alert_animation()
var/image/alert_image = image('icons/obj/storage/closet.dmi', src, "cardboard_special", layer+1)
SET_PLANE_EXPLICIT(alert_image, ABOVE_LIGHTING_PLANE, src)
flick_overlay_view(alert_image, 0.8 SECONDS)
alert_image.alpha = 0
animate(alert_image, pixel_z = 32, alpha = 255, time = 0.5 SECONDS, easing = ELASTIC_EASING)
var/mutable_appearance/alert = mutable_appearance('icons/obj/storage/closet.dmi', "cardboard_special")
SET_PLANE_EXPLICIT(alert, ABOVE_LIGHTING_PLANE, src)
var/atom/movable/flick_visual/exclamation = flick_overlay_view(alert, 1 SECONDS)
exclamation.alpha = 0
animate(exclamation, pixel_z = 32, alpha = 255, time = 0.5 SECONDS, easing = ELASTIC_EASING)
// We use this list to update plane values on parent z change, which is why we need the timer too
// I'm sorry :(
LAZYADD(update_on_z, alert_image)
addtimer(CALLBACK(src, PROC_REF(forget_alert_image), alert_image), 0.8 SECONDS)
LAZYADD(update_on_z, exclamation)
// Intentionally less time then the flick so we don't get weird shit
addtimer(CALLBACK(src, PROC_REF(forget_alert), exclamation), 0.8 SECONDS, TIMER_CLIENT_TIME)
/atom/proc/forget_alert_image(image/alert_image)
LAZYREMOVE(update_on_z, alert_image)
/atom/proc/forget_alert(atom/movable/flick_visual/exclamation)
LAZYREMOVE(update_on_z, exclamation)
/obj/structure/closet/cardboard/metal
name = "large metal box"
@@ -105,9 +105,9 @@
if(!has_buckled_mobs())
end_workout()
return FALSE
var/image/workout_icon = new(icon, src, "[base_icon_state]-o", ABOVE_MOB_LAYER)
workout_icon.plane = GAME_PLANE_UPPER
flick_overlay_view(workout_icon, 8)
var/mutable_appearance/workout = mutable_appearance(icon, "[base_icon_state]-o", ABOVE_MOB_LAYER)
SET_PLANE_EXPLICIT(workout, GAME_PLANE_UPPER, src)
flick_overlay_view(workout, 0.8 SECONDS)
flick("[base_icon_state]-u", src)
var/mob/living/user = buckled_mobs[1]
animate(user, pixel_y = pixel_shift_y, time = 4)