View unanswered posts | View active topics It is currently Thu Mar 28, 2024 8:59 am



Reply to topic  [ 3 posts ] 
 Iterating through stuff in a box in a less brute force way 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Iterating through stuff in a box in a less brute force way
So I have this box, and I want to mess around with the speed of everything inside of it, including particles, actors and items, and there's the classical issue of it getting laggy when there's a lot of objects in the game, because it's still necessary to iterate through all of them to check if they are inside of the box or not.

A solution to this is to keep a table with all the items inside the box and just iterate through that, updating it every once in a while or when certain condition is met. What other solutions could be used for this? The ideal would be a way to check the objects inside the box every frame, but I could also change the physics of what's going on to adjust to checking the objects every other frame instead, which I've tried without success.

Any help is appreciated as always :)


Sun Apr 15, 2018 6:06 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: Iterating through stuff in a box in a less brute force way
What's your current iterate-over-everything code? You might be able to eke some additional performance by checking the condition that is most likely to be false first, which I would guess would be the x coordinate (since most maps are wider than they are tall).

An additional check could be to store the last-updated time and reduce the number of checks to at most x objects per time period, which would be similarly lossy as keeping a table and updating that table every so often, but would prevent overloading things when there's a lot of particles all of a sudden.


Sun Apr 15, 2018 7:59 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Iterating through stuff in a box in a less brute force way
You're definitely best off tabling the things you want to affect and iterating through that table, not much better you can do there.

As far as performance for adding/removing from the table, aside from what Duh said, if you're worried about performance you could try putting the add and remove functions in coroutines and yielding after it iterates through a set number of objects or something, it'd make it consistent even if there are a ton of things going on but it might cause delays in affecting everything it should. Also, I believe there's a built-in position is in area C++ method, which might be a bit more efficient than checking the bounds yourself. You can add a box to an area and do that check if I'm not mistaken. Finally, if you're okay with using a circle instead of a box, shortest distance would probably be faster than checking against multiple coordinates.


Sun Apr 15, 2018 10:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.077s | 15 Queries | GZIP : Off ]