Threads in Irrlicht

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
st0ph
Posts: 27
Joined: Sat Aug 04, 2012 3:00 pm

Threads in Irrlicht

Post by st0ph »

Hi,
I have a .irr file scene, that takes more than 2 minutes to load, and my game is blocked in the time of loading, So I was wondring is there a way to lanch the loading of my scene and playing an animation(loading bar) or a video in the same time ?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Threads in Irrlicht

Post by Nadro »

Yes, of course. You can load a data (textures, meshes etc.) from other threads (in OpenGL for textures You have to use main thread, so load just RAW texture data loadImageFromFile in other thread, but next call IVideoDriver::addTexture). At the same time You can show loading progress bar. I did in this way loading splash screen for Sky Devil: Stairway to Heaven (I use Boost threads).

PS. For *.irr files you have to little modify a loader sources.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
st0ph
Posts: 27
Joined: Sat Aug 04, 2012 3:00 pm

Re: Threads in Irrlicht

Post by st0ph »

@Nadro thanks for the quick responce,
Is there any samples or code snipets that I can use or follow ?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Threads in Irrlicht

Post by Nadro »

I don't think so, but maybe other members will have some links. Anyway I think that Boost thread examples would be enough in this case.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
ritti
Posts: 90
Joined: Tue Apr 10, 2012 12:09 pm

Re: Threads in Irrlicht

Post by ritti »

Hi st0ph,
since your model loading function blocks the app, you could start the progress bar as a thread before you begin to load the model.
To do this with std::threads you should do something like this:

Code: Select all

std::thread progressbar = std::thread(loadBar);   //function to show the progress bar
progressbar.detach();
loadModel();    //function to load the model
 
If this doesn't help you, you could try to load the model within a thread, start the progressbar and apply the texture as soon as the progressbar finishes:

Code: Select all

loadModel(){
  irr_node = device->getSceneManager()->addAnimatedMeshSceneNode(
    device->getSceneManager()->getMesh("../../media/yourmodel"),0, 0);
  build.cube.irr_node->setPosition(core::vector3df(0,0,0));
}
int main(int argc, char* argv[]){
  std::thread loadM = std::thread(loadModel);
  loadM.detach();
  loadBar();
  irr_node->setMaterialTexture( 0, device->getVideoDriver()->getTexture("../../media/some_texture.png") );
}
I hope this works and I could help you :)

Best regards and have a nice day
Ritti
Post Reply