From 7e0a88b672e62c5517850151b9dbd46d79bddfa7 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:16:42 -0700 Subject: [PATCH] Ensures areas are allowed to be non unique (#70118) Did you know that areas can be non unique (unique per area) I didn't, and I wrote mapping code such that we'd make all areas unique This fixes that. It costs 0.1 seconds but without it areas don't work anymore --- code/modules/mapping/reader.dm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/code/modules/mapping/reader.dm b/code/modules/mapping/reader.dm index 1649c70e348..85958c75c97 100644 --- a/code/modules/mapping/reader.dm +++ b/code/modules/mapping/reader.dm @@ -15,6 +15,9 @@ var/key_len = 0 var/list/grid_models = list() var/list/gridSets = list() + /// List of area types we've loaded AS A PART OF THIS MAP + /// We do this to allow non unique areas, so we'll only load one per map + var/list/area/loaded_areas = list() var/list/modelCache @@ -445,7 +448,6 @@ GLOBAL_LIST_EMPTY(map_model_default) // We use static lists here because it's cheaper then passing them around var/static/list/default_list = GLOB.map_model_default - var/static/list/area_cache = GLOB.areas_by_type //////////////// //Instanciation //////////////// @@ -460,14 +462,17 @@ GLOBAL_LIST_EMPTY(map_model_default) if(members[index] != /area/template_noop) if(members_attributes[index] != default_list) world.preloader_setup(members_attributes[index], members[index])//preloader for assigning set variables on atom creation - instance = area_cache[members[index]] - if (!instance) - // Done here because it's cheaper then doing it in the outside check + instance = loaded_areas[members[index]] + if(!instance) var/area_type = members[index] - instance = new area_type(null) - if(!instance) - CRASH("[area_type] failed to be new'd, what'd you do?") - area_cache[area_type] = instance + // If this parsed map doesn't have that area already, we check the global cache + 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) + CRASH("[area_type] failed to be new'd, what'd you do?") + loaded_areas[area_type] = instance instance.contents.Add(crds)