From 7813465ef3e27f4b5a24db5b6e8363afcff9843c Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 7 Nov 2020 06:06:11 +0100 Subject: [PATCH] [MIRROR] Makes the ChangeTurf same turf optimization work properly again, and converts baseturfs into a string_list (#1601) * Makes the ChangeTurf same turf optimization work properly again, and converts baseturfs into a string_list (#54277) I've converted baseturfs into a string list, I had to add a helper proc for baseturf stringlistifying, as the system expects single length baseturfs to not be a list, and I needed to support that. I added a length check of 100 to the helper proc, to help prevent more stuff like what got us into this mess in the first place, the kilo oom bug. Makes ChangeTurf a lot faster in some cases, as it should be, and saves a lot of memory with cached lists. * Makes the ChangeTurf same turf optimization work properly again, and converts baseturfs into a string_list Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/__HELPERS/string_lists.dm | 18 +++++++++++++++++- code/datums/shuttles.dm | 4 +++- code/game/turfs/change_turf.dm | 23 ++++++++++++----------- code/game/turfs/turf.dm | 8 ++++---- code/modules/mapping/mapping_helpers.dm | 5 +++-- icons/turf/debug.dmi | Bin 270 -> 674 bytes 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/code/__HELPERS/string_lists.dm b/code/__HELPERS/string_lists.dm index df01d8a8490..8523c375183 100644 --- a/code/__HELPERS/string_lists.dm +++ b/code/__HELPERS/string_lists.dm @@ -3,7 +3,7 @@ GLOBAL_LIST_EMPTY(string_lists) /** * Caches lists with non-numeric stringify-able values (text or typepath). */ -/datum/proc/string_list(list/values) +/proc/string_list(list/values) var/string_id = values.Join("-") . = GLOB.string_lists[string_id] @@ -12,3 +12,19 @@ GLOBAL_LIST_EMPTY(string_lists) return return GLOB.string_lists[string_id] = values + +///A wrapper for baseturf string lists, to offer support of non list values, and a stack_trace if we have major issues +/proc/baseturfs_string_list(list/values, turf/baseturf_holder) + if(!islist(values)) + values = list(values) + // return values + if(length(values) > 10) + stack_trace("The baseturfs list of [baseturf_holder] at [baseturf_holder.x], [baseturf_holder.y], [baseturf_holder.x] is [length(values)], it should never be this long, investigate. I've set baseturfs to a flashing wall as a visual queue") + return string_list(list(/turf/closed/indestructible/baseturfs_ded)) //I want this reported god damn it + return string_list(values) + +/turf/closed/indestructible/baseturfs_ded + name = "Report this" + desc = "It looks like base turfs went to the fucking moon, TELL YOUR LOCAL CODER TODAY" + icon = 'icons/turf/debug.dmi' + icon_state = "fucked_baseturfs" diff --git a/code/datums/shuttles.dm b/code/datums/shuttles.dm index 147b55bafef..0e5e898847e 100644 --- a/code/datums/shuttles.dm +++ b/code/datums/shuttles.dm @@ -68,7 +68,9 @@ continue if(length(place.baseturfs) < 2) // Some snowflake shuttle shit continue - place.baseturfs.Insert(3, /turf/baseturf_skipover/shuttle) + var/list/sanity = place.baseturfs.Copy() + sanity.Insert(3, /turf/baseturf_skipover/shuttle) + place.baseturfs = baseturfs_string_list(sanity, place) for(var/obj/docking_port/mobile/port in place) if(register) diff --git a/code/game/turfs/change_turf.dm b/code/game/turfs/change_turf.dm index 5b53b6412c5..40084abdfbb 100644 --- a/code/game/turfs/change_turf.dm +++ b/code/game/turfs/change_turf.dm @@ -104,9 +104,9 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list( W.TakeComponent(i) if(new_baseturfs) - W.baseturfs = new_baseturfs + W.baseturfs = baseturfs_string_list(new_baseturfs, W) else - W.baseturfs = old_baseturfs + W.baseturfs = baseturfs_string_list(old_baseturfs, W) //Just to be safe W.explosion_id = old_exi W.explosion_level = old_exl @@ -189,8 +189,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list( assemble_baseturfs(fake_turf_type) if(!length(baseturfs)) baseturfs = list(baseturfs) - baseturfs -= baseturfs & GLOB.blacklisted_automated_baseturfs - baseturfs += old_baseturfs + baseturfs = baseturfs_string_list((baseturfs - (baseturfs & GLOB.blacklisted_automated_baseturfs)) + old_baseturfs, src) return else if(!length(new_baseturfs)) new_baseturfs = list(new_baseturfs, fake_turf_type) @@ -198,6 +197,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list( new_baseturfs += fake_turf_type if(!length(baseturfs)) baseturfs = list(baseturfs) + baseturfs = baseturfs_string_list(new_baseturfs + baseturfs, src) baseturfs.Insert(1, new_baseturfs) // Make a new turf and put it on top @@ -226,25 +226,26 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list( newT.assemble_baseturfs(initial(fake_turf_type.baseturfs)) // The baseturfs list is created like roundstart if(!length(newT.baseturfs)) newT.baseturfs = list(baseturfs) - newT.baseturfs -= GLOB.blacklisted_automated_baseturfs - newT.baseturfs.Insert(1, old_baseturfs) // The old baseturfs are put underneath + // The old baseturfs are put underneath, and we sort out the unwanted ones + newT.baseturfs = baseturfs_string_list(old_baseturfs + (newT.baseturfs - GLOB.blacklisted_automated_baseturfs), newT) return newT if(!length(baseturfs)) baseturfs = list(baseturfs) if(!istype(src, /turf/closed)) - baseturfs += type - baseturfs += new_baseturfs + new_baseturfs = list(type) + new_baseturfs + baseturfs = baseturfs_string_list(baseturfs + new_baseturfs, src) return ChangeTurf(fake_turf_type, null, flags) if(!length(baseturfs)) baseturfs = list(baseturfs) + var/list/temp_baseturfs = list() if(!istype(src, /turf/closed)) - baseturfs += type + temp_baseturfs += type var/turf/change_type if(length(new_baseturfs)) change_type = new_baseturfs[new_baseturfs.len] new_baseturfs.len-- if(new_baseturfs.len) - baseturfs += new_baseturfs + baseturfs = baseturfs_string_list(baseturfs + temp_baseturfs + new_baseturfs, src) else change_type = new_baseturfs return ChangeTurf(change_type, null, flags) @@ -269,7 +270,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list( new_baseturfs += target_baseturfs var/turf/newT = copytarget.copyTurf(src, copy_air) - newT.baseturfs = new_baseturfs + newT.baseturfs = baseturfs_string_list(new_baseturfs, newT) return newT diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index e0542aba3a3..20d2be8b05e 100755 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -325,7 +325,7 @@ GLOBAL_LIST_EMPTY(station_turfs) var/turf/current_target if(fake_baseturf_type) if(length(fake_baseturf_type)) // We were given a list, just apply it and move on - baseturfs = fake_baseturf_type + baseturfs = baseturfs_string_list(fake_baseturf_type, src) return current_target = fake_baseturf_type else @@ -341,9 +341,9 @@ GLOBAL_LIST_EMPTY(station_turfs) if(created_baseturf_lists[current_target]) var/list/premade_baseturfs = created_baseturf_lists[current_target] if(length(premade_baseturfs)) - baseturfs = premade_baseturfs.Copy() + baseturfs = baseturfs_string_list(premade_baseturfs, src) else - baseturfs = premade_baseturfs + baseturfs = baseturfs_string_list(premade_baseturfs, src) return baseturfs var/turf/next_target = initial(current_target.baseturfs) @@ -364,7 +364,7 @@ GLOBAL_LIST_EMPTY(station_turfs) current_target = next_target next_target = initial(current_target.baseturfs) - baseturfs = new_baseturfs + baseturfs = baseturfs_string_list(new_baseturfs, src) created_baseturf_lists[new_baseturfs[new_baseturfs.len]] = new_baseturfs.Copy() return new_baseturfs diff --git a/code/modules/mapping/mapping_helpers.dm b/code/modules/mapping/mapping_helpers.dm index d7f0fad69e3..d8523c418bf 100644 --- a/code/modules/mapping/mapping_helpers.dm +++ b/code/modules/mapping/mapping_helpers.dm @@ -34,11 +34,12 @@ qdel(src) /obj/effect/baseturf_helper/proc/replace_baseturf(turf/thing) - var/list/baseturf_cache = thing.baseturfs - if(length(baseturf_cache)) + if(length(thing.baseturfs)) + var/list/baseturf_cache = thing.baseturfs.Copy() for(var/i in baseturf_cache) if(baseturf_to_replace[i]) baseturf_cache -= i + thing.baseturfs = baseturfs_string_list(baseturf_cache, thing) if(!baseturf_cache.len) thing.assemble_baseturfs(baseturf) else diff --git a/icons/turf/debug.dmi b/icons/turf/debug.dmi index e419b2bf46d5b8d2429703d91de24b64fbfd989b..57bc4eb465592a20a5e93a734b332f77a1630b5e 100644 GIT binary patch delta 588 zcmV-S0<-;&0-^;>iBL{Q4GJ0x0000DNk~Le0000$0000$1Oos709Z$C?EnA(8&FJC zMgRXZ_y8~f%m4rY0001HGXVc)|7HOH|Nk@0EZCs|0001rkvd|3!_}pgCTFLn#3v;d zr-IZMW7l8|6iv-ZtON-g=ztNIvVyCh3)pP{pk*##uX*`;00053Nkla=Ksr@B=$6i&{6emY-Fu-+ut- zHfQZN0>6*IuK3Y^jlk@;4?sp(M6A{+UnI5Qk*o=eMW;#QRAfkYTveq){Hm zJb|kLxQKHnFe6y)TF+_iDu8(ha5%34BJ9hsCKbj>%px?{tgL`Gc;9DkF8Z+7HXO&e z0If?sWj9x#w%VAMfNo8`$@WQ@9cm70jF|$|uiM`OzoUYG|L`u%^pFR*zUDZuFTBl< z&;PF0L#;1?6eTEG0*bOi$f^RVh@c~AL=1wCAQd6Nok4mYl0i9dQ2|Iwe2WS|N@0Ku z;z|u5BXA{dRDz)sphU=F1f)Q?0Hi<|0S=c&fWs95p6jTNBTW0c|LErO!Mxkj_!W3d%W(yl|I#N~FkL>M1#7ZZ%O$K(~6ULud);7GJY{5)`2x z+$sEr40VDULj$NW;Q**#w;urY>vjQBM1^#Ml2M_kcR?iIMF=k-Dve%$JM);NoRY)<0000ERLtq!mDzi5W=piA+idQk(%kA+G=b8#9~%au^~x zBP)PZ_C%kgB5my*zjik8vN6;IOS7G@d!!AN@bq+X43U_coY25{F~ESs(O}86wR70g zJlb0IoRf8;t+)?)aJL#STlnfw(t}f(k%8WhO2NyQp5t*%PI2`;syLN1H9^9|nvI8n YVeXnBu2uRAHh^sPboFyt=akR{0D<^4@&Et;