Optimisation is the true art of programming. Pretty much anyone can make a game that looks good in DBPro if they have the artistic talent, but making it run fast enough to play is an art form.
Two key DB engine issues you can apply are replacing the main do...loop with a for...next loop as thus:
for a=1 to 3
a=a-1
next a
for next loops have no break check in DB and consequently run faster. I think this might have been done to speed up the debugger but I dont really know as I dont use that.
However the most significant speed gain that is easy to achieve is reducing the number of texture files per object. An object which has 7 or 8 texture files rather than 1 composite image with all the textures on runs very slowly by comparison within DB.
Obviously in most cases it is impossible to do this with the world/level object, but it is possible to reduce the quantity of texture images.
The principle optimisation in my own games is born from two methodologies. Firstly exclusive statements:
If...else...endIf
Much code does not need testing if another condition is true.
if upkey()
else
if downkey()
endIf
endIf
In the above example the down key is only tested when the up key is not pressed, lets explore the concept a little further.
if upkey()
speed=speed+acceleration
if speed>topSpeed then speed=topSpeed
else
if downkey()
speed=speed-acceleration
if speed<0 then speed=0
endIf
endIf
Now you will notice that the maximum speed is only tested when the speed is increased because it is part of the if upkey() structure, likewise the stationary speed check is also only tested when the player is decelerating.
The use of if...else...endif is a critical key to developing optimised code. My own code is heavily structured in this way and often results in large sections of massively indented code.
Another trick is to learn the speeds of various commands. Do you know which method of clearing the screen is faster?
ink 0,0
box 0,0,screen width(),screen height()
or
cls 0
You might be suprised

Try it at a few resolutions. Understanding how long it takes to perform given tasks will help you to know when to include a prefixing structured if test to determine whether a task should be completed, or whether it is faster to just perform the task.
Learn the speed of commands with a simple timed loop test.
rem Wait for DB to finish initialising
wait 2000
rem Make a not of the time
time=timer()
rem do a test
for test=1 to 10000
cls 0
next test
rem display the results, lowest wins.
print timer()-time
When positioning an object often the object number we require is calculated, ie:
position object enemy+100,object position x(enemy+100),object position y(enemy+100),object position (enemy+100)+1
In this instance it would be faster to precalculate the enemy object number
enemyObj=enemy+100
position object enemyObj,object position x(enemyObj),object position y(enemyObj),object position (enemyObj)+1
One final point in reading above, I saw this range test:
distancebetween2objects#=sqrt((ob1x#-ob2x#)^2+(ob1y#-ob2y#)^2+(ob1z#-ob2z#)^2)
The technique the poster mentions is very wise also and a good one, but it can be further optimised because square route mathematics are very slow for 3D range testing.
If you would care to look at my Programmers Resource on my web page (
http://www.bansheestudios.com) there you will find a method for range testing using vector mathematics. This is nearly twice the speed and equally accurate.
I hope these help.
Pneumatic Dryll
