type Layer = struct { blocks_input: *fn() bool, input: *fn(InputEvent) bool, is_opaque: *fn() bool, render: *fn() void, }; type InputEvent = (CancelEvent | KeyEvent | MouseButtonEvent | MouseOverEvent); type CancelEvent = void; type KeyEvent = struct { status: ButtonStatus, key: Key, }; type Key = uint; type MouseButtonEvent = struct { status: ButtonStatus, button: MouseButton, }; type MouseButton = enum u8 { LEFT, MIDDLE, RIGHT, X1, X2, }; type ButtonStatus = enum u8 { UP, HELD, DOWN, }; type MouseOverEvent = struct { covered: bool, }; const LAYERS = [ &LAYER_GAME, &LAYER_HUD, &LAYER_DEATH, &LAYER_GAME_WAITING, &LAYER_CLIENT_WAITING, ]; fn layers_input(event: InputEvent, top: size, all: bool) size = { for (top > 0) { top -= 1; if (LAYERS[top].input(event) && !all) { break; }; }; return top; }; fn layers_render() void = { let bottom = len(LAYERS); for (bottom != 0) { bottom -= 1; if (LAYERS[bottom].is_opaque()) { break; }; }; for (let i = bottom; i < len(LAYERS); i += 1) { LAYERS[i].render(); }; };