home *** CD-ROM | disk | FTP | other *** search
/ Micro R&D 1 / MicroRD-CD-ROM-Vol1-1994.iso / os30 / gfx / animdemo.lha / Read.Me < prev    next >
Encoding:
Text File  |  1993-01-26  |  11.3 KB  |  343 lines

  1. This file explains what the PlayRaw code does, describes the V39 and AA features
  2. it uses, and the file format used.
  3.  
  4. First, a message from our lawyers:
  5.  
  6. (c) Copyright 1993 Commodore-Amiga, Inc.  All rights reserved.
  7.  
  8. This software is provided as-is and is subject to change; no warranties
  9. are made.  All use is at your own risk.  No liability or responsibility
  10. is assumed.
  11.  
  12. Now, on with the show.
  13.  
  14. The Animation
  15. =============
  16.  
  17. The Animation is an approximately 3300 frame animation, rendered using VistaPro
  18. (with MakePath generating the script). VistaPro was set to save each frame as a
  19. 24bit image. We then ran a rexx script to control ASDG's Art Department, which
  20. loaded each frame, composed a mask of the cockpit on top, converted the frame to
  21. 6 bitplanes with a locked palette, and saved to an anim file with their new
  22. Anim8 saver module.
  23.  
  24. The mask and the cockpit were drawn by an outside contractor.
  25.  
  26. Thanks must go to both Virtual Realities Limited and ASDG for their help, and
  27. to Mr.J.S ;-)
  28.  
  29.  
  30. Anim8
  31. =====
  32.  
  33. Anim8 is a small variation on the commonly used Anim5 format.  Anim5 won't be
  34. described here; see the IFF documentation in 'Amiga RKM - Devices' for more
  35. details.  The problem with Anim5 is that all the data is encoded in bytes.  On a
  36. machine with only CHIP RAM, thare is a serious overhead on byte reads and writes
  37. as the CPU executes wait states during the memory accesses.  Even on a machine
  38. with FAST RAM, the writes still have to go to CHIP RAM.  Anim8 (which has
  39. recently been registered with C=) extends Anim5 by encoding data as either Words
  40. or Longs; all DLTA opcodes and data are stored as WORDS or LONGS.  This means we
  41. can now read and write 2 or 4 times as much information to the CHIP RAM, thus
  42. cutting down on CHIP RAM accesses.  One of the drawbacks is that the animation
  43. may not compress as well as Anim5, but nevertheless the playback is about twice
  44. as fast!
  45.  
  46. The PlayDLTA() code in ilbm.asm is based on Jim Kent's original Anim5 code, but
  47. I have modified it with a few 68020 instructions, optimised it for my animation
  48. by changing the order of the opcode checks, and hard-coded for LONG DLTA
  49. animations.
  50.  
  51. So Beware - this executable requires a 68020 CPU and AA chips at least!
  52.  
  53.  
  54. The file format
  55. ===============
  56.  
  57. To speed up playback, all the IFF header information has been stripped away,
  58. leaving just the raw DLTA data.  This reduces the overhead of IFFParse.  Each
  59. frame is stored separately, and padded out to a whole number of sectors to speed
  60. up the reading.
  61.  
  62. At the beginning of the raw data file is some information, such as image size,
  63. colours, sounds etc. The format of this Frame1Header is defined in playanim.h as:
  64.  
  65. /* Frame1 is the format of the 1st frame of the sequence.
  66.  * This cannot be defined in C, because the structure is of a variable length.
  67.  *
  68.  *
  69.  * struct Frame1Head
  70.  * {
  71.  *    ULONG f1_MaxSectorSize;    // max number of sectors in a frame
  72.  *     ULONG f1_ByteSize;    // number of bytes in this block
  73.  *    ULONG f1_Sectors;    // number of sectors in this block
  74.  *    UWORD f1_ImageWidth;    // number of pixels accross the image
  75.  *    UWORD f1_ImageHeight;    // number of rows in the image
  76.  *    UWORD f1_ImageDepth;    // depth of the image
  77.  *    UWORD f1_ScreenWidth;    // number of pixels accross the screen
  78.  *    UWORD f1_ScreenHeight;
  79.  *    UWORD f1_ScreenDepth;
  80.  *    ULONG f1_ScreenModeID;
  81.  *    UWORD f1_Colours;    // number of colours in the CMAP
  82.  *    UBYTE f1_CMAP[];    // full CMAP structure.
  83.  *    UBYTE f1_ILBM;        // ILBM of frame 1
  84.  *    ULONG f1_NextByteSize;    // number of bytes in the next frame
  85.  *    ULONG f1_NextSectors;    // number of sectors in the next frame
  86.  *      VistaScript Data
  87.  *    UBYTE f1_pads[];    // pad to the next whole sector
  88.  *    AudioData
  89.  * };
  90.  */
  91.  
  92. struct Frame1Head
  93. {
  94.     ULONG f1_MaxSectorSize;
  95.     ULONG f1_ByteSize;
  96.     ULONG f1_Sectors;
  97.     UWORD f1_ImageWidth;    // number of pixels across the image
  98.     UWORD f1_ImageHeight;    // number of rows in the image
  99.     UWORD f1_ImageDepth;    // depth of the image
  100.     UWORD f1_ScreenWidth;    // number of pixels across the screen
  101.     UWORD f1_ScreenHeight;
  102.     UWORD f1_ScreenDepth;
  103.     ULONG f1_ScreenModeID;
  104.     UWORD f1_Colours;
  105. };
  106.  
  107. f1_MaxSectorSize allows us to allocate a memory buffer before we start playing
  108. the animation that is big enough to hold the DLTA data of the largest frame.
  109.  
  110. After f1_Colours, comes the colours themselves, followed by the ILBM (with the
  111. IFF headers stripped off) of the first frame in the animation, which is normal
  112. for anim files.
  113.  
  114. This is followed by the size (in bytes and whole sectors) of the next frame in
  115. the animation. All other frames follow suit; that is, they store the size of the
  116. *next* frame. This allows us to read in each frame with one Read() call, rather
  117. than one read to find it's size, and another read for the data.
  118.  
  119. f1_NextSectors is followed by some data from the VistaPro script, describing the
  120. position of the 'plane in this frame as:
  121.  
  122. struct VistaScript
  123. {
  124.     WORD vs_CamX;
  125.     WORD vs_CamY;
  126.     WORD vs_CamZ;
  127.     WORD vs_Bank;
  128.     WORD vs_Heading;
  129.     WORD vs_Pitch;
  130.     WORD vs_Focal;
  131. };
  132.  
  133. This could be useful for, say, calculating the 'planes position relative to an
  134. enemy aircraft, or a missile.
  135.  
  136. VistaScript is followed by padding to take the byte count up to a whole
  137. SECTORSIZE. There follows two more "frames" of audio data, both 8SVX files (with
  138. the IFF headers removed), both padded to whole SECTORSIZEs, for the missile
  139. audio and the audio for the plane engines.
  140.  
  141. All this is then followed by the animation DLTA frames themselves. The final
  142. frame sets it's NextSectors and NextByteSize to NULL.
  143.  
  144.  
  145. The raw file is built with the 'makeraw' program. 3300 frames is too large to
  146. fit on a floppy disk, so this example code comes with only a few of the frames.
  147.  
  148.  
  149. The Display
  150. ===========
  151.  
  152. The animation is only 6 bitplanes, but we use an 8 bitplane screen to give us
  153. 256 colours. The animation is rendered into the lower 6 bitplanes, but a 'mask'
  154. image is rendered in the upper 2 bitplanes. This mask is the image of the glass
  155. window of the cockpit. Colours 64-128 are set to be about 20% brighter than the
  156. natural colours of the animation. The cockpit mask provides the planes of the
  157. window panes, thus we fake out our own Extra-HalfBrite screen.
  158.  
  159. The animation screen is 320x98x6 Lores.  Attached to this animation screen, is a
  160. screen containing the image of the cockpit interior, which is 640x102x8.  This
  161. is done by using intuition's V39 attached screens.  Thus, if we move one screen,
  162. the other moves with it, giving the appearance of one large multi-coloured
  163. multi-resolution screen.
  164.  
  165. VistaPro was set to render the sky as a purple background.  We then use
  166. FindColor() to determine which colour number this purple sky is in the
  167. animation, and build a UserCopperlist to gradually change the sky's colour
  168. through a range of skyblues.
  169.  
  170. Becuase we need to ensure that the screen which is displaying the animation can
  171. handle both sprites and doublebuffering, we check the graphics database to see
  172. that the desired ModeID has the DisplayInfo->PropertyFlags DIPF_IS_SPRITES and
  173. DIPF_IS_DBUFFER set.  If not, then we use the V39 graphics function BestModeID()
  174. to find a ModeID that does support both these features, and provides the best
  175. aspect ratio for the animation's size.
  176.  
  177. BestModeID() is also used to find the best mode for the cockpit screen to match
  178. the monitor type of the animation screen.
  179.  
  180. We open the screens behind the workbench, so that all our setups are hidden, and
  181. then bring the screens to the front.
  182.  
  183.  
  184. Sprites and input
  185. =================
  186.  
  187. Input comes from two places; the joystick and the keyboard. The joystick is for
  188. moving the cross-hair cursor around and firing the missiles, the keyboard is for
  189. aborting the animation.
  190.  
  191. Input from the joystick comes from reading the joy1dat RGA register. Kinda
  192. naughty I know, but that register will always be around. I should really open
  193. the gameport device.
  194.  
  195. Input from the keyboard comes from intuition, via it's RAWKEY IDCMP message.
  196.  
  197. The cross-hair sprite is intuition's pointer.  In fact, I keep intuition around,
  198. so it's possible to move the cross-hair with both the joystick and the mouse.  I
  199. use intuition's NewOject() to change the imagery of the pointer to the
  200. cross-hair, and change the pointer's hotspot to the center.
  201.  
  202. The input from the joystick is translated into input events, and sent to
  203. input.device, so intuition knows about the pointer position, and does the sprite
  204. movements for me.
  205.  
  206. The missiles are also sprites.  AllocSpriteData() is used to set it up, and
  207. GetExtSprite() to reserve the sprite for our usage.  We use MoveSprite() to move
  208. them.
  209.  
  210.  
  211. Audio
  212. =====
  213.  
  214. All audio is handled through the audio.device. The audio for the missile is
  215. first allocated, and then the two opposite channels for the thruster audio are
  216. allocated to provide stereo. The two thruster chanels use different audio
  217. channels than the missile.
  218.  
  219.  
  220. Note that all the sprite and audio updates are done in the time that the code
  221. would be Wait()ing for the signal to double-buffer, thus maximising use of the
  222. CPU.
  223.  
  224.  
  225. AsyncIO
  226. =======
  227.  
  228. During development of this code, I noticed that a large proportion of the time
  229. was spent CopyMem()ing the double-buffers used in Martin Taillefer's AsyncIO()
  230. code. I hacked the AsyncIO code to reduce the amount of time spent copying
  231. memory. Instead, if all the data requested is in the AsyncIO read buffer, I
  232. point a UBYTE *rbuff variable to the contents of this buffer, and read from
  233. there directly.
  234.  
  235.  
  236.  
  237. Feature list
  238. ============
  239.  
  240. A list of the V39 OS and AA features used in this code:
  241.  
  242. V39 Graphics:
  243. ChangeVPBitMap() et al for double buffering
  244. (an example of how CalcIVG() should be used)
  245. ExtSprite functions.
  246. ...RGB32() functions
  247. FindColor()
  248. BestModeID() and database checking
  249.  
  250. V39 Intuition:
  251. NewObject() POINTERCLASS
  252. Attached screens
  253.  
  254. Other OS feautures:
  255. IFFParse.library
  256. AsyncIO
  257. audio.device
  258. input.device
  259. UserCopperLists
  260.  
  261. AA features:
  262. variable sprite width and resolution
  263. changing the colour banks of sprites.
  264. 8 bitplane screens.
  265. 24bit colours.
  266.  
  267.  
  268. File List
  269. =========
  270.  
  271. playanim.i
  272. playanim.h    ; general header files
  273. sprites.h    ; sprite definitions
  274. stick.i
  275. stick.h        ; joystick and input structures.
  276. asyncio.h    ; asyncio header file
  277.  
  278. playraw.c    ; the main code
  279. input.c        ; handles input events
  280. audio.c        ; handles audio IO
  281. iff.c        ; reads the IFF files
  282. sprites.c    ; handles sprite allocation and movement
  283. spriteimage.c    ; sprite bitmaps
  284. asyncio.c    ; asynchronous file IO
  285. joystick.asm    ; reads the joystick port
  286. ilbm.asm    ; reads ILBMs and Anim8 LONG form DLTAs
  287.  
  288. lmkfile        ; a makefile
  289.  
  290. playraw.o
  291. ilbm.o
  292. asyncio.o
  293. sprites.o
  294. joystick.o
  295. input.o
  296. spriteimage.o
  297. iff.o
  298. audio.o        ; object files
  299.  
  300. Read.Me        ; this file
  301.  
  302. playraw        ; the executable
  303.  
  304. cp.medres    ; the cockpit image
  305. mask1        ; the cockpit window mask for the animation
  306.  
  307.  
  308. makeraw/makeraw.c    ; code to convert the ANIM and 8SVX files into
  309.             ; the raw file format
  310. makeraw/audio.c        ; converts the audio files.
  311. makeraw/lmkfile        ; a makefile
  312. makeraw/thrust2        ; 8SVX file for the thruster audio
  313. makeraw/alienfires    ; 8SVX file for the gun-fire
  314. makeraw/vistascript    ; VistaPro script file
  315. makeraw/anim        ; an ANIM file
  316. makeraw/makeraw.o
  317. makeraw/audio.o        ; object files
  318. makeraw/makeraw        ; the executable
  319.  
  320. Usage
  321. =====
  322.  
  323. To build the raw animation file, from the CLI type
  324.  
  325. cd makeraw
  326. makeraw from anim to anim.raw fit m `eval 0x11000` f alienfires t thrust2 x 2
  327.  
  328.  
  329. To play the animation, from the CLI, type
  330.  
  331. cd /
  332. playraw makeraw/anim.raw c cp.medres m mask1
  333.  
  334. Use the joystick to move the cross-hair.
  335. Fire button to fire missiles.
  336. Any keypress to abort.
  337.  
  338.  
  339. Have Fun!!
  340.  
  341. Spencer Shanson
  342. Amiga Software Engineer.
  343.