Hey guys! After a lot more work, my game is ~1000% faster, but the last optimization is making me scratch my head. To put objects into a dictionary to load, I check every chunk within a radius, get its distance, and have the dictionary sort them by distance. This means the closest chunks load first. I have a few problems with this.
1. I have to do !toLoad.ContainsKey(distanceSq), which is using about 30% of my cpu, because you cannot enter a value multiple times into a dictionary. Is there a faster way to prevent repeats?
2. Just adding to the dictionary gets laggy - it accounts for 40% of my cpu. I understand this is because of the amount of objects I'm loading.
So, I wanted to know if it was possible to get closest objects first without first iterating over all the possibilities. This would remove the need to queue my chunks or anything - just load them as they're detected, and also remove problems 1 and 2 above. I would be extremely appreciative if anyone knows a way I can go about this (It would finally make the game fully optimized)