Closed sanderman01 closed 7 years ago
I've done some calculations to determine how much memory we would be using both in the case of option 1 and in the case of option 2. My conclusion is that the amount of memory required to store a large number of chunks remains very low.
The main factor here is that this will be a 2D game. There is no need to deal with the third dimension like other games like Minecraft need to, which massively reduces the amount of memory required to store a chunk in memory. Even a huge number of chunks will not require all that much memory. The little bit of extra memory required to use 32 bit values is trivial enough that I feel it is worth spending in order to have a future-proof design.
We have a few options:
Store 16 bit unsigned integers (c# ushort) and use the 4 least significant bits for meta data and the remaining 12 bits for tile type.
Store 32 bit unsigned integers (c# uint) and use the 8 least significant bits for meta and the remaining 24 bits for tile type.
Option 1 has as advantage that it takes the least amount of memory.
Option 2 has as an advantage that it will be much more future-proof. In the future, if modding takes off, we might need the ability to have more than 4096 types of tiles. Unfortunately it would also take double the amount of memory compared to option 1.
There is also another option:
I don't really like option 3 because this means that for rendering a single tile, you'll need to access at least two different buffers per chunk, which might impact performance of the game. (These buffers may not be located near each other in memory, which could affect cache efficiency)
Let me know your thoughts on this topic.
References: Explaination of how minecraft handles block metadata