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

Author Topic: How do you make sf::RenderWindow work in my class' function?  (Read 2050 times)

0 Members and 1 Guest are viewing this topic.

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
The title says it all. I have a class with several private sf::Sprites(the parts of the body of the character) and a function to draw them in an animation embedded into the class. Pretty much I want a character select screen where the characters are a class and have a simple animation on each one of them. Since I want both the animation and the choice process to work at the same time, I'll need threads. But when I write something similar to this:
sf::Thread randum_thread(&player_spr::anim_standby(window), &human);
where player_spr is my class, anim_standby is my function and window is my, well, window ;D , I get an error.
Basically, I want to know how to make a thread calling a class' function with parameters.



Thanks in advance,
Ilman

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do you make sf::RenderWindow work in my class' function?
« Reply #1 on: June 19, 2013, 10:38:30 pm »
Since I want both the animation and the choice process to work at the same time, I'll need threads.
How does the "choice process" look exactly? Anyway, it's a common misconception that anything that seems to happen in parallel needs threads, in reality only few things need to be truly parallel. Mostly, this is the case when one thread is blocking.

Why can't you compute these things sequentially in a single thread?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ilman

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: How do you make sf::RenderWindow work in my class' function?
« Reply #2 on: June 20, 2013, 12:43:56 pm »
I tried doing it in a single thread, but it resulted in too many errors and making it multi-threaded could easily make the whole thing easier.
The choice process gets where the mouse is left-clicked and depending on that position it displays a text about the character that was clicked.
Since I want an animation for all the characters onscreen, it'd be easiest to make several threads, one for each character that draws that respective character onscreen instead of drawing everything in the main function.


Hope that answered your question.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do you make sf::RenderWindow work in my class' function?
« Reply #3 on: June 20, 2013, 02:52:28 pm »
I tried doing it in a single thread, but it resulted in too many errors and making it multi-threaded could easily make the whole thing easier.
What errors? I highly doubt that multithreading makes it easier. In fact it mostly makes things more difficult, because it introduces new problems such as synchronization and non-determinism. You should really not use multithreading if it's not necessary.

Since I want an animation for all the characters onscreen, it'd be easiest to make several threads
Not at all, this works perfectly in a single-threaded environment. Just loop through all the characters and update their animation progress. Then you render them.

If you're not sure how to animate objects without using threads, you could have a look at my implementation in Thor. What I do, is passing a float value to the animation. This value is in [0,1] and denotes the progress; the animation itself can be represented by any function taking the progress and the object to animate.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything