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
⚠️
Work in Progress
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:

ConstantBitmask ValueDescription
KEY_NONE0x00No key pressed
KEY_LEFT0x01Move left / steer left
KEY_RIGHT0x02Move right / steer right
KEY_UP0x04Look up / fly up (helicopter)
KEY_DOWN0x08Look down / descend
KEY_JUMP0x10Jump
KEY_FIRE0x20Fire / action / place bomb

Example: holding Left + Jump = KEY_LEFT | KEY_JUMP = 0x11 = 17.

Input Flow

  1. Win32 window procedure receives WM_KEYDOWN / WM_KEYUP messages
  2. CEvent translates these to KEY_* bitmask values
  3. The key bitmask is passed to CDecor::SetInput(int keys) each game tick
  4. src/decblupi.cpp reads the input and updates player state and physics
  5. In multiplayer, the current key state is included in each NetPacket sent 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

Input Verification

🔍
Needs Verification
The exact key-to-action mapping is derived from code analysis. The original game likely supported custom key configuration. The current mapping may not match the original defaults perfectly.