Flickering with OnRender()

Monkey Targets Forums/Android/Flickering with OnRender()

Midimaster(Posted 2012) [#1]
Because I'm writing a "not game"-app there is no need of rendering as often, 15 or 30 would be enough. But because of music timing I would like to use a high Update-Rate of 120 or 200.

In this content I noticed, that the OnRender is as often called as I select in in SetUpdateRate(). Even if nothing happenend on the screen, the OnRender() tries to fullfill the Rate and stresses the device. Not till the stress is to much, the OnRender()-rate will find an end, because of performance problems. So I tried to save some OnRender() by jumping them.

Now I noticed, that the device seems to have two buffers and if you try to jump some of the OnRender()-Events you will get a heavy flickering. This is not on the html5 target, but on only on the Android.

So I did some test and this code demonstrates, what is happening:

[monkeycode]Import mojo

Class MyExample Extends App
Global Flicker%, CountUpdate%, CountRender%,X%

Method OnCreate()
SetUpdateRate 30
End

Method OnUpdate()
If KeyHit(KEY_ESCAPE) Then Error ""
Flicker=(Flicker+1) Mod 10
CountUpdate=CountUpdate+1
End

Method OnRender()
CountRender=CountRender+1
If Flicker=0
X=X+1
Cls 0,0,255
SetColor 0,255,0
DrawRect 5+X,5,230,310
SetColor 255,0,0
DrawRect 25+3*X,25+3*X,130,110
SetColor 255,255,255
Scale 2,2
DrawText "Update=" +CountUpdate,10,130
DrawText "Render=" +CountRender,10,150
Endif
End
End

Function Main()
New MyExample
End[/monkeycode]

Now my questions:

Isn't it an error, that OnRender() is not event driven, but seems to come as often as OnUpdate()? Is'nt this very stressfull an energy wasting?


Isn't it an error, that each 2nd OnRender() jumps always back to the very first backscreen? You can see this in the sample: the flickering picture is the very first one. All the following OnRender() seems to change always only the second backbuffer.

With a little change in the test code you can see, that two following OnRender() will change both buffers:

[monkeycode]....
Method OnRender()
CountRender=CountRender+1
If Flicker<2
....
[/monkeycode]


Workaround: A odd number of jumping will cause not so much flickering:

[monkeycode]....
Method OnUpdate()
If KeyHit(KEY_ESCAPE) Then Error ""
Flicker=(Flicker+1) Mod 9
CountUpdate=CountUpdate+1
End

Method OnRender()
CountRender=CountRender+1
If Flicker=0
....
[/monkeycode]

Is there a better solution of Updating with 200fps and Rendering with 15fps?


Samah(Posted 2012) [#2]
Music timing on Android, eh? Have fun with that one. :)


Midimaster(Posted 2012) [#3]
yes! at the moment the channel timing sound good enough. I had only short problems when the mobile is moved and the orientation changes.

so this is not my problem at the moment....


Gerry Quinn(Posted 2012) [#4]
I think you have to modify mojo. For Java the function you need to change seems to be gxtkTimer.Run().

I haven't tested it but that seems to be where the decision to render is made.

You can probably add some variable that it checks, and alter that on the fly to change behaviour.