Input System
CEvent Overview
Header: include/event.hpp (~320 lines)
Source: src/event.cpp (~5,878 lines — the largest file in the project)
CEvent is responsible for:
- Processing all keyboard and mouse input
- Dispatching game phase changes (via
WM_PHASE_*messages) - Managing UI interactions (menus, buttons, dialogs)
- Coordinating the game loop with the rendering and game logic systems
event.cpp is the most complex and most incomplete file in the project.
Phase dispatch and many input behaviors need further work.
Key Input Bitmask
Game input is condensed into a bitmask of pressed keys, defined in
include/def.hpp. These flags can be combined:
| Constant | Bitmask Value | Description |
|---|---|---|
KEY_NONE | 0x00 | No key pressed |
KEY_LEFT | 0x01 | Move left / steer left |
KEY_RIGHT | 0x02 | Move right / steer right |
KEY_UP | 0x04 | Look up / fly up (helicopter) |
KEY_DOWN | 0x08 | Look down / descend |
KEY_JUMP | 0x10 | Jump |
KEY_FIRE | 0x20 | Fire / action / place bomb |
Example: holding Left + Jump = KEY_LEFT | KEY_JUMP = 0x11 = 17.
Input Flow
- Win32 window procedure receives
WM_KEYDOWN/WM_KEYUPmessages CEventtranslates these toKEY_*bitmask values- The key bitmask is passed to
CDecor::SetInput(int keys)each game tick src/decblupi.cppreads the input and updates player state and physics- In multiplayer, the current key state is included in each
NetPacketsent to other players
Game Phase Dispatch
CEvent handles phase transitions via Windows messages (WM_USER + N).
Each game phase corresponds to a screen or mode — gameplay, menus, level editor,
win/lose screens, multiplayer lobby, etc.
See Game Phases Reference for all 60+ phases.
Mouse Input
The game uses a mouse cursor (sprites from mouse.blp).
Mouse input is handled in CEvent and used primarily for:
- Clicking UI buttons in menus and dialogs
- Level editor interactions (placing/removing tiles)
- Multiplayer session browser
Platform-Specific Input
Web (Emscripten)
Keyboard events are handled via browser event listeners and translated to the Win32 key message format by Free API. Mouse events are similarly translated.
Android
Touch coordinates are automatically mapped from physical screen coordinates to game logical coordinates by SDL3's logical presentation layer. Touches on letterbox bars do not register as in-game input.
Diagnostic log (first 20 input events):
FREE_DIRECT_INPUT: raw=x,y mapped=x,y evtType=… inside=true/false