Download Amiga Rom Kernel Reference Manual - tele
Transcript
the CoIlHandler field of the GelsInfo list. Which routine is called depends on the 16-bit MeMask and HitMask
members of the VSprite structures involved in the collision.
When you call DoCollision(), the system goes through the GeIsInfo list which, is constantly kept sorted by x, y
position. If a GEL intersects the display boundaries and the GELs HitMask indicates it is appropriate, the
boundary collision routine is called. When DoCollision() finds that two GELs overlap, it compares the MeMask of
one with the HitMask of the other. If corresponding bits are set in both, it calls the appropriate inter-GEL collision
routine at the table position corresponding to the bits in the HitMask and MeMask, as outlined below.
Preparing for Collision Detection
Before you can use the system to detect collisions between GELS, you must allocate and initialize a table of
collision-detection routines and place the address of the table in the GeIsInfo.CoIIHandler field. This table is an
array of pointers to the actual routines that you have provided for your collision types. You must also prepare
some members of the VSprite structure: ColIMask, BorderLine, HitMask, and MeMask.
Building a Table of Collision Routines
The collision handler table is a structure, CoIITable, defined in <graphics/gels.h>. It is accessed as the
ConHandler member of the GeIsInfo structure. The table only needs to be as large as the number of bits for
which you wish to provide collision processing. It is safest, though, to allocate space for all 16 entries, considering
the small amount of space required.
Call the routine SetCollision() to initialize the table entries that correspond to the HitMask and MeMask bits that
you plan to use. Do not set any of the table entries directly, instead give the address to SetCollision() routine
and let it handle the set up of the GeIsInfo.ColITable field.
646 Amiga ROM Kernel Reference Manual: Libraries
For example, SetCollision() could be called as follows:
ULONG num;
VOID (*routine)();
struct GelsInfo *GInfo;
VOID myCollisionRoutine(GELA, GELB) /* sample collision routine */
struct VSprite *GELA;
struct VSprite *GELB;
{
/* process GELs here - GELA and GELB point to the base VSprites of */
/* the GELs, you can use the user extensions to identify what hit */
/* (if you need the info). */
/* GelsInfo must be allocated and initialized */
routine = myCollisionRoutine;
SetCollision(num, routine, Glnfo)
}
The num argument is the collision table vector number (0-15). The (*routine)() argument is a pointer to your
collision routine. And the CInfo argument is a pointer to the GeIsInfo structure.
VSprite Collision Mask
The ColIMask member of the VSprite is a pointer to a memory area allocated for holding the collision mask of
that GEL. This area must be in Chip memory and its size is the equivalent of one bitplane of the GEL’s image.
The collision mask is usually the same as the shadow mask of the GEL, formed from a logical-OR combination of
all planes of the image. The following figure shows an example collision mask.