Render Interpolation possible?

Monkey Archive Forums/Monkey Discussion/Render Interpolation possible?

Shinkiro1(Posted 2011) [#1]
Like described here: http://www.koonsolo.com/news/dewitters-gameloop/
So,
* Update() is called at fixed rate
* Render() takes what's left and interpolates to smooth things out

In Bmax it would look like this (only 10 FPS but will look smooth due to interpolation):
Graphics 640,480
SetClsColor 20,20,24

'Player variables
Global px:Float = 10
Global py:Float = GraphicsHeight() / 2
Global speed:Float = 20

Const TICKS_PER_SECOND:Int = 10
Const SKIP_TICKS:Int = 1000 / TICKS_PER_SECOND
Const MAX_FRAMESKIP:Int = 5

Local next_game_tick:Int = Millisecs()
Local loops:Int
Local interpolation:Float


While (Not Keydown(KEY_ESCAPE))
	
	loops = 0
	While ( Millisecs() > next_game_tick) And(loops < MAX_FRAMESKIP)
		Update()
		next_game_tick:+ SKIP_TICKS
		loops:+ 1
	Wend
	
	interpolation = (Millisecs() + SKIP_TICKS - next_game_tick) / Float(SKIP_TICKS)
	Cls()
	Render( interpolation )
	DrawText( "FPS: " + TICKS_PER_SECOND, 4, 4 )
	Flip 0
	
Wend


Function Update()
	px:+ speed
	If (px - 30 > GraphicsWidth())
		px = -30
	EndIf
EndFunction

Function Render( interpolation:Float)
	SetColor( 100, 200, 250 )
	DrawOval( px + (speed * interpolation), py, 30, 30 )
	SetColor( 255, 255, 255 )
EndFunction


The thing is in monkey when you call SetUpdateRate() it will call both OnUpdate() and OnRender() at the same rate.

Is there any (hacky) way to call OnRender() yourself?


DGuy(Posted 2011) [#2]
The thing is in monkey when you call SetUpdateRate() it will call both OnUpdate() and OnRender() at the same rate.


OnRender() can get called less often (but never more often) than OnUpdate() ...

You'll always receive as many OnUpdates() events per second as you specify with SetUpdateRate(), but if the actual FPS begins to fall below the specified FPS, Monkey will begin to skip OnRender() events so the app can catch-up.

This doesn't answer your question but I just wanted to clarify ... :)


Shinkiro1(Posted 2011) [#3]
[quote]OnRender() can get called less often (but never more often) than OnUpdate() ...[/qoute]
Render tweening is only useful when you can render more times than updating.

But as I think about it, maybe Mark has implented it because typically rendering takes more time than updating (especially on mobile devices).

Maybe I'll just set the update-rate to ~120 and do my own timing inside OnUpdate() and OnRender().