How to efficiently simulate hundreds of instances of something at once?

No worries. :slight_smile: is actually a gender neutral name historically, though recently it’s been pretty much feminine in the French speaking world.

By normalizing both vectors, you remove the need to adjust the dot product as it is already the cosine of the cone angle. Normalizing (through GetSafeNormal, not GetSafeNormalPrecise) uses SSE extensions that are a fair amount faster than a full on square root, at a negligible cost in accuracy. There’s a lot of factors in play when dealing with optimization, removing one extra check could actually speed up the process if branch predication is happening, etc. etc. The only way to find out would be for TheJamsh to profile and optimize as needed.

TheJamsh, the situation you described sounded like a space shooter, so I had assumed that your missiles and actors would have a lot more Z variety to them. You’re right, a quadtree would likely be enough. I’d recommend trying plain old optimizations before you go down that route, though! There’s that old adage about premature optimization, and you may well find that a quadtree wouldn’t be necessary after all.

This is just my gut feeling and you’ll have to profile to find out, but if you need to further optimize, I think you might get bigger gains from working to get your missile calculations into a more cache friendly algorithm instead. As it is, each missile actor requires a pointer dereference so getting the location each for each missile is not cheap. By instead storing all the locations and direction vectors needed into a contiguous buffer, you could see a huge gain. Plus, if done in a thread safe fashion, you could actually parallelize the use of that buffer using a few worker threads. The game thread would end up feeding locations to this buffer (likely a double buffer) and have your worker threads consume this data, then have the game thread flip the buffer and update locations as needed. It’s fairly grueling low level work, mind you, and I may be too much in the mindset of console optimization vs PC.

But if you just want the exercise in implementing a quadtree, then by all means, go hog wild. :wink:

For the networking details, it’s ultimately up to how you want to simulate them. If the server is the only network authority, then it would likely have to do the calculations itself. You could reduce replication load by sending less updates for missiles, and have clients keep a local version of the quadtree to interpolate between updates. It’s the sort of thing that’s tricky to get looking smooth, though.