From 41bbdae2207fb9178b27957aa31a916ec99c2310 Mon Sep 17 00:00:00 2001 From: kevinz000 <2003111+kevinz000@users.noreply.github.com> Date: Tue, 14 Jan 2020 17:50:14 -0700 Subject: [PATCH] micro optimization --- code/__DEFINES/admin.dm | 4 ++-- code/__HELPERS/game.dm | 18 +++++++----------- code/modules/keybindings/bindings_client.dm | 3 +++ code/modules/lighting/lighting_object.dm | 1 - 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/code/__DEFINES/admin.dm b/code/__DEFINES/admin.dm index 3acd1443af..c6be8318fd 100644 --- a/code/__DEFINES/admin.dm +++ b/code/__DEFINES/admin.dm @@ -87,5 +87,5 @@ #define MAX_KEYPRESS_COMMANDLENGTH 16 ///Max amount of keypress messages per second over two seconds before client is autokicked #define MAX_KEYPRESS_AUTOKICK 100 -///Length of held key rolling buffer -#define HELD_KEY_BUFFER_LENGTH 15 +///Length of max held keys +#define MAX_HELD_KEYS 15 diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index ca4b913369..8f41cd621c 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -238,27 +238,24 @@ return found_mobs - /proc/get_hearers_in_view(R, atom/source) // Returns a list of hearers in view(R) from source (ignoring luminosity). Used in saycode. - var/turf/T = get_turf(source) - . = list() - - if(!T) + if(!(source = get_turf(source))) return + . = list() var/list/processing_list = list() if (R == 0) // if the range is zero, we know exactly where to look for, we can skip view - processing_list += T.contents // We can shave off one iteration by assuming turfs cannot hear + processing_list += source.contents // We can shave off one iteration by assuming turfs cannot hear else // A variation of get_hear inlined here to take advantage of the compiler's fastpath for obj/mob in view - var/lum = T.luminosity - T.luminosity = 6 // This is the maximum luminosity - var/list/cachedview = view(R, T) + var/lum = source.luminosity + source.luminosity = 6 // This is the maximum luminosity + var/list/cachedview = view(R, source) for(var/mob/M in cachedview) processing_list += M for(var/obj/O in cachedview) processing_list += O - T.luminosity = lum + source.luminosity = lum while(processing_list.len) // recursive_hear_check inlined here var/atom/A = processing_list[1] @@ -275,7 +272,6 @@ if(R) . |= get_hearers_in_view(R.canhear_range, R) - #define SIGNV(X) ((X<0)?-1:1) /proc/inLineOfSight(X1,Y1,X2,Y2,Z=1,PX1=16.5,PY1=16.5,PX2=16.5,PY2=16.5) diff --git a/code/modules/keybindings/bindings_client.dm b/code/modules/keybindings/bindings_client.dm index 315ba7a381..cff6bc149b 100644 --- a/code/modules/keybindings/bindings_client.dm +++ b/code/modules/keybindings/bindings_client.dm @@ -35,6 +35,9 @@ message_admins("Client [ckey] just attempted to send an invalid keypress. Keymessage was over [MAX_KEYPRESS_COMMANDLENGTH] characters, autokicking due to likely abuse.") QDEL_IN(src, 1) return + + if(length(keys_held) > MAX_HELD_KEYS) + keys_held.Cut(1,2) keys_held[_key] = TRUE var/movement = SSinput.movement_keys[_key] if(!(next_move_dir_sub & movement) && !keys_held["Ctrl"]) diff --git a/code/modules/lighting/lighting_object.dm b/code/modules/lighting/lighting_object.dm index 9ceb341f91..e967008afe 100644 --- a/code/modules/lighting/lighting_object.dm +++ b/code/modules/lighting/lighting_object.dm @@ -56,7 +56,6 @@ var/turf/oldturf = get_turf(myturf) var/turf/newturf = get_turf(loc) warning("A lighting object realised it's loc had changed in update() ([myturf]\[[myturf ? myturf.type : "null"]]([COORD(oldturf)]) -> [loc]\[[ loc ? loc.type : "null"]]([COORD(newturf)]))!") - qdel(src, TRUE) return