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 AppGameKit Corner / [BASIC] - Optimization Tips?

Author
Message
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 12th May 2017 21:47
Hi,

We are about finished, but are seeing some performance issues with our AGK2 [BASIC] video game.
We have tried for a day to optimize code and squeeze the most performance but it's still not enough.
Are there any optimization tips posted somewhere, we Google'd but did not find anything.
We've already checked for memory consumption/leaks and that is OK at this point.
Thanks!

P.S. - You can download the current source code in my signature...
JeZxLee
16BitSoft Inc.
Video Game Design Studio
http://www.16BitSoft.com
Open-Source AppGameKit2 Project!
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 13th May 2017 07:49 Edited at: 13th May 2017 07:49
Of course... in the manual:

https://www.appgamekit.com/documentation/tips.html
Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200. Using AGK2 Tier 1.
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 13th May 2017 07:55
What performance issues do you have?
Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200. Using AGK2 Tier 1.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th May 2017 11:08
Taking one example:



Replace the If/ElseIf/ElseIf.... with a Select/Case construct.
Place them in the order that the player is most likely to use them in.
I assume this code runs every cycle. At 60FPS you are running 60 instances of sound 1 per second while they are using the joystick. The sound is 400 milliseconds long, therefore you are running 25 instances of this one sound concurrently!
Use GetSoundsPlaying() and only play it again if it returns 0.

There's many instances of For loops where you run the same calculation every loop. Precalculate it once before the loops starts into a temporary variable.

This list isn't exhaustive, it's just a couple of tips I saw at a glance.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 13th May 2017 16:45 Edited at: 13th May 2017 16:49
if (SecretCode[0] = 4 or SecretCode[0] = 2) and SecretCode[1] = 7 and SecretCode[2] = 7 and SecretCode[3] = 7 then alphaFPS = 255
^ this is slow

This is faster:


That's faster than your code, where every condition is evaluated, even if the first condition doesn't apply.
I wouldn't check this in the mainloop, but rather when the user changes the code.


You have a lot of these 'long' conditions in your code, I'd change them whereever they are evaluated each cycle.
Should get you a few extra frames.
PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-04-20 15:09:47
Your offset time is: 2024-04-20 15:09:47