home *** CD-ROM | disk | FTP | other *** search
/ APDL Soft Rock Games / APDL_SOFTROCK.iso / trellis / docs / part07 < prev    next >
Encoding:
Text File  |  1999-04-02  |  7.1 KB  |  192 lines

  1.  
  2.                         TRELLIS - The Adventure Interpreter
  3.                       (c) copyright 1991-9 Soft Rock Software
  4.  
  5.                                Speeding The Game Up
  6.                                --------------------
  7.  
  8. The biggest problem you will have with Trellis is speed, or lack of it. For
  9. ease of programming it has been written in Basic, and this means that an
  10. 'interpreted' program is interpreting the TScript program. If you are
  11. familiar with the way programming languages work you will know precisely
  12. what that means. If not, I will tell you: TScript programs are SLOW!
  13.  
  14. If you are using a Risc PC, you will find that speed isn't as much of a
  15. problem as I am claiming. However, you should remember that if you are going
  16. to sell your game the person buying it might be using an older ARM2 based
  17. machine. If it runs with adequate speed on your Risc PC it will probably run
  18. at a snails pace on an unexpanded A3000, for example.
  19.  
  20. The more comprehensive the TScript language becomes, the slower it becomes
  21. to run programs in, since the Basic program has more to look for. By the
  22. same token the more complicated a TScript file becomes, the slower it will
  23. run.
  24.  
  25. One area where speed can be increased is by replacing FNSaid("...") with one
  26. of the variables it accesses. Each word list in your Words file is numbered.
  27. The first line of words is number 1, the second 2, etc. up to the last line,
  28. which is numbered as per the value you placed near the start of the file.
  29.  
  30. The variable you should use is Used_Word%(n) where n is the number of the
  31. word list being checked. When the player enters a command, Trellis scans the
  32. word lists and sets the appropriate variable to either TRUE (-1) if a word
  33. in that list was entered or FALSE (0) if not. So, you could replace
  34.  
  35. IF FNSaid("READ") AND FNSaid("NOTE") THEN
  36. with
  37.  
  38. IF Used_Word%(4) AND Used_Word%(5) THEN
  39. (assuming READ is word 4 and NOTE is word 5)
  40.  
  41. The words that are defined by Trellis are treated in a similar way, but use
  42. a different variable: Used_Command%(n) The appropriate numbers are as
  43. follows:-
  44.  
  45.  Used_Command%(1)  = GET, etc.
  46.  Used_Command%(2)  = TAKE, etc.
  47.  Used_Command%(3)  = NORTH
  48.  Used_Command%(4)  = EAST
  49.  Used_Command%(5)  = SOUTH
  50.  Used_Command%(6)  = WEST
  51.  Used_Command%(7)  = UP
  52.  Used_Command%(8)  = DOWN
  53.  Used_Command%(9)  = INV
  54.  Used_Command%(10) = EXAMINE, etc.
  55.  Used_Command%(11) = LOOK, etc.
  56.  Used_Command%(12) = QUIT, etc.
  57.  Used_Command%(13) = HELP, etc.
  58.  
  59. This increases speed because FNSaid("...") first checks through the word
  60. lists to establish the number of the word given, and whether it is checked
  61. with Used_Word%( ) or Used_Command%( ). It then returns the value of the
  62. appropriate variable. By just checking the value of the appropriate
  63. variable, you are reducing the work that needs to be carried out. Use
  64. FNSaid("...") when you are writing your game, and once it is completed and
  65. working replace all occurrences with the variables. Try to be careful when
  66. making the replacements, however, because it's very easy to put
  67. Used_Command% where Used_Word% should be, or to put the wrong number inside
  68. the brackets.
  69.  
  70. Another way to speed up a TScript program is by employing what would
  71. normally be considered bad programming techniques; a fact that will probably
  72. be criticized in any reviews of Trellis. C'est La Vie.
  73.  
  74. The problem with employing such techniques is that your TScript program will
  75. become a maze of GOTOs, and be difficult to follow. It is worth writing your
  76. program tidily - to make sure it works, etc. - and then, once it is fully
  77. debugged, going through it to replace tidy routines with messy, but faster
  78. ones.
  79.  
  80. If you need to construct a routine that carries out several tasks based on
  81. one conditional result INSIDE an IF block, do not use this:-
  82.  
  83. IF outer_condition THEN
  84.  IF inner_condition THEN first command
  85.  IF inner_condition THEN second command
  86.  etc
  87. END IF
  88.  
  89. The inner_condition will be checked for each line - the more lines, the
  90. slower. Instead use this:-
  91.  
  92. IF NOT outer_condition THEN GOTO nextbit
  93.  IF inner_condition THEN
  94.   all the commands
  95.  END IF
  96. :nextbit
  97.  
  98. It uses a GOTO, which is always considered bad practice, but is much faster.
  99. It has been arranged to at least resemble a nested IF block, which is a
  100. point in its favour. Sometimes, this will not work and you must use a jump
  101. from inside the IF block:-
  102.  
  103. IF outer THEN
  104.  IF inner THEN GOTO morecode
  105.  commands to do if outer TRUE and inner FALSE
  106. ELSE
  107.  commands to do if outer and inner both FALSE
  108. END IF
  109. GOTO restofprogram
  110. :morecode
  111.  commands to do if outer and inner both TRUE
  112. :restofprogram
  113.  the rest of the program.
  114.  
  115. This would normally be considered terrible programming. With Trellis,
  116. however, if it is necessary to do this you should.
  117.  
  118. Another situation where GOTOs can speed up a program is when there are a
  119. whole series of IF's one after the other:-
  120.  
  121. IF condition1 THEN PRINT"something 1"
  122. IF condition2 THEN PRINT"something 2"
  123. IF condition3 THEN PRINT"something 3"
  124. IF condition4 THEN PRINT"something 4"
  125. etc
  126.  
  127. If the conditions are all IF Store%(3)= ??? THEN types, each with a
  128. different location number - perhaps extending the location descriptions -
  129. then all of the conditions will be evaluated, but just one will be found
  130. TRUE and cause something to happen. This will be slow to execute. Do this
  131. instead:-
  132.  
  133. IF condition1 THEN
  134.  PRINT"something 1"
  135.  GOTO nextstage
  136. END IF
  137. IF condition2 THEN
  138.  PRINT"something 2"
  139.  GOTO nextstage
  140. END IF
  141. IF condition3 THEN
  142.  PRINT"something 3"
  143.  GOTO nextstage
  144. END IF
  145. IF condition4 THEN
  146.  PRINT"something 4"
  147.  GOTO nextstage
  148. END IF
  149. etc
  150. :nextstage
  151. rest of program
  152.  
  153. Once one of the conditions is found to be TRUE Trellis will skip the rest -
  154. messy, but effective. The conditions further down the list, however, will
  155. still take a long time to be evaluated because the conditions before them
  156. must first be found to be FALSE. Therefore, put the ones that will be TRUE
  157. more often near the start.
  158.  
  159. Another trick is to check for internal commands (those that you don't have
  160. to include in the words file) that you don't have to help Trellis with and,
  161. if you find one, jump directly to the COMMAND command (!)
  162.  
  163. For example, if none of your doors relate to movement NORTH and SOUTH, use
  164. this right after the INPUT command:-
  165.  
  166. IF FNSaid("NORTH") OR FNSaid("SOUTH") THEN GOTO process_command
  167.  
  168. 'process_command' would be a label immediately before COMMAND.
  169.  
  170. If the software can deal with GET automatically add this to the IF lines
  171. given above:-
  172.  
  173. IF FNSaid("GET") THEN GOTO do_command
  174.  
  175. and so on.
  176.  
  177. If Trellis does need help with a particular command in some cases, but can
  178. deal with other cases automatically - for example, there might be three
  179. doors that allow movement North and South - group the routines that handle
  180. these together, and follow them with appropriate IFs that jump to the
  181. COMMAND routine. Once your routines have been passed by and have not dealt
  182. with the command, control is passed over to Trellis to handle it.
  183.  
  184. The objective is to prevent Trellis running through lots of IF lines that it
  185. won't have to execute, thus speeding up the program.
  186.  
  187. This, of course, is just a small selection of ways to speed up programs
  188. involving lots of IF's. There are other ways - probably including a number I
  189. haven't even thought of!
  190.  
  191. Experiment, and find a method that works best for you.
  192.