1
DotNet / SFML and event management (solved)
« on: March 14, 2017, 12:11:36 am »
Consider the following (very simple) SFML app.
It creates a render window, poll events and print to console each mouse move position:
Imagine we remove the line in comment (Thread.Sleep(...)).
Now the display in the console is very laggy (which is expected).
However it only prints one mouse position per second. I would rather expect that it would wait one second, then print a bunch of mouse positions (actually all the ones send to the window while sleeping), then wait one second , then print some messages and so on.
I have taken a look at source code (both C++ and C# github repos) and AFAIK SFML behavior is to pump all messages from the window (using PeekMessageW()) then store in it's own queue (a C++ vector) and dispatch them one by one. So I don't understand behavior that I got. I expect Console.WriteLine() to be called several times between two Thread.Sleep().
It creates a render window, poll events and print to console each mouse move position:
public static void Main()
{
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
window.MouseMoved += (sender, e) => {
Console.WriteLine(e.X + " " + e.Y);
};
// Start the game loop
while (window.IsOpen())
{
window.DispatchEvents();
window.Clear();
window.Display();
//System.Threading.Thread.Sleep(1000);
}
}
{
RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
window.MouseMoved += (sender, e) => {
Console.WriteLine(e.X + " " + e.Y);
};
// Start the game loop
while (window.IsOpen())
{
window.DispatchEvents();
window.Clear();
window.Display();
//System.Threading.Thread.Sleep(1000);
}
}
Imagine we remove the line in comment (Thread.Sleep(...)).
Now the display in the console is very laggy (which is expected).
However it only prints one mouse position per second. I would rather expect that it would wait one second, then print a bunch of mouse positions (actually all the ones send to the window while sleeping), then wait one second , then print some messages and so on.
I have taken a look at source code (both C++ and C# github repos) and AFAIK SFML behavior is to pump all messages from the window (using PeekMessageW()) then store in it's own queue (a C++ vector) and dispatch them one by one. So I don't understand behavior that I got. I expect Console.WriteLine() to be called several times between two Thread.Sleep().