<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may not be viewable. --> <!-- You can view Contributing.MD for a detailed description of the pull request process. --> ## About The Pull Request This is a REALLY hot proc, takes up to like 2% of total cpu at highpop Let's micro it then First, clients do not go null at random. It's not predictable per say but it is consistent. We can use this understanding to remove a bunch of null checks here For loops are expensive. So rather then doing one each keyLoop, let's cache the client's intended move direction on the client. Simplifies some other code too There is no sense running a turn call if it would have no effect, let's be more intelligent about this ## Changelog <!-- If your PR modifies aspects of the game that can be concretely observed by players or admins you should add a changelog. If your change does NOT meet this description, remove this section. Be sure to properly mark your PRs to prevent unnecessary GBP loss. You can read up on GBP and it's effects on PRs in the tgstation guides for contributors. Please note that maintainers freely reserve the right to remove and add tags should they deem it appropriate. You can attempt to finagle the system all you want, but it's best to shoot for clear communication right off the bat. --> 🆑 refactor: Fucks with how movement keys are handled. Please report any bugs /🆑 <!-- Both 🆑's are required for the changelog to work! You can put your name to the right of the first 🆑 if you want to overwrite your GitHub username as author ingame. --> <!-- You can use multiple of the same prefix (they're only used for the icon ingame) and delete the unneeded ones. Despite some of the tags, changelogs should generally represent how a player might be affected by the changes rather than a summary of the PR's contents. -->
In-code keypress handling system
This whole system is heavily based off of forum_account's keyboard library. Thanks to forum_account for saving the day, the library can be found here!
.dmf macros have some very serious shortcomings. For example, they do not allow reusing parts
of one macro in another, so giving cyborgs their own shortcuts to swap active module couldn't
inherit the movement that all mobs should have anyways. The webclient only supports one macro,
so having more than one was problematic. Additionally each keybind has to call an actual
verb, which meant a lot of hidden verbs that just call one other proc. Also our existing
macro was really bad and tied unrelated behavior into Northeast(), Southeast(), Northwest(),
and Southwest().
The basic premise of this system is to not screw with .dmf macro setup at all and handle
pressing those keys in the code instead. We have every key call client.keyDown()
or client.keyUp() with the pressed key as an argument. Certain keys get processed
directly by the client because they should be doable at any time, then we call
keyDown() or keyUp() on the client's holder and the client's mob's focus.
By default mob.focus is the mob itself, but you can set it to any datum to give control of a
client's keypresses to another object. This would be a good way to handle a menu or driving
a mech. You can also set it to null to disregard input from a certain user.
Movement is handled by having each client call client.keyLoop() every game tick.
As above, this calls holder and focus.keyLoop(). atom/movable/keyLoop() handles movement
Try to keep the calculations in this proc light. It runs every tick for every client after all!
You can also tell which keys are being held down now. Each client a list of keys pressed called
keys_held. Each entry is a key as a text string associated with the world.time when it was
pressed.
No client-set keybindings at this time, but it shouldn't be too hard if someone wants.
Notes about certain keys:
Tabhas client-sided behavior but acts normallyT,O, andMmove focus to the input when pressed. This fires the keyUp macro right away.\needs to be escaped in the dmf so any usage is\\
You cannot TICK_CHECK or check world.tick_usage inside of procs called by key down and up
events. They happen outside of a byond tick and have no meaning there. Key looping
works correctly since it's part of a subsystem, not direct input.