home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sys / amiga / demos / 1707 < prev    next >
Encoding:
Text File  |  1992-11-17  |  5.2 KB  |  123 lines

  1. Newsgroups: alt.sys.amiga.demos
  2. Path: sparky!uunet!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!sifon!charnel!rat!usc!wupost!csus.edu!netcom.com!netcomsv!ntg!ewhac
  3. From: ewhac@ntg.com (Leo 'Bols Ewhac' Schwab)
  4. Subject: Re: Writing a StarField. Which method is best?
  5. Message-ID: <1992Nov17.211753.11335@ntg.com>
  6. Summary: Critique
  7. Organization: Politically Incorrect Software, Ltd.
  8. References: <1992Nov7.104910.60476@cc.usu.edu> <1992Nov11.131803.1276@ifi.uio.no>
  9. Date: Tue, 17 Nov 1992 21:17:53 GMT
  10. Lines: 111
  11.  
  12. In article <1992Nov11.131803.1276@ifi.uio.no> larshaug@ifi.uio.no (Lars Haugseth) writes:
  13. >Here is a small 3D-stars routine, with sine-table and all...
  14.  
  15.     Not to denigrate Lars' contribution to the community, but I thought
  16. I'd try to make a few (hopefully constructive) comments on the coding style.
  17. I've noticed a variety of practices in this and other pieces of demo code
  18. which cause me to sit back and go, "Why?"
  19.  
  20. >No flames about coding-technique, please. After all, this is
  21. >alt.sys.amiga.DEMOS ;-)
  22. >
  23.     Well, okay, but my philosophy in writing demos and hacks was to
  24. learn how the system worked, and then be able to make constructive use of
  25. that knowledge later, without getting bitten in the future.  Although some
  26. of my *old* stuff made some invalid assumptions and looks ugly in some
  27. configurations, they all still work (even "Viacom," the most brutal of the
  28. lot).
  29.  
  30.     Part of this was following the programming standards.  Another was
  31. writing code I felt was readable by myself and others.  Both of these are
  32. religious issues to be sure, but what I'd like to point out below are just a
  33. few simple things that I believe would help make demo code much easier to
  34. write, *read*, maintain, and share.  (I like to share my stuff, you see;
  35. that's why I believe it's important.)
  36.  
  37. >START    move.l    4.w,a6
  38. >    move.l    156(a6),a1
  39.         ^^^
  40.     Okay.  Why isn't this a symbolic offset?  That is, why didn't you
  41. say:
  42.  
  43.     move.l    IntVects+6*IV_SIZE+IV_DATA(a6),a1
  44.  
  45.     Granted, this is more verbose, but it tells me exactly what you're
  46. fetching; the iv_Data field from the seventh interrupt vector in ExecBase.
  47. However, the real weirdness comes in with:
  48.  
  49. >    move.l    38(a1),OLDCP
  50.  
  51.     Translated, this is:
  52.  
  53.     move.l    gb_copinit(a1),OLDCP
  54.  
  55.     Basically, what the programmer has done is dive into the Exec
  56. interrupt tables, pull out the iv_Data field from the "Blitter finished"
  57. interrupt structure, made the *assumption* that this pointer is maintained
  58. by Graphics and points to GfxBase, then fetches the copinit pointer from
  59. GfxBase and saves it for later restoration.
  60.  
  61.     Excuse me but:        Ack!
  62.  
  63.     Why didn't you just open graphics.library?  Yes, it takes slightly
  64. more code and is slower, but it gets executed only once, and you are
  65. guaranteed that you will always get a pointer to GfxBase.  Future versions
  66. of Graphics may (and probably will) put a completely different pointer in
  67. the interrupt vector.  What if some other program in the system has made use
  68. of that vector (which is perfectly legal)?  Poof! you die.
  69.  
  70. >    bsr    SBUFFER
  71. >    bsr    VBLANK
  72. >    move.l    #COPPER,$DFF080
  73.             ^^^^^^^
  74.     Again, why not a symbolic offset?  I don't have the custom hardware
  75. addresses memorized (sorry).  On the other hand, if you had said:
  76.  
  77.     move.l    #COPPER,_cop1lc
  78.  
  79.     I'd know what you were doing without hunting through my RKM.
  80.  
  81.     I'm also the kinda guy who would suggest using Graphics to create
  82. three Views rather than using a custom hard-coded copper list.
  83.  
  84.     [Actually, I have a theory about how one might incorporate such
  85. copper lists into Intuition displays, but I haven't actually tried it out
  86. yet...]
  87.  
  88. >    move.w    #$7FFF,$DFF09A        [ Disable all interrupts ]
  89.  
  90.     ARGH!  Why?  It's a STARFIELD!  It's not like you're modifying
  91. system lists or trying to DMA hard disk data at breakneck speeds.  So why
  92. put the system at risk?  Besides, I might be trying to download more demos
  93. :-).
  94.  
  95.     Example:  CDTV's CD-ROM device driver (cdtv.device) is written in
  96. such a way that multitasking and interrupts *must* remain alive.  The CD-ROM
  97. drive communicates with CDTV via interrupts.  If they are turned off for any
  98. great length of time, cdtv.device will either DIE completely, or lose sync
  99. with the CD-ROM drive and force it to reset (which takes *4* seconds).
  100.  
  101.     Speaking entirely personally, I'd really prefer not to kill the
  102. system for a few extra stars.
  103.  
  104. --------
  105.     However, lest you think I'm only here to bash Euro coders to a pulp,
  106. I think the core algorithm is interesting, and I'll probably spend a fair
  107. amount of time studying it.  Also, there's nothing preventing a persnickety
  108. compatibility freak (like me :-) ) from diving in and making it live more
  109. peacefully with the system (at the cost of some stars).
  110.  
  111.     While I realize these are merely demos and not intended to be
  112. paragons of Perfect Programming Practice, I personally believe there are
  113. acceptable tradeoffs between RAW UNADULTERATED SPEED and "nice" code.
  114.  
  115.     These are, of course, suggestions, and are completely ignorable.
  116. The demos aren't any less interesting to watch.
  117.  
  118. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  119. Leo L. Schwab -- The Guy in The Cape                    ewhac@ntg.com
  120.  \_ -_          Recumbent Bikes:                ..or..  ewhac@well.sf.ca.us
  121. O----^o       The Only Way To Fly.                     (pronounced "EH-wack")
  122.  "Work FOR?  I don't work FOR anybody!  I'm just having fun."  -- The Doctor
  123.