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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - nkrim

Pages: [1]
1
I have a cloth simulation program where the user can manipulate a cloth with their mouse, and I was noticing a strange delay in the invocation of MouseMoved events after clicking with the mouse. This delay would occur no matter how long I waited to move my mouse after the initial click (as long as the mouse button was held). After some investigation, I found that when I turned off v-sync this issue disappeared. I have included a very simple program that recreates this behavior on my machine:

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML works!");
   
    // -- toggle on/off the line below
    window.setVerticalSyncEnabled(true);    

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::MouseMoved) {
                shape.setFillColor(sf::Color::Blue);
                std::cout << "moved" << std::endl;
            }
            else if (event.type == sf::Event::MouseButtonPressed) {
                shape.setFillColor(sf::Color::Red);
                std::cout << "PRESSED" << std::endl;
            }
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

While v-sync is on, I can see the delay by clicking with the mouse, waiting with the mouse button held, and then moving the mouse with the button still held. If the event is MouseButtonPressed the circle becomes red, and if the event is MouseMoved the circle becomes blue (also printed to console during each event). I can see from this that, even in this small program, there is a short delay. In comparison, if you do not turn on v-sync, you can see that the color change and console output are as immediate as one would expect.

In my more complicated program, this delay is much more noticeable. My simulation's FPS doesn't drop during the delay, which makes me think something is affecting how the mouse events are added to the event queue.

I am on a mid-2014 Macbook Pro running MacOS 10.12 and SFML 2.5.1. I kind of suspect the likely cause is my outdated OS, but thought I might as well post this to see if anyone can reproduce what I'm seeing.

Pages: [1]
anything