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.

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Aug 2018 18:25
Came up with this little snippet, not fully knowing what the outcome was going to look like. Looks like a cheap water caustic imitation, not the fastest thing though.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Pingus
9
Years of Service
User Offline
Joined: 24th Nov 2014
Location:
Posted: 18th Aug 2018 03:13
Hi,

I'm not a AppGameKit user, but a old blitzmax user sometime wondering if AppGameKit could became my tool of choice. I am just curious to see how AppGameKit evolve with time so I go here every few months to check the engine evolution (which seems fine).
Picking random topics and showcases, I found your small snippet and tried it.

Then I thought, ok this is quite slow as expected (lot of drawlines which are not reputated to be fast and many loops into loops), but how would it run on bmax ?

Since it is a simple code, it was translated in a matter of minutes. Of course bmax run it much faster (it is a compiled language)... but I was pleasantly surprised to see that it is not *that* much faster.
What's nice with your code is that it pushes the drawline in its last retrenchment and there is a treshold effect very visible.
Of course it will be different for each CPU but on my PC the snippet run at 60 fps until ~150 points. Then at 178 points the fps fall down to ~40 fps. The same slowdown happens on bmax at around 350-400 points.

What I found interresting is that if you replace the line "j= getClosestPoint" by the lines of the function itself (which is really bad programming practice ), you will see a significant enhancement of the slowdow treshold.
On my PC the treshold became 206. So it seems that the simple 'call' to the function cost quite a lot. I don't know how AppGameKit is handled internally but I would guess that the array of points is copied each frame which has a pretty high cost.
Thanks for you snippet, it helped me to better see how AppGameKit code may be optimized in some case. This is what I expected but nothing is better than 'facts' and small code to tweak.
Next step would be to replace the drawlines by sprites which is closer to real practice as we rarely need to draw that much lines every frame in games.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Aug 2018 03:51
One slowdown is the line drawing, yes. But the real hit is the closetPoint function. Because the points are constantly moving there's no way to keep them in any kind of sorted list, therefore leaving me no choice but to iterate through the entire list of points for each point itself.

Quote: "What I found interresting is that if you replace the line "j= getClosestPoint" by the lines of the function itself"

That is quite interesting.

With 180 points I get 62fps, bumping that up to only 200points drops to around 48fps. Adding just a single word took that 48 up to 76fps. So you're right, the array copy to the function was as huge hit. I changed it to pass by reference instead:

function getClosestPoint(j, points ref as Point2D[])


Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Pingus
9
Years of Service
User Offline
Joined: 24th Nov 2014
Location:
Posted: 18th Aug 2018 13:45
Great, I was not sure that it was possible to pass variables by reference in AGK.

What is your CPU ? My I7-6700K seems struggling with that code, either bmax or AGK.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Aug 2018 10:46
Mines a 7700k. I wouldn't think yours would be that much slower. The FPS difference between us could also be simply from the line drawing. I'm using a 1060 GTX, you?

Seeing this noticeable speed difference, I may have to go back through some old code and update it to pass large arrays and UDTs by reference.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Pingus
9
Years of Service
User Offline
Joined: 24th Nov 2014
Location:
Posted: 20th Aug 2018 14:49
Interresting. 7700k is indeed better but I did not imagined it would be that much better. I doubt that my GTX 1080 is the culprit of that fps difference anyway.
Please let us know if your code optimization gives some results

Login to post a reply

Server time is: 2024-11-23 11:58:56
Your offset time is: 2024-11-23 11:58:56