UK
games/alis / src / Alis / FilmVars.php · commit 9c722cf
<?phpnamespace App\Alis;/** * File-scope state of alis/src/video/ (video.c, fli.c, fls.c, film3do.c) and the FLI speech queue of audio.c. * * PORT (memory): the C mallocs the film file and the composition buffer (pvgalogic) outside alis.mem. Here they * are PHP strings of their own (FilmVars::$data, FilmVars::$pvgalogic) and every film pointer is an offset into * them: putting megabytes of film into Alis::$mem would slow down every substr_replace of the VM memory. */final class FilmVars{    /**     * PORT: what a film of the game needs from the screen. The films are framed for the game's view (Socrate's talk     * fills the 3D window, the rest of its 320x200 frame is black) and give a whole palette whose upper entries are     * VGA's defaults, unused by the film: the frame is copied where it has something ($box, grown frame after     * frame) and the entries it does not use get the game's colours back after each frame ($gamePal / $gameDpal,     * taken by inifilm()), so the interface around keeps its pixels and its colours.     * @var array<int, true> the palette entries the film's frames use     */    public static array $palUsed = [];    /** @var array<int, int> Img::$mpalet when the film started */    public static array $gamePal = [];    /** @var array<int, int> ImageVars::$dpal_mpal when the film started (DOS palettes) */    public static array $gameDpal = [];    /** @var array{0: int, 1: int, 2: int, 3: int}|null x1, y1, x2, y2 (exclusive) of the film's picture */    public static ?array $box = null;    /** C: sFLICData bfilm */    public static sFLICData $bfilm;    // video.c    /** C: u8 *endframe (offset into $data) */    public static ?int $endframe = null;    /** C: static u32 fli_pace_anchor, fli_pace_total_ms */    public static int $fli_pace_anchor = 0;    public static int $fli_pace_total_ms = 0;    /** C: u16 pal[16] (unused by the desktop build) */    public const pal = [0x0000, 0x0019, 0x0011, 0x0811, 0x0089, 0x0881, 0x0081, 0x0088,        0x0018, 0x0012, 0x0889, 0x0812, 0x0181, 0x0181, 0x0181, 0x0181];    /** C: u8 *pvgalogic: the film composition buffer (kVgaLogicSize bytes and more), null = NULL */    public static ?string $pvgalogic = null;    /** C: u8 *vgalogic, *vgalogic_df: offsets into $pvgalogic, null = NULL */    public static ?int $vgalogic = null;    public static ?int $vgalogic_df = null;    /** C: u32 vgalogic_sz */    public static int $vgalogic_sz = 0;    /** C: static u8 vgalogic_borrowed */    public static int $vgalogic_borrowed = 0;    /** C: u8 g_s512_ending */    public static int $g_s512_ending = 0;    // fls.c    public static int $fls_drawing = 0;    public static int $fls_pallines = 0;    /** C: s8 fls_state */    public static int $fls_state = 0;    /** C: u8 fls_dirty_lines[200] ... fls_prev_x2[200] */    public static array $fls_dirty_lines = [];    public static array $fls_prev_dirty = [];    public static array $fls_dirty_x1 = [];    public static array $fls_dirty_x2 = [];    public static array $fls_prev_x1 = [];    public static array $fls_prev_x2 = [];    // audio.c: FLI speech queue (channel 3 only), see fli_audio_push() in fli.php    /** C: sFliAudioChunk fli_audio_queue[FLI_AUDIO_QUEUE_SIZE]: ['addr' => offset in Alis::$mem, 'length', 'freq', 'data' => the bytes] */    public static array $fli_audio_queue = [];    /** C: u8 fli_audio_q_head: next slot to write */    public static int $fli_audio_q_head = 0;    /** C: u8 fli_audio_q_tail: next slot to read */    public static int $fli_audio_q_tail = 0;    /** C: u32 fli_chunks_played */    public static int $fli_chunks_played = 0;    /** C: static fli_audio_slot_t *fli_audio_copybuf: host block in Alis::$mem (FLI_AUDIO_QUEUE_SIZE x 4096), 0 = NULL */    public static int $fli_audio_copybuf = 0;    // film3do.c    /** C: static char fname[kPathMaxLen] */    public static string $fname = '';    // ---- port-only state -----------------------------------------------------------------------    /** the film bytes (whole file, streaming window, or a copy of the VM memory for cfilm) + kFilmPad zeros */    public static string $data = '';    /** where $data comes from, for the save states: ['file', path] or ['mem', alis.mem address of offset 0, length] */    public static ?array $src = null;    /** the FLI frame (vgalogic, width x height) as rows while a frame is decoded (fli_next) */    public static array $rows = [];    /** host block of Alis::$mem used to hand a palette chunk to dos_film_palette() (image.php reads alis.mem) */    public static int $scratch = 0;    public static int $scratch_sz = 0;    /** resumable runfilm() / film3do_run() (the C loops until the film ends; the port yields every frame) */    public static bool $run_active = false;    public static ?ScriptLive $run_script = null;    public static int $run_pc = 0;    public static int $run_phase = 0;    public static int $run_result = 0;    public static int $run_wait = 0;    public static int $run_index = 0;    public static int $run_prevclock = 0;    public static bool $run_yielded = false;    public static bool $run_setup = false;    /** the wait of the last frame of the previous runfilm call is still to do */    public static bool $run_pending = false;    /** film3do_run state (null = not playing) */    public static ?array $f3 = null;    /** last 3DO film frame as a 24-bit BMP for film_render_rgb(), null = none */    public static ?string $f3_bmp = null;    public static function init(): void    {        self::$bfilm = new sFLICData();        self::$fls_dirty_lines = array_fill(0, 200, 0);        self::$fls_prev_dirty = array_fill(0, 200, 0);        self::$fls_dirty_x1 = array_fill(0, 200, 0);        self::$fls_dirty_x2 = array_fill(0, 200, 0);        self::$fls_prev_x1 = array_fill(0, 200, 0);        self::$fls_prev_x2 = array_fill(0, 200, 0);        self::$fli_audio_queue = array_fill(0, C::FLI_AUDIO_QUEUE_SIZE, ['addr' => 0, 'length' => 0, 'freq' => 0, 'data' => '']);    }}FilmVars::init();