home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Graphics
/
VSprites
/
VSprites.doc
< prev
next >
Wrap
Text File
|
1993-10-12
|
29KB
|
1,022 lines
4 VSPRITES
4.1 INTRODUCTION
VSprites, or Virtual Sprites as their whole name is, are very
similar to Hardware Sprites. VSprites have the same limitations
such as a maximum width of 16 pixels and can only use three
colours (actually four colours, but the first colour will act
as transparent.) However, VSprites are superior to Hardware
Sprites because you may use much more than eight VSprites at
the same time, and each VSprite may use its own three colours
out of a palette of 4096 colours. The disadvantage with
VSprites compared to Hardware Sprites is that Hardware Sprites
are totally controlled by the hardware and thus very fast,
while VSprites are partly controlled by the software and
because of that a bit slower.
4.2 HOW VSPRITES WORK
The reason why VSprites are so similar to Hardware Sprites is
that VSprites are actually displayed with help of Hardware
Sprites. If you want a VSprite to be at the top of the display
and one further down, the system will position a Hardware Sprite
at the top and change its image so it correspond to the
VSprites image. The colours will also automatically be changed
by altering the Copper List. (See chapter "Hacks" for more
information about the Copper list.)
When the video beam has passed the first VSprite, the Hardware
Sprite is not needed there any more and can therefore be used
again. The system can therefore use the same Hardware Sprite to
display another VSprite, and so on. Because of this you can have
much more than eight sprites at the same time on the display.
If two or more VSprites would be on the same height, more
Hardware Sprites are needed. The system has eight Hardware
Sprites as its disposal, and can therefore display up to
eight VSprites on the same line.
Here is an example. You want to display three VSprites
positioned as below. In this case two Hardware Sprites are
needed. Hardware Sprite one is used to display VSprite A
and B. A and B are not on the same height, and only one
Hardware Sprite is therefore needed. However, VSprite C
is on the same lines as B, and a second Hardware Sprite is
therefore needed.
-----
| A |
-----
-----
| B | -----
----- | C |
-----
4.2.1 LIMITATIONS
There are some important limitations that you need to remember:
1. If you have reserved some Hardware Sprites for your own
use, the system can not use these sprites and this will
limit the maximum numbers of VSprites on the same height.
2. Hardware Sprites 0 and 1, 2 and 3, 4 and 5, 6 and 7 share
the same colours. If sprite 0 is used to display one
VSprite, the computer can not use sprite 1 to display
another VSprite on the same height if it has different
colours. Because of that there is a limitation of a
maximum of four VSprites with different colours on the
same height.
3. If you display the VSprites on a screen with a depth of 5
or more (32 colours or more) you will see strange colour
fluctuations on the lines where the VSprites are. The
reason is that VSprites are now using the same colour
register as the display, and as we said before, the system
is all the time changing these colours to match the
VSprites' colours.
If the system can not find a Hardware Sprite to display a
VSprite because of the limitations above, the VSprite will
simply not be drawn.
4.2.2 HOW TO AVOID THE LIMITATIONS
There are several guidelines to follow in order to avoid the
limitations:
1. Use as few VSprites as possible on the same lines.
2. Try to use VSprites with the same colours.
3. If you are using a display with more than 16 colours, you
should only use colour 16, 20, 24, and 28. (These are the
transparent colours, and will therefore not be changed.)
4.3 CREATE VSPRITES
IF YOU WANT TO USE VSPRITES YOU HAVE TO
---------------------------------------------------------------
1. Declare and initialize some sprite data for each VSprite.
2. Declare a VSprite structure for each VSprite plus two extra
structures for two dummy VSprites.
3. Decide each VSprite's colours.
4. Declare a GelsInfo structure.
5. Open the Graphics Library.
6. Initialize the GelsInfo structure.
7. Initialize the VSprite structure.
8. Add the VSprites to the VSprite list.
9. Sort the Gels list. SortGList()
10. Draw the Gels list. DrawGList()
11. Set the Copper and redraw the display.
[ MrgCop() and LoadView() or ]
[ MakeScreen() and RethinkDisplay() ]
12. Play around with the VSprites.
13. Remove the VSprites. RemVSprite()
(Easy, isn't it?)
4.3.1 VSPRITE DATA
Sprite data for VSprites is declared and initialized as normal
sprite data. Just remember that all sprite data must be placed
in Chip memory.
Example:
UWORD chip vsprite_data[]=
{
0x0FF0, 0x0FF0,
0x0FF0, 0x0FF0,
0x0FF0, 0x0FF0,
0x0FF0, 0x0FF0
};
4.3.2 VSPRITE STRUCTURE
You need to declare a VSprite structure for each VSprite you
are going to use, and two extra for two "dummy VSprites". The
two dummy VSprites are used by the gel system (GEL stands for
Graphic ELements). (One of the two dummy sprites is placed
first in the gel-list, and the other one is placed last. The
gel system can then sort the list much faster, and speed is
essential here.)
Example:
struct VSprite head, tail, vsprite;
The VSprite structure looks like this: [Declared in the header
file "graphics/gels.h".]
struct VSprite
{
struct VSprite *NextVSprite;
struct VSprite *PrevVSprite;
struct VSprite *DrawPath;
struct VSprite *ClearPath;
WORD OldY, OldX;
WORD Flags;
WORD Y, X;
WORD Height;
WORD Width;
WORD Depth;
WORD MeMask;
WORD HitMask;
WORD *ImageData;
WORD *BorderLine;
WORD *CollMask;
WORD *SprColors;
struct Bob *VSBob;
BYTE PlanePick;
BYTE PlaneOnOff;
VUserStuff VUserExt;
};
NextVSprite: Pointer to the next VSprite in the list.
PrevVSprite: Pointer to the previous VSprite in the list.
DrawPath: Used by BOBs.
ClearPath: Used by BOBs.
OldY: Previous Y position.
OldX: Previous X position.
Flags: Following flags may be set by the user:
SUSERFLAGS Mask of the user settable flags.
VSPRITE Set this flag if you are using the
structure for a VSprite.
MUSTDRAW Set this flag if this VSprite must
be drawn.
Following flags are set by the system:
GELGONE This flag is set if the VSprite is
outside the
VSOVERFLOW Too many VSprites on the same lines.
If the flag MUSTDRAW is set, the
system will try to draw it, but it
could look strange.
Y: Y position.
X: X position.
Height: The height of the VSprite.
Width: Number of words used for each line. For the moment
a VSprite can only be 16 pixels wide, which means
two words.
Depth: Number of planes. A VSprite can for the moment
only use two planes, 3 colours and one transparent.
MeMask: What can collide with this VSprite. (Will be
explained in a future version of the manual.)
HitMask: What this VSprite can collide with. (Will be
explained in a future version of the manual.)
ImageData: Pointer to the sprite data.
BorderLine: (Will be explained in a future version of the manual.)
CollMask: (Will be explained in a future version of the manual.)
SprColors: Pointer to a colour table for this VSprite.
VSBob: Used if it is a BOB. (Will be explained in a future
version of the manual.)
PlanePick: Used if it is a BOB. (Will be explained in a future
version of the manual.)
PlaneOnOff: Used if it is a BOB. (Will be explained in a future
version of the manual.)
VUserExt: You may use this as you please. Here you can add
extra information etc. (Is actually declared as a
SHORT variable.)
4.3.3 COLOUR TABLE
Each VSprite can have its own three colours out of a palette
of 4096. The three desired col