UK
games/doom-jumphp / src / Game / Graphics.php · commit 8e1cb9f
<?phpnamespace App\Game;use App\Engine\Art;use App\Engine\HdRenderer;use JumPHP\Kernel\Engine;/** The graphics mode, saved in the options: 'retro' (the software renderer, 320 x 200) or 'hd' (the GPU). */final class Graphics{    public static function mode(Engine $engine): string    {        return $engine->options->get('graphics', 'retro') === 'hd' && $engine->gl()->isAvailable() ? 'hd' : 'retro';    }    public static function toggle(Engine $engine): void    {        if (!$engine->gl()->isAvailable()) {            return;        }        $engine->options->set('graphics', self::mode($engine) === 'hd' ? 'retro' : 'hd');    }    /** The HD renderer, enabled, when the HD mode is on; null otherwise (and the HD layer off). */    public static function hd(Engine $engine): ?HdRenderer    {        if (self::mode($engine) !== 'hd') {            self::retro($engine);            return null;        }        $hd = HdRenderer::get($engine->gl(), Art::get($engine->config->path('assets/data/art.pak')));        $hd->enable();        return $hd;    }    /** Back to the plain 2D output (the retro renderer draws its own picture). */    public static function retro(Engine $engine): void    {        if ($engine->gl()->isAvailable()) {            HdRenderer::get($engine->gl(), Art::get($engine->config->path('assets/data/art.pak')))->disable();        }    }}