SFML community forums

Help => System => Topic started by: Djushima on January 22, 2020, 07:29:29 pm

Title: Thread for class function w/ parameter
Post by: Djushima on January 22, 2020, 07:29:29 pm
Hi everybody,

I'm new on SFML and i have a problem that i understand, but can't find the right solution.

I have a class, named "Animation", with the function Play(), which take a RenderWindow parameter. I wanted to run this function in a thread, to render my animation in the same time the game is running. There is the part of the code:

public:

        Animation(animName index) : animThread(&Animation::Play, this){
                this->Name = index;
                switch (Name) { . . . }
        }

        ~Animation() { . . . }

        void Play(sf::RenderWindow &window);

        sf::Thread animThread;
};

I call it in the main() with the following code:
auto shotAnim = new Animation(animName::Shot);
shotAnim->animThread.launch();

And it gives me the following error: C2064: term does not evaluate to a function taking 1 arguments.

I totally understand that i don't give the necessary renderWindow parameter in "shotAnim->animThread.launch();", but i don't find where/how to set it up.

Working on Visual Studio 2017 (Debug, x86).

Can you help me please? Thanks !
Title: Re: Thread for class function w/ parameter
Post by: eXpl0it3r on January 23, 2020, 09:35:17 am
You really shouldn't use thread here. OpenGL is not multi-thread capable, doing multi-threading is quite complex with lots of places for failures, just have a simple update & draw/render function is a lot easier to write and understand.