[comp.sys.amiga] Looking for help with Gels Animation.

davidc%yak@gatech.edu (Dave Corbin) (02/24/88)

I'm trying to dip my toe into the Animation waters.  Unfortunately, I seem
to have a problem.  A copy of my program follows, and any help that anybody
can give me is apprciated.  What the program is supposed to do:
	move a rectangle from one corner of the screen{_ down a diagonal line,
	pause, and then cleanup.

	Problems:  
		1- The square seems to be a color that I don't think is in
			my screen's pallette. Confusing, but not serious.
		2- When WIDTH is defined as 3L (test.h), I get the big guru
			during my call to InitMasks.  If it is 1L or 2L, no
			guru.
		3- When WIDTH is 2L, SOMETHING seems to be trashing 0000.
			(ThankYou, MemWatch).  (LongWord 0 gets filled with
			my BoB pattern).

Please excuse all the kputs, etc.  They're left over from trying to figure out
where things are going South.  I presume that 2 & 3 are related. Oh yeah.
I use Manx 3.4b with short ints.

Again, thanks for any help.
David Corbin

#-----Cut Here-----
echo Extracting ball.c...
cat >ball.c <<END_OF_FILE
#include <graphics/gels.h>
#include "geltools.h"
#include "test.h"

struct Bob *Bball = NULL;
struct VSprite *Vball = NULL;
StartBall(rp)
struct RastPort *rp;
{
	int i,d;

	Bball = AllocBob();
	if (!Bball)
		Quit(-1);
	Vball = AllocSprite();
	if (!Vball)
		Quit(-1);

	Bball->BobVSprite = Vball;
	Vball->VSBob = Bball;

	Vball->Height = HEIGHT;
	Vball->Width = WIDTHW;
	Vball->Depth = DEPTH;
	Vball->X = 0;
	Vball->Y = 0;

kputs("A");
	Vball->ImageData = AllocMem(WIDTHB*HEIGHT*DEPTH,MEMF_CHIP|MEMF_CLEAR);
	if (!Vball->ImageData)
		Quit(-1);
kputs("B");
	for (i=0; i<HEIGHT*WIDTHW; i++)
		for (d = 0; d< DEPTH; d++)
			Vball->ImageData[i*DEPTH+d] = 0xffff;
	Vball->PlanePick = 0x0f;
	Vball->PlaneOnOff = 0x00;

kputs("C");
	Bball->ImageShadow = AllocMem(DEPTH*HEIGHT*WIDTHB,MEMF_CHIP);
	Vball->CollMask = Bball->ImageShadow;
	if (!Vball->CollMask)
		Quit(-1);

	mprintf("'%08lx",Vball->CollMask);
#ifdef LATER
kputs("D");
/* SaveBackground */
	Vball->Flags |= SAVEBACK;
	Bball->SaveBuffer = AllocRaster(WIDTH,HEIGHT*DEPTH);
	if (!Bball->SaveBuffer)
		Quit(-1);
#endif

	Bball->DBuffer = NULL;
kputs("E");
	InitMasks(Vball);

kputs("F");
	AddBob(Bball,rp);
kputs("G");
}

MoveBall()
{
	Vball->Y++;
	return (Vball->X++ < 180);
}

RemoveBall()
{
	if (Bball)
	{
		if (Bball->ImageShadow)
			FreeMem(Bball->ImageShadow,DEPTH*WIDTHB*HEIGHT);
		if (Bball->SaveBuffer)
			FreeRaster(Bball->SaveBuffer,WIDTH,HEIGHT*DEPTH);
		FreeBob(Bball);
	}
	if (Vball)
	{
		if (Vball->ImageData)
			FreeMem(Vball->ImageData,WIDTHB*HEIGHT*DEPTH);
		FreeSprite(Vball);
	}
}
END_OF_FILE
echo Extracting main.c...
cat >main.c <<END_OF_FILE

#include <intuition/intuition.h>
#include <graphics/gels.h>
#include "geltools.h"
#include "test.h"

extern struct NewScreen NewScreenStructure;
extern USHORT Palette[];

struct Screen *Screen = NULL;
struct RastPort *rp;
struct ViewPort *vp;
struct IntutionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;

struct VSprite *head=NULL,*tail=NULL;
struct GelsInfo GInfo;

main()
{
	int i;

	IntuitionBase  = (void *)OpenLibrary("intuition.library",0L);
	if (!IntuitionBase)
		Quit(-1);
	GfxBase  = (struct GfxBase *)OpenLibrary("graphics.library",0L);
	if (!GfxBase)
		Quit(-1);

	NewScreenStructure.Depth = DEPTH;
	Screen = OpenScreen(&NewScreenStructure);
	if (!Screen)
		Quit(-1);
	rp = &Screen->RastPort;
	vp = &Screen->ViewPort;

	LoadRGB4(vp,Palette,(long)sizeof(Palette)/sizeof(USHORT));

	head = AllocSprite();
	if (!head)
		Quit(-1);
	tail = AllocSprite();
	if (!tail)
		Quit(-1);
	rp->GelsInfo = AllocMem((long)sizeof(struct GelsInfo),MEMF_CHIP|MEMF_CLEAR);
	if (!rp->GelsInfo)
		Quit(-1);
	InitGels(head,tail,rp->GelsInfo);

	StartBall(rp);

#define MOVE
#ifdef MOVE
	for (i=0; i<100; i++)
	{
		SortGList(rp);
		DrawGList(rp,vp);
		MoveBall();
	} 
	Delay(100L);
#else
	SortGList(rp);
	DrawGList(rp,vp);
	Delay(100L);
#endif

	Quit(0);
}

Quit(n)
int n;
{
	RemoveBall();
	if (head)
		FreeSprite(head);
	if (tail)
		FreeSprite(tail);
	if (Screen)
	{
		if (Screen->RastPort.GelsInfo)
			FreeMem(Screen->RastPort.GelsInfo,(long)sizeof(struct GelsInfo));
		CloseScreen(Screen);
	}
	if (GfxBase)
		CloseLibrary(GfxBase);
	if (IntuitionBase)
		CloseLibrary(IntuitionBase);
	exit(n);
}
END_OF_FILE
echo Extracting pwwin.c...
cat >pwwin.c <<END_OF_FILE

struct NewScreen NewScreenStructure = {
	0,0,	/* screen XY origin relative to View */
	640,200,	/* screen width and height */
	4,	/* screen depth (number of bitplanes) */
	0,1,	/* detail and block pens */
	SPRITES+HIRES,	/* display modes for this screen */
	CUSTOMSCREEN,	/* screen type */
	NULL,	/* pointer to default screen font */
	NULL,	/* screen title */
	NULL,	/* first in list of custom screen gadgets */
	NULL	/* pointer to custom BitMap structure */
};

#define NEWSCREENSTRUCTURE NewScreenStructure

USHORT Palette[] = {
	0x0BBB,	/* color #0 */
	0x0007,	/* color #1 */
	0x0FFF,	/* color #2 */
	0x0F40,	/* color #3 */
	0x000B,	/* color #4 */
	0x0B0B,	/* color #5 */
	0x00FF,	/* color #6 */
	0x0080,	/* color #7 */
	0x0620,	/* color #8 */
	0x0E50,	/* color #9 */
	0x09F1,	/* color #10 */
	0x0EB0,	/* color #11 */
	0x055F,	/* color #12 */
	0x092F,	/* color #13 */
	0x0FF0,	/* color #14 */
	0x0FC0	/* color #15 */
#define PaletteColorCount 16
};

#define PALETTE Palette


/* end of PowerWindows source generation */
END_OF_FILE
echo Extracting geltools.h...
cat >geltools.h <<END_OF_FILE
#define AllocSprite() (struct VSprite *)AllocMem((long)sizeof(struct VSprite),MEMF_CHIP|MEMF_CLEAR);
#define FreeSprite(p) FreeMem(p,(long)sizeof(struct VSprite));
#define AllocBob() (struct Bob *)AllocMem((long)sizeof(struct Bob),MEMF_CHIP|MEMF_CLEAR);
#define FreeBob(p) FreeMem(p,(long)sizeof(struct Bob));
END_OF_FILE
echo Extracting test.h...
cat >test.h <<END_OF_FILE
#define DEPTH 4
#define HEIGHT 20L
#define WIDTHW 3L
#define WIDTHB (WIDTHW*2)
#define WIDTH (WIDTHW*16)
END_OF_FILE
echo Extracting makefile...
cat >makefile <<END_OF_FILE
CFLAGS=+Ivd0:Inc

OBJ=main.o pwwin.o ball.o
play: $(OBJ)
	ln +q -WT -o play $(OBJ) -lc
END_OF_FILE

cs178abu@sdcc8.ucsd.EDU (John Schultz) (02/25/88)

  I screwed around with the gel routines for a while and found them
to be unacceptably slow.  Furthermore, I didn't have enough control
over those routines to use for fast animation in bizarre view
setups.  Although the initial startup time is longer, you're better
off creating your own simple animation routines custom tailored to
your application. (In my case, generic animation routines for my
video game development system).  The basic routines you'll have to
learn are: BltBitMap() (or Blt(Mask)BitMapRastPort()).  You can do
simple clipping in a few lines of code or attach a cliprect to your
rastport (much slower).  Also, BltMaskBitMapRastPort() is much
slower than the other two blit functions.  If your are blitting many
rectangles, the fastest way to clear the screen is using BltClear()
(SetRast is slower).  If you have a background you must preserve,
you must revert to backup-restore-draw techniques (But there is at
least one other technique you can use on the amiga that is much
faster).
  Again, it is harder to implement at first, but the rewards are
much greater.  And when something hoses up, you know it's your
fault, not the system's.

  John

lindwall@sdsu.UUCP (John Lindwall) (02/25/88)

In article <798@sdcc8.ucsd.EDU>, cs178abu@sdcc8.ucsd.EDU (John Schultz) writes:
>                       If you have a background you must preserve,
> you must revert to backup-restore-draw techniques (But there is at
> least one other technique you can use on the amiga that is much
> faster).

	You do mean Simple Sprites, don't you?  If not, please share your
knowledge with us.

>   Again, it is harder to implement at first, but the rewards are
> much greater.  And when something hoses up, you know it's your
> fault, not the system's.
> 
>   John

JOHN:

keithd@cadovax.UUCP (Keith Doyle) (02/26/88)

In article <5074@pyr.gatech.EDU> davidc%yak@gatech.edu (Dave Corbin) writes:
>		3- When WIDTH is 2L, SOMETHING seems to be trashing 0000.
>			(ThankYou, MemWatch).  (LongWord 0 gets filled with
				   ^^^^^^^^

What the heck's MemWatch?  Sounds useful, where does it come from?

Keith Doyle
#  {ucbvax,decvax}!trwrb!cadovax!keithd  Contel Business Systems 213-323-8170

cs178abu@sdcc8.ucsd.EDU (John Schultz) (02/26/88)

In article <2936@sdsu.UUCP> lindwall@sdsu.UUCP (John Lindwall) writes:
>
>	You do mean Simple Sprites, don't you?  If not, please share your
>knowledge with us.
>
>JOHN:

  No, I mean your own bitmap manager, where you handle all of the
animation.  You can move hardware sprites at will, without worrying
about the background.  VSprites are too slow.  Use hardware sprites
if you don't need too many, and blitobs (your own) if you need
more.
  

   John