Makes the input system use an assoc list instead of a rolling buffer (#13466)

This commit is contained in:
Farie82
2021-03-11 19:01:44 +00:00
committed by GitHub
parent a7b16d08e6
commit 1d3e68544f
3 changed files with 9 additions and 18 deletions
+1 -2
View File
@@ -1,10 +1,9 @@
/mob/living/carbon/key_down(_key, client/user)
user.keys_held[_key] = world.time
if(!user.keys_held["Shift"])
switch(_key)
if("R", "Southwest") // Southwest is End
toggle_throw_mode()
return
return
if("1")
a_intent_change("help")
return
+6 -10
View File
@@ -35,14 +35,13 @@
message_admins("Client [ckey] just attempted to send an invalid keypress. Keymessage was over [MAX_KEYPRESS_COMMANDLENGTH] characters, autokicking due to likely abuse.")
qdel(src)
return
//offset by 1 because the buffer address is 0 indexed because the math was simpler
keys_held[current_key_address + 1] = _key
if(length(keys_held) > HELD_KEY_BUFFER_LENGTH)
return
//the time a key was pressed isn't actually used anywhere (as of 2019-9-10) but this allows easier access usage/checking
keys_held[_key] = world.time
current_key_address = ((current_key_address + 1) % HELD_KEY_BUFFER_LENGTH)
var/movement = SSinput.movement_keys[_key]
if (prefs.toggles & PREFTOGGLE_AZERTY) movement = SSinput.alt_movement_keys[_key]
if(!(next_move_dir_sub & movement) && !keys_held["Ctrl"])
@@ -79,11 +78,8 @@
/client/verb/keyUp(_key as text)
set instant = TRUE
set hidden = TRUE
//Can't just do a remove because it would alter the length of the rolling buffer, instead search for the key then null it out if it exists
for(var/i in 1 to HELD_KEY_BUFFER_LENGTH)
if(keys_held[i] == _key)
keys_held[i] = null
break
keys_held -= _key
var/movement = SSinput.movement_keys[_key]
if (prefs.toggles & PREFTOGGLE_AZERTY) movement = SSinput.alt_movement_keys[_key]
if(!(next_move_dir_add & movement))
+2 -6
View File
@@ -1,8 +1,6 @@
/client
/// A rolling buffer of any keys held currently
/// An assoc list of any keys held currently
var/list/keys_held = list()
///used to keep track of the current rolling buffer position
var/current_key_address = 0
/// These next two vars are to apply movement for keypresses and releases made while move delayed.
/// Because discarding that input makes the game less responsive.
/// On next move, add this dir to the move that would otherwise be done
@@ -36,10 +34,8 @@
/client/proc/set_macros()
set waitfor = FALSE
//Reset and populate the rolling buffer
//Reset the assoc list
keys_held.Cut()
for(var/i in 1 to HELD_KEY_BUFFER_LENGTH)
keys_held += null
erase_all_macros()