mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-18 21:15:21 +00:00
## About The Pull Request Converts /datum/component/mirage_border to an element, saving init time spent attaching components to thousands of objects. It also repaths it from /obj/effect/abstract to /atom/movable, since it doesn't need to be an object, as it's not a physical object within the game. ~~Also adds a case handling when world.view is not an integer.~~ This never happens Here it is working: https://github.com/tgstation/tgstation/assets/10366817/c8cfe2df-275a-4c97-b063-4fd83f7f09c3 Port of https://github.com/BeeStation/BeeStation-Hornet/pull/9490/ ## Why It's Good For The Game Saves init time, approx 0.32sec on Meta on my machine.   ## Changelog 🆑 code: Optimized z-level transition mirages, saving ~0.32s init. /🆑 --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
42 lines
1.7 KiB
Plaintext
42 lines
1.7 KiB
Plaintext
/**
|
|
* Creates a mirage effect allowing you to see around the world border, by adding the opposite side to its vis_contents.
|
|
*/
|
|
/datum/element/mirage_border
|
|
|
|
/datum/element/mirage_border/Attach(datum/target, turf/target_turf, direction, range=world.view)
|
|
. = ..()
|
|
if(!isturf(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
#ifdef TESTING
|
|
// This is a highly used proc, and these error states never occur, so limit it to testing.
|
|
// If something goes wrong it will runtime anyway.
|
|
if(!target_turf || !istype(target_turf) || !direction)
|
|
stack_trace("[type] improperly attached with the following args: target=\[[target_turf]\], direction=\[[direction]\], range=\[[range]\]")
|
|
return ELEMENT_INCOMPATIBLE
|
|
#endif
|
|
|
|
var/atom/movable/mirage_holder/holder = new(target)
|
|
|
|
var/x = target_turf.x
|
|
var/y = target_turf.y
|
|
var/z = clamp(target_turf.z, 1, world.maxz)
|
|
var/turf/southwest = locate(clamp(x - (direction & WEST ? range : 0), 1, world.maxx), clamp(y - (direction & SOUTH ? range : 0), 1, world.maxy), z)
|
|
var/turf/northeast = locate(clamp(x + (direction & EAST ? range : 0), 1, world.maxx), clamp(y + (direction & NORTH ? range : 0), 1, world.maxy), z)
|
|
holder.vis_contents += block(southwest, northeast)
|
|
if(direction & SOUTH)
|
|
holder.pixel_y -= world.icon_size * range
|
|
if(direction & WEST)
|
|
holder.pixel_x -= world.icon_size * range
|
|
|
|
/datum/element/mirage_border/Detach(atom/movable/target)
|
|
. = ..()
|
|
var/atom/movable/mirage_holder/held = locate() in target.contents
|
|
if(held)
|
|
qdel(held)
|
|
|
|
INITIALIZE_IMMEDIATE(/atom/movable/mirage_holder)
|
|
// Using /atom/movable because this is a heavily used path
|
|
/atom/movable/mirage_holder
|
|
name = "Mirage holder"
|
|
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
|