home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / Libraries / SAT / SATTP.p < prev   
Encoding:
Text File  |  1994-12-24  |  12.1 KB  |  263 lines  |  [TEXT/CWIE]

  1. unit SAT;
  2.  
  3. interface
  4.  
  5.     type
  6.         {BMPtr = ^BitMap;}
  7.  
  8.         FacePtr = ^Face;
  9.         Face = record
  10.                 colorData: Ptr;
  11.                 resNum: integer;
  12.                 iconMask: BitMap;
  13.                 rowBytes: integer;
  14.                 next: FacePtr;
  15.                 maskRgn: RgnHandle;
  16.             end;
  17.  
  18.         SpritePtr = ^Sprite;
  19.         Sprite = record
  20. { Variables that you should change as appropriate }
  21.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  22.                 position: Point;
  23.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  24.                                     {hotRect is set by you. hotRect2 is offset to the current position.}
  25.                 face: FacePtr;            { Pointer to the Face (appearance) to be used. }
  26.                 task: ProcPtr;            { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  27.                 hitTask: ProcPtr;        { Callback in collisions. }
  28.                 destructTask: ProcPtr;    { Called when a sprite is disposed. (Usually nil.) }
  29.                 clip: RgnHandle;            {Clip region to be used when this sprite is drawn.}
  30. { SAT variables that you shouldn't change: }
  31.                 oldpos: Point;                {Used by RunSAT2}
  32.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  33.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  34.                 oldFace: FacePtr;            {Used by RunSAT2}
  35.                 dirty: Boolean;            {Used by RunSAT2}
  36. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  37. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  38. {after initializing (before any sprites are created)!}
  39.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  40.                 speed: Point; { Can be used for speed, but not necessarily. }
  41.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  42.                 appPtr: Ptr; {Pointer for use by the application - i.e. pointer to extra data}
  43.                 appLong: Longint; {Longint for free use by the application.}
  44.             end;
  45.  
  46. {Type for SATs pattern utilities.}
  47.     type
  48.         SATPattern = record
  49.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  50.                 thePat: PixPatHandle; {or PatHandle}
  51.             end; {record}
  52.         SATPatPtr = ^SATPattern;
  53.         SATPatHandle = ^SATPatPtr;
  54.  
  55. {Update list. Used internally}
  56.         UpdatePtr = ^UpdateRec;
  57.         UpdateRec = record
  58.                 updateRect: Rect;
  59.                 next: UpdatePtr;
  60.             end;
  61.  
  62. {The globals record. Some fields are important for you. These are marked with *}
  63.         SATglobalsRec = record
  64.                 wind: WindowPtr;                            {*The window that SAT draws in. }
  65.                 offSizeH, offSizeV: integer;                    {*Offscreen size, used to limit sprite positions}
  66.                 offScreen: GrafPtr;                            {*Offscreen image }
  67.                 backScreen: GrafPtr;                        {*Background image }
  68.                 offScreenGD, backScreenGD: GDHandle;    {GDevices for offScreen and backScreen.}
  69.  
  70.                 ox, oy: longint;                                {Internal}
  71.                 pict, bwpict: integer;                        {PICT id's}
  72.                 fitThePICTs: boolean;                        {Resize PICTs to fit?}
  73.                 sorting: integer;                                {Chosen sorting}
  74.                 collision: integer;                            {Chosen collision handling}
  75.                 searchWidth: integer;                        {Chosen search width}
  76.                 device: GDHandle;                            {Chosen screen}
  77.                 screen: PixMapHandle;                        {Internal}
  78.                 bounds: Rect;                                    {Internal}
  79.                 initDepth: Integer;                            {*Depth at last icon initialization}
  80.                 synchHook: ProcPtr;                            {Synch procedure}
  81.                 sRoot: SpritePtr;                                {Sprite list root}
  82.                 updateRoot: UpdatePtr;                        {Update list root}
  83.                 anyMonsters: Boolean;                        {*False when no sprites with kind < -1 are active }
  84.  
  85.                 ditherOff: CGrafPtr;                            {Internal}
  86.                 ditherOffGD: GDHandle;                        {Internal}
  87.                 iconPort: CGrafPtr;                            {Internal}
  88.                 iconPortGD: GDHandle;                        {Internal}
  89.                 iconPort2: CGrafPtr;                        {Internal}
  90.                 iconPort2GD: GDHandle;                        {Internal}
  91.                 bwIconPort: GrafPtr;                         {Internal}
  92. {Environment-independent globals:}
  93.                 faceRoot: FacePtr;                    {Root of face list}
  94.                 colorFlag: Boolean;                    {True if color QuickDraw is available.}
  95. {Blitters! You should not change these fields yourself.}
  96.                 rectBlit1, maskBlit1: ProcPtr; {Supplied - this is either RBlt/MBlt 0 or 1}
  97.                 rectBlit2, maskBlit2: ProcPtr; {Will probably never be used}
  98.                 rectBlit4, maskBlit4: ProcPtr; {Supplied}
  99.                 rectBlit8, maskBlit8: ProcPtr; {Supplied}
  100.                 rectBlit16, maskBlit16: ProcPtr; {Not supplied}
  101.                 rectBlit32, maskBlit32: ProcPtr; {Not supplied}
  102.                 curRectBlit, curMaskBlit: ProcPtr; {Currently selected fast blitter}
  103.             end;
  104.  
  105. {Configuration types: VPositionSort and KindCollision are defaults.}
  106.     const
  107. {Sorting options}
  108.         kVPositionSort = 0;
  109.         kLayerSort = 1;
  110.         kNoSort = 2;
  111. {Collision detection options}
  112.         kKindCollision = 0;
  113.         kForwardCollision = 1;
  114.         kBackwardCollision = 2;
  115.         kNoCollision = 3;
  116.         kForwardOneCollision = 4;
  117.  
  118.     var
  119. {$J+}
  120.         gSAT: SATglobalsRec;                {Most globals in a record. See above.}
  121.         gSATSoundErrorProc: ProcPtr;        {Pointer to procedure to call on sound error.}
  122. {$J-}
  123.  
  124. {Initializing and customizing}
  125.     procedure SATConfigure (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  126.     procedure SATInit (pictID, bwpictID, Xsize, Ysize: integer);
  127.     procedure SATCustomInit (pictID, bwpictID: integer; SATdrawingArea: Rect; {}
  128.                                     preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  129.                                     centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);
  130. {Maintainance, background manipulation etc.}
  131.     function SATDepthChangeTest: Boolean;
  132.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  133.     procedure SATRedraw;
  134. {Drawing}
  135.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: GrafPtr; theGDevice: GDHandle;{}
  136.                                     where: Point; fast: boolean);
  137.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; fast: boolean);
  138.     procedure SATCopyBits (src, dest: GrafPtr; destGD: GDHandle; {}
  139.                                     srcRect, destRect: Rect; fast: Boolean);
  140.     procedure SATCopyBitsToScreen (src: GrafPtr; srcRect, destRect: Rect; fast: Boolean);
  141.     procedure SATBackChanged (r: Rect); {Tell SAT about changes in backScreen}
  142. {SetPort replacements}
  143.     procedure SATGetPort (var port: GrafPtr; var device: GDHandle);
  144.     procedure SATSetPort (port: GrafPtr; device: GDHandle);
  145.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  146.     procedure SATSetPortBackScreen; {Use before using QuickDraw on backScreen}
  147.     procedure SATSetPortScreen; {Use to set port to gSAT.wind}
  148. {Basic sprite handling}
  149.     function SATGetFace (resNum: integer): FacePtr;
  150.     procedure SATDisposeFace (theFace: FacePtr);
  151.     function SATNewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  152.     function SATNewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  153.     procedure SATKillSprite (who: Spriteptr);
  154. {Animating}
  155.     procedure SATRun (fast: Boolean); {The heart of the whole package!}
  156.     procedure SATRun2 (fast: Boolean); {Alternate routine for allowing resting sprites}
  157. {Special functions for advanced programmers}
  158.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  159.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  160.     procedure SATSetSpriteRecSize (theSize: longint);
  161.     procedure SATSkip;
  162.     procedure SATKill; {Dispose of offscreen buffers to allow re-init}
  163. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  164.     procedure SATMakeOffscreen (var portP: GrafPtr; rectP: Rect; var retGDevice: GDHandle); {Make offscreen buffer in current screen depth and CLUT.}
  165.     procedure SATDisposeOffScreen (var portP: GrafPtr; theGDevice: GDHandle); {Get rid of offscreen}
  166.     function CreateOffScreen (bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  167.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  168. {Face manipulation (for advanced programmers)}
  169.     procedure SATSetPortMask (theFace: FacePtr);
  170.     procedure SATSetPortFace (theFace: FacePtr);
  171.     procedure SATSetPortFace2 (theFace: FacePtr);
  172.     function SATNewFace (faceBounds: Rect): FacePtr;
  173.     procedure SATChangedFace (theFace: FacePtr);
  174.  
  175. {Old names, kept for compatibility with old programs}
  176. {To use them, include SATold.p in the project and de-comment the declarations below.}
  177. {***}
  178. {function GetFace (resNum: integer): FacePtr;}
  179. {procedure DisposeFace (theFace: FacePtr);}
  180. {function NewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;}
  181. {function NewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;}
  182. {procedure KillSprite (who: SpritePtr);}
  183. {function NewFace (faceBounds: Rect): FacePtr;}
  184. {procedure ChangedFace (theFace: FacePtr);}
  185. {procedure PeekOffscreen; {Old name for SATRedraw}
  186. {procedure ConfigureSAT (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);}
  187. {procedure InitSAT (pictID, bwpictID, Xsize, Ysize: integer);}
  188. {procedure CustomInitSAT (pictID, bwpictID: integer; SATdrawingArea: Rect; {}
  189. {preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  190. {centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);}
  191. {procedure SkipSAT;}
  192. {procedure RunSAT (fast: Boolean);}
  193. {procedure KillSAT;}
  194.  
  195. {New procedures, EXPERIMENTAL, intended for making a C++ interface}
  196.     function SATGetFacePP (resNum: integer; fStorage: Ptr): FacePtr;
  197.     function SATNewSpritePP (afterthis: SpritePtr; sStorage: Ptr; theKind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  198.     procedure SATCopySprite (destSprite: SpritePtr; srcSprite: SpritePtr);
  199.     function SATNewFacePP (faceBounds: Rect; fStorage: Ptr): FacePtr;
  200.     procedure SATCopyFace (destFace: FacePtr; srcFace: FacePtr);
  201.     procedure SATDisposeFacePP (theFace: FacePtr);
  202.  
  203.  
  204. {Cicn utilities}
  205.     function SATGetCicn (cicnId: integer): CIconHandle;
  206.     procedure SATPlotCicn (theCicn: CIconHandle; dest: GrafPtr; destGD: GDHandle; r: Rect); {Borde jag lägga till device?}
  207.     procedure SATDisposeCicn (theCicn: CIconHandle);
  208.  
  209. {Utilities}
  210.     procedure SATSetStrings (ok, yes, no, quit, memerr, noscreen, nopict, nowind: Str255);
  211.     function SATTrapAvailable (theTrap: Integer): Boolean;
  212.     procedure DrawInt (i: integer);
  213.     procedure DrawLong (l: longint);
  214.     function Rand (n: integer): integer;
  215.     function Rand10: integer;
  216.     function Rand100: integer;
  217.     procedure ReportStr (str: str255);
  218.     function QuestionStr (str: str255): Boolean;
  219.     function SATFakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton, cancelButton: integer;{}
  220.                                     t1, t2, t3: Str255): integer;
  221.     procedure CheckNoMem (p: Ptr); {If the Ptr is nil, out of memory emergency exit}
  222.     procedure SetMouse (where: point);
  223. {Pattern utilities}
  224.     procedure SATPenPat (SATpat: SATPatHandle);
  225.     procedure SATBackPat (SATpat: SATPatHandle);
  226.     function SATGetPat (patID: integer): SATPatHandle;
  227.     procedure SATDisposePat (SATpat: SATPatHandle);
  228. {Menu bar utilities}
  229.     procedure SATShowMBar;
  230.     procedure SATHideMBar (wind: WindowPtr);
  231. {PICT utilities}
  232.     procedure SATGetandDrawPICTRes (id: integer);
  233.     procedure SATGetandDrawPICTResInRect (id: integer; frame: Rect);
  234.     procedure SATGetandCenterPICTResInRect (id: integer; frame: Rect);
  235. {Sound}
  236.     procedure SATSoundInit; {Called from SATInit}
  237.     procedure SATSoundPlay (TheSound: Handle; Priority: integer; CanWait: boolean);
  238.     procedure SATSoundEvents; {Call this once in a while when not calling SATRun often}
  239.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  240.     procedure SATSoundOn;
  241.     procedure SATSoundOff;
  242.     function SATSoundDone: Boolean; {Any sound going on ?}
  243.     function SATGetSound (sndId: integer): handle;        { To load a sound and get a handle for SATSoundPlay }
  244.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  245.     procedure SATDisposeSound (theSnd: handle);
  246. {Multi-channel sound routines}
  247.     function SATSoundInitChannels (num: integer): integer;
  248.     function SATSoundDoneChannel (chanNum: integer): Boolean;
  249.     procedure SATSoundPlayChannel (theSound: Handle; chanNum: integer);
  250.     procedure SATSoundReserveChannel (chanNum: integer; reserve: Boolean);
  251.     procedure SATSoundShutupChannel (chanNum: integer);
  252.     procedure SATPreloadChannels;
  253. {Experimental, likely to be renamed/removed/changed:}
  254.     procedure SATSoundPlay2 (theSound: Handle; priority: integer; canWait, skipIfSame: Boolean);
  255.     procedure SATSoundPlayEasy (theSound: Handle; canWait: Boolean);
  256. {More multi-channel:}
  257.     function SATGetNumChannels: integer;
  258.     function SATGetChannel (chanNum: integer): Ptr;
  259. {Customization}
  260.     procedure SATSetSoundInitParams (params: Longint);
  261.  
  262. implementation
  263. end.