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 / Speeding up your code

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 24th Aug 2004 17:29
I thought it would be interesting to start up a thread with general tips on speeding programs up and coding efficiently. I guess this is a very wide area, but I'm sure lots of people here have some simple tips that would apply to most programs.

For example - I realised just today by reading through some of the archives, that there can be a number of things in your game loop that don't need updating every single cycle - like the calculations for slow moving objects for example. By setting these things to update once every 10 or 20 loops, say, I guess that would speed things up a fair bit.

So - the ball is rolling - add your insight!!


The Videogameaholic
20
Years of Service
User Offline
Joined: 20th Jul 2004
Location: Blackfield Asylum
Posted: 24th Aug 2004 17:44
I remember I was messing around with something when I first started. The behind-the-scenes array calculations were going plenty fast but then when it came to drawing the information to the screen my fps went way down. I found out it was in the "get image" command. I used a couple of little images instead of one big image and my fps increased by like 60. Getting large images takes a long time so only update the parts you need to. Don't know if that helps, but w/e...

RMPVG (Real Men Play Video Games)
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 24th Aug 2004 23:45
Hey - good tip! I'll remember that one.


BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Aug 2004 01:22 Edited at: 25th Aug 2004 01:23
"Multiplexing" is the word you are looking for. It's good for stats, scores etc.

The basics are as follows:

1. Decide on a suitable number of cycles. This may depend on the number of outputs. For example a display with score, speed, energy and ammo may be split into 4 cycles.

2. Create a counter that counts up every loop, and resets to 1 when it reaches the maximum:



2. Create a simple case statement:



Now, each section only gets updated every 4 cycles. This cuts the stats update code to 25% per cycle, but you would still be updating, for example, 10 times a second at 40 FPS.

BatVink
http://biglaugh.co.uk/catalog AMD 3000+ Barton, 512Mb Ram, 120 Gig Drive space, GeForce 5200 FX 128 Mb, Asus A7N8X Mobo.
Terms & Conditions apply
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 27th Aug 2004 02:48
Two questions about reducing poly counts:

1. Is the poly count which affects the program speed influenced by objects off the screen, or just on screen? In other words, is there any speed advantage in using 'hide object' or 'delete object' for objects that are already off the screen?

2. Is there a way of reducing the number of rows/columns in an object for when it is in the distance - like for example when you use 'make object sphere 1,5,20,20' representing a sphere with 20 rows by 20 columns, is there a way to change it to 10 rows by 10 columns for when it's not close enough for you to notice the difference - or would you have to delete and recreate the object to do this? Or does DBPro automatically reduce the poly count for you when its in the distance?

Thanks.


Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 28th Aug 2004 10:09
Well - I've got the answer to the first question - hiding objects does speed things up quite a lot.

The second question - whether there's a simple way to reduce the number of polygons of an object as it moves into the distance - I think the answer must be no. Unless anyone knows better!


hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 28th Aug 2004 12:33
Did you check out the speed tip thread that JessTicular posted? It's full of good ideas.

http://forum.thegamecreators.com/?m=forum_view&t=32948&b=10

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 2nd Sep 2004 08:55
Thanks Hyrichter - I just read it. Good thread.


Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 4th Sep 2004 22:51
Just remember that's for DBC but most of them will work for DBP as well anyway.

Also, one of the main things that speeds up code is using a For Loop instead of a Do Loop for your main loop. This is because the Do Loop checks for Windows messages while the For Loop doesn't, normally you'd want to always check for Windows messages as it stops the computer from locking up but the 'Sync' command effectively does this anyway, so when you have a Do Loop with a Sync inside, you're checking twice, which can slow your program down quite a bit. In conclusion, you should use an infinite For Loop most of the time.



Then when you want to quit, set n to 2.


"Computers are useless they can only give you answers."
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Sep 2004 00:28
Well, I just gave that a try, but unfortunately it made no noticable difference to the FPS (for the program I'm working on at the moment at least). Worth a try though.

One thing that did increase the fps (by one) was to change all the calculations which involved squaring a value using a^2, to a*a. Don't know why that helps, but it does.


zao420
21
Years of Service
User Offline
Joined: 5th Aug 2003
Location: Canada
Posted: 7th Sep 2004 12:12
you can also speed up the do loop by changing RemoveSafetyCode=No to yes in the setting.ini in the compiler folder. there is also SafeArrays=Yes i am not sure what that does. you can also tell it not to add dll to your exe in there.

http://cavesoft.no-ip.com
WIP Version of my site. Usally it is offline.
http://dev-cavesoft.no-ip.com
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 8th Sep 2004 03:01
Safe arrays causes an error if you attemt to read or write outside the boundries of an array. Proberly something you want to leave on during development but might want to turn off for that little bit of extra speed after testing.


it's cool to hate
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Sep 2004 08:12
That's right - When it was introduced, I spotted that some of my code triggered array errors, including my Pathing code (now corrected of course).

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2024-09-22 23:30:34
Your offset time is: 2024-09-22 23:30:34