home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / new / dev / obero / oberon-a / examples / libraries / graphics / animtools.mod next >
Text File  |  1995-07-02  |  9KB  |  256 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: AnimTools.mod $
  4.   Description: Port of animtools.h and animtools.c
  5.  
  6.                "This file is a collection of tools which are used with
  7.                the VSprite, Bob and Animation system software. It is
  8.                intended as a useful EXAMPLE, and while it shows what
  9.                must be done, it is not the only way to do it.  If Not
  10.                Enough Memory, or error return, each cleans up after
  11.                itself before returning.  NOTE that these routines assume
  12.                a very specific structure to the GEL lists.  Make sure
  13.                that you use the correct pairs together (i.e.
  14.                MakeObj()/FreeObj(), etc.)."
  15.  
  16.    Created by: fjc (Frank Copeland)
  17.     $Revision: 1.1 $
  18.       $Author: fjc $
  19.         $Date: 1995/01/25 23:51:02 $
  20.  
  21.   Copyright © 1995, Frank Copeland.
  22.   This example program is part of Oberon-A.
  23.   See Oberon-A.doc for conditions of use and distribution.
  24.  
  25. *************************************************************************)
  26.  
  27. <* STANDARD- *>
  28.  
  29. MODULE AnimTools;
  30.  
  31. IMPORT Kernel, SYS := SYSTEM, e := Exec, gfx := Graphics, s := Sets;
  32.  
  33. (*
  34. ** These data structures are used by the functions in AnimTools to
  35. ** allow for an easier interface to the animation system.
  36. *)
  37.  
  38. (* Data structure to hold information for a new VSprite *)
  39.  
  40. TYPE
  41.  
  42.   NewVSprite *= RECORD
  43.     image      *: e.APTR;  (* image data for the vsprite  *)
  44.     colorSet   *: e.APTR;  (* color array for the vsprite *)
  45.     wordWidth  *: INTEGER; (* width in words              *)
  46.     lineHeight *: INTEGER; (* height in lines             *)
  47.     imageDepth *: INTEGER; (* depth of the image          *)
  48.     x          *: INTEGER; (* initial x position          *)
  49.     y          *: INTEGER; (* initial y position          *)
  50.     flags      *: s.SET16; (* vsprite flags               *)
  51.     hitMask    *: s.SET16; (* Hit mask.                   *)
  52.     meMask     *: s.SET16; (* Me mask.                    *)
  53.   END; (* NewVSprite *)
  54.  
  55. (* Data structure to$hold information for a new Bob. *)
  56.  
  57. TYPE
  58.  
  59.   NewBob *= RECORD
  60.     image      *: e.APTR;  (* image data for the vsprite  *)
  61.     wordWidth  *: INTEGER; (* width in words              *)
  62.     lineHeight *: INTEGER; (* height in lines             *)
  63.     imageDepth *: INTEGER; (* depth of the image          *)
  64.     planePick  *: s.SET16; (* planes that get image data  *)
  65.     planeOnOff *: s.SET16; (* unused planes to turn on    *)
  66.     bFlags     *: s.SET16; (* bob flags                   *)
  67.     dBuf       *: BOOLEAN; (* TRUE=double buf, FALSE=not  *)
  68.     rasDepth   *: INTEGER; (* depth of the raster         *)
  69.     x          *: INTEGER; (* initial x position          *)
  70.     y          *: INTEGER; (* initial y position          *)
  71.     hitMask    *: s.SET16; (* Hit mask.                   *)
  72.     meMask     *: s.SET16; (* Me mask.                    *)
  73.   END; (* NewBob *)
  74.  
  75. (* Data structure to hold information for a new animation component. *)
  76.  
  77. TYPE
  78.  
  79.   NewAnimComp *= RECORD
  80.     routine *: e.PROC;  (* routine called when Comp is displayed *)
  81.     xt      *: INTEGER; (* initial delta offset position.        *)
  82.     yt      *: INTEGER; (* initial delta offset position.        *)
  83.     time    *: INTEGER; (* initial Timer value.                  *)
  84.     cFlags  *: s.SET16; (* Flags for the Component.              *)
  85.   END; (* NewAnimComp *)
  86.  
  87. (* Data structure to hold information for a new animation sequence. *)
  88.  
  89. TYPE
  90.  
  91.   ImageArray   *= POINTER TO ARRAY OF e.APTR;
  92.   IntegerArray *= POINTER TO ARRAY OF INTEGER;
  93.   RoutineArray *= POINTER TO ARRAY OF e.PROC;
  94.  
  95.   NewAnimSeq *= RECORD
  96.     headOb      *: gfx.AnimOb;   (* common Head of Object.              *)
  97.     images      *: ImageArray;   (* array of Comp image data            *)
  98.     xt          *: IntegerArray; (* arrays of initial offsets.          *)
  99.     yt          *: IntegerArray; (* arrays of initial offsets.          *)
  100.     times       *: IntegerArray; (* array of initial Timer values.      *)
  101.     routines    *: RoutineArray; (* array of fns called when comp drawn *)
  102.     cFlags      *: s.SET16;      (* Flags for the Component.            *)
  103.     count       *: INTEGER;      (* Num Comps in seq (= arrays size)    *)
  104.     singleImage *: BOOLEAN;      (* one (or count) images.              *)
  105.   END; (* NewAnimSeq *)
  106.  
  107.  
  108. (* SetupGelSys (rPort, reserved)
  109. **
  110. ** Setup the GELs system. After this call is made you can use VSprites,
  111. ** Bobs, AnimComps and AnimObs.  Not that this links the GelsInfo
  112. ** structure into the RastPort, and calls InitGels().  It uses
  113. ** information in your RastPort structure to establish boundary collision
  114. ** defaults at the outer edges of the raster.  This routine sets up for
  115. ** everything - collision detection and all.  You must already have run
  116. ** LoadView before ReadyGelSys is called
  117. *)
  118.  
  119. PROCEDURE SetupGelSys *
  120.   ( rPort    : gfx.RastPortPtr;
  121.     reserved : SHORTINT )
  122.   : gfx.GelsInfoPtr;
  123.  
  124.   VAR
  125.     gInfo : gfx.GelsInfoPtr;
  126.     vsHead, vsTail : gfx.VSpritePtr;
  127.  
  128. BEGIN (* SetupGelSys *)
  129.   NEW (gInfo);
  130.   IF gInfo # NIL THEN
  131.     SYS.NEW (gInfo.nextLine, SIZE (INTEGER) * 8);
  132.     IF gInfo.nextLine # NIL THEN
  133.       SYS.NEW (gInfo.lastColor, SIZE (e.APTR) * 8);
  134.       IF gInfo.lastColor # NIL THEN
  135.         NEW (gInfo.collHandler);
  136.         IF gInfo.collHandler # NIL THEN
  137.           NEW (vsHead);
  138.           IF vsHead # NIL THEN
  139.             NEW (vsTail);
  140.             IF vsTail # NIL THEN
  141.               gInfo.sprRsrvd := reserved;
  142.               (* Set left- and top-most to 1 to better keep items *)
  143.               (* inside the display boundaries.                   *)
  144.               gInfo.leftmost := 1; gInfo.topmost := 1;
  145.               gInfo.rightmost := (rPort.bitMap.bytesPerRow * 8) - 1;
  146.               gInfo.bottommost := rPort.bitMap.rows - 1;
  147.               rPort.gelsInfo := gInfo;
  148.               gfx.InitGels (vsHead, vsTail, gInfo);
  149.               RETURN gInfo
  150.             END;
  151.             SYS.DISPOSE (vsHead)
  152.           END;
  153.           SYS.DISPOSE (gInfo.collHandler)
  154.         END;
  155.         SYS.DISPOSE (gInfo.lastColor)
  156.       END;
  157.       SYS.DISPOSE (gInfo.nextLine)
  158.     END;
  159.     SYS.DISPOSE (gInfo)
  160.   END;
  161.   RETURN NIL
  162. END SetupGelSys;
  163.  
  164.  
  165. (* CleanupGelSys (gInfo, rPort)
  166. **
  167. ** Free all of the stuff allocated by SetpGelSys().  Only call this
  168. ** routine if SetupGelSys() returned successfully.  The GelsInfo
  169. ** structure is the one returned by SetupGelSys().  It also unlinks the
  170. ** GelsInfo from the RastPort.
  171. *)
  172.  
  173. PROCEDURE CleanupGelSys *
  174.   ( gInfo : gfx.GelsInfoPtr;
  175.     rPort : gfx.RastPortPtr );
  176.  
  177. BEGIN (* CleanupGelSys *)
  178.   rPort.gelsInfo := NIL;
  179.   SYS.DISPOSE (gInfo.collHandler);
  180.   SYS.DISPOSE (gInfo.lastColor);
  181.   SYS.DISPOSE (gInfo.nextLine);
  182.   SYS.DISPOSE (gInfo.gelHead);
  183.   SYS.DISPOSE (gInfo.gelTail);
  184.   SYS.DISPOSE (gInfo);
  185. END CleanupGelSys;
  186.  
  187.  
  188. (* MakeVSprite (nVSprite)
  189. **
  190. ** Create a VSptrite from the information given in nVSprite.  Use
  191. ** FreeVSprite() to free this GEL.
  192. *)
  193.  
  194.  
  195. (*------------------------------------*)
  196. PROCEDURE MakeVSprite *
  197.   ( VAR nVSprite : NewVSprite )
  198.   : gfx.VSpritePtr;
  199.  
  200.   VAR
  201.     vsprite : gfx.VSpritePtr;
  202.     lineSize : LONGINT;
  203.     planeSize : LONGINT;
  204.  
  205. BEGIN (* MakeVSprite *)
  206.   lineSize := SIZE (INTEGER) * nVSprite.wordWidth;
  207.   planeSize := lineSize * nVSprite.lineHeight;
  208.  
  209.   NEW (vsprite);
  210.   IF vsprite # NIL THEN
  211.     Kernel.Allocate (vsprite.borderLine, lineSize, {e.chip});
  212.     IF vsprite # NIL THEN
  213.       Kernel.Allocate (vsprite.collMask, planeSize, {e.chip});
  214.       IF vsprite.collMask # NIL THEN
  215.         vsprite.y := nVSprite.y;
  216.         vsprite.x := nVSprite.x;
  217.         vsprite.flags := nVSprite.flags;
  218.         vsprite.width := nVSprite.wordWidth;
  219.         vsprite.depth := nVSprite.imageDepth;
  220.         vsprite.height := nVSprite.lineHeight;
  221.         vsprite.meMask := nVSprite.meMask;
  222.         vsprite.hitMask := nVSprite.hitMask;
  223.         vsprite.imageData := nVSprite.image;
  224.         vsprite.sprColors := nVSprite.colorSet;
  225.         vsprite.planePick := {}; vsprite.planeOnOff := {};
  226.         gfx.InitMasks (vsprite);
  227.         RETURN vsprite
  228.       END;
  229.       SYS.DISPOSE (vsprite.borderLine)
  230.     END;
  231.     SYS.DISPOSE (vsprite)
  232.   END;
  233.   RETURN NIL
  234. END MakeVSprite;
  235.  
  236.  
  237. (* FreeVSp