Skip to content

Commit

Permalink
Macros multi-z code, removes the false premise of manual offsets (#76…
Browse files Browse the repository at this point in the history
…248)

[Removes the pretense of relative multiz
levels](tgstation/tgstation@0293fdc)

Our multiz system does not support having a z level that is only
connected one way, or which goes down backwards or anything like that.

That's a fiction of the trait system, the actual backend has never
really supported this.

This pr removes the assumptions we were making backend around this, and
uses that to save cpu time.

I am also converting multiz_levels from an assoc list to a pure one,
which saves significantly on access times and cleans up the code
somewhat.

Also I'm making the get_below/get_above procs into macros, for the sake
of cpu time.

[Converts the starlight disease to use BYOND's directional defines
instead of our
own](tgstation/tgstation@7d698f0)

To some extent spurred on by
DaedalusDock/daedalusdock#298, tho it was known
before

Faster multiz code, faster init, etc etc etc
  • Loading branch information
LemonInTheDark authored and dwasint committed Sep 30, 2023
1 parent c3ff6d2 commit 260e2da
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 120 deletions.
8 changes: 4 additions & 4 deletions _maps/icebox.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"traits": [
{
"Up": 1,
"Up": true,
"Mining": true,
"Linkage": null,
"Gravity": true,
Expand All @@ -27,8 +27,8 @@
"No Parallax": true
},
{
"Down": -1,
"Up": 1,
"Down": true,
"Up": true,
"Mining": true,
"Linkage": null,
"Gravity": true,
Expand All @@ -38,7 +38,7 @@
"No Parallax": true
},
{
"Down": -1,
"Down": true,
"Mining": true,
"Linkage": null,
"Gravity": true,
Expand Down
8 changes: 4 additions & 4 deletions _maps/multiz_debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"map_file": "multiz.dmm",
"traits": [
{
"Up": 1,
"Up": true,
"Linkage": "Cross"
},
{
"Up": 1,
"Down": -1,
"Up": true,
"Down": true,
"Baseturf": "/turf/open/openspace",
"Linkage": "Cross"
},
{
"Down": -1,
"Down": true,
"Baseturf": "/turf/open/openspace",
"Linkage": "Cross"
}
Expand Down
12 changes: 6 additions & 6 deletions _maps/northstar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"space_empty_levels": 2,
"traits": [
{
"Up": 1,
"Up": true,
"Linkage": "Cross"
},
{
"Up": 1,
"Down": -1,
"Up": true,
"Down": true,
"Baseturf": "/turf/open/openspace",
"Linkage": "Cross"
},
{
"Up": 1,
"Down": -1,
"Up": true,
"Down": true,
"Baseturf": "/turf/open/openspace",
"Linkage": "Cross"
},
{
"Down": -1,
"Down": true,
"Baseturf": "/turf/open/openspace",
"Linkage": "Cross"
}
Expand Down
4 changes: 2 additions & 2 deletions _maps/tramstation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
},
"traits": [
{
"Up": 1,
"Up": true,
"Baseturf": "/turf/open/misc/asteroid/airless",
"Linkage": "Cross"
},
{
"Down": -1,
"Down": true,
"Baseturf": "/turf/open/openspace",
"Linkage": "Cross"
}
Expand Down
6 changes: 6 additions & 0 deletions code/__DEFINES/mapping.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Defines for SSmapping's multiz_levels
/// TRUE if we're ok with going up
#define Z_LEVEL_UP 1
/// TRUE if we're ok with going down
#define Z_LEVEL_DOWN 2
#define LARGEST_Z_LEVEL_INDEX Z_LEVEL_DOWN
2 changes: 1 addition & 1 deletion code/__DEFINES/maps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Always compile, always use that verb, and always make sure that it works for wha
// number - default gravity if there's no gravity generators or area overrides present
#define ZTRAIT_GRAVITY "Gravity"

// numeric offsets - e.g. {"Down": -1} means that chasms will fall to z - 1 rather than oblivion
// Whether this z level is linked up/down. Bool.
#define ZTRAIT_UP "Up"
#define ZTRAIT_DOWN "Down"

Expand Down
45 changes: 23 additions & 22 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ SUBSYSTEM_DEF(mapping)
if(multiz_levels.len < z_level)
multiz_levels.len = z_level

var/linked_down = level_trait(z_level, ZTRAIT_DOWN)
var/linked_up = level_trait(z_level, ZTRAIT_UP)
multiz_levels[z_level] = list()
if(linked_down)
multiz_levels[z_level]["[DOWN]"] = TRUE
if(linked_up)
multiz_levels[z_level]["[UP]"] = TRUE
var/z_above = level_trait(z_level, ZTRAIT_UP)
var/z_below = level_trait(z_level, ZTRAIT_DOWN)
if(!(z_above == TRUE || z_above == FALSE || z_above == null) || !(z_below == TRUE || z_below == FALSE || z_below == null))
stack_trace("Warning, numeric mapping offsets are deprecated. Instead, mark z level connections by setting UP/DOWN to true if the connection is allowed")
multiz_levels[z_level] = new /list(LARGEST_Z_LEVEL_INDEX)
multiz_levels[z_level][Z_LEVEL_UP] = !!z_above
multiz_levels[z_level][Z_LEVEL_DOWN] = !!z_below

/datum/controller/subsystem/mapping/proc/calculate_z_level_gravity(z_level_number)
if(!isnum(z_level_number) || z_level_number < 1)
Expand Down Expand Up @@ -970,32 +970,33 @@ GLOBAL_LIST_EMPTY(the_station_areas)

/datum/controller/subsystem/mapping/proc/update_plane_tracking(datum/space_level/update_with)
// We're essentially going to walk down the stack of connected z levels, and set their plane offset as we go
// Yes this will cause infinite loops if our templating is fucked. Fuck off
var/below_offset = 0
// I'm sorry, it needs to start at 0
var/current_level = -1
var/current_z = update_with.z_value
var/plane_offset = 0
var/datum/space_level/current_z = update_with
var/list/datum/space_level/levels_checked = list()
do
current_level += 1
current_z += below_offset
z_level_to_plane_offset[current_z] = current_level
var/datum/space_level/next_level = z_list[current_z]
below_offset = next_level.traits[ZTRAIT_DOWN]
levels_checked += next_level
while(below_offset)
var/list/z_stack = list()
while(TRUE)
var/z_level = current_z.z_value
z_stack += z_level
z_level_to_plane_offset[z_level] = plane_offset
levels_checked += current_z
if(!current_z.traits[ZTRAIT_DOWN]) // If there's nothing below, stop looking
break
// Otherwise, down down down we go
current_z = z_list[z_level - 1]
plane_offset += 1

/// Updates the lowest offset value
for(var/datum/space_level/level_to_update in levels_checked)
z_level_to_lowest_plane_offset[level_to_update.z_value] = current_level
z_level_to_lowest_plane_offset[level_to_update.z_value] = plane_offset
z_level_to_stack[level_to_update.z_value] = z_stack

// This can be affected by offsets, so we need to update it
// PAIN
for(var/i in 1 to length(z_list))
generate_lighting_appearance_by_z(i)

var/old_max = max_plane_offset
max_plane_offset = max(max_plane_offset, current_level)
max_plane_offset = max(max_plane_offset, plane_offset)
if(max_plane_offset == old_max)
return

Expand Down
12 changes: 6 additions & 6 deletions code/datums/diseases/advance/symptoms/heal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

/datum/symptom/heal/starlight/proc/CanTileHealDirectional(turf/turf_to_check, direction)
if(direction == UP)
turf_to_check = GET_TURF_ABOVE(turf_to_check)
turf_to_check = turf_to_check.above()
if(!turf_to_check)
return STARLIGHT_CANNOT_HEAL
var/area/area_to_check = get_area(turf_to_check)
Expand All @@ -86,7 +86,7 @@
// while space covers normal space and those caused by explosions,
// if there is a floor tile when checking above, that means
// a roof exists so the outdoors should only work downwards
if(isspaceturf(turf_to_check) || (area_to_check.outdoors && direction == ZTRAIT_DOWN))
if(isspaceturf(turf_to_check) || (area_to_check.outdoors && direction == DOWN))
if (levels_of_glass)
return STARLIGHT_CAN_HEAL_WITH_PENALTY // Glass gives a penalty.
return STARLIGHT_CAN_HEAL // No glass = can heal fully.
Expand All @@ -99,7 +99,7 @@
if(istransparentturf(turf_to_check) || istype(turf_to_check, /turf/open/openspace))
// Check above or below us
if(direction == UP)
turf_to_check = GET_TURF_ABOVE(turf_to_check)
turf_to_check = turf_to_check.above()
else
turf_to_check = GET_TURF_BELOW(turf_to_check)

Expand All @@ -114,20 +114,20 @@
// Checking below, we assume that space is below us (as we're standing on station)
// Checking above, we check that the area is "outdoors" before assuming if it is space or not.
else
if(direction == ZTRAIT_DOWN || (direction == ZTRAIT_UP && area_to_check.outdoors))
if(direction == DOWN || (direction == UP && area_to_check.outdoors))
if (levels_of_glass)
return STARLIGHT_CAN_HEAL_WITH_PENALTY
return STARLIGHT_CAN_HEAL

return STARLIGHT_CANNOT_HEAL // Hit a non-space, Non-transparent turf - no healsies

/datum/symptom/heal/starlight/proc/CanTileHeal(turf/original_turf, satisfied_with_penalty)
var/current_heal_level = CanTileHealDirectional(original_turf, ZTRAIT_DOWN)
var/current_heal_level = CanTileHealDirectional(original_turf, DOWN)
if(current_heal_level == STARLIGHT_CAN_HEAL)
return current_heal_level
if(current_heal_level && satisfied_with_penalty) // do not care if there is a healing penalty or no
return current_heal_level
var/heal_level_from_above = CanTileHealDirectional(original_turf, ZTRAIT_UP)
var/heal_level_from_above = CanTileHealDirectional(original_turf, UP)
if(heal_level_from_above > current_heal_level)
return heal_level_from_above
else
Expand Down
8 changes: 4 additions & 4 deletions code/game/machinery/camera/camera.dm
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/camera/xray, 0)
/obj/machinery/camera/proc/can_see()
var/list/see = null
var/turf/pos = get_turf(src)
var/turf/directly_above = GET_TURF_ABOVE(pos)
var/check_lower = pos != get_lowest_turf(pos)
var/check_higher = pos != get_highest_turf(pos)

Expand All @@ -545,23 +546,22 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/camera/xray, 0)
see = get_hear(view_range, pos)
if(check_lower || check_higher)
// Haha datum var access KILL ME
var/datum/controller/subsystem/mapping/local_mapping = SSmapping
for(var/turf/seen in see)
if(check_lower)
var/turf/visible = seen
while(visible && istransparentturf(visible))
var/turf/below = local_mapping.get_turf_below(visible)
var/turf/below = GET_TURF_BELOW(visible)
for(var/turf/adjacent in range(1, below))
see += adjacent
see += adjacent.contents
visible = below
if(check_higher)
var/turf/above = local_mapping.get_turf_above(seen)
var/turf/above = GET_TURF_ABOVE(seen)
while(above && istransparentturf(above))
for(var/turf/adjacent in range(1, above))
see += adjacent
see += adjacent.contents
above = local_mapping.get_turf_above(above)
above = GET_TURF_ABOVE(above)
return see

/obj/machinery/camera/proc/Togglelight(on=0)
Expand Down
5 changes: 2 additions & 3 deletions code/game/objects/effects/decals/cleanable/aliens.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
return
if(mapload)
for (var/i in 1 to range)
var/turf/my_turf = get_turf(src)
if(!isgroundlessturf(my_turf) || GET_TURF_BELOW(my_turf))
new /obj/effect/decal/cleanable/xenoblood/xsplatter(my_turf)
if(!isgroundlessturf(loc) || GET_TURF_BELOW(loc))
new /obj/effect/decal/cleanable/xenoblood/xsplatter(loc)
if (!step_to(src, get_step(src, direction), 0))
break
return
Expand Down
5 changes: 2 additions & 3 deletions code/game/objects/effects/decals/cleanable/humans.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@
return
if(mapload)
for (var/i in 1 to range)
var/turf/my_turf = get_turf(src)
if(!isgroundlessturf(my_turf) || GET_TURF_BELOW(my_turf))
new /obj/effect/decal/cleanable/blood/splatter(my_turf)
if(!isgroundlessturf(loc) || GET_TURF_BELOW(loc))
new /obj/effect/decal/cleanable/blood/splatter(loc)
if (!step_to(src, get_step(src, direction), 0))
break
return
Expand Down
5 changes: 2 additions & 3 deletions code/game/objects/effects/decals/cleanable/robots.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
return
if(mapload)
for (var/i in 1 to range)
var/turf/my_turf = get_turf(src)
if(prob(40) && (!isgroundlessturf(my_turf) || GET_TURF_BELOW(my_turf)))
new /obj/effect/decal/cleanable/oil/streak(my_turf)
if(prob(40) && (!isgroundlessturf(loc) || GET_TURF_BELOW(loc)))
new /obj/effect/decal/cleanable/oil/streak(loc)
if (!step_to(src, get_step(src, direction), 0))
break
return
Expand Down
5 changes: 3 additions & 2 deletions code/game/objects/effects/decals/decal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
if(B && B.loc == loc)
qdel(src)

/obj/effect/decal/proc/NeverShouldHaveComeHere(turf/T)
return isclosedturf(T) || isgroundlessturf(T)
///Checks if we are allowed to be in `here_turf`, and returns that result. Subtypes should override this when necessary.
/obj/effect/decal/proc/NeverShouldHaveComeHere(turf/here_turf)
return isclosedturf(here_turf) || (isgroundlessturf(here_turf) && !GET_TURF_BELOW(here_turf))

/obj/effect/decal/ex_act(severity, target)
qdel(src)
Expand Down
5 changes: 3 additions & 2 deletions code/game/objects/effects/spawners/random/random.dm
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@

if(radius >= 0)
for(var/turf/turf_in_view in view(radius, get_turf(src)))
if(!turf_in_view.density)
scatter_locations += turf_in_view
if(isclosedturf(turf_in_view) || (isgroundlessturf(turf_in_view) && !GET_TURF_BELOW(turf_in_view)))
continue
scatter_locations += turf_in_view

return scatter_locations

Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/structures/ladders.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
var/obj/structure/ladder/L

if (!down)
L = locate() in SSmapping.get_turf_below(T)
L = locate() in GET_TURF_BELOW(T)
if (L)
if(crafted == L.crafted)
down = L
L.up = src // Don't waste effort looping the other way
L.update_appearance()
if (!up)
L = locate() in SSmapping.get_turf_above(T)
L = locate() in GET_TURF_ABOVE(T)
if (L)
if(crafted == L.crafted)
up = L
Expand Down
4 changes: 2 additions & 2 deletions code/game/sound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ GLOBAL_LIST_INIT(proxy_sound_channels, list(

. = list()//output everything that successfully heard the sound

var/turf/above_turf = SSmapping.get_turf_above(turf_source)
var/turf/below_turf = SSmapping.get_turf_below(turf_source)
var/turf/above_turf = GET_TURF_ABOVE(turf_source)
var/turf/below_turf = GET_TURF_BELOW(turf_source)

if(ignore_walls)

Expand Down
4 changes: 4 additions & 0 deletions code/game/turfs/open/chasm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
else if(istype(C, /obj/item/stack/tile/iron))
build_with_floor_tiles(C, user)

/// Handles adding the chasm component to the turf (So stuff falls into it!)
/turf/open/chasm/proc/apply_components()
AddComponent(/datum/component/chasm, GET_TURF_BELOW(src))

// Chasms for Lavaland, with planetary atmos and lava glow
/turf/open/chasm/lavaland
initial_gas_mix = LAVALAND_DEFAULT_ATMOS
Expand Down
8 changes: 4 additions & 4 deletions code/game/turfs/open/lava.dm
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
var/border_turf = FALSE
var/list/turfs_to_check = RANGE_TURFS(1, src)
if(GET_LOWEST_STACK_OFFSET(z))
var/turf/above = SSmapping.get_turf_above(src)
var/turf/above = GET_TURF_ABOVE(src)
if(above)
turfs_to_check += RANGE_TURFS(1, above)
var/turf/below = SSmapping.get_turf_below(src)
var/turf/below = GET_TURF_BELOW(src)
if(below)
turfs_to_check += RANGE_TURFS(1, below)

Expand All @@ -95,10 +95,10 @@
// We have gone from a lava turf to a non lava turf, time to let them know
var/list/turfs_to_check = RANGE_TURFS(1, result)
if(GET_LOWEST_STACK_OFFSET(z))
var/turf/above = SSmapping.get_turf_above(result)
var/turf/above = GET_TURF_ABOVE(result)
if(above)
turfs_to_check += RANGE_TURFS(1, above)
var/turf/below = SSmapping.get_turf_below(result)
var/turf/below = GET_TURF_BELOW(result)
if(below)
turfs_to_check += RANGE_TURFS(1, below)
for(var/turf/open/lava/inform in turfs_to_check)
Expand Down
Loading

0 comments on commit 260e2da

Please sign in to comment.