SFML community forums

Bindings - other languages => DotNet => Topic started by: gualtyphone on December 08, 2018, 07:32:27 pm

Title: [SOLVED] .NET DispatchEvents problem
Post by: gualtyphone on December 08, 2018, 07:32:27 pm
SOLUTION:
Updated csfml libraries to 2.5. issue disappeared

Hey fellow Devs,
So I'm working on a project in SFML.NET and I did the standard sfml game loop:
       while (_renderer.Window.IsOpen)
            {
                totalTimeElapsed = clock.ElapsedTime.AsSeconds();
                deltaTime = totalTimeElapsed - previousTimeElapsed;

                totalTimeBeforeUpdate += deltaTime;

                if (totalTimeBeforeUpdate >= Renderer.TIME_TO_UPDATE)
                {
                    _renderer.Window.DispatchEvents();

                    _time.Update(totalTimeBeforeUpdate, clock.ElapsedTime.AsSeconds());

                    _renderer.Clear();

                    Update(_time);
                    Draw(_time);

                    fps.DisplayedString = (1.0f / totalTimeBeforeUpdate).ToString();
                    _renderer.Window.Draw(fps);

                    _renderer.EndDraw();

                    totalTimeBeforeUpdate = 0f;
                }

                previousTimeElapsed = totalTimeElapsed;
            }
 

but I'm getting some strange 'slower' frames, every second or so, Window.DispatchEvents() is taking much longer to run (0.1s vs the normal 0.01s) which causes the application to be jittery... I've tried removing all of my event bindings and this is still happening...
Does anyone know why it might be the case?
Title: Re: .NET DispatchEvents problem
Post by: gualtyphone on December 09, 2018, 03:00:33 pm
UPDATE:
To eliminate any and all confusion I made a new project and the most basic implementation of a game loop I could
namespace TestSFML
{
    class MainClass
    {
        private static RenderWindow _window;
        public static void Main(string[] args)
        {
            _window = new RenderWindow(new VideoMode(800, 600), "SFML window");
            _window.SetVisible(true);
            _window.Closed += new EventHandler(OnClosed);
            Clock clock = new Clock();
            float timePassed = 0f;
            float previousTimePassed = 0f;
            float dt = 0;
            while (_window.IsOpen)
            {
                timePassed = clock.ElapsedTime.AsSeconds();
                dt = timePassed - previousTimePassed;
                _window.DispatchEvents();
                _window.Clear(Color.Red);
                Debug.WriteLine((1.0f / dt).ToString());
                _window.Display();
                previousTimePassed = timePassed;
            }
        }

        private static void OnClosed(object sender, EventArgs e)
        {
            _window.Close();
        }
    }
}
 

And the issue is still present on multiple machines... Don't really know where to go from here...