Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Extended API for sf::Thread in SFML 2  (Read 3240 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Extended API for sf::Thread in SFML 2
« 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:
Code: [Select]
void f();
sf::Thread t(&f);

Code: [Select]
void f(int arg); // arg type can be anything
sf::Thread t(&f, 5);

Code: [Select]
class Task
{
public:

    void run();
};
Task task;
sf::Thread t(&Task::run, &task);

Code: [Select]
struct Functor
{
    void operator()();
};
sf::Thread t(Functor());

Code: [Select]
struct Functor
{
    void operator()(std::string arg);
};
sf::Thread t(Functor(), "toto");

Code: [Select]
sf::Thread t(boost::bind(...));

So the previous scenarios are still possible, plus a lot of new ones.
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Extended API for sf::Thread in SFML 2
« Reply #1 on: November 20, 2010, 02:42:20 pm »
That looks really good making it also more generic, object-oriented and easier to create synchronisation nodes.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

nfries88

  • Newbie
  • *
  • Posts: 42
    • View Profile
Extended API for sf::Thread in SFML 2
« Reply #2 on: November 20, 2010, 05:19:52 pm »
This will be a great convenience. Thanks.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Extended API for sf::Thread in SFML 2
« Reply #3 on: November 21, 2010, 03:53:02 pm »
Nice to see sf::Thread go from the Java inheritance approach towards function objects which are much more flexible and require less boilerplate-code! :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: