[MIRROR] Massively optimize space turf initializations (~20 seconds on Meta to ~3 seconds) [MDB IGNORE] (#15858)

This commit is contained in:
SkyratBot
2022-08-26 14:40:13 -07:00
committed by GitHub
parent 03a1a627f0
commit f94d34fea2
5 changed files with 28 additions and 34 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
#define SPACE_SIGNAL_GPSTAG "Distant Signal"
///The icon_state for space. There is 25 total icon states that vary based on the x/y/z position of the turf
#define SPACE_ICON_STATE "[((x + y) ^ ~(x * y) + z) % 25]"
#define SPACE_ICON_STATE(x, y, z) "[((x + y) ^ ~(x * y) + z) % 25]"
+1 -1
View File
@@ -43,7 +43,7 @@
var/mutable_appearance/underlay_appearance = mutable_appearance(layer = TURF_LAYER, plane = FLOOR_PLANE)
if(fixed_underlay["space"])
underlay_appearance.icon = 'icons/turf/space.dmi'
underlay_appearance.icon_state = SPACE_ICON_STATE
underlay_appearance.icon_state = SPACE_ICON_STATE(x, y, z)
underlay_appearance.plane = PLANE_SPACE
else
underlay_appearance.icon = fixed_underlay["icon"]
+2 -2
View File
@@ -787,10 +787,10 @@
/turf/open/floor/fakespace/Initialize(mapload)
. = ..()
icon_state = SPACE_ICON_STATE
icon_state = SPACE_ICON_STATE(x, y, z)
/turf/open/floor/fakespace/get_smooth_underlay_icon(mutable_appearance/underlay_appearance, turf/asking_turf, adjacency_dir)
underlay_appearance.icon = 'icons/turf/space.dmi'
underlay_appearance.icon_state = SPACE_ICON_STATE
underlay_appearance.icon_state = SPACE_ICON_STATE(x, y, z)
underlay_appearance.plane = PLANE_SPACE
return TRUE
+23 -29
View File
@@ -38,47 +38,41 @@
/**
* Space Initialize
*
* Doesn't call parent, see [/atom/proc/Initialize]
* Doesn't call parent, see [/atom/proc/Initialize].
* When adding new stuff to /atom/Initialize, /turf/Initialize, etc
* don't just add it here unless space actually needs it.
*
* There is a lot of work that is intentionally not done because it is not currently used.
* This includes stuff like smoothing, blocking camera visibility, etc.
* If you are facing some odd bug with specifically space, check if it's something that was
* intentionally ommitted from this implementation.
*/
/turf/open/space/Initialize(mapload)
SHOULD_CALL_PARENT(FALSE)
icon_state = SPACE_ICON_STATE
icon_state = SPACE_ICON_STATE(x, y, z)
air = space_gas
vis_contents.Cut() //removes inherited overlays
visibilityChanged()
if(flags_1 & INITIALIZED_1)
stack_trace("Warning: [src]([type]) initialized multiple times!")
flags_1 |= INITIALIZED_1
if (length(smoothing_groups))
sortTim(smoothing_groups) //In case it's not properly ordered, let's avoid duplicate entries with the same values.
SET_BITFLAG_LIST(smoothing_groups)
if (length(canSmoothWith))
sortTim(canSmoothWith)
if(canSmoothWith[length(canSmoothWith)] > MAX_S_TURF) //If the last element is higher than the maximum turf-only value, then it must scan turf contents for smoothing targets.
smoothing_flags |= SMOOTH_OBJ
SET_BITFLAG_LIST(canSmoothWith)
var/area/our_area = loc
if(our_area.area_has_base_lighting && always_lit) //Only provide your own lighting if the area doesn't for you
add_overlay(GLOB.fullbright_overlay)
// Intentionally not add_overlay for performance reasons.
// add_overlay does a bunch of generic stuff, like creating a new list for overlays,
// queueing compile, cloning appearance, etc etc etc that is not necessary here.
overlays += GLOB.fullbright_overlay
if(requires_activation)
SSair.add_to_active(src, TRUE)
if (!mapload)
if(requires_activation)
SSair.add_to_active(src, TRUE)
if (light_system == STATIC_LIGHT && light_power && light_range)
update_light()
if (opacity)
directional_opacity = ALL_CARDINALS
var/turf/T = SSmapping.get_turf_above(src)
if(T)
T.multiz_turf_new(src, DOWN)
T = SSmapping.get_turf_below(src)
if(T)
T.multiz_turf_new(src, UP)
var/turf/T = SSmapping.get_turf_above(src)
if(T)
T.multiz_turf_new(src, DOWN)
T = SSmapping.get_turf_below(src)
if(T)
T.multiz_turf_new(src, UP)
return INITIALIZE_HINT_NORMAL
@@ -190,7 +184,7 @@
/turf/open/space/get_smooth_underlay_icon(mutable_appearance/underlay_appearance, turf/asking_turf, adjacency_dir)
underlay_appearance.icon = 'icons/turf/space.dmi'
underlay_appearance.icon_state = SPACE_ICON_STATE
underlay_appearance.icon_state = SPACE_ICON_STATE(x, y, z)
underlay_appearance.plane = PLANE_SPACE
return TRUE
+1 -1
View File
@@ -115,7 +115,7 @@
icon_state = "0"
/turf/open/floor/holofloor/space/Initialize(mapload)
icon_state = SPACE_ICON_STATE // so realistic
icon_state = SPACE_ICON_STATE(x, y, z) // so realistic
. = ..()
/turf/open/floor/holofloor/hyperspace