Computing world generation then meshing into voxels?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
dart_theg
Posts: 66
Joined: Sun Dec 29, 2024 3:13 am

Computing world generation then meshing into voxels?

Post by dart_theg »

I have found that because I can't separate Irrlicht in threads or anything (to my knowledge), I have to stick computing world chunks AND meshing them on the same thread as everything else in my project. Is there a way around this? Think Minecraft.
CuteAlien
Admin
Posts: 9963
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Computing world generation then meshing into voxels?

Post by CuteAlien »

Irrlicht is generally not thread-safe, but there is a lot you can put into threads. The main things you have be careful about:
- Anything that uses OpenGL functions needs to have the opengl context. This is mainly about rendering and creating textures. Creating meshes is generally not affected by that
- If you add/remove anything to Irrlicht's global structures like ISceneManager or any of the caches you should synchronize that carefully. Obviously adding/removing from 2 threads same time is for example bad. But also adding/removing stuff while some other thread is rendering and going over that structures will fail.

What works is creating new meshbuffers for example. And you can modify each meshbuffer independently (while it's not used for rendering). And then add them at a defined point to ISceneManager that's risk-free, like the start or end of a frame. Until that point cache them yourself. For example you can also implement some kind of double-buffering where you clone meshes and then replace them at the end of a frame in the scenenodes using them. So the one not used for rending can be modified in another thread.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply