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

Author Topic: Polling network messages & VSYNC  (Read 2298 times)

0 Members and 1 Guest are viewing this topic.

kamac

  • Newbie
  • *
  • Posts: 19
    • View Profile
Polling network messages & VSYNC
« on: March 30, 2015, 07:47:49 pm »
Hey there.

I am using a 3rd party networking library, and I need to poll my packets as often as possible - framerate independent. But I also would like to have VSYNC enabled.

How do I go about that? When I turn VSYNC on, window.display() will block for a certain amount of time, and there's no way around it. I can't run my packet polling on a separate thread.

Should I just manually limit the framerate, and poll my packets independently? But that wouldn't be like turning VSYNC on - it'd be just limiting the framerate, right?

Cheers.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Polling network messages & VSYNC
« Reply #1 on: March 30, 2015, 08:04:32 pm »
When there is enough time left in the current frame, you can poll more than once. Thus, you have different rates for polling and screen update.

See also here, some of the resources mentioned by Jesper Juhl address this issue, too.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kamac

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Polling network messages & VSYNC
« Reply #2 on: March 30, 2015, 08:10:13 pm »
I don't quite follow. I can't do anything during the time window.display() is called - and it will block for some milliseconds, for Vsync's sake. How can I poll my stuff during that time on the same thread? (By poll I mean call an object's member function, not poll keyboard events)

Didn't find the answer in the link you've linked.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Polling network messages & VSYNC
« Reply #3 on: March 30, 2015, 09:31:27 pm »
Of course you can't do anything while display() blocks. But if there's extra time left in the current frame you can poll() your network stuff a few times before calling display().
It's all about keeping track of the time spent per frame and managing how it is used.

kamac

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Polling network messages & VSYNC
« Reply #4 on: March 30, 2015, 11:06:38 pm »
But if I turn VSync on, won't swapping buffers block by itself? Maybe I'm getting the wrong idea, but each time I turned it on, my framerate dropped to 60 FPS.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Polling network messages & VSYNC
« Reply #5 on: March 30, 2015, 11:11:01 pm »
You were able to do other things between two display() calls, like game logic, so why shouldn't you be able to poll the network?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kamac

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Polling network messages & VSYNC
« Reply #6 on: March 30, 2015, 11:29:26 pm »
Uh,

Quote
But if I turn VSync on, won't swapping buffers block by itself? Maybe I'm getting the wrong idea, but each time I turned it on, my framerate dropped to 60 FPS.

Buffer swap occurs on .display().

@EDIT
Nevermind, figured it out.
« Last Edit: March 30, 2015, 11:52:20 pm by kamac »

 

anything