mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-06-05 06:05:58 +01:00
910b97cd37
Starts shaving off a lot of less than 0.1s performance killers by, in nearly every case, just writing better code. Numbers are amount saved. - /obj/machinery/bluespace_vendor/LateInitialize -> 29.4ms Changes a loop over all machines to a specialized list. - /obj/structure/table/glass/Initialize -> 42.53ms Stops every table from initializing glass shards and table frames before any destruction. - /obj/structure/chair/Initialize -> 24.64ms Removes an unnecessary addtimer that existed for chairs that weren't anchored in emergency shuttles. Didn't do anything. - /datum/orderable_item/New -> 44.3ms Instead of initializing every item to get its desc, just uses initial. Added a unit test to make sure none are dynamic. - /obj/machinery/computer/slot_machine/Initialize -> 26.19ms Currently goes through every coin subtype, creates it, calls a proc, then qdels it. Changes that to only run once. Could be optimized further by making the coin info on a datum to avoid creating the object, but it currently sits at 7.82ms, far below worth caring about for now. - /obj/machinery/door_buttons/airlock_controller/findObjsByTag -> 3.51ms Loops over just doors instead of typechecking airlock in machines. - /obj/structure/closet/Initialize -> 60.57ms Moves the code for taking everything on the tile from a next-tick timer to LateInitialize. - /obj/machinery/rnd/experimentor/Initialize -> 36.92ms Changes a list that is generated by going through every item in the game and getting information from a large amount of them to only run when needed. - /obj/structure/tank_dispenser/Initialize -> 20.81ms No longer initializes every tank in it right away, only when needed. - /obj/machinery/telecomms/LateInitialize -> 16.63ms Removes `urange` to instead just loop over telecomms machines and check distance. There's not that many of them. - /mob/living/simple_animal/hostile/carp/cayenne/Initialize -> 3.17ms Defers a GAGS overlay creation until its needed. BTW GAGS is *horrendous* on init costs, and is the root cause for a lot of pretty terrible performance. I investigated precompiling but the gains weren't crazy, but likely could be the more stuff is GAGS'd. - /turf/open/floor/engine/cult/Initialize -> 14.64ms Temporary visual effect that is created is no longer done on mapload, since nobody will see it. - /datum/techweb/specialized/autounlocking/proc/autounlock -> 5.55ms Changes some loops to shorter checks. This whole proc is pretty bad and it's still 14.21ms for 17 calls. - /matrix/New -> 13.41ms - /matrix/proc/Translate -> 42.06ms ~~Changed the mineral matrice to only generate once, then take it from a static.~~ An extra ~0.05s taken off by avoiding setting icon and transform every Initialize.
121 lines
2.9 KiB
Plaintext
121 lines
2.9 KiB
Plaintext
#define TANK_DISPENSER_CAPACITY 10
|
|
|
|
/obj/structure/tank_dispenser
|
|
name = "tank dispenser"
|
|
desc = "A simple yet bulky storage device for gas tanks. Holds up to 10 oxygen tanks and 10 plasma tanks."
|
|
icon = 'icons/obj/objects.dmi'
|
|
icon_state = "dispenser"
|
|
density = TRUE
|
|
anchored = TRUE
|
|
max_integrity = 300
|
|
var/oxygentanks = TANK_DISPENSER_CAPACITY
|
|
var/plasmatanks = TANK_DISPENSER_CAPACITY
|
|
|
|
/obj/structure/tank_dispenser/oxygen
|
|
plasmatanks = 0
|
|
|
|
/obj/structure/tank_dispenser/plasma
|
|
oxygentanks = 0
|
|
|
|
/obj/structure/tank_dispenser/Initialize(mapload)
|
|
. = ..()
|
|
update_appearance()
|
|
|
|
/obj/structure/tank_dispenser/update_overlays()
|
|
. = ..()
|
|
switch(oxygentanks)
|
|
if(1 to 3)
|
|
. += "oxygen-[oxygentanks]"
|
|
if(4 to TANK_DISPENSER_CAPACITY)
|
|
. += "oxygen-4"
|
|
switch(plasmatanks)
|
|
if(1 to 4)
|
|
. += "plasma-[plasmatanks]"
|
|
if(5 to TANK_DISPENSER_CAPACITY)
|
|
. += "plasma-5"
|
|
|
|
/obj/structure/tank_dispenser/wrench_act(mob/living/user, obj/item/tool)
|
|
. = ..()
|
|
default_unfasten_wrench(user, tool)
|
|
return TOOL_ACT_TOOLTYPE_SUCCESS
|
|
|
|
/obj/structure/tank_dispenser/attackby(obj/item/I, mob/living/user, params)
|
|
var/full
|
|
if(istype(I, /obj/item/tank/internals/plasma))
|
|
if(plasmatanks < TANK_DISPENSER_CAPACITY)
|
|
plasmatanks++
|
|
else
|
|
full = TRUE
|
|
else if(istype(I, /obj/item/tank/internals/oxygen))
|
|
if(oxygentanks < TANK_DISPENSER_CAPACITY)
|
|
oxygentanks++
|
|
else
|
|
full = TRUE
|
|
else if(!user.combat_mode)
|
|
to_chat(user, span_notice("[I] does not fit into [src]."))
|
|
return
|
|
else
|
|
return ..()
|
|
if(full)
|
|
to_chat(user, span_notice("[src] can't hold any more of [I]."))
|
|
return
|
|
|
|
if(!user.transferItemToLoc(I, src))
|
|
return
|
|
to_chat(user, span_notice("You put [I] in [src]."))
|
|
update_appearance()
|
|
|
|
/obj/structure/tank_dispenser/ui_state(mob/user)
|
|
return GLOB.physical_state
|
|
|
|
/obj/structure/tank_dispenser/ui_interact(mob/user, datum/tgui/ui)
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
ui = new(user, src, "TankDispenser", name)
|
|
ui.open()
|
|
|
|
/obj/structure/tank_dispenser/ui_data(mob/user)
|
|
var/list/data = list()
|
|
data["oxygen"] = oxygentanks
|
|
data["plasma"] = plasmatanks
|
|
|
|
return data
|
|
|
|
/obj/structure/tank_dispenser/ui_act(action, params)
|
|
. = ..()
|
|
if(.)
|
|
return
|
|
switch(action)
|
|
if("plasma")
|
|
if (plasmatanks == 0)
|
|
return TRUE
|
|
|
|
dispense(/obj/item/tank/internals/plasma, usr)
|
|
plasmatanks--
|
|
if("oxygen")
|
|
if (oxygentanks == 0)
|
|
return TRUE
|
|
|
|
dispense(/obj/item/tank/internals/oxygen, usr)
|
|
oxygentanks--
|
|
|
|
update_appearance()
|
|
return TRUE
|
|
|
|
|
|
/obj/structure/tank_dispenser/deconstruct(disassembled = TRUE)
|
|
if(!(flags_1 & NODECONSTRUCT_1))
|
|
for(var/X in src)
|
|
var/obj/item/I = X
|
|
I.forceMove(loc)
|
|
new /obj/item/stack/sheet/iron (loc, 2)
|
|
qdel(src)
|
|
|
|
/obj/structure/tank_dispenser/proc/dispense(tank_type, mob/receiver)
|
|
var/existing_tank = locate(tank_type) in src
|
|
if (isnull(existing_tank))
|
|
existing_tank = new tank_type
|
|
receiver.put_in_hands(existing_tank)
|
|
|
|
#undef TANK_DISPENSER_CAPACITY
|