Handle lots of units

Discussion and feedback on Construct 2

Post » Thu Sep 28, 2017 9:42 pm

tunepunk wrote:@tarek2

16 objects doesn't sound like a lot. Care to explain how it works?, maybe I can come up with something more efficient in your case.

Are they all checking distance too eachother and get picked if colliding?


That's what I thought is not many and the problem they will be more on the gameplay, at the moment I'm testing just to see where are the limitations to have an idea.

Yess that's right 16 objects on the screen and say like (150 of the screen) they are all instances of the same object even I stop everything off the screen, I use a family to check distances between them and make sure they don't check distances with their selfs by filtering the UID of each one and them when picking the family don't pick this Uid wich mean himself so they check distance against all the other ones on the screen.

To give you a perfect Example of the mechanics is like (Agar.io) when you split and has to stop the overlap between your cells you can be split up into 16 pieces and all of them they cant overlap they have to move next to each other

I'm not sure if I explained properly haha

so say 170 instances of one object is the total
from those 170 instances, 16 are the player and the rest are the enemy
I filter the 16 instances for the player by instance Variable say Var = "Player" to identify them
Then check the distances between this 16 instances

For what I see the problem can be when I filter pick the ones with Var = "Player" c2 will have to loop through the whole 170 if I'm not mistaking and all of this every thick, even if I put another condition first like (is on screen) or (is Active)
B
40
S
22
G
81
Posts: 297
Reputation: 44,735

Post » Thu Sep 28, 2017 10:11 pm

@tarek2

Here's a capx I did that has 160 in layout and checking distances between everything on screen very low CPU usage. The trick is to use nearest, you dont have to check distance of every single one every tick. if the nearest one is not even within range there's no point to check all the rest of the instances either.
Hope that can help you out.

https://www.dropbox.com/s/3mc7dmbnfs8o8 ... .capx?dl=0
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,025
Reputation: 13,347

Post » Fri Sep 29, 2017 1:13 am

@tunepunk Thanks a lot for the capx that's a great example it definitely improves performance a lot but in my case what I win in performance I lose it on accuracy ending behaving a bit jumping as they can be 4 or 5 famili1 instances at the same time touching one sprite. is a bit complicated and demanding I will keep testing

Thanks anyway for your help take care
B
40
S
22
G
81
Posts: 297
Reputation: 44,735

Post » Fri Sep 29, 2017 9:01 am

Hi, thank you all for replies,

@mekonbekon, I found a similar solution than yours to avoid checking every object every tick. But I don't get enough performance improvements with it cause you can't abuse this trick, if you do so then many objects won't be updated every tick and can alter the gameplay. For things like weapons positionning on characters, it has to be every tick instead you got a lag. And if I filter onscreen/not on screen to position things, it creates a lag between what's on screen and what's not. So I ca use the trick to alleviate CPU usage just a bit.

@tunepunk, same here, I already use a lot of filter condition. By the way your ideas on picking are maybe a kind of solution. Your test works well but I do more calculation per object in my project and that causes more CPU usage.

Maybe a solution would be to separate states that require to be updated every tick from states that doesn't and store objects UID in different arrays to loop through at different frequence. But again, after testing things like this the gain is very little. At some moment, I can't prevent the player to make all his units attack and switch a lot of units to array that require update every tick.
B
14
S
4
Posts: 112
Reputation: 1,287

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests