[MIRROR] Builds logic that manages turfs contained inside an area [MDB IGNORE] (#17379)

* Builds logic that manages turfs contained inside an area

* Mirror Conflict

* Modular!

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: Funce <funce.973@gmail.com>
Co-authored-by: tastyfish <crazychris32@gmail.com>
This commit is contained in:
SkyratBot
2022-11-16 20:42:22 +01:00
committed by GitHub
parent bd4e73411d
commit 24eb8217c0
45 changed files with 299 additions and 143 deletions
+4 -6
View File
@@ -133,14 +133,13 @@
var/x = round((world.maxx - width) * 0.5) + 1
var/y = round((world.maxy - height) * 0.5) + 1
var/datum/space_level/level = SSmapping.add_new_zlevel(name, secret ? ZTRAITS_AWAY_SECRET : ZTRAITS_AWAY)
var/datum/parsed_map/parsed = load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=should_place_on_top)
var/datum/space_level/level = SSmapping.add_new_zlevel(name, secret ? ZTRAITS_AWAY_SECRET : ZTRAITS_AWAY, contain_turfs = FALSE)
var/datum/parsed_map/parsed = load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS), placeOnTop=should_place_on_top, new_z = TRUE)
var/list/bounds = parsed.bounds
if(!bounds)
return FALSE
repopulate_sorted_areas()
require_area_resort()
//initialize things that are normally initialized after map load
initTemplateBounds(bounds)
smooth_zlevel(world.maxz)
@@ -181,8 +180,7 @@
if(!bounds)
return
if(!SSmapping.loading_ruins) //Will be done manually during mapping ss init
repopulate_sorted_areas()
require_area_resort()
//initialize things that are normally initialized after map load
initTemplateBounds(bounds)
+27 -18
View File
@@ -50,10 +50,10 @@
/// - `no_changeturf`: When true, [/turf/proc/AfterChange] won't be called on loaded turfs
/// - `x_lower`, `x_upper`, `y_lower`, `y_upper`: Coordinates (relative to the map) to crop to (Optional).
/// - `placeOnTop`: Whether to use [/turf/proc/PlaceOnTop] rather than [/turf/proc/ChangeTurf] (Optional).
/proc/load_map(dmm_file as file, x_offset as num, y_offset as num, z_offset as num, cropMap as num, measureOnly as num, no_changeturf as num, x_lower = -INFINITY as num, x_upper = INFINITY as num, y_lower = -INFINITY as num, y_upper = INFINITY as num, placeOnTop = FALSE as num)
/proc/load_map(dmm_file as file, x_offset as num, y_offset as num, z_offset as num, cropMap as num, measureOnly as num, no_changeturf as num, x_lower = -INFINITY as num, x_upper = INFINITY as num, y_lower = -INFINITY as num, y_upper = INFINITY as num, placeOnTop = FALSE as num, new_z)
var/datum/parsed_map/parsed = new(dmm_file, x_lower, x_upper, y_lower, y_upper, measureOnly)
if(parsed.bounds && !measureOnly)
parsed.load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop)
parsed.load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z = new_z)
return parsed
/// Parse a map, possibly cropping it.
@@ -157,10 +157,10 @@
src.key_len = key_len
/// Load the parsed map into the world. See [/proc/load_map] for arguments.
/datum/parsed_map/proc/load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, whitelist = FALSE)
/datum/parsed_map/proc/load(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, whitelist = FALSE, new_z)
//How I wish for RAII
Master.StartLoadingMap()
. = _load_impl(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop)
. = _load_impl(x_offset, y_offset, z_offset, cropMap, no_changeturf, x_lower, x_upper, y_lower, y_upper, placeOnTop, new_z)
Master.StopLoadingMap()
@@ -171,7 +171,7 @@
SSatoms.map_loader_begin(); \
}
// Do not call except via load() above.
/datum/parsed_map/proc/_load_impl(x_offset = 1, y_offset = 1, z_offset = world.maxz + 1, cropMap = FALSE, no_changeturf = FALSE, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY, placeOnTop = FALSE)
/datum/parsed_map/proc/_load_impl(x_offset = 1, y_offset = 1, z_offset = world.maxz + 1, cropMap = FALSE, no_changeturf = FALSE, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY, placeOnTop = FALSE, new_z = FALSE)
PRIVATE_PROC(TRUE)
var/list/modelCache = build_cache(no_changeturf)
var/space_key = modelCache[SPACE_KEY]
@@ -288,7 +288,7 @@
if(!cache)
SSatoms.map_loader_stop()
CRASH("Undefined model key in DMM: [line]")
build_coordinate(cache, locate(true_xcrd, ycrd, zcrd), no_afterchange, placeOnTop)
build_coordinate(cache, locate(true_xcrd, ycrd, zcrd), no_afterchange, placeOnTop, new_z)
// only bother with bounds that actually exist
if(!first_found)
@@ -320,7 +320,7 @@
if(!cache)
SSatoms.map_loader_stop()
CRASH("Undefined model key in DMM: [model_key]")
build_coordinate(cache, locate(xcrd, ycrd, zcrd), no_afterchange, placeOnTop)
build_coordinate(cache, locate(xcrd, ycrd, zcrd), no_afterchange, placeOnTop, new_z)
// only bother with bounds that actually exist
if(!first_found)
@@ -347,6 +347,10 @@
//we do this after we load everything in. if we don't; we'll have weird atmos bugs regarding atmos adjacent turfs
T.AfterChange(CHANGETURF_IGNORE_AIR)
if(new_z)
for(var/z_index in bounds[MAP_MINZ] to bounds[MAP_MAXZ])
SSmapping.build_area_turfs(z_index)
if(has_expanded_world_maxx || has_expanded_world_maxy)
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_EXPANDED_WORLD_BOUNDS, has_expanded_world_maxx, has_expanded_world_maxy)
@@ -437,7 +441,7 @@ GLOBAL_LIST_EMPTY(map_model_default)
.[model_key] = list(members, members_attributes)
/datum/parsed_map/proc/build_coordinate(list/model, turf/crds, no_changeturf as num, placeOnTop as num)
/datum/parsed_map/proc/build_coordinate(list/model, turf/crds, no_changeturf as num, placeOnTop as num, new_z)
// If we don't have a turf, nothing we will do next will actually acomplish anything, so just go back
// Note, this would actually drop area vvs in the tile, but like, why tho
if(!crds)
@@ -458,29 +462,34 @@ GLOBAL_LIST_EMPTY(map_model_default)
//The next part of the code assumes there's ALWAYS an /area AND a /turf on a given tile
//first instance the /area and remove it from the members list
index = members.len
var/atom/instance
if(members[index] != /area/template_noop)
var/area/area_instance
if(members_attributes[index] != default_list)
world.preloader_setup(members_attributes[index], members[index])//preloader for assigning set variables on atom creation
instance = loaded_areas[members[index]]
if(!instance)
area_instance = loaded_areas[members[index]]
if(!area_instance)
var/area_type = members[index]
// If this parsed map doesn't have that area already, we check the global cache
instance = GLOB.areas_by_type[area_type]
area_instance = GLOB.areas_by_type[area_type]
// If the global list DOESN'T have this area it's either not a unique area, or it just hasn't been created yet
if (!instance)
instance = new area_type(null)
if(!instance)
if (!area_instance)
area_instance = new area_type(null)
if(!area_instance)
CRASH("[area_type] failed to be new'd, what'd you do?")
loaded_areas[area_type] = instance
loaded_areas[area_type] = area_instance
instance.contents.Add(crds)
if(!new_z)
var/area/old_area = crds.loc
old_area.turfs_to_uncontain += crds
area_instance.contained_turfs.Add(crds)
area_instance.contents.Add(crds)
if(GLOB.use_preloader)
world.preloader_load(instance)
world.preloader_load(area_instance)
// Index right before /area is /turf
index--
var/atom/instance
//then instance the /turf
//NOTE: this used to place any turfs before the last "underneath" it using .appearance and underlays
//We don't actually use this, and all it did was cost cpu, so we don't do this anymore
@@ -16,10 +16,10 @@
for (var/I in 1 to default_map_traits.len)
var/list/features = default_map_traits[I]
var/datum/space_level/S = new(I, features[DL_NAME], features[DL_TRAITS])
manage_z_level(S)
manage_z_level(S, filled_with_space = FALSE)
generate_z_level_linkages() // Default Zs don't use add_new_zlevel() so they don't automatically generate z-linkages.
/datum/controller/subsystem/mapping/proc/add_new_zlevel(name, traits = list(), z_type = /datum/space_level)
/datum/controller/subsystem/mapping/proc/add_new_zlevel(name, traits = list(), z_type = /datum/space_level, contain_turfs = TRUE)
UNTIL(!adding_new_zlevel)
adding_new_zlevel = TRUE
var/new_z = z_list.len + 1
@@ -28,7 +28,7 @@
CHECK_TICK
// TODO: sleep here if the Z level needs to be cleared
var/datum/space_level/S = new z_type(new_z, name, traits)
manage_z_level(S)
manage_z_level(S, filled_with_space = TRUE, contain_turfs = contain_turfs)
generate_linkages_for_z_level(new_z)
calculate_z_level_gravity(new_z)
adding_new_zlevel = FALSE