Files
Bubberstation/code/game/objects/items/blueprints.dm
SkyratBot ab5a4d0f99 [MIRROR] split area.contained_turfs up by zlevel, make init 10 seconds faster (#26161)
* split area.contained_turfs up by zlevel, make init 10 seconds faster (#80941)

## About The Pull Request

Situation: areas have a list of all turfs in their area.

Problem: `/area/space` is an area and has a 6 to 7 digit count of turfs
that has to be traversed for every turf we need to remove from it. This
can take multiple byond ticks just to preform this action for a single
space rune

Solution: split the list by zlevel, and only search the right zlevel
list when removing turfs from areas.

replaces `area.get_contained_turfs()` with a few new procs:

* `get_highest_zlevel()` - returns the highest zlevel the area contains
turfs in. useful for use with `get_turfs_by_zlevel`
* `get_turfs_by_zlevel(zlevel)` - returns a list of turfs in the area in
a given zlevel. Useful for code that only cares about a specific zlevel
or changes behavior based on zlevel like lighting init.
* `get_turfs_from_all_zlevels()` - the replacement for
`get_contained_turfs()`, renamed as such so anybody copying/cargo
culting code gets a hint that a zlevel specific version might exist.
Still used in for loops that type checked so byond would do that all at
once
* `get_zlevel_turf_lists()` - returns the area's zlevel lists of lists
but only for non-empty zlevels. very useful for for loops.

The area contents unit test has been rewritten to ensure any improper
data triggers failures or runtimes by not having it use the helpers
above (some of which ensure a list is always returned) and access the
lists directly.

* split area.contained_turfs up by zlevel, make init 10 seconds faster

* eeyes

* Update area_spawn_subsystem.dm

* Unshits turf contain code slightly (#81023)

Literally just implements my reviews from #80941 
I am frankly a smidge pissed that the pr was merged without them being
handled. No code is worth merging past known issues, and if the author
is just gonna dip then that's life.
I don't like privileging mso on stuff like this, especially because
frankly I'm kinda mad at him rn but also because when a pr is made the
onus on finishing it falls to the person who made it.

Should not need to clean up after someone as a maintainer, and shouldn't
normalize doing it. I'm not like mad at zypher directly mind he offered
to do this too, just the idea he was espousing here.

---------

Co-authored-by: Kyle Spier-Swenson <kyleshome@gmail.com>
Co-authored-by: Gandalf <9026500+Gandalf2k15@users.noreply.github.com>
Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
2024-01-21 03:34:23 +00:00

255 lines
8.4 KiB
Plaintext

/obj/item/areaeditor
name = "area modification item"
icon = 'icons/obj/scrolls.dmi'
icon_state = "blueprints"
inhand_icon_state = "blueprints"
attack_verb_continuous = list("attacks", "baps", "hits")
attack_verb_simple = list("attack", "bap", "hit")
var/fluffnotice = "Nobody's gonna read this stuff!"
var/in_use = FALSE
///When using it to create a new area, this will be its type.
var/new_area_type = /area
/obj/item/areaeditor/attack_self(mob/user)
add_fingerprint(user)
. = "<BODY><HTML><head><title>[src]</title></head> \
<h2>[station_name()] [src.name]</h2> \
<small>[fluffnotice]</small><hr>"
switch(get_area_type())
if(AREA_SPACE)
. += "<p>According to the [src.name], you are now in an unclaimed territory.</p>"
if(AREA_SPECIAL)
. += "<p>This place is not noted on the [src.name].</p>"
. += "<p><a href='?src=[REF(src)];create_area=1'>Create or modify an existing area</a></p>"
/obj/item/areaeditor/Topic(href, href_list)
if(..())
return TRUE
if(!usr.can_perform_action(src) || usr != loc)
usr << browse(null, "window=blueprints")
return TRUE
if(href_list["create_area"])
if(in_use)
return
var/area/A = get_area(usr)
if(A.area_flags & NOTELEPORT)
to_chat(usr, span_warning("You cannot edit restricted areas."))
return
in_use = TRUE
create_area(usr, new_area_type)
in_use = FALSE
updateUsrDialog()
//Station blueprints!!!
/obj/item/areaeditor/blueprints
name = "station blueprints"
desc = "Blueprints of the station. There is a \"Classified\" stamp and several coffee stains on it."
icon = 'icons/obj/scrolls.dmi'
icon_state = "blueprints"
fluffnotice = "Property of Nanotrasen. For heads of staff only. Store in high-secure storage."
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | ACID_PROOF
var/list/image/showing = list()
var/client/viewing
var/legend = FALSE //Viewing the wire legend
/obj/item/areaeditor/blueprints/Destroy()
clear_viewer()
return ..()
/obj/item/areaeditor/blueprints/attack_self(mob/user)
. = ..()
if(!legend)
var/area/A = get_area(user)
if(get_area_type() == AREA_STATION)
. += "<p>According to \the [src], you are now in <b>\"[html_encode(A.name)]\"</b>.</p>"
. += "<p><a href='?src=[REF(src)];edit_area=1'>Change area name</a></p>"
. += "<p><a href='?src=[REF(src)];view_legend=1'>View wire colour legend</a></p>"
if(!viewing)
. += "<p><a href='?src=[REF(src)];view_blueprints=1'>View structural data</a></p>"
else
. += "<p><a href='?src=[REF(src)];refresh=1'>Refresh structural data</a></p>"
. += "<p><a href='?src=[REF(src)];hide_blueprints=1'>Hide structural data</a></p>"
else
if(legend == TRUE)
. += "<a href='?src=[REF(src)];exit_legend=1'><< Back</a>"
. += view_wire_devices(user);
else
//legend is a wireset
. += "<a href='?src=[REF(src)];view_legend=1'><< Back</a>"
. += view_wire_set(user, legend)
var/datum/browser/popup = new(user, "blueprints", "[src]", 700, 500)
popup.set_content(.)
popup.open()
onclose(user, "blueprints")
/obj/item/areaeditor/blueprints/Topic(href, href_list)
if(..())
return
if(href_list["edit_area"])
if(get_area_type() != AREA_STATION)
return
if(in_use)
return
in_use = TRUE
edit_area()
in_use = FALSE
if(href_list["exit_legend"])
legend = FALSE;
if(href_list["view_legend"])
legend = TRUE;
if(href_list["view_wireset"])
legend = href_list["view_wireset"];
if(href_list["view_blueprints"])
set_viewer(usr, span_notice("You flip the blueprints over to view the complex information diagram."))
if(href_list["hide_blueprints"])
clear_viewer(usr,span_notice("You flip the blueprints over to view the simple information diagram."))
if(href_list["refresh"])
clear_viewer(usr)
set_viewer(usr)
attack_self(usr) //this is not the proper way, but neither of the old update procs work! it's too ancient and I'm tired shush.
/obj/item/areaeditor/blueprints/proc/get_images(turf/central_turf, viewsize)
. = list()
var/list/dimensions = getviewsize(viewsize)
var/horizontal_radius = dimensions[1] / 2
var/vertical_radius = dimensions[2] / 2
for(var/turf/nearby_turf as anything in RECT_TURFS(horizontal_radius, vertical_radius, central_turf))
if(nearby_turf.blueprint_data)
. += nearby_turf.blueprint_data
/obj/item/areaeditor/blueprints/proc/set_viewer(mob/user, message = "")
if(user?.client)
if(viewing)
clear_viewer()
viewing = user.client
showing = get_images(get_turf(viewing.eye || user), viewing.view)
viewing.images |= showing
if(message)
to_chat(user, message)
/obj/item/areaeditor/blueprints/proc/clear_viewer(mob/user, message = "")
if(viewing)
viewing.images -= showing
viewing = null
showing.Cut()
if(message)
to_chat(user, message)
/obj/item/areaeditor/blueprints/dropped(mob/user)
..()
clear_viewer()
legend = FALSE
/obj/item/areaeditor/proc/get_area_type(area/A)
if (!A)
A = get_area(usr)
if(A.outdoors)
return AREA_SPACE
var/list/SPECIALS = list(
/area/shuttle,
/area/centcom,
/area/centcom/asteroid,
/area/centcom/tdome,
/area/centcom/wizard_station,
/area/misc/hilbertshotel,
/area/misc/hilbertshotelstorage
)
for (var/type in SPECIALS)
if ( istype(A,type) )
return AREA_SPECIAL
return AREA_STATION
/obj/item/areaeditor/blueprints/proc/view_wire_devices(mob/user)
var/message = "<br>You examine the wire legend.<br>"
for(var/wireset in GLOB.wire_color_directory)
message += "<br><a href='?src=[REF(src)];view_wireset=[wireset]'>[GLOB.wire_name_directory[wireset]]</a>"
message += "</p>"
return message
/obj/item/areaeditor/blueprints/proc/view_wire_set(mob/user, wireset)
//for some reason you can't use wireset directly as a derefencer so this is the next best :/
for(var/device in GLOB.wire_color_directory)
if("[device]" == wireset) //I know... don't change it...
var/message = "<p><b>[GLOB.wire_name_directory[device]]:</b>"
for(var/Col in GLOB.wire_color_directory[device])
var/wire_name = GLOB.wire_color_directory[device][Col]
if(!findtext(wire_name, WIRE_DUD_PREFIX)) //don't show duds
message += "<p><span style='color: [Col]'>[Col]</span>: [wire_name]</p>"
message += "</p>"
return message
return ""
/obj/item/areaeditor/proc/edit_area()
var/area/A = get_area(usr)
var/prevname = "[A.name]"
var/str = tgui_input_text(usr, "New area name", "Area Creation", max_length = MAX_NAME_LEN)
if(!str || !length(str) || str == prevname) //cancel
return
if(length(str) > 50)
to_chat(usr, span_warning("The given name is too long. The area's name is unchanged."))
return
rename_area(A, str)
to_chat(usr, span_notice("You rename the '[prevname]' to '[str]'."))
usr.log_message("has renamed [prevname] to [str]", LOG_GAME)
A.update_areasize()
interact()
return TRUE
//Blueprint Subtypes
/obj/item/areaeditor/blueprints/cyborg
name = "station schematics"
desc = "A digital copy of the station blueprints stored in your memory."
icon = 'icons/obj/scrolls.dmi'
icon_state = "blueprints"
fluffnotice = "Intellectual Property of Nanotrasen. For use in engineering cyborgs only. Wipe from memory upon departure from the station."
/obj/item/areaeditor/blueprints/golem
name = "land claim"
desc = "Use it to build new structures in the wastes."
fluffnotice = "In memory of the Liberator's brother, Delaminator, and his Scarlet Macaw-iathan, from which this artifact was stolen."
new_area_type = /area/golem
/proc/rename_area(a, new_name)
var/area/A = get_area(a)
var/prevname = "[A.name]"
set_area_machinery_title(A, new_name, prevname)
A.name = new_name
require_area_resort() //area renamed so resort the names
if(A.firedoors)
for(var/D in A.firedoors)
var/obj/machinery/door/firedoor/FD = D
FD.CalculateAffectingAreas()
A.update_areasize()
return TRUE
/proc/set_area_machinery_title(area/area, title, oldtitle)
if(!oldtitle) // or replacetext goes to infinite loop
return
//stuff tied to the area to rename
var/static/list/to_rename = typecacheof(list(
/obj/machinery/airalarm,
/obj/machinery/atmospherics/components/unary/vent_scrubber,
/obj/machinery/atmospherics/components/unary/vent_pump,
/obj/machinery/door,
/obj/machinery/firealarm,
/obj/machinery/light_switch,
/obj/machinery/power/apc,
))
for (var/list/zlevel_turfs as anything in area.get_zlevel_turf_lists())
for (var/turf/area_turf as anything in zlevel_turfs)
for(var/obj/machine as anything in typecache_filter_list(area_turf.contents, to_rename))
machine.name = replacetext(machine.name, oldtitle, title)
//TODO: much much more. Unnamed airlocks, cameras, etc.