Mail Archives: djgpp/1997/04/23/13:41:03
From: | Shawn Hargreaves <shawn AT talula DOT demon DOT co DOT uk>
|
To: | djgpp AT delorie DOT com
|
MMDF-Warning: | Parse error in original version of preceding line at relay-11.mail.demon.net
|
Subject: | Re: Measuring frame rate more often
|
Date: | Wed, 23 Apr 1997 18:17:35 +0100
|
MIME-Version: | 1.0
|
Message-ID: | <861816224.096629.0@[194.129.18.166]>
|
Ian D Romanick writes:
> This is *NOT* the right way to do this. The right way uses a single
> timer interrupt going at whatever your target rate is. Just update your
> position values during the interrupt. You will need to be careful to
> make sure that the position values don't get modified while you're using
> them.
I used to use that technique all the time, but have recently gone off it
because of the hassles with unexpected modifications, and also because
running large chunks of code inside a timer interrupt handler results
in you having to lock large amounts of memory, which is a huge pain.
IMHO a better technique is to just have the timer interrupt increment
a global variable, and then have a main control loop along the lines of:
timer_variable = 0;
while (!game_over) {
while (timer_variable > 0) {
move_all_objects();
timer_variable--;
}
redraw_display();
}
That handles changing frame rates, avoids all problems with reentrancy,
and means there's only one little increment going on inside the
interrupt...
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk
"Beauty is a French phonetic corruption of a short cloth neck ornament"
- Raw text -