From 5c0b4f824f81560fad4f1bf0916890c94969167e Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Sat, 26 Dec 2020 12:42:03 -0800 Subject: [PATCH] hoh boy --- code/controllers/subsystem/mapping.dm | 2 +- .../subsystem/persistence/cleanable_debris.dm | 88 +++++++++++++++++-- code/game/objects/effects/decals/cleanable.dm | 3 - code/game/objects/effects/decals/crayon.dm | 4 +- 4 files changed, 82 insertions(+), 15 deletions(-) diff --git a/code/controllers/subsystem/mapping.dm b/code/controllers/subsystem/mapping.dm index 3d45672c3b..1893e9ccd9 100644 --- a/code/controllers/subsystem/mapping.dm +++ b/code/controllers/subsystem/mapping.dm @@ -264,7 +264,7 @@ SUBSYSTEM_DEF(mapping) /datum/controller/subsystem/mapping/proc/setup_station_z_index() z_to_station_z_index = list() var/sz = 1 - for(var/i in station_start to (station_Start + islist(config.map_file)? (length(config.map_file) - 1) : 0)) + for(var/i in station_start to (station_start + islist(config.map_file)? (length(config.map_file) - 1) : 0)) z_to_station_z_index["[i]"] = sz++ /datum/controller/subsystem/mapping/proc/loadWorld() diff --git a/code/controllers/subsystem/persistence/cleanable_debris.dm b/code/controllers/subsystem/persistence/cleanable_debris.dm index 6f85436df8..8b8cd55d0d 100644 --- a/code/controllers/subsystem/persistence/cleanable_debris.dm +++ b/code/controllers/subsystem/persistence/cleanable_debris.dm @@ -21,8 +21,12 @@ if(loaded_debris) return loaded_debris = TRUE + if(CONFIG_GET(flag/persistent_debris_only)) + wipe_existing_debris() var/list/allowed_turf_typecache = typecacheof(/turf/open) - typecacheof(/turf/open/space) var/list/allowed_z_cache = list() + for(var/z in SSmapping.levels_by_trait(ZTRAIT_STATION)) + allowed_z_cache[num2text(z)] = TRUE var/list/data = json_decode(file2text("[get_map_persistence_path()]/debris.json")) var/list/z_lookup = list() /// reverse it @@ -39,31 +43,78 @@ if(!tile) continue var/list/objects = data[z][x][y] - for(var/path in objects) + for(var/_L in objects) + var/list/data + var/path + if(islist(_L)) + data = _L + path = data["__PATH__"] + else + path = _L + data = objects[_L] if(!IsValidDebrisLocation(tile, allowed_turf_typecache, allowed_z_cache, path, TRUE)) continue + var/path = data["__PATH__"] + if(!path) + continue var/obj/effect/cleanable/instantiated = new path(tile) - var/list/data = objects[path] if(data) - instantiated.PersistenceLoad(data) + instantiated.LoadPersistence(data) /datum/controller/subsystem/persistence/proc/SaveMapDebris() if(fexists("[get_map_persistence_path()]/debris.json")) fdel("[get_map_persistence_path()]/debris.json") - var/list/allowed_turf_typecache = typecacheof(/turf/open) - typecacheof(/turf/open/space) - var/list/allowed_z_cache = list() - for(var/z in SSmapping.levels_by_trait(ZTRAIT_STATION)) - allowed_z_cache[num2text(z)] = TRUE var/list/data = list() var/list/z_lookup = SSmapping.z_to_station_z_index + var/list/debris = RelevantPersistentDebris() + var/obj/effect/cleanable/saving + var/global_max = CONFIG_GET(number/persistent_debris_global_max) + var/type_max = CONFIG_GET(number/persistent_debris_type_max) + var/stored = 0 + var/list/stored_by_type = list() + for(var/i in debris) + saving = i + var/list/serializing = list() + var/path = saving.PersistenceSave(serializing) + if(!path) + continue + if(stored_by_type[path] > type_max) + continue + var/text_z = num2text(saving.z) + var/text_y = num2text(saving.y) + var/text_x = num2text(saving.x) + LAZYINITLIST(data[text_z]) + LAZYINITLIST(data[text_z][text_x]) + LAZYINITLIST(data[text_z][text_x][text_y]) + if(storing.persistence_allow_stacking) + serializing["__PATH__"] = path + data[text_z][text_x][text_y] += serializing + else + data[text_z][text_x][text_y][path] = serializing + stored++ + if(stored > global_max) + var/w = "Persistent debris saving globally aborted due to global max >= [global_max]. Either janitors never do their jobs or something is wrong." + message_admins(w) + subsystem_log(w)) + return + stored_by_type[path] = stored_by_type[path]? stored_by_type[path] + 1 : 1 + if(stored_by_type[path] > type_max) + var/w = "Persistent debris saving aborted for type [path] due to type max >= [global_max]. Either janitors never do their jobs or something is wrong." + message_admins(w) + subsystem_log(w)) - + subsystem_log({" + Debris saving completed: + Total: [global_max] + By type: [english_list(stored_by_type)] + "}) WRITE_FILE("[get_map_persistence_path()]/debris.json", json_encode(data)) /datum/controller/subsystem/persistence/proc/IsValidDebrisLocation(turf/tile, list/allowed_typecache, list/allowed_zcache, type, loading = FALSE) if(!allowed_typecache[tile.type]) return FALSE - if(!tile.loc.persistent_debris_allowed) + var/area/A = tile.loc + if(!A.persistent_debris_allowed) return FALSE if(!allowed_zcache[num2text(tile.z)]) return FALSE @@ -77,3 +128,22 @@ if(W.fulltile) return FALSE return TRUE + +/datum/controller/subsystem/persistence/proc/wipe_existing_debris() + var/list/existing = RelevantPersistentDebris() + QDEL_LIST(existing) + +/datum/controller/subsystem/persistence/proc/RelevantPersistentDebris() + var/list/allowed_turf_typecache = typecacheof(/turf/open) - typecacheof(/turf/open/space) + var/list/allowed_z_cache = list() + for(var/z in SSmapping.levels_by_trait(ZTRAIT_STATION)) + allowed_z_cache[num2text(z)] = TRUE + . = list() + for(var/obj/effect/cleanable/C in world) + if(!C.loc || QDELETED(C)) + continue + if(!C.persistent) + continue + if(!IsValidDebrisLocation(C.loc, allowed_turf_typecache, allowed_z_cache, C.type, FALSE)) + continue + . += C diff --git a/code/game/objects/effects/decals/cleanable.dm b/code/game/objects/effects/decals/cleanable.dm index 1ad2173f76..11d76d3cdf 100644 --- a/code/game/objects/effects/decals/cleanable.dm +++ b/code/game/objects/effects/decals/cleanable.dm @@ -14,9 +14,6 @@ /obj/effect/decal/cleanable/Initialize(mapload, list/datum/disease/diseases) . = ..() - #warn OPTIMIZE THE BELOW LINE, CACHE THINGS, THIS IS INSANELY EXPENSIVE - if(mapload && persistent && CONFIG_GET(flag/persistent_debris_only) && (z in SSmapping.levels_by_trait(ZTRAIT_STATION))) - return INITIALIZE_HINT_QDEL LAZYINITLIST(blood_DNA) //Kinda needed if (random_icon_states && (icon_state == initial(icon_state)) && length(random_icon_states) > 0) icon_state = pick(random_icon_states) diff --git a/code/game/objects/effects/decals/crayon.dm b/code/game/objects/effects/decals/crayon.dm index d62f8fccb6..6ebd798e40 100644 --- a/code/game/objects/effects/decals/crayon.dm +++ b/code/game/objects/effects/decals/crayon.dm @@ -36,7 +36,7 @@ . = ..() if(icon != initial(icon)) // no support for alticons yet, awful system anyways return null - data["icon_state"] = icon_stsate + data["icon_state"] = icon_state data["paint_color"] = paint_colour if(do_icon_rotate) data["rotation"] = rotation @@ -51,7 +51,7 @@ M.turn(data["rotation"]) transform = M if(data["paint_color"]) - paint_colour = data["paint_color"]) + paint_colour = data["paint_color"] add_atom_colour(paint_colour, FIXED_COLOUR_PRIORITY) if(data["icon_state"]) icon_state = data["icon_state"]