[comp.sys.amiga] Help for a games programmer

ins_adjb@jhunix.HCF.JHU.EDU (Daniel Jay Barrett) (08/11/89)

	A friend of mine has written a PD game, and he has a question about
how to improve it.

	The game is "Peter's Quest" and it is on a Fish Disk.  It is an
arcade-type game like Lode Runner, and it takes input from the keyboard
and the joystick.
	The problem?  It busy-waits.  His main loop looks like this:

		Check for user keyboard input.
		If none, check for joystick input.
		If none, continue with the animation.

	Could someone please send me a code fragment how to do this in
a multitasking-friendly way?  I know how to write Amiga programs that
don't busy-wait, but I have never done it in a program that has a continuous
animation running.  I mean, how can you use Wait() and still have the
animation running?  Do you need a separate process to check for input?
Or what?

	Thanks very much.

                                                        Dan

 //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
| Dan Barrett, Systems Administrator  --  barrett@cs.jhu.edu (128.220.13.4) |
| Dept. of Computer Science, Johns Hopkins University, Baltimore, MD  21218 |
| E-mail addresses:  ARPANET: barrett@cs.jhu.edu                            |
|                    BITNET:  ins_adjb@jhuvms.bitnet                        |
|                    UUCP:    ins_adjb@jhunix.UUCP                     noog |
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////////////////

farren@well.UUCP (Mike Farren) (08/13/89)

ins_adjb@jhunix.HCF.JHU.EDU (Daniel Jay Barrett) writes:
>... how can you use Wait() and still have the animation running?
>Do you need a separate process to check for input?

You can't, really.  If you've got to execute code to keep the animation
going, you're stuck - the best you'll be able to do is to Wait() during
the periods you're not actually doing the animation.  I presume you're
on a 30th of a second clock - you could do something like this:

   Check keyboard.
   Check joystick.
   Do one frame of animation.
   Wait() until next 30th of a second tick.
   Loop.

Launching a separate process isn't going to help - the original process
(task, actually) will still be running, still eating CPU time.

-- 
Mike Farren 				     farren@well.sf.ca.usa

shf@well.UUCP (Stuart H. Ferguson) (08/16/89)

+-- ins_adjb@jhunix.HCF.JHU.EDU (Daniel Jay Barrett) writes:
| arcade-type game like Lode Runner, and it takes input from the keyboard
| and the joystick.
| 	The problem?  It busy-waits.   [ ... ]
| 	Could someone please send me a code fragment how to do this in
| a multitasking-friendly way?  I know how to write Amiga programs that
| don't busy-wait, but I have never done it in a program that has a continuous
| animation running.  

Seems to me that if the program is actually doing something -- like
displaying some animation -- then it is not "busy-waiting," it's 
"busy-working." :-)  Busy-waiting refers to programs that have an input
loop like:
		forever {
			Check for user input.
			if something happened, respond.
		}

Such a program will burn CPU cycles just sitting doing nothing.  The correct
way to do this on the Amiga (just to make this an educational posting ;-)
is to have an input loop like this:

		forever {
			Check for user input.
			if something happened, respond,
			otherwise Wait() for some user input.
		}

A way to make the game multi-tasking friendly is to have a pause mode that
can be explicitly envoked.  This would cause the animation to stop playing
and put the program into the second type of input loop above, waiting for
the user to indicate that she wants to continue playing.  If you've 
followed all the other rules correctly (i.e. not disabled Exec) then other
tasks should be able to run normally while your game waits.
-- 
		Stuart Ferguson		(shf@well.UUCP)
		Action by HAVOC		(ferguson@metaphor.com)