diff options
-rw-r--r-- | src/Gameboy/Core.php | 9 | ||||
-rw-r--r-- | src/Gameboy/DrawContext.php | 18 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/Gameboy/Core.php b/src/Gameboy/Core.php index 32438bc..ace9c70 100644 --- a/src/Gameboy/Core.php +++ b/src/Gameboy/Core.php @@ -2210,10 +2210,9 @@ class Core $dst -= $x; $src -= $x; } + while ($dst < $dstEnd) { - if ($im[$src] < 0) { - $this->frameBuffer[$dst] = $im[$src]; - } + $this->frameBuffer[$dst] = $im[$src]; $dst++; $src++; } @@ -2232,9 +2231,9 @@ class Core $src -= $x; } while ($dst < $dstEnd) { - if ($im[$src] < 0 && $this->frameBuffer[$dst] >= 0) { + //if ($im[$src] < 0 && $this->frameBuffer[$dst] >= 0) { $this->frameBuffer[$dst] = $im[$src]; - } + // } $dst++; $src++; } diff --git a/src/Gameboy/DrawContext.php b/src/Gameboy/DrawContext.php index 82c243d..36a13f8 100644 --- a/src/Gameboy/DrawContext.php +++ b/src/Gameboy/DrawContext.php @@ -8,6 +8,9 @@ class DrawContext // 160 x 144 protected $canvas; + protected $currentSecond = 0; + protected $framesInSecond = 0; + protected $fps = 0; public function __construct() { @@ -26,27 +29,32 @@ class DrawContext for ($i = 0; $i < count($canvasBuffer); $i = $i + 4) { // IGNORE ALPHA - $total = $canvasBuffer[$i] + $canvasBuffer[$i + 1] + $canvasBuffer[$i + 2]; // + $canvasBuffer[$i + 3]; + $total = $canvasBuffer[$i] + $canvasBuffer[$i + 1] + $canvasBuffer[$i + 2]; $x = ($i / 4) % 160; $y = ceil(($i / 4) / 160); if ($total > 350) { $this->canvas->set($x, $y); - // echo 'SET ' . $x . ' - ' . $y . PHP_EOL; } } + if ($this->currentSecond != time()) { + $this->fps = $this->framesInSecond; + $this->currentSecond = time(); + $this->framesInSecond = 1; + } else { + $this->framesInSecond++; + } + echo "\e[H\e[2J"; + echo 'FPS: ' . $this->fps . PHP_EOL; echo $this->canvas->frame(); $this->canvas->clear(); - - // echo 'Draw' . PHP_EOL; } public function fillRect($left, $top, $width, $height) { - $this->canvas->clear(); // echo 'Fill' . PHP_EOL; } }
\ No newline at end of file |