From 08dcdba926536db34b2b9491c417177e56a51ea7 Mon Sep 17 00:00:00 2001 From: Lohikar Date: Sat, 2 Sep 2017 13:33:03 -0500 Subject: [PATCH] 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. --- code/controllers/subsystems/machinery.dm | 52 ++++++++++++++++++------ code/game/area/areas.dm | 1 + code/game/atoms_movable.dm | 45 +++++++++++--------- code/game/machinery/computer/camera.dm | 3 +- code/game/machinery/machinery.dm | 5 +-- code/modules/mob/mob.dm | 8 ++++ 6 files changed, 77 insertions(+), 37 deletions(-) diff --git a/code/controllers/subsystems/machinery.dm b/code/controllers/subsystems/machinery.dm index 4b8010b20b6..abeecf454df 100644 --- a/code/controllers/subsystems/machinery.dm +++ b/code/controllers/subsystems/machinery.dm @@ -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 diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 0135439cefd..217689140c1 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -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" diff --git a/code/game/atoms_movable.dm b/code/game/atoms_movable.dm index 9222e2811f8..d6dae4f44d4 100644 --- a/code/game/atoms_movable.dm +++ b/code/game/atoms_movable.dm @@ -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) diff --git a/code/game/machinery/computer/camera.dm b/code/game/machinery/computer/camera.dm index 621e4e6722e..68d1888e030 100644 --- a/code/game/machinery/computer/camera.dm +++ b/code/game/machinery/computer/camera.dm @@ -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) diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index 9b616c11284..2c4d170c302 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -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 diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 92ab793e3b9..0766010e911 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -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))