Get Nearby Actors from Binary?
Hi, I've been through the process of creating a game similar to Minecraft and I've managed to create a system which saves multiple blocks to binary.. So far for the purpose of optimization, I created a system which uses a For Loop to loop the binary array of blocks, checking whether each block is within range of the player and spawning that block to reduce lag. The problem is that this for loop is very CPU costly, and I'm wondering if there is a way to loop through blocks in binary that are in the range of the player instead of having to loop through the entire binary array.
asked Jul 29 '18 at 09:59 AM in C++ Programming
There is a mathematical concept for storing 2D/3D array linearly where the distances remain relatively close. See Wikipedia article on Hilbert curve. However these curves have some edge cases and seams which would need to be handled separately.
On top of this it would be largely beneficial if you divide up your data in big chunks (quadrants) and check only the 4/9 quadrants that are closest to your player to avoid checking blocks that are sure to be too far away.
Thirdly: Spawning is a very CPU and memory expensive process. This is also the case with reading from the HDD. Try to avoid doing these things by:
I would really suggest you divide your "for" loop in "Reading file", "Checking distances" and "Placing new blocks" and check which takes up the most time.
I can really bet that the "Checking distances" is the lightest of these processes.
Follow this question
Once you sign in you will be able to subscribe for any updates here