Posted: 17th Jul 2003 23:19
Ok, I don't know if everybody already knows this, or doesn't need but I decided to post it anyway. Ok this uses the timer() function as IanM adviced me to do. I couldn't find any example from his web site (Don't know why. Maybe I'm just stupid ) wich propaply contains this same. This should do the thing, thought I'm not 100000000% sure. You can try it by putting thousand lines of "print"s in the source“and noticing that it still runs at the same speed. Or then if you have older computer then try with it. Please post if you notice any bugs! And if it works, post that too! THANX!!! Hope this helps you...


+ Code Snippet
make matrix 1,1000,1000,20,20
randomize matrix 1,50
update matrix 1
make object sphere 1,10
spd#=1
a#=0
st#=timer()
loppu#=0
do
alku#=timer()-st#
if upkey()=1 then move object 1,spd#/10
if downkey()=1 then move object 1,-spd#/10
if leftkey()=1 then a#=a#-spd#/10 ; yrotate object 1,a#
if rightkey()=1 then a#=a#+spd#/10 ; yrotate object 1,a#
set cursor 0,0
print spd#
x#=object position x(1)
z#=object position z(1)
y#=get ground height(1,x#,z#)+4
position object 1,x#,y#,z#
angle#=object angle y(1)
set camera to follow x#,y#,z#,angle#,50,y#+20,20,0
loppu#=timer()-st#
if alku#=loppu#
else
spd#=loppu#-alku#
endif
loop
Posted: 17th Jul 2003 23:29
Oh, and this goes only for PRO, but someone with classic could fix it. It is because I used the Set camera to follow command.
Posted: 17th Jul 2003 23:36
Ok. I added "rem"s and fixed the variable more clearer.


+ Code Snippet
Rem Make A Landscape
make matrix 1,1000,1000,20,20
randomize matrix 1,50
update matrix 1

rem Make the Player
make object sphere 1,10

rem Prepare Variables
spd#=1
a#=0
st#=timer()
end#=0

rem Start Loop
do
rem Get the start time
start#=timer()-st#

rem Cheap movement
if upkey()=1 then move object 1,spd#/10
if downkey()=1 then move object 1,-spd#/10
if leftkey()=1 then a#=a#-spd#/10 ; yrotate object 1,a#
if rightkey()=1 then a#=a#+spd#/10 ; yrotate object 1,a#

rem Prints How long did one loop last
set cursor 0,0
print spd#


rem Camera to Pro, Classic users please make a new one
x#=object position x(1)
z#=object position z(1)
y#=get ground height(1,x#,z#)+4
position object 1,x#,y#,z#
angle#=object angle y(1)
set camera to follow x#,y#,z#,angle#,50,y#+20,30,0

rem gets the end time
end#=timer()-st#

rem If the start time is equal to the end time keep the speed untouched
if start#=end#
else
rem Count the loop time from the start and the and value
spd#=end#-start#
endif
loop
Posted: 17th Jul 2003 23:59
Now I made new camera code and added FPS shower.
Use this!!!
This works in classic too(I think so) and is better in DBpro
(cause with the "set camera to follow" I didn't manage to get the smooth value to match the timer).


+ Code Snippet
Rem Make A Landscape
make matrix 1,1000,1000,20,20
randomize matrix 1,50
update matrix 1

rem Make the Player
make object sphere 1,10

rem Prepare Variables
spd#=1
a#=0
st#=timer()
end#=0

rem Start Loop
do
rem Get the start time
start#=timer()-st#

rem Cheap movement
if upkey()=1 then move object 1,spd#/10
if downkey()=1 then move object 1,-spd#/10
if leftkey()=1 then a#=a#-spd#/10 ; yrotate object 1,a#
if rightkey()=1 then a#=a#+spd#/10 ; yrotate object 1,a#

rem Prints How long did one loop last and FPS"
set cursor 0,0
print "Loop time: ",spd#,", FPS: ",screen fps()

rem Camera
x#=object position x(1)
z#=object position z(1)
y#=get ground height(1,x#,z#)+4
position object 1,x#,y#,z#
angle#=object angle y(1)

position camera x#,y#+20,z#
rotate camera 0,angle#,0
move camera -50
rem gets the end time
end#=timer()-st#

rem If the start time is equal to the end time keep the speed untouched
if start#=end#
else
rem Count the loop time from the start and the and value
spd#=end#-start#
endif
loop