Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / How can I stop programs slowing down?

Author
Message
Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 18th Oct 2002 22:03
I often give up on projects because I cannot do what I want at a reasonable speed. Whenever I make a program that can do more that just a simple task, the frame rate slows right down.
Note: I still use DB v1.11 enhanced
Does anyone have suggestions about how I can write my programs so that they run as fast as possible?
Any tips will be greatly appreciated.
Hotshot
21
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 18th Oct 2002 22:12
If u tell us what simple task u making then we will able to help ya.

cheer

Hotshot

Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 18th Oct 2002 22:26
It hasn't happened that recently, but here's my best example:

I once wrote this program (which was supposed to run at 30 fps). It slowed down to 1 fps eventually (and even that was a struggle). When I removed ALL collision detection it managed 15 fps. The main loop was made up of lots of gosub commands which did all the other stuff.

The program was basically first person, where you move around a jail cell and escape by blowing the wall up (that was pretty much it apart from a cool (for a newbie) weather effect).
Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 18th Oct 2002 22:28
Actually, this program slows down:

`initial values

invertm=1
target_fps=20

sync rate target_fps
sync on
autocam off
hide mouse
disable escapekey




`summon arrays
`communication text
dim mancom$(3)

`emotions
dim emotions(10)
`0=happiness (value negative if sad)
`1=
`2=

`load media - note initial sizes: mannequin=170, hoverbot=25.3, penguin=0.775

`objex
load object "mannequin.x",1
load object "stereo.x",4
load object "chair1.x",5
load object "lamp.x",6
load object "tv.x",7
load object "tree.x",8
load object "sofa.x",9
load object "bookcas1.x",10
load object "book6.x",11
load object "book6.x",12
load object "desk.x",14
load object "book5.x",15




`images
load image "stars.bmp",1
load image "ceramic.bmp",2
load image "clock.bmp",3
load image "grass.bmp",4


`construct world
`mannequin
scale object 1,5,5,5
position object 1,25,0,50
set object 1,1,1,0
yrotate object 1,45


`clock
make object cube 2,4
position object 2,100,10,100
texture object 2,3
xrotate object 2,180

`mannequin text positioner
make object sphere 3,1
hide object 3

`stereo
scale object 4,400,400,400
position object 4,25,3,100

`chair
scale object 5,350,350,350
position object 5,15,3,80
yrotate object 5,90

`desk
scale object 14,200,200,200
position object 14,5,3,80
yrotate object 14,270

`book
scale object 15,400,400,400
position object 15,6,5.75,78
xrotate object 15,100
zrotate object 15,90

`lamp
position object 6,50,4,50
scale object 6,400,400,400
yrotate object 6,45

color ambient light rgb(255,192,128)
make light 1
position light 1,50,10,50
color light 1,255,128,0

`television
position object 7,95,0,10
scale object 7,1244,700,700
yrotate object 7,135

`tree
position object 8,15,6,15
scale object 8,400,400,400

`sofa
position object 9,72.5,3,32.5
yrotate object 9,315
scale object 9,800,800,800

`bookcase
position object 10,2,5,65
scale object 10,400,400,400
yrotate object 10,270

position object 11,2,5,65
position object 12,2,6.5,65


for i = 11 to 12
scale object i,300,300,300
xrotate object i,90
zrotate object i,90
next i

`matrix
make matrix 1,100,100,10,10
prepare matrix texture 1,2,1,1
update matrix 1

`backdrop
texture backdrop 1




`MAIN LOOP!!!!
DO

if options=0

gosub camera_control

gosub animate_world

gosub user_interact

gosub communication

gosub bot_mind

gosub over_display

if escapekey() then wait 100: options=1

endif

if options=1

gosub world_options
if escapekey() then wait 100: options=0

endif


sync
LOOP


`SUBROUTINES!!!!!!!

`CAMERA CONTROL
camera_control:


`invert mouse
if invertm=1 and inkey$()="i" then invertm=0: wait 100
if invertm=0 and inkey$()="i" then invertm=1: wait 100


`forward/backward
if upkey()=1 then move camera 1
if downkey()=1 then move camera -1

`turning
yrotate camera wrapvalue(camera angle y()+mousemovex())
if invertm=1 then xrotate camera wrapvalue(camera angle x()-mousemovey())
if invertm=0 then xrotate camera wrapvalue(camera angle x()+mousemovey())

if camera angle x()<180 and camera angle x()>90 then xrotate camera 90
if camera angle x()>180 and camera angle x()<270 then xrotate camera 270


`position variables
posx# = camera position x()
posy# = camera position y()
posz# = camera position z()

`keep within confines
if posx#<0.5 then posx#=0.5
if posx#>99.5 then posx#=99.5
if posz#<0.5 then posz#=0.5
if posz#>99.5 then posz#=99.5

`stay on ground
posy# = get ground height(1,posx#,posz#)+8-(4*controlkey())

