delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/03/13:24:15

Message-ID: <199808031925530430.00020541@pogwizd.tcs.uni.wroc.pl>
In-Reply-To: <35C4420A.500482B8@aditfree.com>
References: <35C396B2 DOT C31C29EA AT aditfree DOT com>
<35d43129 DOT 140559707 AT news DOT ican DOT net>
<35C4420A DOT 500482B8 AT aditfree DOT com>
Date: Mon, 03 Aug 1998 19:25:53 +0200
From: "Pawel Kowalski" <pk AT tcs DOT uni DOT wroc DOT pl>
To: enquiries AT aditfree DOT com, djgpp AT delorie DOT com
Subject: Re: Same speed on every machine
Mime-Version: 1.0


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


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