-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathOrderedEventLoop.php
53 lines (41 loc) · 1.11 KB
/
OrderedEventLoop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace Serafim\Bic\EventLoop;
use FFI\CData;
class OrderedEventLoop extends EventLoop
{
/**
* @var Timer
*/
public Timer $render;
/**
* @var Timer
*/
public Timer $updates;
public function __construct()
{
parent::__construct();
$this->render = new Timer(self::DEFAULT_FRAME_RATE);
$this->updates = new Timer(self::DEFAULT_UPDATE_RATE);
}
/**
* {@inheritDoc}
*/
protected function execute(int $frameRate, int $updateRate, CData $event, CData $eventPtr): void
{
$this->render->rate($frameRate)->touch();
$this->updates->rate($updateRate)->touch();
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);
}
while ($this->sdl->SDL_PollEvent($eventPtr)) {
$this->poll($event);
}
}
}
}