home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / tech / animatio.txt < prev    next >
Text File  |  1985-09-11  |  5KB  |  99 lines

  1.  3-Sep-85 17:07:58-PDT,5533;000000000005
  2. Return-Path: <oster%ucblapis.CC@Berkeley>
  3. Received: from UCB-VAX.ARPA by SUMEX-AIM.ARPA with TCP; Tue 3 Sep 85 17:07:09-PDT
  4. Received: from ucbjade.Berkeley.Edu (ucbjade.ARPA) by UCB-VAX.ARPA (4.24/5.3) id AA08875; Tue, 3 Sep 85 17:03:12 pdt
  5. Received: from ucblapis.Berkeley.Edu (ucblapis.ARPA) by ucbjade.Berkeley.Edu (4.19/4.38.2) id AA04885; Tue, 3 Sep 85 17:06:10 pdt
  6. Received: by ucblapis.Berkeley.Edu (4.19/4.38.1) id AA19147; Tue, 3 Sep 85 17:06:00 pdt
  7. Date: Tue, 3 Sep 85 17:06:00 pdt
  8. From: oster%ucblapis.CC@Berkeley
  9. Message-Id: <8509040006.AA19147@ucblapis.Berkeley.Edu>
  10. To: info-mac@sumex-aim.ARPA
  11. Subject: Flicker-free animation on the mac.
  12.  
  13. When you do animation, you show the viewer successive frames at a rate high
  14. enough that the viewer percieves the successive frames as continuous motion.
  15. At the movies, you just show successive frames.  On the computer the frame to
  16. frame transition is a little more complex:  You draw a frame, erase it, and
  17. draw the next.  This is ususally optimized to:  You draw a frame, undraw the
  18. parts that change, and draw the parts that change in the next.
  19.  
  20. If the viewer can percieve the undrawn state, the viewer will call your
  21. animation "flickery".  The flicker problem of animation is to hide the frame to
  22. frame transition from the viewer.  A movie projector hides the frame to frame
  23. transition by concealing the film with a shutter while it is moving the film.
  24.  
  25. On a TV set, the picture is drawn by sweeping an electron beam across the
  26. surface of a cathode ray tube in many horizontal scan lines.  If you look
  27. closely at the Mac screen, you can see the scan line structure.  The Mac
  28. picture tube, in order to take advantage of the mass production of the TV
  29. industry, follows the TV convention of only drawing while the beam moves from
  30. left to right, and drawing each scan line below the previous one.  (I don't
  31. know why TV was not designed to scan in alternate directions on alternate scan
  32. lines and draw scan lines top down in one frame and bottom up in the next.  I
  33. just know it doesn't.) The beam is deflected by magnetic fields (or electric
  34. fields on some older sets).  These fields behave as if they had inertia - they
  35. can not be changed instantaneously.  It takes time to bring the beam back to
  36. the position of the start of the next scan line.  During that time the Mac can
  37. make multiple changes to screen memory, and only the cumulative results of
  38. those changes will be seen by the viewer.
  39.  
  40. The Mac circuitry generates an interrupt at the end of each horizontal scan
  41. line and at the end of each frame.
  42.  
  43. During the horizontal sync interrupt, while the electron beam is moving back
  44. from the right edge of the screen to the left, the Mac may send a byte to the
  45. speaker and the floppy motor.  The horizontal retrace is completed very
  46. quickly, so there isn't time to do much.
  47.  
  48. During the vertical sync interrupt, while the electron beam is moving from the
  49. lower right corner to the upper left corner, the Mac executes procedures in its
  50. vertical retrace queue.  There are system calls for adding and removing
  51. procedures from the queue.
  52.  
  53. The standard vertical interrupt procedure increments a global variable called
  54. Ticks, a longInt at location $16A.  If you pause in you screen modification
  55. loop until this changes, your screen modification loop will be synched to the
  56. video.
  57.  
  58. (Don't depend on $16A for the time.  As I discovered when I wrote my menu bar
  59. clock desk accessory, the value drifts slightly so that after ten hours, it
  60. will be a minute or two slow.)
  61.  
  62. Synching to the video may not be good enough.  If your graphics commands take
  63. more than about 1/128th second to execute, they will still be in progress while
  64. the beam is scanning out the picture, and syncing to the video will just have
  65. traded you intermitant flicker for continuous flicker.  The other way of hiding
  66. the changes from the viewer is to hide the changes from the viewer - draw where
  67. the viewer can't see them and them quickly put them on the screen.  There are
  68. two ways to do this:
  69.  
  70. 1.) Use the Mac's alternate screen.  There is a bit on the Mac's VIA chip that
  71. changes which memory locations are shown on the screen.  You draw on the hidden
  72. one, and when you are done, you make it visible and draw the next frame on the
  73. other one.  The viewer never sees drawing in progress.  This method has
  74. problems:
  75.  
  76. a.) The stack is right in the middle of the alternate video page.  To begin to
  77. use it, you must move the stack out of the way, and when you are done, move the
  78. stack back.  (There is a parameter to the Launch system call so that when the
  79. program exits, the cleaning up will be done for you, but the only way to use
  80. that parameter is to write one program that launches a second one, so its
  81. pretty useless.)
  82.  
  83. b.) It takes 22k of memory.  Any program that uses the alternate video probably
  84. won't run on a thin Mac, because there probably isn't room.
  85.  
  86. c.) The Mac XL doesn't have an alternate video page and future Macs probably
  87. won't.
  88.  
  89. The second method is the one I prefer:
  90.  
  91. 2.) Do your drawing off screen and use CopyBits when you are done.  Allocate a
  92. new GrafPort, and change the .bitMap field to point to a new bitMap that you
  93. have allocated elsewhere than in screen memory.  Copy the portion of the screen
  94. that is going to change into it, make the changes, and copy it back.  If the
  95. new bitMap is aligned to a byte boundary on the screen, the transfers are very
  96. fast.
  97.  
  98. -- David Oster, THE unknown hacker.
  99.