Data Realms Fan Forums http://868000.nnhp.asia/ |
|
Iterating through stuff in a box in a less brute force way http://868000.nnhp.asia/viewtopic.php?f=73&t=46265 |
Page 1 of 1 |
Author: | Asklar [ Sun Apr 15, 2018 6:06 pm ] |
Post subject: | 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 |
Author: | Duh102 [ Sun Apr 15, 2018 7:59 pm ] |
Post subject: | 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. |
Author: | Bad Boy [ Sun Apr 15, 2018 10:40 pm ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |