mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-26 13:37:58 +01:00
Code effeciency project: Canister icon updates
Before: If a canister is hooked up to a connector port it's icons were being deleted and recreated every tick. After: We store an update_flag that is a bitfield of the current icon and overlay states, and created a proc to check if it should change. If not, we don't mess with icons. Real simple. Conflicts: code/game/machinery/atmoalter/canister.dm
This commit is contained in:
@@ -18,16 +18,7 @@
|
||||
use_power = 0
|
||||
var/release_log = ""
|
||||
var/busy = 0
|
||||
/* m_amt=10*CC_PER_SHEET_METAL
|
||||
|
||||
// Need to redefine /obj/item's recyk method
|
||||
/obj/machinery/portable_atmospherics/canister/recycle(var/obj/machinery/mineral/processing_unit/recycle/rec)
|
||||
if (src.m_amt == 0 && src.g_amt == 0)
|
||||
return 0
|
||||
rec.iron += src.m_amt/CC_PER_SHEET_METAL
|
||||
rec.glass += src.g_amt/CC_PER_SHEET_GLASS
|
||||
return 1
|
||||
*/
|
||||
var/update_flag = 0
|
||||
|
||||
/obj/machinery/portable_atmospherics/canister/sleeping_agent
|
||||
name = "Canister: \[N2O\]"
|
||||
@@ -60,42 +51,65 @@
|
||||
_color = "grey"
|
||||
can_label = 0
|
||||
|
||||
/*
|
||||
* return 0 (reached the proc code end)
|
||||
* 1 (canister is destroyed)
|
||||
*/
|
||||
/obj/machinery/portable_atmospherics/canister/update_icon()
|
||||
var/L[0]
|
||||
overlays = L
|
||||
|
||||
if (destroyed)
|
||||
icon_state = "[_color]-1"
|
||||
return 1
|
||||
|
||||
icon_state = "[_color]"
|
||||
|
||||
L += "can-o3"
|
||||
/obj/machinery/portable_atmospherics/canister/proc/check_change()
|
||||
var/old_flag = update_flag
|
||||
update_flag = 0
|
||||
if(holding)
|
||||
update_flag |= 1
|
||||
if(connected_port)
|
||||
update_flag |= 2
|
||||
|
||||
var/tank_pressure = air_contents.return_pressure()
|
||||
if(tank_pressure < 10)
|
||||
update_flag |= 4
|
||||
else if(tank_pressure < ONE_ATMOSPHERE)
|
||||
update_flag |= 8
|
||||
else if(tank_pressure < 15*ONE_ATMOSPHERE)
|
||||
update_flag |= 16
|
||||
else
|
||||
update_flag |= 32
|
||||
|
||||
if (tank_pressure < 10)
|
||||
L[L.len] = "can-o0"
|
||||
else if (tank_pressure < ONE_ATMOSPHERE)
|
||||
L[L.len] = "can-o1"
|
||||
else if (tank_pressure < 15 * ONE_ATMOSPHERE)
|
||||
L[L.len] = "can-o2"
|
||||
if(update_flag == old_flag)
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
|
||||
tank_pressure = null
|
||||
/obj/machinery/portable_atmospherics/canister/update_icon()
|
||||
/*
|
||||
update_flag
|
||||
1 = holding
|
||||
2 = connected_port
|
||||
4 = tank_pressure < 10
|
||||
8 = tank_pressure < ONE_ATMOS
|
||||
16 = tank_pressure < 15*ONE_ATMOS
|
||||
32 = tank_pressure go boom.
|
||||
*/
|
||||
|
||||
if (holding)
|
||||
L += "can-open"
|
||||
if (src.destroyed)
|
||||
src.overlays = 0
|
||||
src.icon_state = text("[]-1", src._color)
|
||||
|
||||
if (connected_port)
|
||||
L += "can-connector"
|
||||
if(icon_state != "[_color]")
|
||||
icon_state = "[_color]"
|
||||
|
||||
overlays = L
|
||||
L = null
|
||||
return 0
|
||||
if(check_change()) //Returns 1 if no change needed to icons.
|
||||
return
|
||||
|
||||
src.overlays = 0
|
||||
|
||||
if(update_flag & 1)
|
||||
overlays += "can-open"
|
||||
if(update_flag & 2)
|
||||
overlays += "can-connector"
|
||||
if(update_flag & 4)
|
||||
overlays += "can-o0"
|
||||
if(update_flag & 8)
|
||||
overlays += "can-o1"
|
||||
else if(update_flag & 16)
|
||||
overlays += "can-o2"
|
||||
else if(update_flag & 32)
|
||||
overlays += "can-o3"
|
||||
return
|
||||
|
||||
/obj/machinery/portable_atmospherics/canister/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume)
|
||||
if(exposed_temperature > temperature_resistance)
|
||||
|
||||
Reference in New Issue
Block a user