Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

CPU close to 100% when scene is idle #19

Closed
VoxelPerfect opened this issue Nov 23, 2011 · 5 comments
Closed

CPU close to 100% when scene is idle #19

VoxelPerfect opened this issue Nov 23, 2011 · 5 comments

Comments

@VoxelPerfect
Copy link

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
Copy link
Owner

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:
#19

@VoxelPerfect
Copy link
Author

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
Copy link
Owner

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:
#19 (comment)

@VoxelPerfect
Copy link
Author

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
Copy link
Owner

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:
#19 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants