49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace PHPNative\Framework\Loop;
|
|
|
|
use PHPNative\Event\Driver;
|
|
use PHPNative\Event\EventType;
|
|
|
|
class OrderedEventLoop extends EventLoop
|
|
{
|
|
public Timer $render;
|
|
|
|
public Timer $updates;
|
|
|
|
public function __construct(private Driver $eventDriver)
|
|
{
|
|
$this->render = new Timer(self::DEFAULT_FRAME_RATE);
|
|
$this->updates = new Timer(self::DEFAULT_UPDATE_RATE);
|
|
}
|
|
|
|
protected function execute(int $frameRate, int $updateRate): void
|
|
{
|
|
$this->render->rate($frameRate)->touch();
|
|
$this->updates->rate($updateRate)->touch();
|
|
$tray = new \Tray("Demo App", __DIR__ .'/../../../../../../app/app/Assets/icon.png');
|
|
$tray->init();
|
|
|
|
while ($this->running) {
|
|
$now = \microtime(true);
|
|
|
|
if (($delta = $this->updates->next($now)) !== null) {
|
|
$this->update($delta);
|
|
}
|
|
|
|
if (($delta = $this->render->next($now)) !== null) {
|
|
$this->render($delta);
|
|
$poll = $tray->poll();
|
|
if($poll != null) {
|
|
echo sprintf("%s", $poll).PHP_EOL;
|
|
}
|
|
}
|
|
|
|
while ($event = $this->eventDriver->pollEvent()) {
|
|
if($event == null) break;
|
|
$this->poll($event);
|
|
}
|
|
}
|
|
$tray->close();
|
|
}
|
|
} |