home *** CD-ROM | disk | FTP | other *** search
-
- TRELLIS - The Adventure Interpreter
- (c) copyright 1991-9 Soft Rock Software
-
- Speeding The Game Up
- --------------------
-
- The biggest problem you will have with Trellis is speed, or lack of it. For
- ease of programming it has been written in Basic, and this means that an
- 'interpreted' program is interpreting the TScript program. If you are
- familiar with the way programming languages work you will know precisely
- what that means. If not, I will tell you: TScript programs are SLOW!
-
- If you are using a Risc PC, you will find that speed isn't as much of a
- problem as I am claiming. However, you should remember that if you are going
- to sell your game the person buying it might be using an older ARM2 based
- machine. If it runs with adequate speed on your Risc PC it will probably run
- at a snails pace on an unexpanded A3000, for example.
-
- The more comprehensive the TScript language becomes, the slower it becomes
- to run programs in, since the Basic program has more to look for. By the
- same token the more complicated a TScript file becomes, the slower it will
- run.
-
- One area where speed can be increased is by replacing FNSaid("...") with one
- of the variables it accesses. Each word list in your Words file is numbered.
- The first line of words is number 1, the second 2, etc. up to the last line,
- which is numbered as per the value you placed near the start of the file.
-
- The variable you should use is Used_Word%(n) where n is the number of the
- word list being checked. When the player enters a command, Trellis scans the
- word lists and sets the appropriate variable to either TRUE (-1) if a word
- in that list was entered or FALSE (0) if not. So, you could replace
-
- IF FNSaid("READ") AND FNSaid("NOTE") THEN
- with
-
- IF Used_Word%(4) AND Used_Word%(5) THEN
- (assuming READ is word 4 and NOTE is word 5)
-
- The words that are defined by Trellis are treated in a similar way, but use
- a different variable: Used_Command%(n) The appropriate numbers are as
- follows:-
-
- Used_Command%(1) = GET, etc.
- Used_Command%(2) = TAKE, etc.
- Used_Command%(3) = NORTH
- Used_Command%(4) = EAST
- Used_Command%(5) = SOUTH
- Used_Command%(6) = WEST
- Used_Command%(7) = UP
- Used_Command%(8) = DOWN
- Used_Command%(9) = INV
- Used_Command%(10) = EXAMINE, etc.
- Used_Command%(11) = LOOK, etc.
- Used_Command%(12) = QUIT, etc.
- Used_Command%(13) = HELP, etc.
-
- This increases speed because FNSaid("...") first checks through the word
- lists to establish the number of the word given, and whether it is checked
- with Used_Word%( ) or Used_Command%( ). It then returns the value of the
- appropriate variable. By just checking the value of the appropriate
- variable, you are reducing the work that needs to be carried out. Use
- FNSaid("...") when you are writing your game, and once it is completed and
- working replace all occurrences with the variables. Try to be careful when
- making the replacements, however, because it's very easy to put
- Used_Command% where Used_Word% should be, or to put the wrong number inside
- the brackets.
-
- Another way to speed up a TScript program is by employing what would
- normally be considered bad programming techniques; a fact that will probably
- be criticized in any reviews of Trellis. C'est La Vie.
-
- The problem with employing such techniques is that your TScript program will
- become a maze of GOTOs, and be difficult to follow. It is worth writing your
- program tidily - to make sure it works, etc. - and then, once it is fully
- debugged, going through it to replace tidy routines with messy, but faster
- ones.
-
- If you need to construct a routine that carries out several tasks based on
- one conditional result INSIDE an IF block, do not use this:-
-
- IF outer_condition THEN
- IF inner_condition THEN first command
- IF inner_condition THEN second command
- etc
- END IF
-
- The inner_condition will be checked for each line - the more lines, the
- slower. Instead use this:-
-
- IF NOT outer_condition THEN GOTO nextbit
- IF inner_condition THEN
- all the commands
- END IF
- :nextbit
-
- It uses a GOTO, which is always considered bad practice, but is much faster.
- It has been arranged to at least resemble a nested IF block, which is a
- point in its favour. Sometimes, this will not work and you must use a jump
- from inside the IF block:-
-
- IF outer THEN
- IF inner THEN GOTO morecode
- commands to do if outer TRUE and inner FALSE
- ELSE
- commands to do if outer and inner both FALSE
- END IF
- GOTO restofprogram
- :morecode
- commands to do if outer and inner both TRUE
- :restofprogram
- the rest of the program.
-
- This would normally be considered terrible programming. With Trellis,
- however, if it is necessary to do this you should.
-
- Another situation where GOTOs can speed up a program is when there are a
- whole series of IF's one after the other:-
-
- IF condition1 THEN PRINT"something 1"
- IF condition2 THEN PRINT"something 2"
- IF condition3 THEN PRINT"something 3"
- IF condition4 THEN PRINT"something 4"
- etc
-
- If the conditions are all IF Store%(3)= ??? THEN types, each with a
- different location number - perhaps extending the location descriptions -
- then all of the conditions will be evaluated, but just one will be found
- TRUE and cause something to happen. This will be slow to execute. Do this
- instead:-
-
- IF condition1 THEN
- PRINT"something 1"
- GOTO nextstage
- END IF
- IF condition2 THEN
- PRINT"something 2"
- GOTO nextstage
- END IF
- IF condition3 THEN
- PRINT"something 3"
- GOTO nextstage
- END IF
- IF condition4 THEN
- PRINT"something 4"
- GOTO nextstage
- END IF
- etc
- :nextstage
- rest of program
-
- Once one of the conditions is found to be TRUE Trellis will skip the rest -
- messy, but effective. The conditions further down the list, however, will
- still take a long time to be evaluated because the conditions before them
- must first be found to be FALSE. Therefore, put the ones that will be TRUE
- more often near the start.
-
- Another trick is to check for internal commands (those that you don't have
- to include in the words file) that you don't have to help Trellis with and,
- if you find one, jump directly to the COMMAND command (!)
-
- For example, if none of your doors relate to movement NORTH and SOUTH, use
- this right after the INPUT command:-
-
- IF FNSaid("NORTH") OR FNSaid("SOUTH") THEN GOTO process_command
-
- 'process_command' would be a label immediately before COMMAND.
-
- If the software can deal with GET automatically add this to the IF lines
- given above:-
-
- IF FNSaid("GET") THEN GOTO do_command
-
- and so on.
-
- If Trellis does need help with a particular command in some cases, but can
- deal with other cases automatically - for example, there might be three
- doors that allow movement North and South - group the routines that handle
- these together, and follow them with appropriate IFs that jump to the
- COMMAND routine. Once your routines have been passed by and have not dealt
- with the command, control is passed over to Trellis to handle it.
-
- The objective is to prevent Trellis running through lots of IF lines that it
- won't have to execute, thus speeding up the program.
-
- This, of course, is just a small selection of ways to speed up programs
- involving lots of IF's. There are other ways - probably including a number I
- haven't even thought of!
-
- Experiment, and find a method that works best for you.
-