This is a follow-up to discussion in the welcome thread about preserving battery by allowing longer frames when there’s no input without getting lag when there is. Taking it here to avoid hi-jacking that thread any longer.
We have talked some more internally about what we could potentially do. We are thinking about this approach:
- Implement a way to reduce the frame rate when there’s no input but get a new frame immediately when there is.
- Implement this functionality only for touch input for a start. It will treat all touch input as events that can interrupt sleep and only touch input. We may expand it with other event types in the future if there is demand for it.
We’re considering different approaches for what the API would be like.
Potentially:
- int Application.targetFrameRate
- int Application.targetSleepFrameRate
- bool Application.sleepAndWakeOnEvent
Or alternatively:
- float Application.minFrameTime
- float Application.maxFrameTime
- bool Application.sleepAndWakeOnEvent
If we at one point support handling different event types than touches for this, we may add API to specify what types of input should unblock.
Example use case:
You’d set targetFramerate to a normal active rate like 30 fps and targetSleepFrameRate to 1 fps. Then, when nothing needs animation etc. and you just want to wait for the next input, you set sleepAndWakeOnEvent to true.
If there’s input, it will trigger the next frame. If the input causes an animation or similar to start you can set sleepAndWakeOnEvent to false. Then when the animation has finished, set it to true again.
Questions for you:
A) Should input always halt a wait immediately, or still ensure a minimum frame time?
If you have set sleepAndWakeOnEvent to true so you only want a new frame quickly if there’s input, do you want:
- To immediately halt the sleep, even if it results in a frame that’s shorter than the normal targetFrameRate?
- To use the normal targetFrameRate to ensure the sleep is halted as soon as a normal frame length has passed?
The former can result in very fast frames during a swipe. If sleepAndWakeOnEvent is set to false as soon as the swipe starts, most of the frames will have normal length, but the initial one could still be shorter.
The latter guarantees a minimum frame time (max frame rate) even when there’s input.
B) For your own current use cases, would you need sleep to resume on any other types of events than touch events?
And if so, which types of input is that? What game is this for? (platform, brief description of style and interaction, etc.)