SFML community forums
General => General discussions => Topic started by: Laurent on November 20, 2010, 02:26:31 pm
-
Hi
I changed the sf::Thread class in SFML 2 to make it more flexible. I removed the Run() virtual function (so, no more inheritance from sf::Thread) and added a bunch of template constructors instead.
So now you can do this:
void f();
sf::Thread t(&f);
void f(int arg); // arg type can be anything
sf::Thread t(&f, 5);
class Task
{
public:
void run();
};
Task task;
sf::Thread t(&Task::run, &task);
struct Functor
{
void operator()();
};
sf::Thread t(Functor());
struct Functor
{
void operator()(std::string arg);
};
sf::Thread t(Functor(), "toto");
sf::Thread t(boost::bind(...));
So the previous scenarios are still possible, plus a lot of new ones.
-
That looks really good making it also more generic, object-oriented and easier to create synchronisation nodes.
-
This will be a great convenience. Thanks.
-
Nice to see sf::Thread go from the Java inheritance approach towards function objects which are much more flexible and require less boilerplate-code! :)