hyperandroid/CAAT — Issue #19: CPU close to 100% when scene is idle
Author: VoxelPerfect
Created: 2011-11-23 09:58:23+00:00
State: open

In `Director.render`, the initialization code (canvas clear, etc) is ran even if all calls to `Scene.isInAnimationFrame` return false. A proposed solution:

...
var initialized = false;
if (this.glEnabled) {
for (i = 0; i < ne; i++) {
var c = this.childrenList[i];
if (c.isInAnimationFrame(this.time)) {
if (!initialized) {
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
this.coordsIndex = 0;
this.uvIndex = 0;
initialized = true;
}
...
} else {
for (i = 0; i < ne; i++) {
var c= this.childrenList[i];
if (c.isInAnimationFrame(this.time)) {
if (!initialized) {
this.ctx.globalAlpha = 1;
this.ctx.globalCompositeOperation = 'source-over';

if (this.clear) {
this.ctx.clearRect(0, 0, this.width, this.height);
}
initialized = true;
}
...
}

(I am working on a project that will also target mobile devices where CPU consumption results to battery consumption :-))