Files
Bubberstation/code/modules/power/generator.dm
Kyle Spier-Swenson 8df93ba39e [Ready] CDN browser assets! (#52681)
Rewrites the asset_cache system to handle sending assets to a CDN via a webroot.

see https://github.com/MrStonedOne/tgstation/blob/asset-cdn/code/modules/asset_cache/readme.md

Fixed a lot of bugs with assets, removed some dead code.

Changes:
    Moved asset cache code to transport datums, the currently loaded one is located at SSassets.transport, asset cache calls made before the config is loaded use the simple browse_rsc transport.
    Added subsystem call for when the config loads or reloads.
    Added a webroot CDN asset transport. assets are saved to a file in a format based on the file's hash (currently md5).
    Assets that don't use get_asset_url or get_url_mappings (such as browser assets referred to by static html files like changelog.html or static css files) can be saved to browse_rsc even when in cdn asset mode by setting legacy to TRUE on the datum returned by register_assets
    Added a system for saving assets on a cdn in a hash based namespace (folder), assets within the same namespace will always be able to refer to each other by relative names. (used to allow cdn'ing font awesome without having to make something that regenerates it's css files.).
    The simple/namespaced asset cache datum helper will handle generating a namespace composed of the combined md5 of everything in the same datum, as well as registering them properly.
    Moved external resource from a snowflake loaded file to a config entry, added it to resources.txt
    To ensure the system breaks in local testing in any situation that wouldn't work in cdn mode, the simple transport will mutate the filenames of non-legacy and non-namespaced assets and return this with get_asset_url.
    Simple transport's passive send of all roundstart assets to all clients is now a config that defaults to off. this is to break race conditions during local testings from devs accidentally relying on this instead of using send() properly.

cl
refactor: Interface assets (js/css/images) can now be managed using an external webserver instead of byond's one at a time file transfer queue.
admin: Adds admin verb toggle-cdn that allows admins to disable the external webserver asset transport and revert to the old system. Useful if the webserver backing this goes down (thanks cloudflare).
config: New config file, resources.txt, (must be loaded by an $include statement from the main config)
server: The external_rsc_urls.txt config has been moved to the main config system.
/cl
Porting notes:

Interface webpages must refer to their assets (css/js/image/etc) by a generated url, or the asset must register itself as a legacy asset. The system is designed to break in localtest (on simple/legacy mode) in most situations that would break in cdn mode.

Requires latest tgui.

The webserver must set the proper CORS headers for font files or font awesome (and other fonts) won't load.

/tg/'s webserver config: https://gist.github.com/MrStonedOne/523388b2f161af832292d98a8aad0eae
2020-08-12 13:51:43 +12:00

229 lines
6.8 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
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)
. = ..()
find_circs()
connect_to_network()
SSair.atmos_machinery += src
update_icon()
component_parts = list(new /obj/item/circuitboard/machine/generator)
/obj/machinery/power/generator/ComponentInitialize()
. = ..()
AddComponent(/datum/component/simple_rotation,ROTATION_ALTCLICK | ROTATION_CLOCKWISE | ROTATION_COUNTERCLOCKWISE | ROTATION_VERBS )
/obj/machinery/power/generator/Destroy()
kill_circs()
SSair.atmos_machinery -= src
return ..()
/obj/machinery/power/generator/update_overlays()
. = ..()
if(!(machine_stat & (NOPOWER|BROKEN)))
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_icon()
var/circ = "[cold_circ && cold_circ.last_pressure_delta > 0 ? "1" : "0"][hot_circ && hot_circ.last_pressure_delta > 0 ? "1" : "0"]"
if(circ != lastcirc)
lastcirc = circ
update_icon()
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: [DisplayPower(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 class='notice'>You [anchored?"secure":"unsecure"] [src].</span>")
return TRUE
/obj/machinery/power/generator/multitool_act(mob/living/user, obj/item/I)
. = ..()
if(!anchored)
return
find_circs()
to_chat(user, "<span class='notice'>You update [src]'s circulator links.</span>")
return TRUE
/obj/machinery/power/generator/screwdriver_act(mob/user, obj/item/I)
if(..())
return TRUE
panel_open = !panel_open
I.play_tool_sound(src)
to_chat(user, "<span class='notice'>You [panel_open?"open":"close"] the panel on [src].</span>")
return TRUE
/obj/machinery/power/generator/crowbar_act(mob/user, obj/item/I)
default_deconstruction_crowbar(I)
return TRUE
/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