markfguerra / GLWallpaperService

Please submit issues and pull requests to the main repository
https://github.com/GLWallpaperService/GLWallpaperService
Apache License 2.0
218 stars 114 forks source link

Configurable FPS #12

Closed florinbratu closed 11 years ago

florinbratu commented 13 years ago

Hello!

Just an improvement idea, it would be nice to be able to configure the FPS of the GL Live Wallpaper. This way, users may set the FPS count to lower levels in order to save up CPU and battery life. Don't know how easy it is to do it though...

Cheers, Florin.

b1naryatr0phy commented 13 years ago

If I remember correctly, the renderer used in min3d has an implementation fps control, I imagine it would be fairly easy to port it over.

florinbratu commented 13 years ago

Yes, min3d has an implementation for fps control. And yes, it's fairly easy to port it over; however, it's very inefficient. IMO the most efficient is to do it at the renderer layer level.

b1naryatr0phy commented 13 years ago

I always assumed it would be as easy as this: during onDrawFrame, but before actual drawing, get current time; draw and get time again; if end time - start time is < framerate, sleep

I suppose I'm not 100% sure what you mean by at 'renderer layer'

florinbratu commented 13 years ago

And how do you know for how long will you have to sleep? Please note that within the solution you presented, you will have to sleep after each frame drawn, for small time intervals. And AFAIK java's sleep implementation is not so accurate at the millisecond level...

By 'renderer layer' I mean GLWallpaperService, in our particular case.

b1naryatr0phy commented 13 years ago

When did I say to use java's sleep implementation? Just make your own by checking against the system uptime. For example:

while (frameStartTime + 40 > frameCurrentTime) { //do nothing }

You could even use nanoTime if you're that picky about accuracy, but if you're looking for a timer that is 100% accurate, good luck. It doesn't exist, regardless of what platform or programming language you use.

I think you need to remember that the system is going to process and execute every bit of code as fast as it possibly can, if you can propose any other way of slowing that process down without using a form of sleep, I'm all ears.

Ultimately you're going to have to tell the system when it is allowed to draw a new frame. So how do you ever expect to control the framerate without a timer/sleep method?

markfguerra commented 11 years ago

This issue is being closed because the project is being moved to the GLWallpaperService GitHub organization

If you're still interested in this change, please go there and open new issue or pull request. Don't forget to link back to this page.