Input handling
The Death Dawn input handler is a stripped-down version of the code used for Dark Matter. input_get() scans the keyboard for input, and returns a set of bitflags indicating which game controls are being pressed. The key redefinition system is kept internal to the input handler; the only external part of the game that accesses it is the WIMP configuration interface.
Keyboard map
The keymap array contains 128 entries, allowing for the full range of keys that OS_Byte 121 recognises to be used by the game. Each entry in the array contains the following information:
- ASCII code of the key (currently unused by the game)
- A string containing the name of the key (displayed by the keyboard config window)
- A set of bitflags: KEY_REDEFINABLE if the key can be used for input, and KEY_PRESSED if the key is currently pressed.
The KEY_REDEFINABLE flag is important, as some keys (Shift, Control, Alt) return multiple values when pressed. The REDEFINABLE flag is also used to prevent mouse clicks from being used for input (since the game doesn't use the mouse for anything).
Unknown keys
The initialisation function (input_init()) will scan the keymap array, looking for unset entries, and produce generic names for the keys of the form 'KEY n'. These will be redefinable keys. The intention is that this allows any extra keys on future/non-standard keyboards to be used for the game, but it may also prevent problems if the undefined key entries turn out to be dupes of some existing keys (much like Alt, Ctrl, etc.)
Control map
The controls array contains CONTROL_MAX entries, i.e. one for each control recognised by the game code. This array contains the control -> key mapping, allowing zero, one, or two keyboard keys to be assigned to each control. The array contains the following information:
- A string containing the name of the control (as used by the keyboard config window)
- The two key IDs that are assigned to this control
- The control type (global, foot, car)
- The bitflag to set when generating input_get() output.
Input scanning
Input scanning is a two-stage process: First the keyboard_scan() function of WOUM (a thin veneer to OS_Byte 121) is used to iterate through all key definitions in the keymap array, setting or resetting the KEY_PRESSED flags as appropriate. Then, the controls array is scanned, and all pressed keys appropriate to the current mode (in car or on foot, as specified by the incar parameter to input_get()) are added to the bitflags to be returned. The code also prevents certain controls from repeating (such as the weapon and radio next/prev keys), by comparing the current bitflags with the previous bitflags.
Key redefinition
wimp_cfg.c contains the code for the key redefinition window. This displays the game controls organised by type (global, foot, car), and the two (or less) keys currently assigned to them. It also contains logic (in the checkclash() function) to detect keyboard clashes, when the same keyboard key is used for more than one action (and the two actions are capable of being performed at the same time). It also ensures that each control has at least one key defined for it, as otherwise the game would likely be unplayable. Any keyboard clashes, undefined controls, or other problems detected will result in the relevant entries being highlighted in red, and the OK button disabled until the clash is resolved.
TODO:
CODE: QUICK: Always-run for player? (Pressing run key would make player walk) Toggleable in controls config window?
???
Profit!