Mail Archives: djgpp/1998/08/03/13:24:15
*********** REPLY SEPARATOR ***********
On 98-08-02, at 14:00, C.Rothwell wrote: 
>cam and or nenette remove trailing 666 wrote:
>
>> On Sat, 01 Aug 1998 23:29:06 +0100, "C.Rothwell"
>> <enquiries AT aditfree DOT com> added to the entropy with:
>> >Is there a fool proof way of getting somethng to run at the same speed
>> >on any PC without it slowing down the older machines?
>>
>> yeah - run it on the slowest machine you want it to run on, and then
>> use that as the standard for how fast the program is allowed to run on
>> faster machines.
>
>  Well, my problem is that It works fin on a 386 and up to a P150 then it
>starts to get faster (more so on cyrix machines) and I suspect that on a
>P400 it would be unplayable.
>
>Although I don't have access to anything more than a P200.
>I could put a screen update on an interupt but it might cause problems on
>the slower machines with slow graphics cards. I have been used to using the
>Amiga and this is the first time I have had to deal with such variance in
>speed of CPU's.
My first solution: (I used a couple of months ago)
Place functions like:
  -read_controls();
  -move_player();
  -move_opponents();
  -...
in and interrupt function, that is run every same period of time.
(main game loop will look like this:
while (!game_over) {
  render_screen();
})
My second solution: (I'm using now)
main game loop:
while (!game_over) {
  update_frame();
  render_frame();
}
int this_uclock, prev_uclock;
float time_elapsed;
void update_frame()
{
  prev_uclock=this_uclock;
  this_uclock=uclock();
  elapsed=this_uclock-prev_uclock;
  read_controls(); 
  move_player();
}
void move_player()
{
  if (key_up) player->pos_y-=elapsed*MOVEMENT_CONSTANT;
  ...
}
The first solution worked ok in most cases. (but there was
a bug I couldn't find... :(
The second will work fine, but you have to be careful not to
skip "elapsed*CONSTANT" in any movement,... formula.
I hope it will help you...
Pawel Kowalski
- Raw text -