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.

AppGameKit Classic Chat / AGK optimisation ?

Author
Message
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 6th Jul 2016 11:50
Hi

In some of my game level, the fps drop at 30 (instead of 60). I know my PC is really slow ^^, but I would like to know if you know technic to optimisate a game or a level.

I have tried :


But :
1) it's not very accurate
2) the fps drop when the loop is on this part (to test the distance between the player/camera and the objects).

So you have some ideas to get a better fps ?
- For example, how can I do a LOD system ?
- perhap's I could turn off the physic for objects far of the player ?

my scene is "only" :
- 40000 polygons and 220 objects (with box physic (250 static box, 1 ground (terrain with 6000 poly) and 1 character (1000 poly)).

Here is main loop (test) :

AGK2 tier1 - http://www.dracaena-studio.com
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jul 2016 12:06
You could check only a small subset of the objects each time...



Here, you are still checking all objects every second at 60FPS.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
BraindeaD
16
Years of Service
User Offline
Joined: 30th Mar 2008
Location:
Posted: 6th Jul 2016 16:32 Edited at: 6th Jul 2016 16:36
Not sure if this helps, but try to store the player coords in variables before the for instead ask for them each for loop:



Similar to the BatVink's method, you can use a value in the tree type structure to see if this element must be checked in this loop, i.e.:


Hope it helps.
Best Regards.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Jul 2016 17:07
Get distance will be a fairly taxing command, basically a square root function which is not ideal when your trying to save FPS. Perhaps just do a X,Z range check instead and see if that helps... along with adding a limit to the object checks per loop as suggested of course.

Like...
If abs(x-GetObjectX(n))>1000
SetObjectVisible(n,0)
else
If abs(z-GetObjectZ(n))>1000
SetObjectVisible(n,0)
else
SetObjectVisible(n,1)
endif
endif

If your game is glitching really badly, then perhaps adopting timer based movement is an idea - at least it'll blend those glitches a bit and improve consistency. Time based movement is probably not ideal for games primarily designed for phones and tablets, it would increase battery usage - maybe an idea to allow a fixed frame rate for mobile devices as well, that would be a case of just setting the frame rate, timer based movement would still work the same way.
The code is dark and full of errors
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Jul 2016 23:36
in agk i find the for x loops the major fps kill. try to merge code and use less loops per sync if possible. an example would be to check your house lengths and tree lengths in the same for x loop. another way to speed things up is to merge all your 3d models into a single model as agk can process a single object composed of all your level geometry faster then processing it over multiple objects. I also agree with vanb that too many square root calls per sync can hurt a fair bit. maybe check a section of them per sync but not all of them.
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Jul 2016 06:07
in a runtime it's important to tweak the number of operations out of such brute forces loops. The cost of polling an array, calling function is high, so a you can make it easier on the runtime by storing values that aren't changing (within the inner loop) in temp variables. So the runtime has less work to do when executung the loop.

eg.


IF/ELSE/ENDIF block can be removed also, which will remove at least two branches (depending upon the course the code takes) from the inner loop.

eg.


so we can make the loop look fairly leen, but it's still a brute force operation.

a better solution is by partitioning the space. Depending the size of the game world you can get away with a 1D or 2D partition. Which just means running through and storing objects in lists, Then we work out which list we're closest too and only check that group of objects.

for some ramble Crash crouse in optimization


PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code

Login to post a reply

Server time is: 2024-11-25 05:46:07
Your offset time is: 2024-11-25 05:46:07