I've seen multiple people on this forum that started using PolyVox and hit the problem of multithreading their application. Those who do not know what I'm talking about, read
this.
Solutions to PolyVox and multithreading vary. I've seen
using a mutex to allow one thread at a time to access the volume,
creating a separate volume per "threaded chunk", and even
creating their own volume type.
I'm yet another victim of PolyVox' lack of multithreading support. Having used all the different types of volumes, my needs have boiled down to these:
- Thread safety
- Serialization (save to/load from disk), preferably compressable.
I was impressed by the complex LargeVolume which has advanced paging capabilities, but lacking thread safety, and missed awareness of which blocks are loaded and unloaded. On the other hand, I was happy with the simple-yet-effective RawVolume which in turn lacks serialization.
So I decided to combine the best of both worlds. I've added the functions 'getData' and 'getDataSizeInBytes' from LargeVolume to RawVolume, giving the volume the capability to be serialized. Next I duplicated MinizBlockCompressor and renamed it MinizRawVolumeCompressor. The name says it all; it accepts a RawVolume, using the 'getData' and 'getDataSizeInBytes' functions, and compresses it into a CompressedBlock which is then serialized to/from disk.
In my minecraft-like terrain, terrain consists of chunks of 16x16 blocks, and a RawVolume consists of 16x16 chunks. With the abovementioned solution, I can easily manage loading/saving the RawVolumes, yielding my infinite, procedural terrain.
I felt like sharing this solution to PolyVox and Threading as it might bring future PolyVox users up to speed. Any thoughts or remarks are more than welcome.