Skip to content
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

Best method to check all players against all players in the quadtree? #13

Closed
Chroma72 opened this issue Jul 9, 2020 · 2 comments
Closed
Labels

Comments

@Chroma72
Copy link

Chroma72 commented Jul 9, 2020

I have a case where I am using this on the server side and I need to loop through all players, and, on each players loop iteration, I would do a tree retrieve with player object and then insert the player etc etc for up to 500 players. In your opinion is this the right approach? Each player has the x, y, width, and height, and unique id properties.

Pseudo-code:
tree.clear()
tree.insert(allBullets)
for each player in players {
player.update; // update this player position
var objs = tree.retrieve(player) // first retrieve against this player
// do coll checks with objs if any are found

tree.insert(player) // do this after so this player won't be in his own retrieve
}

This way we only loop through the players once and each one is checked against all bullets and the previous players already inserted so all player to player checks are covered.

@timohausmann
Copy link
Owner

timohausmann commented Jul 11, 2020

This way we only loop through the players once and each one is checked against all bullets and the previous players already inserted so all player to player checks are covered.

From my understanding this wont check all players against each other but only - like you say, too - against previously inserted. So e.g. the first loop execution won't have any player in the Quadtree. I'm afraid you need two loops, one for inserting and one retrieving, and test the retrieved IDs to prevent self-collision.

Haven't thought about many-to-many yet and I cannot say if this is the best method. Let me know if this works for you or not.

@timohausmann
Copy link
Owner

I created a new example for many-to-many checks

https://timohausmann.de/quadtree.js/many.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants