public function drawToCanvas()
{
//Draw the frame buffer to the canvas:
if (Settings::$frameskipAmout == 0 || $this->frameCount > 0) {
//Copy and convert the framebuffer data to the CanvasPixelArray format.
$bufferIndex = $this->pixelCount;
$canvasIndex = $this->rgbCount;
if ($this->drawContext->colorEnabled) {
// Generate colored CanvasBuffer Version
while ($canvasIndex > 3) {
//Red
$this->canvasBuffer[$canvasIndex -= 4] = $this->frameBuffer[--$bufferIndex] >> 16 & 0xff;
//Green
$this->canvasBuffer[$canvasIndex + 1] = $this->frameBuffer[$bufferIndex] >> 8 & 0xff;
//Blue
$this->canvasBuffer[$canvasIndex + 2] = $this->frameBuffer[$bufferIndex] & 0xff;
}
} else {
// Generate black&white CanvasBuffer Version
while ($bufferIndex > 0) {
$r = $this->frameBuffer[--$bufferIndex] >> 16 & 0xff;
$g = $this->frameBuffer[$bufferIndex] >> 8 & 0xff;
$b = $this->frameBuffer[$bufferIndex] & 0xff;
// 350 is a good threshold for black and white
if ($r + $g + $b > 350) {
$this->canvasBuffer[$bufferIndex] = true;
} else {
$this->canvasBuffer[$bufferIndex] = false;
}
}
}
//Draw out the CanvasPixelArray data:
$this->drawContext->draw($this->canvasBuffer);
if (Settings::$frameskipAmout > 0) {
//Decrement the frameskip counter:
$this->frameCount -= Settings::$frameskipAmout;
}
} else {
//Reset the frameskip counter:
$this->frameCount += Settings::$frameskipBaseFactor;
}
}