0
\$\begingroup\$

My voxel engine will do a lot of threading. If I used locks, There would be too much contention, Because they all need to access the chunks.

I decided to implement my threaded section using Functional Programming. The problem is, every time a player places a block, It has to rebuild the chunk with the changes applied. I feel like this is too much work for the CPU if lots of blocks get changed quickly.

Is functional programming a good fit for a voxel engine?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ It sounds to me like the limitations you're describing have nothing to do with functional programming, and are instead intrinsic to the chunk-based solution you're using - no matter what programming paradigm you code it in. Have you tried writing a test and profiling it to determine whether the performance is adequate for your needs / how many chunks you can afford to update each frame in your budget? \$\endgroup\$
    – DMGregory
    Commented Sep 5, 2022 at 21:42
  • \$\begingroup\$ I guess @Macho Onion means that with a purely functional approach you are not allowed to "modify" the data of the chunk, and must instead create a new version that has the modification applied --because data has to be inmutable, and all that. But, would that even solve the threading issue? Because, presumably, you'll need to overwrite the old chunk with the new one, which means you still have race conditions if mutiple threads are retrieving the current chunk, creating a modified version and then writing it back. \$\endgroup\$
    – PepeOjeda
    Commented Sep 6, 2022 at 7:33
  • \$\begingroup\$ Rebuilding a chunk from scratch when it changes is fairly conventional in imperative/procedural coding styles too — locating exactly which indices and triangles in the chunk mesh need to change is more complex or would need additional book-keeping. So I don't think immutability of chunks creates a unique obstacle for functional code here. \$\endgroup\$
    – DMGregory
    Commented Sep 6, 2022 at 11:37
  • \$\begingroup\$ Hm, I see. I must admit I'm not very familiar with this sort of thing. \$\endgroup\$
    – PepeOjeda
    Commented Sep 7, 2022 at 10:07

0

You must log in to answer this question.

Browse other questions tagged .