[comp.sys.amiga.programmer] Timing in a Game

morgan@cory.Berkeley.EDU (Alan Morgan) (04/23/91)

I am in the process of writing a Tron-style game to be released (I hope)
as freeware in the near future (it has a few improvements over other
such games I have seen like 2 player mode and saved high-scores to name
but two.  Anyway, even if you are sick of them, it won't stop me).
But I have a problem with the delay function.

I advance each little dude (players and bad-guys) and then have to wait
a little until I can advance them again.  They question is how to cause
this wait.  I was originally using the Delay function but it is far too
long even with Delay(1), so for right now I am forced to use a for
loop even though I know I will go to hell for it and have my genitals
roasted over an open fire (or something).

Ideally what I want is something that can give me a machine independent,
non-busy delay of about, say, 1/100 of a second.  Any takers?  Should I
be using the internal clock in some arcane way? HELP!

Alan Morgan
---
Amiga and Macintosh users aren't *that* different.  They both hate IBM's.

colin_fox@ice.outbound.wimsey.bc.ca (Colin Fox) (04/24/91)

>But I have a problem with the delay function.
>
>I advance each little dude (players and bad-guys) and then have to wait
>a little until I can advance them again.  They question is how to cause
>this wait.  I was originally using the Delay function but it is far too
>long even with Delay(1), so for right now I am forced to use a for
>loop even though I know I will go to hell for it and have my genitals
>roasted over an open fire (or something).

:) Why don't you use the WaitTOF()? It's a non busy-wait and it's easy. It
will syncronize your animations to 60Hz (or if you do 2 WaitTOF()s, 30Hz),
and you won't suffer any burns. :):) It's in GfxBase, by the way.

+-------------------------------------+----------------------------------+
| Colin_Fox@ice.outbound.wimsey.bc.ca | "...heavy!"                      |
+-------------------------------------+ "There's that word again! Is     |
| Informal home of SIGGRAPH Vancouver,|  there a problem with gravity in |
| and proud of it!                    |  the future?" -- Doc             |
+-------------------------------------+----------------------------------+

valentin@public.BTR.COM (Valentin Pepelea) (04/24/91)

In article <12960@pasteur.Berkeley.EDU> morgan@cory.Berkeley.EDU (Alan Morgan)
writes:
>
>Ideally what I want is something that can give me a machine independent,
>non-busy delay of about, say, 1/100 of a second.  Any takers?  Should I
>be using the internal clock in some arcane way? HELP!

Try using WaitTOF() or WaitBOF(). These will offer you a delay of a maximum
of 1/60th of a second, but with an added advantage. No matter how long your
processing is before the WaitTOF(), you usually will still be synchronized
with the vertical blank (depending on whether your processing takes *more*
than a vertical blank cycle.) Thus whether your code runs on 68000's or
68030's, and whether you have many objects on the scree or just a few, your
game will still run at the same pace. Neat, eh?

Valentin

-- 
"An operating system without virtual memory      Name:      Valentin Pepelea
 is an operating system without virtue."         Phone:     (408) 985-1700
                                                 Usenet:    mips!btr!valentin
                     - Ancient Inca Proverb      Internet:  valentin@btr.com