mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 13:10:02 +01:00
Refactors the keys_held rolling buffer (#53773)
* rolling key rip * category * comment * oops
This commit is contained in:
@@ -41,11 +41,11 @@
|
||||
winset(src, null, "input.focus=true ; input.text=[url_encode(_key)]")
|
||||
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 && !keys_held[_key])
|
||||
keyUp(keys_held[1]) //We are going over the number of possible held keys, so let's remove the first one.
|
||||
|
||||
//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 = movement_keys[_key]
|
||||
if(!(next_move_dir_sub & movement) && !movement_locked)
|
||||
next_move_dir_add |= movement
|
||||
@@ -75,11 +75,9 @@
|
||||
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
|
||||
if(!keys_held[_key])
|
||||
return
|
||||
keys_held -= _key
|
||||
var/movement = movement_keys[_key]
|
||||
if(!(next_move_dir_add & movement))
|
||||
next_move_dir_sub |= movement
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
/client
|
||||
/// A rolling buffer 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
|
||||
var/next_move_dir_add
|
||||
/// On next move, subtract this dir from the move that would otherwise be done
|
||||
var/next_move_dir_sub
|
||||
|
||||
// Set a client's focus to an object and override these procs on that object to let it handle keypresses
|
||||
|
||||
/datum/proc/key_down(key, client/user) // Called when a key is pressed down initially
|
||||
@@ -33,10 +21,9 @@
|
||||
/client/proc/set_macros()
|
||||
set waitfor = FALSE
|
||||
|
||||
//Reset and populate the rolling buffer
|
||||
keys_held.Cut()
|
||||
for(var/i in 1 to HELD_KEY_BUFFER_LENGTH)
|
||||
keys_held += null
|
||||
//Reset the buffer
|
||||
for(var/key in keys_held)
|
||||
keyUp(key)
|
||||
|
||||
erase_all_macros()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user