NL
games/alis / src / Alis / SysVars.php · commit 9c722cf
<?phpnamespace App\Alis;use JumPHP\Save\Storage;/** File-scope state of the host layer (C sys/sys.c, sys/sys_sdl2.c) plus the JumPHP bridge. */final class SysVars{    public static int $dirty_len = 0;    /** C sys_timeclock_hz: rate of alis.timeclock (1000 / timer ms: 58 on PC, 50 elsewhere), set by Machine::boot */    public static int $sys_timeclock_hz = 50;    public static bool $dirty_mouse = false;    /** C mouse (game pixel coordinates) */    public static MouseT $mouse;    /** C button.sym: the last key pressed (SDL key code), 0 when released */    public static int $button = 0;    public static int $shift = 0;    public static int $joystick0 = 0;    public static int $joystick1 = 0;    /** v3 DOS VM: offset set by csetmouse ([0x18a98] / [0x18a9a]), added by cmouse to the raw position */    public static int $mouseOffX = 0;    public static int $mouseOffY = 0;    /** keys held now (SDL key code => true), set by the scene before each frame */    public static array $held = [];    /** joystick bits from the gamepad / touch pad (bit0 up, 1 down, 2 left, 3 right, 7 fire) */    public static int $pad = 0;    /** milliseconds of game time */    public static int $msec = 0;    /** @var array{0: float, 1: float, 2?: string}|null debugging (tools/run.php --lazy-delay=s,MBps[,regex]): a delay for the developer's copy */    public static ?array $lazyDelay = null;    /** @var array<string, float> when each file of the developer's copy is "downloaded" (game seconds) */    public static array $lazyReadyAt = [];    /** state of sys_random() (C rand() without srand(): seed 1 at each start) */    public static int $randSeed = 1;    /** the last frame as a BMP file in memory (sys_render) */    public static string $frameBmp = '';    public static int $frameW = 0;    public static int $frameH = 0;    public static int $frameCount = 0;    /** mouse cursor: rows of palette indexes (-1 transparent) + hot spot, null = none (sys_dirty_mouse) */    public static ?array $cursor = null;    public static int $cursorVersion = 0;    /** JumPHP storage for the files the game writes (saves) */    public static ?Storage $storage = null;    /** open write streams: (int) resource => storage name */    public static array $writeStreams = [];    /** folder => [lower-case name => real name] */    public static array $dirIndex = [];    /** files loaded on demand: lower-case name => [size, hash] (catalog/<game>.json), their URL folder, a local full copy */    public static array $lazy = [];    public static string $lazyBase = '';    public static string $lazyDev = '';    /** seconds spent running the scripts (Machine::loop(), the instructions and what they draw): speed checks */    public static float $scriptTime = 0.0;    public static ?string $lazyPending = null;    /**     * name => true while downloading; name => why it failed; downloaded path => size     * @var array<string, true>     */    public static array $fetching = [];    /** @var array<string, string> */    public static array $lazyFailed = [];    /** @var array<string, int> */    public static array $lazyLoaded = [];    public const LAZY_CACHE = 64 * 1024 * 1024;    /**     * downloads by parts (fn/sys.php sys_lazy_download()): an answer reaches PHP in base64 inside the page's events,     * and a string of 2 MB or more leaks in the browser; measured: 1 MB parts leak, 512 KB do not. 3 x 256 KB.     */    public const LAZY_PART = 256 * 1024;    public const LAZY_PARALLEL = 6;    public static ?\JumPHP\Http\Http $http = null;    /** true while the VM runs opcodes (Machine::loop): a missing download may then yield */    public static bool $inLoop = false;    /** source edition: the folder of the ALIS sources (.als + .res) used instead of the .io scripts ('' = off) */    public static string $sourceDir = '';    /** @var array<string, string> compiled sources: script name => the .io file made from it */    public static array $sourceCache = [];    /** @var array<string, int> script name => the packing byte its original .io had (Alis::$typepack) */    public static array $sourcePack = [];    /** data files opened (diagnostics) */    public static array $opened = [];    /**     * the playground's externals (JumPHP\Externals\Externals, the jumphp/externals extension) when the game has them,     * and its folder there (alis/<game>): the big files come from it, by blocks (sys_lazy_download())     */    public static ?object $externals = null;    public static string $externalsDir = '';    /** the externals answered no (not shared, missing): the private files are used */    public static bool $externalsOff = false;    /** the game whose sources are compiled (its player's changed scripts are used: App\Editor\SourceStore) */    public static string $sourceGame = '';    /** HD edition: the game's font characters are drawn by the host (a real font), not in the 8-bit frame (fn/hd.php) */    public static bool $hdText = false;    /** the character put_char() is putting (-1: not a character) */    public static int $hdChar = -1;    /** @var array<int, array<string, mixed>> sprite record => the glyph it drew (hd.php) */    public static array $hdGlyphs = [];    /** @var array{x: int, y: int, w: int, h: int, key: int, bmp: string}|null HD edition: the land at twice the resolution (fn/hd3d.php) */    public static ?array $hdLand = null;    /** @var list<array<string, mixed>> the glyphs on the screen at the last sys_render(), for the host */    public static array $hdShown = [];    public static function init(): void    {        self::$mouse = new MouseT();        self::$mouseOffX = self::$mouseOffY = 0;        self::$randSeed = 1;        self::$held = [];        self::$button = 0;        self::$shift = 0;        self::$frameBmp = '';        self::$cursor = null;        self::$writeStreams = [];        self::$hdGlyphs = self::$hdShown = [];    }}