mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-23 07:26:05 +00:00
## About The Pull Request [Saves 0.2 seconds of init time. 50% of emissive blockers](8318b648f6) Emissive blockers are a decent expense during init, even these, which are the ones that update outside of initialize. I've inlined them, removed some redundant vars and checks, reduced the arg count, and shifted some things around. This ends up saving 200ms, or 50% of its total cost. I also shifted mutable_appearance about a bit. it's not a massive saving, but it is technically faster [Prevents a few redundant appearance_updates, saves 0.8 seconds of init](5475cd778b) Prequisit info: update_appearance is decently expensive It's good then to only do it if we have a reason to, right? Me and moth were shooting the shit about just general init time, and we came up with the idea of tracking which update_appearances actually "worked" and which didn't. That bit comes later, let's enjoy the fruits of that work first First, holograms were calling update_appearance on process, for almost no reason. I patched the one event they don't already "react" to, and then locked it behind a change decection if. good for live, doesn't impact init. Next, decals. If you add a decal to something before it inits, it'll react to the after successful init signal. The trouble is the same atom could have its appearance updated from this MORE then once, since decals can be stacked on tiles, and signal unregisters don't work once the signal is sent. So we add a flag to track if we've had this happen to us or not, so it only happens once. saves 80 ms Power! lots of things call power_change on init, often more then once. We'll update appearance for each of those calls, even if only one is an actual change. That's silly, better to track what sort of power we're using for our appearance and go off that changing This was taking about 300ms. Really stupid Icon smoothing. After emissive blockers were added, any change to something's icon smoothing would lead to an update_appearance call. Nasty shit, specially cause of walls, which don't even use emissive blockers. Ok then, so we'll always update appearance for movables, and will allow turfs that are interested to hook it manually. Not many of those anyhow This is slightly a dev ux thing, but it saves 600ms so I think it's worth it. Rare case anyway Telecomms: telecomm machines were updating appearance on process. This is to cover for them turning on/off on process. Better then to just check if on actually changed. This cost adds up midgame, doesn't impact init tho Materials: There's this update_appearance call in material on_apply. it doesn't do anything. The logs will lie to you and say it does, but it's just like reapplying emissives. It doesn't need to exist Saves like 50ms Canisters: Live thing, lots of time wasted updating appearance for no reason, lets see if we change anything first yes? [Uses defines to wrap update_appearance for tracking](4fa82e1c9d) [Undoes _update_appearance changes, instead reccomends 2 regexes to use](a8c8fec57a) I need file and line number for my tracking, so I need to override update_appearance calls, and also preferably not require every override of update_appearance to handle dummy file + line args. So instead, I created a wrapper proc that checks to see if appearanaces match (they're unique remember, the two of the same visual appearance will be equivalent) The trouble is I can't intercept JUST proc calls, or JUST function definitions with defines. it needs to be both. So I renamed the /update_appearance proc to /_update_appearance this way I can capture old uses, and don't need to worry about merge/dev brain skew ~~It does mean that all update_appearance proc definitions now look weird tho. My profiling is leaking into dev ux. I wish I had better templating.~~ **The above is no longer being pr'd**, it's instead just recommended via a few regexes adjacent to the define. Smelled wrong anyhow [Adds a setter for panel_open, so I can update_appearance on it](cf1df8a69f) ## Why It's Good For The Game Speed
231 lines
6.7 KiB
Plaintext
231 lines
6.7 KiB
Plaintext
/obj/machinery/power/generator
|
|
name = "thermoelectric generator"
|
|
desc = "It's a high efficiency thermoelectric generator."
|
|
icon_state = "teg"
|
|
density = TRUE
|
|
use_power = NO_POWER_USE
|
|
|
|
circuit = /obj/item/circuitboard/machine/generator
|
|
|
|
var/obj/machinery/atmospherics/components/binary/circulator/cold_circ
|
|
var/obj/machinery/atmospherics/components/binary/circulator/hot_circ
|
|
|
|
var/lastgen = 0
|
|
var/lastgenlev = -1
|
|
var/lastcirc = "00"
|
|
|
|
|
|
/obj/machinery/power/generator/Initialize(mapload)
|
|
. = ..()
|
|
AddComponent(/datum/component/simple_rotation)
|
|
find_circs()
|
|
connect_to_network()
|
|
SSair.start_processing_machine(src)
|
|
update_appearance()
|
|
|
|
/obj/machinery/power/generator/Destroy()
|
|
kill_circs()
|
|
SSair.stop_processing_machine(src)
|
|
return ..()
|
|
|
|
/obj/machinery/power/generator/update_overlays()
|
|
. = ..()
|
|
if(machine_stat & (NOPOWER|BROKEN))
|
|
return
|
|
|
|
var/L = min(round(lastgenlev / 100000), 11)
|
|
if(L != 0)
|
|
. += mutable_appearance('icons/obj/power.dmi', "teg-op[L]")
|
|
if(hot_circ && cold_circ)
|
|
. += "teg-oc[lastcirc]"
|
|
|
|
|
|
#define GENRATE 800 // generator output coefficient from Q
|
|
|
|
/obj/machinery/power/generator/process_atmos()
|
|
|
|
if(!cold_circ || !hot_circ)
|
|
return
|
|
|
|
if(powernet)
|
|
var/datum/gas_mixture/cold_air = cold_circ.return_transfer_air()
|
|
var/datum/gas_mixture/hot_air = hot_circ.return_transfer_air()
|
|
|
|
if(cold_air && hot_air)
|
|
|
|
var/cold_air_heat_capacity = cold_air.heat_capacity()
|
|
var/hot_air_heat_capacity = hot_air.heat_capacity()
|
|
|
|
var/delta_temperature = hot_air.temperature - cold_air.temperature
|
|
|
|
|
|
if(delta_temperature > 0 && cold_air_heat_capacity > 0 && hot_air_heat_capacity > 0)
|
|
var/efficiency = 0.65
|
|
|
|
var/energy_transfer = delta_temperature*hot_air_heat_capacity*cold_air_heat_capacity/(hot_air_heat_capacity+cold_air_heat_capacity)
|
|
|
|
var/heat = energy_transfer*(1-efficiency)
|
|
lastgen += energy_transfer*efficiency
|
|
|
|
hot_air.temperature = hot_air.temperature - energy_transfer/hot_air_heat_capacity
|
|
cold_air.temperature = cold_air.temperature + heat/cold_air_heat_capacity
|
|
|
|
//add_avail(lastgen) This is done in process now
|
|
// update icon overlays only if displayed level has changed
|
|
|
|
if(hot_air)
|
|
var/datum/gas_mixture/hot_circ_air1 = hot_circ.airs[1]
|
|
hot_circ_air1.merge(hot_air)
|
|
|
|
if(cold_air)
|
|
var/datum/gas_mixture/cold_circ_air1 = cold_circ.airs[1]
|
|
cold_circ_air1.merge(cold_air)
|
|
|
|
update_appearance()
|
|
|
|
var/circ = "[cold_circ?.last_pressure_delta > 0 ? "1" : "0"][hot_circ?.last_pressure_delta > 0 ? "1" : "0"]"
|
|
if(circ != lastcirc)
|
|
lastcirc = circ
|
|
update_appearance()
|
|
|
|
src.updateDialog()
|
|
|
|
/obj/machinery/power/generator/process()
|
|
//Setting this number higher just makes the change in power output slower, it doesnt actualy reduce power output cause **math**
|
|
var/power_output = round(lastgen / 10)
|
|
add_avail(power_output)
|
|
lastgenlev = power_output
|
|
lastgen -= power_output
|
|
..()
|
|
|
|
/obj/machinery/power/generator/proc/get_menu(include_link = TRUE)
|
|
var/t = ""
|
|
if(!powernet)
|
|
t += "<span class='bad'>Unable to connect to the power network!</span>"
|
|
else if(cold_circ && hot_circ)
|
|
var/datum/gas_mixture/cold_circ_air1 = cold_circ.airs[1]
|
|
var/datum/gas_mixture/cold_circ_air2 = cold_circ.airs[2]
|
|
var/datum/gas_mixture/hot_circ_air1 = hot_circ.airs[1]
|
|
var/datum/gas_mixture/hot_circ_air2 = hot_circ.airs[2]
|
|
|
|
t += "<div class='statusDisplay'>"
|
|
|
|
t += "Output: [display_power(lastgenlev)]"
|
|
|
|
t += "<BR>"
|
|
|
|
t += "<B><font color='blue'>Cold loop</font></B><BR>"
|
|
t += "Temperature Inlet: [round(cold_circ_air2.temperature, 0.1)] K / Outlet: [round(cold_circ_air1.temperature, 0.1)] K<BR>"
|
|
t += "Pressure Inlet: [round(cold_circ_air2.return_pressure(), 0.1)] kPa / Outlet: [round(cold_circ_air1.return_pressure(), 0.1)] kPa<BR>"
|
|
|
|
t += "<B><font color='red'>Hot loop</font></B><BR>"
|
|
t += "Temperature Inlet: [round(hot_circ_air2.temperature, 0.1)] K / Outlet: [round(hot_circ_air1.temperature, 0.1)] K<BR>"
|
|
t += "Pressure Inlet: [round(hot_circ_air2.return_pressure(), 0.1)] kPa / Outlet: [round(hot_circ_air1.return_pressure(), 0.1)] kPa<BR>"
|
|
|
|
t += "</div>"
|
|
else if(!hot_circ && cold_circ)
|
|
t += "<span class='bad'>Unable to locate hot circulator!</span>"
|
|
else if(hot_circ && !cold_circ)
|
|
t += "<span class='bad'>Unable to locate cold circulator!</span>"
|
|
else
|
|
t += "<span class='bad'>Unable to locate any parts!</span>"
|
|
if(include_link)
|
|
t += "<BR><A href='?src=[REF(src)];close=1'>Close</A>"
|
|
|
|
return t
|
|
|
|
/obj/machinery/power/generator/ui_interact(mob/user)
|
|
. = ..()
|
|
var/datum/browser/popup = new(user, "teg", "Thermo-Electric Generator", 460, 300)
|
|
popup.set_content(get_menu())
|
|
popup.open()
|
|
|
|
/obj/machinery/power/generator/Topic(href, href_list)
|
|
if(..())
|
|
return
|
|
if( href_list["close"] )
|
|
usr << browse(null, "window=teg")
|
|
usr.unset_machine()
|
|
return FALSE
|
|
return TRUE
|
|
|
|
|
|
|
|
/obj/machinery/power/generator/proc/find_circs()
|
|
kill_circs()
|
|
var/list/circs = list()
|
|
var/obj/machinery/atmospherics/components/binary/circulator/C
|
|
var/circpath = /obj/machinery/atmospherics/components/binary/circulator
|
|
if(dir == NORTH || dir == SOUTH)
|
|
C = locate(circpath) in get_step(src, EAST)
|
|
if(C && C.dir == WEST)
|
|
circs += C
|
|
|
|
C = locate(circpath) in get_step(src, WEST)
|
|
if(C && C.dir == EAST)
|
|
circs += C
|
|
|
|
else
|
|
C = locate(circpath) in get_step(src, NORTH)
|
|
if(C && C.dir == SOUTH)
|
|
circs += C
|
|
|
|
C = locate(circpath) in get_step(src, SOUTH)
|
|
if(C && C.dir == NORTH)
|
|
circs += C
|
|
|
|
if(circs.len)
|
|
for(C in circs)
|
|
if(C.mode == CIRCULATOR_COLD && !cold_circ)
|
|
cold_circ = C
|
|
C.generator = src
|
|
else if(C.mode == CIRCULATOR_HOT && !hot_circ)
|
|
hot_circ = C
|
|
C.generator = src
|
|
|
|
/obj/machinery/power/generator/wrench_act(mob/living/user, obj/item/I)
|
|
. = ..()
|
|
if(!panel_open)
|
|
return
|
|
set_anchored(!anchored)
|
|
I.play_tool_sound(src)
|
|
if(!anchored)
|
|
kill_circs()
|
|
connect_to_network()
|
|
to_chat(user, span_notice("You [anchored?"secure":"unsecure"] [src]."))
|
|
return TRUE
|
|
|
|
/obj/machinery/power/generator/multitool_act(mob/living/user, obj/item/I)
|
|
. = ..()
|
|
if(!anchored)
|
|
return
|
|
find_circs()
|
|
to_chat(user, span_notice("You update [src]'s circulator links."))
|
|
return TRUE
|
|
|
|
/obj/machinery/power/generator/screwdriver_act(mob/user, obj/item/I)
|
|
if(..())
|
|
return TRUE
|
|
toggle_panel_open()
|
|
I.play_tool_sound(src)
|
|
to_chat(user, span_notice("You [panel_open?"open":"close"] the panel on [src]."))
|
|
return TRUE
|
|
|
|
/obj/machinery/power/generator/crowbar_act(mob/user, obj/item/I)
|
|
default_deconstruction_crowbar(I)
|
|
return TRUE
|
|
|
|
/obj/machinery/power/generator/AltClick(mob/user)
|
|
return ..() // This hotkey is BLACKLISTED since it's used by /datum/component/simple_rotation
|
|
|
|
/obj/machinery/power/generator/on_deconstruction()
|
|
kill_circs()
|
|
|
|
/obj/machinery/power/generator/proc/kill_circs()
|
|
if(hot_circ)
|
|
hot_circ.generator = null
|
|
hot_circ = null
|
|
if(cold_circ)
|
|
cold_circ.generator = null
|
|
cold_circ = null
|