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 / Aircraft ammunition, fps drop, what method to use?

Author
Message
Santiago3D
3
Years of Service
User Offline
Joined: 11th May 2020
Location: Argentina
Posted: 3rd Jun 2021 16:07
hello, some time ago I had a drop in FPS due to my ammunition presence.

dropping from 60 to 30 FPS when there are many and resumes at 60 when the ammunition is disappearing.

my ammunition is a type, which has an object which I move.
If the munitions are active, they calculate possible collisions with other planes or ships.

They only activate, when they are close to another object.

For example, if I fly with my plane alone, and shoot, the ammunition does not calculate collisions since they would not have to hit. And so I save the whole process of detecting whether or not they collide with something.

My ocean is always at height 0, so if its height is negative, I know they fell into the water.


I would like to consult you, what is the best method to have a lot of ammunition and that AppGameKit can handle it without falling.

and what method is better to calculate if a munition had an impact.



share some part of my code, this is when i create a ammo when someone fire.



----------------------------------------------

My idea, for now, is to replace the projectiles with a more effective method, I have everything separated into functions.

- projectile creation
- update projectile
- I calculate if it collides or not
- projectile death

damage calculations and others are in different functions.

it's obvious that I'm doing something wrong, and I lost track of when I started getting this drop in FPS.

Are there ammunition systems for shaders? Or is there a more polished system for this type of need?


----------------------------------------------

thanks for read, , im back to dev again.
regards!






Santiago3D
3
Years of Service
User Offline
Joined: 11th May 2020
Location: Argentina
Posted: 3rd Jun 2021 16:20 Edited at: 3rd Jun 2021 16:26
maibe here is the problem, If I cancel this part where it detects collisions, I don't have the FPS drop


Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 3rd Jun 2021 21:48
For best Performance you want to avoid Arrays with > 2,500 Elements
You are also going to want to use REPEAT...UNTIL or WHILE...ENDWHILE over FOR...NEXT., I don't know why but the FOR...NEXT Loop is about 20% Slower than the Conditional Branch Loops; or of course you could use DO...LOOP with a Conditional "EXIT"... not tested the performance for that., but I'd imagine it should be pretty fast.

Another thing to note is while IF...ENDIF has reasonable performance., any Conditional with an ELSE has a noticeable performance hit.
If possible try to use Branchless Conditionals (i.e. Binary True / False) with a Finite State Machine (SELECT...CASE)., this provides the best performance especially with Recursive Code (i.e. Loops of large volumes of Data)

Now the last thing to consider is that the Physics Engine is SLOW, especially with Ray Casting.
I'm not sure why, as it should be SSE / VMX Accelerated; but yeah the performance is somewhat dire... so really you want to performance distance calculations., in-fact a Simplified BVH (Binary Volume Hierarchy) is best; which is a fancy way of saying you want to break down the problem to where you're creating virtual boxes and instead check to see if bullets are within those Volumes; then check the Vector to see if any will pass through the Box containing the Target Collider (Object).
ONLY then do you perform the Ray Cast to check to see if a Collision has occurred.

It's one of the downsides of AppGameKit Script being well a Scripting Engine, and not a very well optimised one at that... is for more ambitious things, like Bullet Hell Shooters for example; you have to be a bit more creative to get Decent Performance., which I'd argue somewhat ends up going against the Concept of AppGameKit being more Approachable and New Programmer Friendly.
But then AppGameKit is contradictive in so many ways.

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jun 2021 22:21
I would suggest the following;
1) Do odds and evens. Odd array elements one frame and even the next. You could split this up further as well
2) Add a broad proximity check beore you go raycasting
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 3rd Jun 2021 23:43
"You are also going to want to use REPEAT...UNTIL or WHILE...ENDWHILE over FOR...NEXT., I don't know why but the FOR...NEXT Loop is about 20% Slower than the Conditional Branch Loops" - Raven

I did not know that. Thank you!
LynxJSA's web games/quizzes - LynxJSA's Android apps
AGK Resource Directory
"Stick to a single main loop (DO...LOOP) and loop through it every frame.
Do everything inside functions.
Use finite state machines to control your game.
Use lots and lots of source files.
Use virtual resolution instead of the default percentage system." - Digital Awakening
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th Jun 2021 01:00 Edited at: 4th Jun 2021 01:07
Quick loop test results (counting to 10,000,000)

