我已經建立了我自己的flip
命令,它的速度很慢並且需要很長時間。我想知道javascript是否有blit
或memcpy
樣式命令。現在,我正在逐項逐條循環做一個副本,它需要「永遠」。JavaScript是否有blit或memcpy命令?
Here是我的翻轉功能的一個例子。我正在運行3層,如果全高,則只有1層,其中3個簡單的動畫和fps以大約35 FPS排在前面。理想情況下,3層佈局應該遠遠高於FPS,在我期望的200+範圍內。
v:36.8 l0:36.8 l1:57.8 l2:36.8圖層的FPS是對其緩衝區的渲染,v是使用flip
函數對畫布的渲染。 (這些FPS是從瀏覽器上的MAC)
v = the screen update, the main flip function listed below.
l0 = The bottom fire, its a full height layer
l2 = The static noise, its a 1/2 height layer
l3 = The top fire, its a 1/4 height layet
想象具有9或10層時,FPS將下降象石頭。在FF版本12中,它已經不可用......甚至沒有兩位數的FPS費率。歌劇至少是雙倍的消費者。
v:4.2 l0:4.2 l1:4.2 l2:4.2 (FF 12 OSX)
v:15.5 l0:15.5 l1:15.5 l2:15.5 (Opera latest OSX)
我翻轉功能
flip : function() {
var fps = '';
// Combine the layers onto the back buffer
for (var l = 0; l < this.layers.length; l++)
{
fps += 'l' + l + ':' + this.layers[l].fps.toFixed(1) + ' ';
var layerWidth = this.layers[l].options.width;
var layerHeight = this.layers[l].options.height;
for (var x = 0; x < layerWidth; x++)
{
for (var y = 0; y < layerHeight; y++)
{
var index = (y*this.layers[l].options.width + x)*4;
var r = this.layers[l].buffer[index+0];
var g = this.layers[l].buffer[index+1];
var b = this.layers[l].buffer[index+2];
var a = this.layers[l].buffer[index+3];
if (r|g|b|a != 0) {
this.buffer.data[index+0] = r;
this.buffer.data[index+1] = g;
this.buffer.data[index+2] = b;
this.buffer.data[index+3] = a;
}
}
}
}
fps = 'v:' + this.fps.toFixed(1) + ' ' + fps;
this.$fps.html(fps);
// blit the buffer
this.context.putImageData(this.buffer, 0, 0);
// Calculate fps
var now = new Date;
var thisFrameFPS = 1000/(now - this.last);
this.fps += (thisFrameFPS - this.fps)/50;
this.last = now;
var t = this;
setTimeout(function() {t.flip.apply(t);}, this.speed);
}