Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Performance limit of spawnable tiles

All reported bugs that's actually by design.
Forum rules
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
Post Reply
User avatar
JakSparro98
Superfighter
Superfighter
Posts: 478
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 20

Performance limit of spawnable tiles

Post by JakSparro98 » Sun Dec 23, 2018 7:24 pm

I'm trying to get lots of tiles for a terrain generation test, I've come into the conclusion that even if the game can handle more than 2000 tiles at runtime it struggles in spawning more than that, every time I call CreateObject it sums the time it took from the previous tile with this one, and you will end up waiting even some minutes for only one tile more.

But that's not all... if you try to select more than 6000 tiles in the editor you will see that some are not marked as selected (yellow box is not present)
Image

I really cannot get why, even if the game "sweats" in handling all the tiles together, when it comes to play test the map it behaves smooth as always, yes, but you will need to wait ages.
1 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1593
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 29

Post by Gurt » Wed Dec 26, 2018 11:41 pm

There is a limit on how many tiles you can select at the same time in the editor and after that you won't see any more yellow outlines anymore.

I suspect you have some algorithm that doesn't scale well with increasingly number of tiles in your code. Some nested loops perhaps.
0 x
Gurt

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 478
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 20

Post by JakSparro98 » Thu Dec 27, 2018 4:58 pm

Gurt wrote:
Wed Dec 26, 2018 11:41 pm
[..]I suspect you have some algorithm that doesn't scale well with increasingly number of tiles in your code. Some nested loops perhaps.
Actually Nothing mysterious is happening under the hood, yes, there are two nested loops but I'm using a coroutine to make a tile to spawn at every frame (only one actual tile spawn per frame), I can share the code just to prove that but again, after reaching lots of tiles spawned the game struggles to keep spawning another tile.

I just noticed that if I try to remove some previously spawned tiles the lag temporarily stops and more tiles will be generated without issues before returning to the lag state a bit later, a lag that stops definitely when the are no more tile to spawn.
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1593
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 29

Post by Gurt » Thu Dec 27, 2018 10:49 pm

I tried the map out and it turns out that the box2D engine is doing some heavy internal calculations to rebalance its internal dynamic tree and what-not - which it fails due to some hardcoded constants. Probably to handle a certain maximum amount of tiles. You're really pushing the boundries for number of tiles that the box2D engine can handle here.
I made some experimental tweaks to the hardcoded constants to be more dynamic and it looks like it speeds up the creation of your terrain and finishes it within a few seconds (depending on how many tiles you spawn per second) - but further tests need to be performed so nothing breaks here and it will still slow down to crawling speeds if you keep spawning in more than 10 000 + tiles.

I strongly recommend to not create maps with this many tiles in them. :)
2 x
Gurt

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 478
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 20

Post by JakSparro98 » Thu Dec 27, 2018 11:50 pm

Gurt wrote:
Thu Dec 27, 2018 10:49 pm
I tried the map out and it turns out that the box2D engine is doing some heavy internal calculations to rebalance its internal dynamic tree and what-not - which it fails due to some hardcoded constants. Probably to handle a certain maximum amount of tiles. You're really pushing the boundries for number of tiles that the box2D engine can handle here.
I made some experimental tweaks to the hardcoded constants to be more dynamic and it looks like it speeds up the creation of your terrain and finishes it within a few seconds (depending on how many tiles you spawn per second) - but further tests need to be performed so nothing breaks here and it will still slow down to crawling speeds if you keep spawning in more than 10 000 + tiles.

I strongly recommend to not create maps with this many tiles in them. :)
Good to know it's not an engine limit but a safe limit, well, I won't go beyond then, at least for now.
0 x

Post Reply