Classic:


Studio:


Didn't expect Do/Loop to be the slowest (64-bit compiles, if it matters?)


[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]

Attachments

Login to view attachments
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 4th Jun 2021 13:15
Quote: "You are also going to want to use REPEAT...UNTIL or WHILE...ENDWHILE over FOR...NEXT., I don't know why but the FOR...NEXT Loop is about 20% Slower than the Conditional Branch Loops"


Cannot confirm 100%...
REPEAT is the fastest loop in both Studio and Classic
WHILE is faster than FOR in Studio, but MUCH SLOWER in Classic

Win 10 64bit
I-7 2600K


PSY LABS Games
Coders don't die, they just gosub without return
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 4th Jun 2021 18:42

Have you tried making your ammunition objects invisible, so that they're there for the calculations, but not actually drawn to the screen?
Send your parents to noisy sprite demo hell... enter the D-Zone
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 5th Jun 2021 00:42
Quote: "Have you tried making your ammunition objects invisible, so that they're there for the calculations, but not actually drawn to the screen?"


Drawing Objects actually has a pretty negligible performance hit., of course GPU / CPU Dependant; but typically unless you're drawing A LOT of High Polygon Objects; you're going to hit Script Performance Limits LONG before you hit Rendering Performance Limits.
As I noted in my original response., essentially the Ray-Casting (or anything to do with the built-in Physics Engine) will simply destroy performance.

AGK uses Bullet Physics., which is an excellent Physics Engine... but at the same time, it also doesn't support 64bit, Multi-Core or Multi-Threading... meaning it's running on a Single Core / Thread with 32bit Operations.
While this is "Fine" for Physics Engines like Open Dynamics Engine and PhysX., which were developed and designed when Uni-Core 32-bit Processors were still Commonplace., Bullet Physics was instead developed by Sony for the PlayStation 3.
This means the backend has a HEAVY reliance on Multi-Threading across multiple SIMD Units for acceleration.

While there is a "Software" Fallback that can use minimal resources., it was never really intended for Retail Products; but rather as a baseline for when porting to New Platforms.
A major failing of AppGameKit is that TGC seems highly reluctant to abandon what are essentially obsolete Mobile Platforms., and while this to a degree is "Okay" for say AppGameKit Classic (as v2 tends to get called)., I think this was a major mis-step when it comes to AppGameKit Studio; and would've been an excellent way to differentiate them by increasing the Minimum Specifications; and working to more Modern Architecture considerations.



As a result., you have to be exceptionally frugal with the number of Rays, Dynamic Objects, etc. that you have the Physics System handling.
Ideally speaking you want to use it as little as possible., or even better use a more bespoke solution that entirely removes it's usage.
With the performance it has; and again this isn't a fault of Bullet Physics, it is an excellent, capable and performant Physics Engine when properly implemented... it more or less feels like it's there to allow for a Feature Checkbox to be ticked off., and is useful in a more limited scope.

For something that uses A LOT of entities., I'd instead suggest relying exclusively on just a basic Distance Check; with a prescribed Distance denoting the "Collision" Area; so if it's within a given Distance you have a Hit, and if not; you don't.
On top of this breaking the problem down into a BVH Tree; or even just a simple Octree to perform more general distance checks and then only actually perform a check and compare on those within a proximity Volume; would again allow for much larger numbers of Entities without any real performance hits.
Santiago3D
3
Years of Service
User Offline
Joined: 11th May 2020
Location: Argentina
Posted: 6th Jun 2021 15:19
hello, thank you very much for the answers!

Some things I do not understand, since being self-taught and gross I find it difficult to understand a little things that are surely basic.

From what I see, raycast is a slow function, both from what they say, and also that if I cancel that function, the performance of the game does not drop.

so it is obvious that there I have the problem.

the main solution is to have distance detection.
and only use the raycast on a few special occasions.

in my case, my planes have "objects" of impacts, to detect if you hit the engine, the wing, the cockpit, the ailerons, etc.

