hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

CPU close to 100% when scene is idle #19

Closed VoxelPerfect closed 12 years ago

VoxelPerfect commented 12 years ago

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 :-))

hyperandroid commented 12 years ago

Hey Kostas,

maybe director.setClear(false) will do it for you. probably you're having the screen cleared twice, once by the director (which unless called the previous code will clear the screen) and by the scene ? let me know. Another thing, i've just uploaded regarding behavior transformation into css3 keyframes. i'm focusing on this issue since i'm also targeting mobile dev. even though css3 animations totally suck, i'm getting good results.

-i

2011/11/23 Kostas Karolemeas < reply@reply.github.com

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 :-))


Reply to this email directly or view it on GitHub: https://github.com/hyperandroid/CAAT/issues/19

VoxelPerfect commented 12 years ago

Hi Ibon,

I am afraid setClear(false) creates some artifacts and I think the scene is not clearing the screen, at least I have not added any code to do that.

I will give a try to the CSS renderer and let you know!

Kostas

hyperandroid commented 12 years ago

ok. will check scene status then. thanks.

-i

2011/11/23 Kostas Karolemeas < reply@reply.github.com

Hi Ibon,

I am afraid setClear(false) creates some artifacts and I think the scene is not clearing the screen, at least I have not added any code to do that.

I will give a try to the CSS renderer and let you know!

Kostas


Reply to this email directly or view it on GitHub: https://github.com/hyperandroid/CAAT/issues/19#issuecomment-2847174

VoxelPerfect commented 12 years ago

Look what I did:

  1. called director.setClear(false)
  2. implemented scene.paint to call ctx.clearRect

Now it works! Is this the recommended way to do it?

In parallel, I have started reading the Sumon code :-)

hyperandroid commented 12 years ago

hey Kostas, send me a personal email.

-ibon

2011/11/23 Kostas Karolemeas < reply@reply.github.com

Look what I did:

  1. called director.setClear(false)
  2. implemented scene.paint to call ctx.clearRect

Now it works! Is this the recommended way to do it?

In parallel, I have started reading the Sumon code :-)


Reply to this email directly or view it on GitHub: https://github.com/hyperandroid/CAAT/issues/19#issuecomment-2847462