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 / Optimization

Author
Message
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 2nd Nov 2011 03:28
Whats a good way to optimize my code here, Its either a glitch, or bad programming, but after about a minute of playing my fps drops to like 3. And I'm looking for a fix, I've been looking myself, but that doesnt seem to work. So I made this thread.



(You don't need the main menu images, just rem that part out if you want to test. Also suggestions are taken, even though this is just for learning anyways lol)

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd Nov 2011 03:35
alpha_value = alpha_value

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 2nd Nov 2011 03:43
Oh yeah, forgot to get rid of that, also one more question, in my enemy AI is there a way to make sure they don't run into each other, since I use the same function on all of the enemies?

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd Nov 2011 12:50 Edited at: 2nd Nov 2011 12:51
There's options; but a simple way is to do the reverse of what you are already doing in relation to the player position.

If the enemy is close; increase X/Y in the opposite direction of it; until out of range.

Derived from your algorithm:


Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 2nd Nov 2011 17:46 Edited at: 2nd Nov 2011 18:18
Thanks!

EDIT: They just go straight down, The AI thinks its constantly already colliding or something.



EDIT TWO: Never mind, fixed it. (The just moving down thing)

They still collide.

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd Nov 2011 20:05
My example was a quick idea, it's not done right; change the INC to DEC, and vise versa; if A is > B, B needs to be decremented. (Their positions that is)

Assuming from your code, if they are still colliding after the above change, 4 is to small a radius for what you want; replace it with a variable and set it higher.

I'm not sure what status means in your program, but you might want to check the status of object A aswell.

Finally, something to consider after you get around the basics. It may be more smoother if you worked with floating point forces; instead of constant speed integers. Yes sprites use pixels which are integers; but storing floating point coordinate properties allows you to accelerate movement more smoothly; and shouldn't hurt the performance.

EG: inc XSpeed#, Acceleration# : inc XPosition#, XSpeed# : dec XSpeed#, XDeceleration#
Sprite Id, XPosition#, YPosition#, Image


Something along those lines, where deceleration# lower than acceleration#

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 3rd Nov 2011 02:25 Edited at: 3rd Nov 2011 02:36
Oh ok, and also the status is just to check if the enemies have been set up and properly placed.

EDIT: I made some changes and it works fine now. Its a bit buggy, though that buggy jittering sort of makes the enemies (Actually zombies, should've explained that eariler) seem more menacing.



EDIT TWO: Ok, that lag bug is back lol. I probally need to do some fixing. (Still waiting on some tips to optimize)
But if you can find anything then tell me.



Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 3rd Nov 2011 13:05
You need to investigate the bottle neck. Place this at the top of the code. And set it to 1 when you experience a slow down.


Add the FPS to the display after the DO statement:


Put the next line before each major IF branch and function call or sub in the main loop.



Then put this after each major function call, with the name of the the process in quotes. You must make sure this gets called before the next start timer.


Make sure there is a setcursor or cls command to reset the position of the text every loop.

Now you can check what part of the code is taking too long. 15 ms tops for your loop.

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 3rd Nov 2011 15:33
The problem is in the enemytimer() function. I remmed out the function call and ran the game for over 5 minutes and it still was at 100 FPS. What are you trying to get done by using wait 0200 in that function?. Also, why set b = 1 to 1? Is that a typo?

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 3rd Nov 2011 17:16
I knew it was in there (Probably shouldve mentioned that) because its usually laggy when an enemy spawns.

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 3rd Nov 2011 17:52
Ok my advice was over the top as I wasn't expecting you to be using a Wait command in an active game loop; but when it is not so obvious, when the project gets larger, use the timer methods to find out the problem if you are unable to see it.

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 3rd Nov 2011 17:59 Edited at: 3rd Nov 2011 18:01
Replace your enemytimer() function with this:



It respawns and does not lag. I ran it for a minute or so.

BTW, Chris Tate's idea is a good one for troubleshooting.

Login to post a reply

Server time is: 2024-05-20 04:54:37
Your offset time is: 2024-05-20 04:54:37