Hi.
I'm using CSFML, and I created a c code in the main thread, which draws a sprite to a window and uses
sfRenderWindow_setFramerateLimit(60).
The sprite x and y positions are taken from two global variables (SPR_X and SPR_Y).
Don't ask why I'm doing the following
... but I created a thread which only modifies the sprite position by changing SPR_X and SPR_Y variables. The problem is, how do I sync the thread to the vsync of the main one, so that the sprite moves at 60 fps?
I used
usleep(1000000/60) and it works, but you surely know what happens next... Sometimes the positions are changed in the middle of a frame, and you can see screen tearing.
Then I tried using
sfRenderWindow_display() again inside the thread function. But that resulted in a black screen. So I think I must use a custom
sfRenderWindow_display():
void custom_windowdisplay()
{
// Display the backbuffer on screen
//if (setActive()) m_context->display(); don't do this again!!
// Limit the framerate if needed
if (m_frameTimeLimit != Time::Zero)
{
sleep(m_frameTimeLimit - m_clock.getElapsedTime());
//m_clock.restart(); //don't restart the clock again!!
}
}
I can convert that to CSFML, But I need to get the same clock used internally for the original
sfRenderWindow_display(), and also get the m_frameTimeLimit value.
How do I get the clock and the m_frameTimeLimit?.
Is there any other way to do it? I read about "mutex", but that was way complex for me to understand, and I did not make it work.
Thanks.