www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/24/17:45:13

Message-Id: <335FD162.3F2@canvaslink.com>
Date: Thu, 24 Apr 1997 17:32:18 -0400
From: Tom Grandgent <tgrand AT canvaslink DOT com>
Reply-To: tgrand AT canvaslink DOT com
Organization: Canvas Link, Inc.
Mime-Version: 1.0
To: shawn AT talula DOT demon DOT co DOT uk
Cc: djgpp AT delorie DOT com
Subject: Re: Measuring frame rate more often

> 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...

Argh!  I have been doing this all along with all of the objects in the
game -except- for the player.  I had long ago tried to do this with
the player, but I was using a timer function that is only being called
100 times a second..  Now I will change everything over to 1000 times
a second (especially since I have learned that 1KHz will not impact
performance much at all.)

The method that I use (which I actually figured out for myself, for
once) is actually a little different than yours.  I have things that
need to be done at different speeds (processing unit movement, letting
the player turn their ship, etc) so I have a different global variable
for each task.  The timer function increments each of these variables.
Then I do something like:

while (ms_unit > 50)
{
    ms_unit -= 50;
    process_units();
}

while (ms_turn > 30)
{
    ms_turn -= 30;
    turn_player();
}

Does this make any sense?  I think it does ...

Anyway, thanks for getting me to realize the obvious. :)

	Tom Grandgent
	tgrand AT canvaslink DOT com
	Canvas Link, Inc.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019