`strafe
side=rightkey()-leftkey()

posx#=posx#+side*sin(camera angle y()+90)
posz#=posz#+side*cos(camera angle y()+90)


position camera posx#,posy#,posz#

if inkey$()="l" then point camera object position x(1), object position y(1)+8, object position z(1)

return

`ANIMATE WORLD
animate_world:

`backdrop
bx# = bx#+2*mousemovex()
by# = by#-2*mousemovey()

scroll backdrop bx#,by#

`clock
yrotate object 2,wrapvalue(object angle y(2)+1)



return

`USER INTERACTION
user_interact:

`stereo
if cdtrack <1 then cdtrack=1

` text 1,120, str$(object screen x(4))+" "+str$(object screen y(4))
if object screen x(4) <= 326 and object screen x(4) >= 314
if object screen y(4) <= 246 and object screen y(4) >= 234
if mouseclick()=1 then interact$="stereo"
endif
endif

if interact$="stereo"
center text 320,100,"CD Player Menu"
center text 320,150,"(P)lay"
center text 320,170,"(S)top"
center text 320,190,"P(a)use"
center text 320,210,"(R)esume"
center text 320,230,"(N)ext Track"
center text 320,250,"Pre(v)ious Track"
center text 320,280,"E(x)it menu"


if lower$(inkey$())="n" then inc cdtrack: wait 100
if lower$(inkey$())="v" then dec cdtrack: wait 100

if lower$(inkey$())="p"
if music exist(1) then delete music 1
load cdmusic cdtrack,1
play music 1
interact$=""
endif

if music exist(1)
if lower$(inkey$())="s" then stop music 1: interact$=""
if lower$(inkey$())="a" then pause music 1: interact$=""
if lower$(inkey$())="r" then resume music 1: interact$=""
if lower$(inkey$())="x" then interact$=""
endif
endif


return

`COMMUNICATION
communication:


` communication 'bubble'
position object 3,object position x(1),object position y(1)+9, object position z(1)



return


`BOT MIND
bot_mind:



return


`OVER-DISPLAY
over_display:

`pointer
ink rgb(255,128,0),0

box 319,239,321,241
circle 320,240,2

ink rgb(255,255,255),0

set text font "Arial"
set text size 12
`position
text 1,1,str$(camera position x())+" "+str$(camera position z())
text 1,30,str$(screen fps())

`clocktime
if object in screen(2)=1
center text object screen x(2),object screen y(2)-10,get time$()
endif

`mannequin com
if object in screen(3)=1
center text object screen x(3),object screen y(3)-10,mancom$(1)
endif

if object in screen(3)=0 and mancom$<>""
text 1,90, "Mannequin: "+mancom$(1)
endif

`stereo/cd player
if object in screen(4)=1
center text object screen x(4),object screen y(4)-20,"Tr"+str$(cdtrack)
circle object screen x(4),object screen y(4),6
endif


return

`WORLD OPTIONS
world_options:

box mousex()-1,mousey()-1,mousex()+1,mousey()+1
circle mousex(),mousey(),2

center text 320,100,"WORLD OPTIONS"

center text 320,150, "Target Framerate: "+str$(target_fps)
center text 320,170, "Inverted Mouse: "+str$(invertm)

if mouseclick()=1

if mousey()>140 and mousey()<160
inc target_fps,10
if target_fps > 60 then target_fps=10
wait 100
endif

if mousey()>160 and mousey()<180
if invertm=0 then a=1
if invertm=1 then a=0

invertm=a
wait 100
endif



endif

if escapekey()
sync rate target_fps

endif

return
Obear
21
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 18th Oct 2002 23:16
Just out of Interest what are your system specs??

Processor

Ram

Graphics Card.

Milamber
21
Years of Service
User Offline
Joined: 27th Sep 2002
Location: Australia
Posted: 19th Oct 2002 16:08
Lots of polygons will always slow a program down, as will lots of collision commands. There are a few other eccentricities with certain commands that run slowly (eg color object makes the program run slower than texture object) but other than that, you're using the original DB, which uses an interpreter, not a compiler, so practically everything should run slower than the equivalent DBPro code. At this time, please note I said SHOULD. Bugs are causing some major slowdowns in DBPro FOR THE MOMENT.

System Specs: AMD Athlon 1700+ XP, GA-7VRX motherboard, 128MB DDR RAM, GeForce2 MX400 64MB VRAM
Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 21st Oct 2002 21:41
Pentium II
64 megs ram
Not sure about graphics card - is this it: ATI XPERT 98D AGP 2X ?

I'm not really sure how to find out these details

Login to post a reply

Server time is: 2024-04-19 02:29:31
Your offset time is: 2024-04-19 02:29:31