home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17883 < prev    next >
Encoding:
Internet Message Format  |  1992-12-12  |  5.2 KB

  1. Path: sparky!uunet!spool.mu.edu!wupost!cs.utexas.edu!tamsun.tamu.edu!tamsun.tamu.edu!news
  2. From: pinky@tamu.edu (The Man Behind The Curtain)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Criticisms Wanted:Callbacks&Runtime methods
  5. Date: 12 Dec 1992 22:36:46 -0600
  6. Organization: Texas A&M University
  7. Lines: 103
  8. Sender: ski8032@tamsun.tamu.edu
  9. Message-ID: <1geekuINNml9@tamsun.tamu.edu>
  10. References: <1gc6fhINN6nr@tamsun.tamu.edu> <1992Dec12.154030.1342@ucc.su.OZ.AU>
  11. NNTP-Posting-Host: tamsun.tamu.edu
  12. Keywords: callbacks C++ Runtime methods
  13.  
  14. Thus spake maxtal@extro.ucc.su.OZ.AU (John MAX Skaller):
  15. >In article <1gc6fhINN6nr@tamsun.tamu.edu> pinky@tamu.edu (The Man Behind The Curtain) writes:
  16. >>
  17. >> [..runtime determination of methods..]
  18. >>
  19. >>But these capabilities are useful, and even necessary when you try
  20. >>to model the real world.  For instance, might double click a key, and
  21. >>then select from the screen any object to try to unlock with the key,
  22. >>be it a bear, bush, or door.  These classes are mostly unrelated, but
  23. >>in order to be able even attempt the operation, the base class of such
  24. >>objects must at least have method for unlocking.  If objects can
  25. >>interact in a wide variety of ways (a large number of verbs), then
  26. >>the base class would contain an unweildy number of virtual functions.
  27. >
  28. >    So put in all those methods! It is not expensive per object,
  29. >only per class. I know exactly what you are talking about, having
  30. >spent some months preparing a quote for a D&D game. There is
  31. >a simple set of properties, but the objects all have different
  32. >combinations of them. The interactions of different weapons,
  33. >wielded by different characters against different classes of
  34. >monsters is complex, and it cannot be easily generalised.
  35.  
  36. Yes, that's my problem.  But I would like to try to avoid the
  37. class complexity which you mention, by encoding into each class
  38. only those methods which belong.  You are right about not being
  39. easily generalized -- one ends up trying to impliment a kind
  40. of 'naive physics.'
  41.  
  42. >    One approach is to emulate the dynamism that C++ lacks.
  43. >For while C++ is essentially static, it provides the low level
  44. >tools to implement much more powerful systems.
  45. That's what I'm trying to do.
  46.  
  47. >    For example, you can suuply to each object a linked
  48. >list of attributes: asking if an object has the attribute
  49. >'can be unlocked' is then simple to implement (scan the list
  50. >for the attribute name 'unlockable'.
  51.  
  52. But the overhead for such scanning would be prohibitive.  True,
  53. one could impliment it as a set (something I played with for
  54. a while).  But I didn't like the additional memory requirements
  55. then, which simply duplicated information which could possibly
  56. be extracted in code.  I may decide that the space overhead is
  57. trivial.
  58.  
  59. >    The static alternative is to make all objects
  60. >unlockable, except some have probability of sucess 0 with
  61. >any key.
  62. That's one approach.  But for 'cleanliness' I'd like to have that
  63. zero probability implicit.
  64.  
  65. >    The third approach is to use Smalltalk :-)
  66.  
  67. That's a possibility.  But given the choice of using Smalltalk and
  68. implimenting these easily, but then trying to coax it into acceptable
  69. performance, and using C++ and painfully implimenting similar
  70. dynamics in the classes which need it and taking performance hits
  71. only when necessary, I think I'll pick C++. 
  72.  
  73. >You will note that your problem cannot be solved 'properly' no matter
  74. >what you do, since it requires nonexistant multimethods, that is, the effect
  75. >of putting some key in some door cannot in general be computed
  76. >with virtual functions: it depends on the exact type of the two objects.
  77. >The only way to do it in general is with a very large lookup table.
  78. >To avoid this, simplifiying assumptions are required: some general code
  79. >and some special cases.
  80.  
  81. Actually, I don't believe that this is true.  Vaguely, I recall a paper
  82. presented at OOPSLA '91 which described Multimethods in a Static-
  83. Typing System.  Theoretically at least, it is possible, but I haven't
  84. had much success in implimenting it--apparently I would have to
  85. go down to the compiler level.
  86.  
  87. >    For example, all swords work the same way, they just have
  88. >different probabilities of hitting, penetration and damage.
  89. >Multiplication and addition of numbers is the most general
  90. >mechanism I can think of, along with a few special cases.
  91. >
  92. >    (Whenever a Dragon Slayer is used on a Dragon, triple
  93. >damage results and the dragon loses er fire for two rounds,
  94. >provided the damage was to the head .... )
  95.  
  96. While I can currently impliment the simple sword, and even the
  97. DragonSlayer (with some cooperation between the sword & the dragon--
  98. both must know of their own existance, the sword to triple its
  99. damage and the dragon to inhibit its fire) what I can't impliment
  100. is a dynamic addition of methods.  For instance, if one disguises
  101. one's self as a guard, the method isGuard() would be added to
  102. the class, but the way that I do it now, this is only possible
  103. if I verb(isGuard); to begin with, and implimented ..::isGuard(void) {
  104. return 0; }.  In order to be able to do such things, I would need
  105. to go with the set idea that you expressed earlier.
  106.  
  107. > JOHN (MAX) SKALLER
  108.  
  109. Thank you for your very thoughtful and informative post!
  110.  
  111.  
  112. -- 
  113. Till next time,                \o/   \o/
  114.                                 V \o/ V     email:pinky@tamu.edu
  115. <>  Sam  Inala  <>                 V
  116.  
  117.