[comp.sys.amiga.tech] Please help w/ Double Buffer, Blitter Access

brett@smosjc.UUCP (Brett Coon) (11/27/90)

I am working on a video game similar to the arcade game Robotron.  If you
aren't familiar with that game, it involves hundreds of little "bad guys"
swarming towards the guy you control, while you shoot them unmercifully.
The problem I'm having is how do I get hundreds of 12 pixel by 12 pixel
characters to move about the screen at a decent frame rate without taking
control of the Amiga?  This game has to work well on standard unexpanded
A500's, which of course makes it harder.

Question 1:  How fast is the blitter?
Right now, I have a routine that uses the blitter to draw a single 2 bit plane
12 x 12 character on the screen very quickly.  It takes control of the blitter
and accesses the registers directly, which isn't entirely "nice" but has the
advantages of being very fast and still allowing the operating system to go
on its merry way.  Drawing a character on the screen involves a cookie-cut
operation, using 3 sources to draw the character without destroying background
pixels that aren't actually in the character.  Doing nothing but drawing the
characters, I am able to draw approx. 650 in 1/10 of a second, which is my
target frame speed.  I've heard some discussion on the net regarding the 
actual speed of the blitter versus the cpu, so my question on this subject
is:  Is this speed "good" and is it possible to make it faster by using the
CPU?  My speed almost doubles when I run under 68030 mode, leading me to
believe that I'm wasting a lot of time in overhead.  The characters can have
arbitrary pixel alignment, so I have to waste some time computing shift
amounts.  Any advice on efficient use of the blitter would be appreciated.

Question 2:  How do you double buffer efficiently under Intuition?
Because I have to draw so many possibly overlapping characters on the screen
for each frame, I plan to double-buffer the display.  The only option to
double-buffering that I think would work for me is to draw into a dummy bitmap,
and then copy the bitmap to the one actually being displayed.  Based on my
performance measurements so far, this might not actually be as foolish as it
sounds.  Right now I have a program that uses the above mentioned blitter 
routine to draw as many characters on the screen as it can in 1/10 of a second.
I use double buffering to animate the characters.  In the tenth of a second,
I first swap bitmaps by changing the bitmap pointers in my RastPort and RasInfo
and calling MakeScreen and RethinkDisplay, then I call SetRast to clear the
new drawing bitmap, and finally start blitting characters to it.  When the
time is up, I display how many characters I was able to draw at the bottom of
the screen and restart the loop.  When I added this double buffering, my
performance dropped to approx 330 characters per frame, meaning that about
1/20 of a second is used by the MakeScreen, RethinkDisplay, and SetRast calls.
(I say 1/20 because with these calls I can display 330 characters in 1/10 of
a second, but without these calls I can display 650 in the same amount of 
time, so 1/2 of the time must be spent on these calls).  I discovered this
method of double buffering from the BOB example in RKM.  My question here
is:  Is there an EFFICIENT way to double buffer under Intuition?  RKM suggests
swapping copper lists in the View structure and calling LoadView to make the
display use them, but unless I'm confused I don't think Intuition would be
very pleased if I actually did this.  It would be acceptable to me to only
half support Intuition, for example by taking control of the display while
my program runs, but then allowing control to revert to Intuition when my
game pauses or exits.  Is this possible?  Unless I can get double buffering to
run faster under Intuition, I think I'll have to take control of the Amiga,
which of course is BAD.  As I mentioned earlier, it occurred to me that it 
might work to draw into a seperate bitmap, then block copy the bitmap to the
displayed bitmap.  This would eliminate the double-bufferring, but I'm not
sure I could do a 320x200x4 block copy in significantly less than 1/20 of 
a second.

Question 3:  Can I use both joysticks under Intuition?
I have to admit that I haven't really done my homework on this question, but
I'll ask anyway in case I'm on the right track.  I recall reading somewhere
that as long as Intuition is active, the best you can hope for is to receive
roughly every other event from the left (mouse) joystick port.  My game, like
Robotron, will expect the user to play with a joystick in each port, and if the
left one is flakey it won't make the game very fun.  Is this a real concern?
If so, how can I get all of the events from the left port without disabling
Intuition?  Could I just (gasp) read the hardware registers?  I know that
doing things like that is what makes America unsafe for children, but I think
risking future compatibility is better than just killing Intuition and forcing
a reboot after each game play.  And if I were to read the joystick registers,
would Intuition think the user was doing wierd things with the mouse and get
confused?  I seem to recall the mouse and joystick sharing several signals, so
I tend to suspect this last possibility.

Thanks for any help you can give me,
-brett


-- 
|Brett Coon           |  uunet!smosjc!brett         |
|S-MOS Systems, Inc.  |  "You like 'em, anchovies?" |
|San Jose, CA         |            -Runaway Train   |

peter@sugar.hackercorp.com (Peter da Silva) (11/28/90)

If you send an IND_SETMPORT to input.device to set the port to 2 you can get
the mouse out of the way.

(and if you send an IND_SETMTYPE to GPCT_*JOYSTICK you can cruise the mouse
around with a joystick!)
-- 
Peter da Silva.   `-_-'
<peter@sugar.hackercorp.com>.