but I could use that, which I get using raycast, only for very special occasions.

also used RAYCAST for the collisions of the plane when it passes near a ship.

I must evaluate well how to approach the general solution of all this.

since the yield is something non-negotiable.

regards!


What I can do is add the usage counters that I have, to see how many times I use raycast, and how much time it takes.

and so know how much I can use it.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 7th Jun 2021 13:27
Santiago., you may have to test this... but I don't believe AppGameKit will automatically generate and use (Bounding) Box Collision for your Objects.
It instead likely uses Polygon (Triangle) Collision., which is great for Accuracy but not so good for Performance.

Let's say you're using a Low Triangle (Polygon) Count Model., like maybe 500 Triangles... even if we were to use Triangular Collision., a Box Representation of the Object is going to be substantially Faster to Calculation when Collision occurs as it made up from 12 Triangles.
Even still., Box Collision is typically even faster still; because it doesn't NEED to be a Comprehensive approach, where each individual Triangle has to be Calculated and Intersected to Detect if Collision has occurred.
Instead a more simplified approach of "Is the Ray within this Volume?" needs to be done, which is essentially half a dozen calculations and binary checks as opposed to Triangular Collision which is several hundred calculations with branching checks.

And realistically., we don't actually need to rely on Ray Casting to even handle said Collision; a more simplified Distance Calculation and then Volume Check can be utilised.
I'd suggest experimenting with that and work from there.
If it helps I can see about writing some code to showcase this and draw some pictures that explain what's happening.

There's nothing wrong with being "Self Taught", so don't fret about that... you'll likely find more than a few here have been there too.
Doing new things is always going to be a learning experience., the best programmers are those who are always open to learning; as there is never a "Perfect" or "Right" way to do something... and more often than not; it's a case of Trial & Error until you get the results you hope / want.
Santiago3D
3
Years of Service
User Offline
Joined: 11th May 2020
Location: Argentina
Posted: 9th Jun 2021 18:55 Edited at: 9th Jun 2021 18:56
Thanks for the answers.

i have this function to messure distances





you could use it to detect projectiles near potential targets.

as if it were a collision of sphere to sphere.

since the distance from one point to another would be like the radius, if it is within the radius I am within the sphere.


reading the answers, I also think that maybe it would be faster if I make 3 conditions to detect if two objects are close, in the shape of a rectangle.


something like this to check if oneobject is near to other very fast?
if abs (x1 - x2) <R then
if abs (y1 - y2) <R then
if abs (z1 - z2) <R then
// box collision detected
endif
endif
endif

What do you think? Both options are fast?
in this way I would have 3 if that would be faster than a combined condition

and could have a point-sphere or box sector collision
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 9th Jun 2021 20:28
Quote: "reading the answers, I also think that maybe it would be faster if I make 3 conditions to detect if two objects are close, in the shape of a rectangle."

It may be best to create a sample test program to see which is fastest but it looks like your making great progress looking forward to seeing more
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Jun 2021 21:46 Edited at: 9th Jun 2021 21:46
I would divide the area into a grid. Then check cells for proximity
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 16th Jun 2021 13:51 Edited at: 16th Jun 2021 14:58
My knowledge of BASIC tanks when the English is changed to a different language, sorry.

Quote: "My ocean is always at height 0, so if its height is negative, I know they fell into the water."




Quote: "the main solution is to have distance detection.
and only use the raycast on a few special occasions.
"

Sounds like you have it figured out.

Looking forward to playing this when it is finished.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 24th Jul 2021 06:24
From what I've read so far, a good solution is to use bounding boxes to test whether a round is even within proximity to something that it could hit, then use a distance squared method (since you don't need the accurate distance) to test if it is a hit, then move on to testing specific hit points on the aircraft/ship. You could even arrange hitpoints the same way using bounding boxes and that would limit the use of dot product and raycasting. Also, test for bounding box hits and add those to an array for processing on the next frame. Then test for distance and add those to a processing array for the next frame, continuing on splitting things up so that the frame rate doesn't dip.

Login to post a reply

Server time is: 2024-04-20 08:03:03
Your offset time is: 2024-04-20 08:03:03