[epiar-devel] Virtual framerate + interpolated graphics demo
chris at epiar.net
Sun Jan 24 23:16:56 PST 2010
Just for education and knowledge's sake, attached is the result of
extracting the important bits from Dan Olfson's "fixed frame rate pig"
demo which I will use in the coming days to fix up Epiar's timer and
drawing speed issues.
The demo is simple: a box bounces up and down the screen. Pressing 'i'
toggles the interpolation (it starts out on). The interpolation effect
is subtle and is more noticeable when your sprite coordinates do not
fall on integers. It also works better at certain speeds, e.g. very slow
and very fast don't matter because integers tend to be within a few
percetange points of being correct, but those important in-between
speeds look a little smoother.
The important aspect of this however is the implementation of a virtual
frame rate. The game becomes locked at a certain virtual frame rate,
e.g. 50 Hz for a game like Epiar, in which the drawing loop is ignored
giving the logic time to catch up; this is how a lot of modern games do
it, and this removes the problem of the game literally running slower on
slower computers, e.g. on a slower computer, things will still move at a
constant rate unless it is _much_, _much_ slower than what we would
expect, but only in the case where the drawing code and the update code
take similar amounts of time, and they don't, it's not even close.
Noticeably, having a virtual frame rate means you can use hard-coded
values in the code (you mustn't, fyi, but technically could) just like
the old days where you were programming for one machine that always ran
at the same speed and didn't have to worry about the code running on
various machines with various speeds. tl;dr you don't need to calculate
deltas for movement based on the timer anymore. HOWEVER, we will because
this is proper and in case we ever switch timer behavior, we don't want
to have to go back in and add them. Plus, it gives us a little added
bonus in ensuring proper game logic speed and drawing positions across
an even wider array of hardware.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the epiar-devel