home *** CD-ROM | disk | FTP | other *** search
- (*************************************************************************
-
- $RCSfile: AnimTools.mod $
- Description: Port of animtools.h and animtools.c
-
- "This file is a collection of tools which are used with
- the VSprite, Bob and Animation system software. It is
- intended as a useful EXAMPLE, and while it shows what
- must be done, it is not the only way to do it. If Not
- Enough Memory, or error return, each cleans up after
- itself before returning. NOTE that these routines assume
- a very specific structure to the GEL lists. Make sure
- that you use the correct pairs together (i.e.
- MakeObj()/FreeObj(), etc.)."
-
- Created by: fjc (Frank Copeland)
- $Revision: 1.1 $
- $Author: fjc $
- $Date: 1995/01/25 23:51:02 $
-
- Copyright © 1995, Frank Copeland.
- This example program is part of Oberon-A.
- See Oberon-A.doc for conditions of use and distribution.
-
- *************************************************************************)
-
- <* STANDARD- *>
-
- MODULE AnimTools;
-
- IMPORT Kernel, SYS := SYSTEM, e := Exec, gfx := Graphics, s := Sets;
-
- (*
- ** These data structures are used by the functions in AnimTools to
- ** allow for an easier interface to the animation system.
- *)
-
- (* Data structure to hold information for a new VSprite *)
-
- TYPE
-
- NewVSprite *= RECORD
- image *: e.APTR; (* image data for the vsprite *)
- colorSet *: e.APTR; (* color array for the vsprite *)
- wordWidth *: INTEGER; (* width in words *)
- lineHeight *: INTEGER; (* height in lines *)
- imageDepth *: INTEGER; (* depth of the image *)
- x *: INTEGER; (* initial x position *)
- y *: INTEGER; (* initial y position *)
- flags *: s.SET16; (* vsprite flags *)
- hitMask *: s.SET16; (* Hit mask. *)
- meMask *: s.SET16; (* Me mask. *)
- END; (* NewVSprite *)
-
- (* Data structure to$hold information for a new Bob. *)
-
- TYPE
-
- NewBob *= RECORD
- image *: e.APTR; (* image data for the vsprite *)
- wordWidth *: INTEGER; (* width in words *)
- lineHeight *: INTEGER; (* height in lines *)
- imageDepth *: INTEGER; (* depth of the image *)
- planePick *: s.SET16; (* planes that get image data *)
- planeOnOff *: s.SET16; (* unused planes to turn on *)
- bFlags *: s.SET16; (* bob flags *)
- dBuf *: BOOLEAN; (* TRUE=double buf, FALSE=not *)
- rasDepth *: INTEGER; (* depth of the raster *)
- x *: INTEGER; (* initial x position *)
- y *: INTEGER; (* initial y position *)
- hitMask *: s.SET16; (* Hit mask. *)
- meMask *: s.SET16; (* Me mask. *)
- END; (* NewBob *)
-
- (* Data structure to hold information for a new animation component. *)
-
- TYPE
-
- NewAnimComp *= RECORD
- routine *: e.PROC; (* routine called when Comp is displayed *)
- xt *: INTEGER; (* initial delta offset position. *)
- yt *: INTEGER; (* initial delta offset position. *)
- time *: INTEGER; (* initial Timer value. *)
- cFlags *: s.SET16; (* Flags for the Component. *)
- END; (* NewAnimComp *)
-
- (* Data structure to hold information for a new animation sequence. *)
-
- TYPE
-
- ImageArray *= POINTER TO ARRAY OF e.APTR;
- IntegerArray *= POINTER TO ARRAY OF INTEGER;
- RoutineArray *= POINTER TO ARRAY OF e.PROC;
-
- NewAnimSeq *= RECORD
- headOb *: gfx.AnimOb; (* common Head of Object. *)
- images *: ImageArray; (* array of Comp image data *)
- xt *: IntegerArray; (* arrays of initial offsets. *)
- yt *: IntegerArray; (* arrays of initial offsets. *)
- times *: IntegerArray; (* array of initial Timer values. *)
- routines *: RoutineArray; (* array of fns called when comp drawn *)
- cFlags *: s.SET16; (* Flags for the Component. *)
- count *: INTEGER; (* Num Comps in seq (= arrays size) *)
- singleImage *: BOOLEAN; (* one (or count) images. *)
- END; (* NewAnimSeq *)
-
-
- (* SetupGelSys (rPort, reserved)
- **
- ** Setup the GELs system. After this call is made you can use VSprites,
- ** Bobs, AnimComps and AnimObs. Not that this links the GelsInfo
- ** structure into the RastPort, and calls InitGels(). It uses
- ** information in your RastPort structure to establish boundary collision
- ** defaults at the outer edges of the raster. This routine sets up for
- ** everything - collision detection and all. You must already have run
- ** LoadView before ReadyGelSys is called
- *)
-
- PROCEDURE SetupGelSys *
- ( rPort : gfx.RastPortPtr;
- reserved : SHORTINT )
- : gfx.GelsInfoPtr;
-
- VAR
- gInfo : gfx.GelsInfoPtr;
- vsHead, vsTail : gfx.VSpritePtr;
-
- BEGIN (* SetupGelSys *)
- NEW (gInfo);
- IF gInfo # NIL THEN
- SYS.NEW (gInfo.nextLine, SIZE (INTEGER) * 8);
- IF gInfo.nextLine # NIL THEN
- SYS.NEW (gInfo.lastColor, SIZE (e.APTR) * 8);
- IF gInfo.lastColor # NIL THEN
- NEW (gInfo.collHandler);
- IF gInfo.collHandler # NIL THEN
- NEW (vsHead);
- IF vsHead # NIL THEN
- NEW (vsTail);
- IF vsTail # NIL THEN
- gInfo.sprRsrvd := reserved;
- (* Set left- and top-most to 1 to better keep items *)
- (* inside the display boundaries. *)
- gInfo.leftmost := 1; gInfo.topmost := 1;
- gInfo.rightmost := (rPort.bitMap.bytesPerRow * 8) - 1;
- gInfo.bottommost := rPort.bitMap.rows - 1;
- rPort.gelsInfo := gInfo;
- gfx.InitGels (vsHead, vsTail, gInfo);
- RETURN gInfo
- END;
- SYS.DISPOSE (vsHead)
- END;
- SYS.DISPOSE (gInfo.collHandler)
- END;
- SYS.DISPOSE (gInfo.lastColor)
- END;
- SYS.DISPOSE (gInfo.nextLine)
- END;
- SYS.DISPOSE (gInfo)
- END;
- RETURN NIL
- END SetupGelSys;
-
-
- (* CleanupGelSys (gInfo, rPort)
- **
- ** Free all of the stuff allocated by SetpGelSys(). Only call this
- ** routine if SetupGelSys() returned successfully. The GelsInfo
- ** structure is the one returned by SetupGelSys(). It also unlinks the
- ** GelsInfo from the RastPort.
- *)
-
- PROCEDURE CleanupGelSys *
- ( gInfo : gfx.GelsInfoPtr;
- rPort : gfx.RastPortPtr );
-
- BEGIN (* CleanupGelSys *)
- rPort.gelsInfo := NIL;
- SYS.DISPOSE (gInfo.collHandler);
- SYS.DISPOSE (gInfo.lastColor);
- SYS.DISPOSE (gInfo.nextLine);
- SYS.DISPOSE (gInfo.gelHead);
- SYS.DISPOSE (gInfo.gelTail);
- SYS.DISPOSE (gInfo);
- END CleanupGelSys;
-
-
- (* MakeVSprite (nVSprite)
- **
- ** Create a VSptrite from the information given in nVSprite. Use
- ** FreeVSprite() to free this GEL.
- *)
-
-
- (*------------------------------------*)
- PROCEDURE MakeVSprite *
- ( VAR nVSprite : NewVSprite )
- : gfx.VSpritePtr;
-
- VAR
- vsprite : gfx.VSpritePtr;
- lineSize : LONGINT;
- planeSize : LONGINT;
-
- BEGIN (* MakeVSprite *)
- lineSize := SIZE (INTEGER) * nVSprite.wordWidth;
- planeSize := lineSize * nVSprite.lineHeight;
-
- NEW (vsprite);
- IF vsprite # NIL THEN
- Kernel.Allocate (vsprite.borderLine, lineSize, {e.chip});
- IF vsprite # NIL THEN
- Kernel.Allocate (vsprite.collMask, planeSize, {e.chip});
- IF vsprite.collMask # NIL THEN
- vsprite.y := nVSprite.y;
- vsprite.x := nVSprite.x;
- vsprite.flags := nVSprite.flags;
- vsprite.width := nVSprite.wordWidth;
- vsprite.depth := nVSprite.imageDepth;
- vsprite.height := nVSprite.lineHeight;
- vsprite.meMask := nVSprite.meMask;
- vsprite.hitMask := nVSprite.hitMask;
- vsprite.imageData := nVSprite.image;
- vsprite.sprColors := nVSprite.colorSet;
- vsprite.planePick := {}; vsprite.planeOnOff := {};
- gfx.InitMasks (vsprite);
- RETURN vsprite
- END;
- SYS.DISPOSE (vsprite.borderLine)
- END;
- SYS.DISPOSE (vsprite)
- END;
- RETURN NIL
- END MakeVSprite;
-
-
- (* FreeVSprite (vsprite)
- **
- ** Free the data created by MakeVSprite(). Assumes images deallocated
- ** elsewhere.
- *)
-
- PROCEDURE FreeVSprite * ( vsprite : gfx.VSpritePtr );
-
- VAR
- lineSize : LONGINT;
- planeSize : LONGINT;
-
- BEGIN (* FreeVSprite *)
- SYS.DISPOSE (vsprite.borderLine);
- SYS.DISPOSE (vsprite.collMask);
- SYS.DISPOSE (vsprite);
- END FreeVSprite;
-
- END AnimTools.
-