-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast update of items #28
Comments
Removing and adding again is fine. There's probably an algorithm for fast move in case the item isn't moving too much at once (such as when doing continuous movement) — could be a nice optimization to think about for future. The docs says that nodes are not reorganized when the number of items drop below threshold, but in practice this doesn't affect tree efficiency much. |
I'm thinking of the following simple algorithm:
|
Wait, shouldn't you delete the node before adding it again? |
Right, updated the comment. |
If you don't mind I've got a further question relating to this - what would you recommend if all of the items are moving? (for example a typical game) - in most games the total quantity of items is lower, but they generally all move every frame. Is it better to just create a brand new tree each frame and bulk insert everything, or would you still advise some kind of search and move sweep? |
@photonstorm that probably depends on how much the points move, but my bet is that specialized algorithm would be faster, since most of the points won't move out from their node bbox. |
I'm thinking of two potential new methods for this: // we're passing a function because we need to do some work both before and after the update
tree.update(item, function (item) {
// change item's bbox
});
// iterates through all items — e.g. useful when you update everything once per frame
tree.updateAll(function (item) {
// change item's bbox
}); |
I wonder if there might be another potential way of handling updates: some kind of If the Sprite moved during play, then it'd be handy to either just call Of course I fully appreciate that rbush wasn't built with games in mind at all, and this may be bending it to try and do something it was never meant to. However if you think it'd work, and be fast enough, this could be an awesome solution for things like camera culling, or a broad phase sweep for further physics checks. |
@photonstorm on a second thought, global I also wonder how RBush performs in your case if you just manually |
I don't know if it would be fast enough, but I'm happy to make some tests to find out. I guess the issue will be not so much 'is it fast', but 'could it be better?' :) By way of comparison we currently empty and re-populate our quad tree every single frame, which isn't ideal, but works. However our quadtree is limited to physics entities only, where-as I was hoping this would be fast enough to use for culling as well, an action that impacts every object in the game, not just those with physics. |
It would be nice to implement this bottom-up approach: http://net.pku.edu.cn/~cuibin/Papers/2003-vldb.pdf |
@MaxGraey thanks for sharing, this looks like a good paper on the matter! |
Any further work on this? I'm trying to optimize my broad-phase physics search. |
I'm in the same situation, would find an efficient update mechanism very helpful. |
I'm using this approach, but I'm not happy with it performance public update(item: RNode, bounds: BBox): this {
const parent: RNode = item.parentNode;
if (
bounds.minX < parent.minX || bounds.maxX > parent.maxX ||
bounds.minY < parent.minY || bounds.maxY > parent.maxY
) {
this.remove(item);
item.minX = bounds.minX;
item.maxX = bounds.maxX;
item.minY = bounds.minY;
item.maxY = bounds.maxY;
this.insert(item);
} else {
item.minX = bounds.minX;
item.maxX = bounds.maxX;
item.minY = bounds.minY;
item.maxY = bounds.maxY;
}
return this;
} |
I noticed that when you add references to parent nodes (like above) then you can greatly simplify the implementation of There's also quite an interesting talk at GDC Vault: R-Trees -- Adapting out-of-core techniques to modern memory architectures. The guy pitches the idea that we don't necessarily have to reinsert. We can just keep enlarging the AABB and the topology stays valid. Then we either reinsert every now and then - maybe based on how much the object has moved - or implement an incremental refinement algorithm which optimizes the tree little by little. |
Hi, I have the same use case. I will go ahead using remove() then insert() for now. Thanks for the library, much appreciated! |
De nada e nem o que eu não s, o //. //. 021 021 021 021
---------- Mensagem encaminhada ----------
De: "tobinam" ***@***.***>
Data: 19/04/2021 08:56
Assunto: Re: [mourner/rbush] Fast update of items (#28)
Para: "mourner/rbush" ***@***.***>
Cc: "Subscribed" ***@***.***>
Hi, I have the same use case. I will go ahead using remove() then
insert() for now. Thanks for the library, much appreciated!
…
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
This is a question about the proper way to handle an object that is moving around in an r-bush. Would one remove the object and add it every time it moves, or is there a more efficient way? In the documentation it said something about deleted items not actually being removed from the list.
The text was updated successfully, but these errors were encountered: