Performance tweaks (#3359)

Mostly aims to reduce meaningless proc-calls in Move() and forceMove(), also inlines the rest of the power calculations in SSmachinery to remove a lot of proc-calls.
This commit is contained in:
Lohikar
2017-09-02 21:33:03 +03:00
committed by Erki
parent 68d3fa60f5
commit 08dcdba926
6 changed files with 77 additions and 37 deletions
+40 -12
View File
@@ -1,3 +1,5 @@
#define MACHINERY_GO_TO_NEXT if (no_mc_tick) { CHECK_TICK; } else if (MC_TICK_CHECK) { return; } else { continue; }
/var/datum/controller/subsystem/machinery/SSmachinery
/datum/controller/subsystem/machinery
@@ -108,23 +110,47 @@
log_debug("SSmachinery: Type '[M.type]' slept during machinery_process().")
slept_in_process[M.type] = TRUE
if (M.use_power)
// I'm sorry.
if (M.use_power && isturf(M.loc))
powerusers_this_tick++
if (M.has_special_power_checks)
M.auto_use_power()
else
var/area/A = M.loc ? M.loc.loc : null
if (isarea(A))
var/chan = M.power_channel
if (A.powered(chan))
var/usage = 0
switch (M.use_power)
if (1)
usage = M.idle_power_usage
if (2)
usage = M.active_power_usage
var/area/A = M.loc.loc
var/chan = M.power_channel
if ((A.has_weird_power && !A.powered(chan)))
MACHINERY_GO_TO_NEXT
if (A.requires_power)
if (A.always_unpowered)
MACHINERY_GO_TO_NEXT
switch (chan)
if (EQUIP)
if (!A.power_equip)
MACHINERY_GO_TO_NEXT
if (LIGHT)
if (!A.power_light)
MACHINERY_GO_TO_NEXT
if (ENVIRON)
if (!A.power_environ)
MACHINERY_GO_TO_NEXT
else // ?!
log_debug("SSmachinery: Type '[M.type]' has insane channel [chan] (expected value in range 1-3).")
M.use_power = FALSE
MACHINERY_GO_TO_NEXT
A.use_power(usage, chan)
if (A.has_weird_power)
A.use_power(M.use_power == 2 ? M.active_power_usage : M.idle_power_usage, chan)
else
switch (chan)
if (EQUIP)
A.used_equip += M.use_power == 2 ? M.active_power_usage : M.idle_power_usage
if (LIGHT)
A.used_equip += M.use_power == 2 ? M.active_power_usage : M.idle_power_usage
if (ENVIRON)
A.used_environ += M.use_power == 2 ? M.active_power_usage : M.idle_power_usage
else // ?!
log_debug("SSmachinery: Type '[M.type]' has insane channel [chan] (expected value in range 1-3).")
M.use_power = FALSE
if (no_mc_tick)
CHECK_TICK
@@ -198,3 +224,5 @@
if (remove_from_global)
SSmachinery.all_machines -= M
#undef MACHINERY_GO_TO_NEXT
+1
View File
@@ -60,6 +60,7 @@
var/allow_nightmode = 0 // if 1, lights in area will be darkened by the night mode controller
var/station_area = 0
var/centcomm_area = 0
var/has_weird_power = FALSE // If TRUE, SSmachinery will not use the inlined power checks and will call powered() and use_power() on this area.
/area/Initialize(mapload)
icon_state = "white"
+25 -20
View File
@@ -50,17 +50,6 @@
..()
return
/atom/movable/proc/forceMove(atom/destination)
if(destination)
if(loc)
loc.Exited(src)
loc = destination
loc.Entered(src)
update_client_hook(loc)
return 1
update_client_hook(loc)
return 0
//called when src is thrown into hit_atom
/atom/movable/proc/throw_impact(atom/hit_atom, var/speed)
if(istype(hit_atom,/mob/living))
@@ -282,27 +271,43 @@ var/list/accessible_z_levels = list("8" = 5, "9" = 10, "7" = 15, "2" = 60)
if (. && hud_used && client && get_turf(client.eye) == destination)
hud_used.update_parallax_values()
// Core movement hooks & procs.
/atom/movable/proc/forceMove(atom/destination)
if(destination)
if(loc)
loc.Exited(src)
loc = destination
loc.Entered(src)
if (contained_mobs)
update_client_hook(loc)
return 1
if (contained_mobs)
update_client_hook(loc)
return 0
// Movement hooks.
/atom/movable/Move()
var/old_loc = loc
. = ..()
if (.)
// Events.
moved_event.raise_event(src, old_loc, loc)
if (moved_event.listeners_assoc[src])
moved_event.raise_event(src, old_loc, loc)
// Parallax.
update_client_hook(loc)
if (contained_mobs)
update_client_hook(loc)
// Lighting.
var/datum/light_source/L
var/thing
for (thing in light_sources)
L = thing
L.source_atom.update_light()
if (light_sources)
var/datum/light_source/L
var/thing
for (thing in light_sources)
L = thing
L.source_atom.update_light()
// Openturf.
if (bound_overlay)
// The overlay will handle cleaning itself up on non-openspace turfs.
bound_overlay.forceMove(get_step(src, UP))
bound_overlay.set_dir(dir)
if (bound_overlay.dir != dir)
bound_overlay.set_dir(dir)
+2 -1
View File
@@ -195,8 +195,9 @@
if(istype(usr.machine,/obj/machinery/computer/security))
var/obj/machinery/computer/security/console = usr.machine
console.jump_on_click(usr,src)
//Camera control: arrow keys.
/mob/Move(n,direct)
/mob/living/Move(n,direct)
if(istype(machine,/obj/machinery/computer/security))
var/obj/machinery/computer/security/console = machine
var/turf/T = get_turf(console.current_camera)
+1 -4
View File
@@ -160,10 +160,7 @@ Class Procs:
return ..()
/obj/machinery/proc/machinery_process()
. = process()
/obj/machinery/process()//If you dont use process or power why are you here
/obj/machinery/proc/machinery_process() //If you dont use process or power why are you here
if(!(use_power || idle_power_usage || active_power_usage))
return PROCESS_KILL
+8
View File
@@ -1191,6 +1191,14 @@ mob/proc/yank_out_object()
. = ..()
if (!contained_mobs) // If this is true, the parent will have already called the client hook.
update_client_hook(loc)
/mob/Move()
. = ..()
if (. && !contained_mobs && client)
update_client_hook(loc)
/mob/verb/northfaceperm()
set hidden = 1
set_face_dir(client.client_dir(NORTH))