Hello from Canada! (French Canadian, but nope not a "Quebecois")
I'm new to SFML, as of today. I'm porting my SDL application to SFML 1.6 for performance reasons. A simple 1080p video is rendering about 4x faster in SFML.
So, I got a problem with my threads... I'm not really an expert with C++ nor an expert with multi-threading.
The problem is that I create and launch a thread in the constructor of one of my classes, but my main loop (in which the object is created, hence the constructor called), doesn't display the RenderWindow until the thread is finished. Which is the reason I want to have threads.
So here is an example of my situation (not the exact code, but you'll understand):
main.cpp
new Scene();
while(App->IsRunning())
{
... my render stuff, that only starts after the thread is terminated (so after the FadeInThread method is done) ...
}
Scene.cpp
Scene::Scene(sf::RenderWindow* Window, float Length)
{
... some code ...
this->fadeIn();
}
void Scene::FadeIn()
{
this->Opacity = 0;
sf::Thread Thread(FadeInWrap, this);
Thread.Launch();
// SDL : SDL_CreateThread(FadeInWrap, this);
}
// This is a static method.
void FadeInWrap(void* Scn)
{
((Scene*) Scn)->FadeInThread();
}
void Scene::FadeInThread()
{
float Delay = 0.007;
while(this->Opacity < 255)
{
this->Opacity++;
sf::Sleep(Delay);
// SDL: SDL_Delay(Delay); (Delay was an int calculated differently)
}
}
I know the static to non-static method is kinda weird, but only way I found out in SDL.
There's not much of a difference between a thread in SDL and in SFML, as far as I can see. Just don't understand why it doesn't continue the main execution while performing an operation in a thread.
Basically, if I launch my application, there's a 1.785 second delay because of the FadeInThread.
Could anyone help me out? I'm currently using the SDL_Thread, it works along SFML, but why import and use a huge library when SFML could do that for me.