Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip a frame if there is no action updated or event dispatched #6178

Closed
wants to merge 3 commits into from

Conversation

heliclei
Copy link
Contributor

@heliclei heliclei commented Apr 8, 2014

To reduce power consumption

@heliclei
Copy link
Contributor Author

heliclei commented Apr 8, 2014

@ricardoquesada : I know this is a very premature and risky feature, but if we can do on-demand frame update eventually, I think it could reduce cocos2d-x engine's power consumption substantially.

@thoechsmann
Copy link

Great feature. We implemented it for cocos2d-x v2.

Am 08.04.2014 um 18:38 schrieb heliclei notifications@github.com:

@ricardoquesada : I know this is a very premature and risky feature, but if we can do on-demand frame update eventually, I think it could reduce cocos2d-x engine's power consumption substantially.


Reply to this email directly or view it on GitHub.

@ricardoquesada
Copy link
Contributor

I like the idea, but I think the current patch is not covering all the possible updates.
Perhaps I didn't understand the patch correctly, but are you covering the "updates" ?
Also, if an event is dispatched (no matter which event), then the directory should be dirty, so the code on the EventDispatcher could be simplified.

Anyway, I think reducing the power consumption is a great feature. What other things should we do in order to say that cocos2d is eco-friendly ? :)

As an example: How about networking ? can we improve our network library to be eco-friendly ?

@heliclei
Copy link
Contributor Author

heliclei commented Apr 9, 2014

Thanks! @ricardoquesada, I will run more tests to verify if it works on all cases.

@heliclei
Copy link
Contributor Author

heliclei commented Apr 9, 2014

@thoechsmann ,That's great, Can you join to improve this PR?

@dumganhar
Copy link

@ricardoquesada is right. This patch didn't cover all updates.
Scheduler::update also needs to set the dirty flag.

@@ -274,6 +278,11 @@ void Director::drawScene()
_eventDispatcher->dispatchEvent(_eventAfterUpdate);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dumganhar : if we set dirty bit in scheduler->update(), The dirty bit will be set every frame. So, We have to set it in scheduler target update() function, such as ActionManager, or other targets. This approach is more precise, but application code have to set the dirty bit if it has custom scheduler update(). Another choice is set dirty bit for all custom update(), it's less precise, but simpler.

@thoechsmann
Copy link

We introduced a global variable that was set to true if a property of a CCNode changed.

You only seem to cover scheduled actions. What happens if you set e.g. the position of a sprite. It will not trigger a redraw.

@heliclei
Copy link
Contributor Author

heliclei commented Apr 9, 2014

@thoechsmann : In such case, Does Application code need set the dirty flag manually, or engine can detect the property change?

@thoechsmann
Copy link

The Application should never be responsible for this. Otherwise there will be tons of problems. It must be handled inside of cocos. Maybe Ric has a better idea, but I would add code to CCNode. flag must be set to dirty if you add/remove a child or set properties like position, color, … In most (but not all) cases it can be set when _transformUpdated is set.

Other things to keep in mind is that you cannot stop rendering after one frame when there are no more changes. This will not work on all android devices. We rendered always 3 frames after the last change. I think two frames should be enough, but we got problems with that. I can merge in our changes in V3 and make a pull request so you can take a look at the changes.

On 09 Apr 2014, at 11:29, heliclei notifications@github.com wrote:

@thoechsmann : In such case, Does Application code need set the dirty flag manually, or engine can detect the property change?


Reply to this email directly or view it on GitHub.

@heliclei
Copy link
Contributor Author

heliclei commented Apr 9, 2014

@thoechsmann: Thank you very much! I haven't test android device yet.

@ricardoquesada
Copy link
Contributor

yes, the best way to do it is in visit. and visit should return a boolean indicating whether or not the scene is dirty.

We are already passing the dirty flag as an argument. what we have to do it, is to return it.
We are planning to modify the API for visit in v3.1... so, we should introduce this change there.

@heliclei
Copy link
Contributor Author

That's great! @ricardoquesada 👍

@cocosQA
Copy link

cocosQA commented Apr 29, 2014

Dear heliclei:
We have created a new branch 'v3' to replace branch 'develop', and this PR has been moved from 'develop' branch to 'v3' branch, the new PR is #6418
The old 'develop' branch will be deleted soon, and this PR will be closed accordingly.

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

Successfully merging this pull request may close these issues.

None yet

7 participants