Skip to content

Commit

Permalink
Merge pull request #16028 from DeltaFire15/powernet-optim
Browse files Browse the repository at this point in the history
Minor power_change optimization (updated)
  • Loading branch information
silicons authored Nov 17, 2023
2 parents b771da0 + 7bb6d4c commit 9f7685d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions code/game/area/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ GLOBAL_LIST_EMPTY(teleportlocs)
A.power_light = FALSE
A.power_equip = FALSE
A.power_environ = FALSE
INVOKE_ASYNC(A, .proc/power_change)
A.power_change()
STOP_PROCESSING(SSobj, src)
return ..()

Expand Down Expand Up @@ -579,15 +579,20 @@ GLOBAL_LIST_EMPTY(teleportlocs)
// called when power status changes

/area/proc/power_change()
for(var/obj/machinery/M in src) // for each machine in the area
M.power_change() // reverify power status (to update icons etc.)
if(sub_areas)
for(var/i in sub_areas)
var/area/A = i
A.power_light = power_light
A.power_equip = power_equip
A.power_environ = power_environ
INVOKE_ASYNC(A, .proc/power_change)
SHOULD_NOT_SLEEP(TRUE)
if(contents.len < GLOB.machines.len) // it would be faster to loop over contents
for(var/obj/machinery/M in src) // for each machine in the area
M.power_change() // reverify power status (to update icons etc.)
else // it would be faster to loop over the machines list
for(var/obj/machinery/M as anything in GLOB.machines) // for each machine
if(get_area(M) != src) // in the area
continue
M.power_change() // reverify power status (to update icons etc.)
for(var/area/A as anything in sub_areas)
A.power_light = power_light
A.power_equip = power_equip
A.power_environ = power_environ
A.power_change()
update_appearance()

/area/proc/usage(chan)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/doors/firedoor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
/obj/machinery/door/firedoor/power_change()
if(powered(power_channel))
stat &= ~NOPOWER
latetoggle()
INVOKE_ASYNC(src, .proc/latetoggle)
else
stat |= NOPOWER

Expand Down
2 changes: 1 addition & 1 deletion code/modules/power/power.dm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
addStaticPower(-value, powerchannel)

/obj/machinery/proc/power_change()
//SIGNAL_HANDLER
SHOULD_NOT_SLEEP(TRUE)
//SHOULD_CALL_PARENT(TRUE)

if(stat & BROKEN)
Expand Down

0 comments on commit 9f7685d

Please sign in to comment.