Optimization to canister's update_icon

Shamelessly rips off the APC's sweet ass method of dealing with overlay updates in update_icon and applies them to canisters, helping with the odd occasion where canister's starting chewing through cpu cycles.
This commit is contained in:
clusterfack
2015-05-17 03:55:27 -05:00
parent 3b411f8281
commit f4406d1a87
2 changed files with 91 additions and 22 deletions

View File

@@ -1,3 +1,10 @@
#define OVERLAY_HOLDING 1
#define OVERLAY_CONNECTED 2
#define OVERLAY_NO_PRESSURE 4
#define OVERLAY_LOW_PRESSURE 8
#define OVERLAY_MEDIUM_PRESSURE 16
#define OVERLAY_HIGH_PRESSURE 32
/obj/machinery/portable_atmospherics/canister /obj/machinery/portable_atmospherics/canister
name = "canister" name = "canister"
icon = 'icons/obj/atmos.dmi' icon = 'icons/obj/atmos.dmi'
@@ -11,6 +18,7 @@
var/release_pressure = ONE_ATMOSPHERE var/release_pressure = ONE_ATMOSPHERE
var/canister_color = "yellow" var/canister_color = "yellow"
var/old_color = 0
var/can_label = 1 var/can_label = 1
var/filled = 0.5 // Mapping var: Set to 0 for empty, 1 to full, anywhere between. var/filled = 0.5 // Mapping var: Set to 0 for empty, 1 to full, anywhere between.
pressure_resistance = 7*ONE_ATMOSPHERE pressure_resistance = 7*ONE_ATMOSPHERE
@@ -23,8 +31,18 @@
w_type = RECYK_METAL w_type = RECYK_METAL
melt_temperature = MELTPOINT_STEEL melt_temperature = MELTPOINT_STEEL
//Icon Update Code
var/global/status_overlays = 0
var/global/list/status_overlays_pressure
var/global/list/status_overlays_other
var/overlay_status = 0
var/log="" // Bad boys, bad boys. var/log="" // Bad boys, bad boys.
/obj/machinery/portable_atmospherics/canister/New()
..()
old_color = canister_color
/obj/machinery/portable_atmospherics/canister/sleeping_agent /obj/machinery/portable_atmospherics/canister/sleeping_agent
name = "Canister: \[N2O\]" name = "Canister: \[N2O\]"
icon_state = "redws" icon_state = "redws"
@@ -62,33 +80,76 @@
can_label = 0 can_label = 0
/obj/machinery/portable_atmospherics/canister/update_icon() /obj/machinery/portable_atmospherics/canister/update_icon()
overlays = null
if(destroyed) if(destroyed)
icon_state = "[canister_color]-1" icon_state = "[canister_color]-1"
else return
icon_state = canister_color
overlays = new/list()
if (holding) if(!status_overlays)
overlays.Add("can-open") status_overlays = 1
if (connected_port) status_overlays_pressure = new
overlays.Add("can-connector") status_overlays_other = new
status_overlays_pressure.len = 4
status_overlays_other.len = 2
status_overlays_pressure[1] = image(icon, "can-o0")
status_overlays_pressure[2] = image(icon, "can-o1")
status_overlays_pressure[3] = image(icon, "can-o2")
status_overlays_pressure[4] = image(icon, "can-o3")
status_overlays_other[1] = image(icon, "can-open")
status_overlays_other[2] = image(icon, "can-connector")
if (canister_color != old_color)
icon_state = "[canister_color]"
old_color = canister_color
var/tank_pressure = air_contents.return_pressure() var/tank_pressure = air_contents.return_pressure()
if(check_updates(tank_pressure))
if(overlays.len)
overlays = 0
if (tank_pressure < 10) overlay_status = 0
overlays.Add("can-o0")
else if (tank_pressure < ONE_ATMOSPHERE) if (holding)
overlays.Add("can-o1") overlays += status_overlays_other[1]
else if (tank_pressure < 15 * ONE_ATMOSPHERE) overlay_status |= OVERLAY_HOLDING
overlays.Add("can-o2")
if (connected_port)
overlays += status_overlays_other[2]
overlay_status |= OVERLAY_CONNECTED
switch(tank_pressure)
if(15 * ONE_ATMOSPHERE to INFINITY)
overlays += status_overlays_pressure[4]
overlay_status |= OVERLAY_HIGH_PRESSURE
if(ONE_ATMOSPHERE to 15 * ONE_ATMOSPHERE)
overlays += status_overlays_pressure[3]
overlay_status |= OVERLAY_MEDIUM_PRESSURE
if(10 to ONE_ATMOSPHERE)
overlays += status_overlays_pressure[2]
overlay_status |= OVERLAY_LOW_PRESSURE
else else
overlays.Add("can-o3") overlays += status_overlays_pressure[1]
overlay_status |= OVERLAY_NO_PRESSURE
return return
/obj/machinery/portable_atmospherics/canister/proc/check_updates(tank_pressure = 0)
if((overlay_status & OVERLAY_HOLDING) != holding)
return 1
if((overlay_status & OVERLAY_CONNECTED) != connected_port)
return 1
if((overlay_status & OVERLAY_HIGH_PRESSURE) && tank_pressure < 15*ONE_ATMOSPHERE)
return 1
if((overlay_status & OVERLAY_MEDIUM_PRESSURE) && (tank_pressure < ONE_ATMOSPHERE || tank_pressure > 15*ONE_ATMOSPHERE))
return 1
if((overlay_status & OVERLAY_LOW_PRESSURE) && (tank_pressure < 10 || tank_pressure > ONE_ATMOSPHERE))
return 1
if((overlay_status & OVERLAY_NO_PRESSURE) && tank_pressure > 10)
return 1
return 0
/obj/machinery/portable_atmospherics/canister/fire_act(datum/gas_mixture/air, exposed_temperature, exposed_volume) /obj/machinery/portable_atmospherics/canister/fire_act(datum/gas_mixture/air, exposed_temperature, exposed_volume)
if(exposed_temperature > temperature_resistance) if(exposed_temperature > temperature_resistance)
@@ -443,3 +504,10 @@
for(var/obj/effect/beam/B in beams) for(var/obj/effect/beam/B in beams)
apply_beam_damage(B) apply_beam_damage(B)
healthcheck() healthcheck()
#undef OVERLAY_HOLDING
#undef OVERLAY_CONNECTED
#undef OVERLAY_NO_PRESSURE
#undef OVERLAY_LOW_PRESSURE
#undef OVERLAY_MEDIUM_PRESSURE
#undef OVERLAY_HIGH_PRESSURE

View File

@@ -254,7 +254,8 @@ var/global/floorIsLava = 0
usr << "Error: you are not an admin!" usr << "Error: you are not an admin!"
return return
checkSessionKey() checkSessionKey()
var/cid = input("Type computer ID", "CID", 0) var/cid = input("Type computer ID", "CID", 0) as num | null
if(cid)
usr << link(getVGPanel("rapsheet",admin=1,query=list("cid"=cid))) usr << link(getVGPanel("rapsheet",admin=1,query=list("cid"=cid)))
//usr << link("[config.vgws_base_url]/index.php/rapsheet/?s=[sessKey]&cid=[cid]") //usr << link("[config.vgws_base_url]/index.php/rapsheet/?s=[sessKey]&cid=[cid]")
return return