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

Author Topic: VSync does not work properly!  (Read 8548 times)

0 Members and 1 Guest are viewing this topic.

Haikarainen

  • Guest
VSync does not work properly!
« on: September 07, 2011, 12:19:16 pm »
Hello!

I've noticed something very buggy the past few months; VSync doesnt work properly at all in SFML-products!

The more intense processing required, the more this bug seems to want to be seen.

Without VSync, my game is working perfectly fine, but with it, every few frames it's like it isn't on so it skips to 1000fps instead of the 60cap. As said the more intense processing required; The more skips = More choppy gameplay. This is really annoying!

Without VSync i get a steady 1000fps nomatter how intense i do my code, so you dont think its performance problems.

This is noted in both 1.6 and 2.0

EDIT; Current system:
ATi HD 5570 1GB
Windows XP SP3 32bit
Newest Git of SFML2

EDIT2; This seems to happen regardless of VSync is enabled in SFML or in ATI Catalyst control center

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
VSync does not work properly!
« Reply #1 on: September 07, 2011, 12:33:22 pm »
Are you sure that it's v-sync itself that causes the bug, or rather time calculation (sf::Clock, Window::GetFrameTime)?
Laurent Gomila - SFML developer

Haikarainen

  • Guest
VSync does not work properly!
« Reply #2 on: September 07, 2011, 03:21:36 pm »
Quote from: "Laurent"
Are you sure that it's v-sync itself that causes the bug, or rather time calculation (sf::Clock, Window::GetFrameTime)?


Yes, I watch the fpscounter topright of my game, and everytime it goes from 60 to 1000 and back the game chops a bit. As said the more intense processing the more chops

EDIT: But yeah it might actually be frametime, i use it for all my direct position alters, but that shouldnt make ´the whole game "lag" like it does.

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
VSync does not work properly!
« Reply #3 on: September 07, 2011, 04:49:28 pm »
I'm also having some trouble with v-sync.

Every time I start an SFML application for the first time, the framerate is always between 22 and 33 FPS.
However after closing and re-opening the same application, the framerate backs up to 56 and 62, but I never get a precise 60 or 59.5 like I did on SFML 1.6.

Could I fix this somehow?

System:
Windows 7 Pro (x64)
ATI HD4870 (driver up-to-date, no clock changes, default factory settings)

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
VSync does not work properly!
« Reply #4 on: September 07, 2011, 11:19:07 pm »
Ditto!

When V-Sync is enabled, the counter is at around 60 FPS +-2, and every now-and-then I see it jumps to a high value (probably 1000).

Though I admit this bug has no effext on my game, since I use framerate independant movement.

Haikarainen

  • Guest
VSync does not work properly!
« Reply #5 on: September 08, 2011, 12:12:28 pm »
Quote from: "easy"
Though I admit this bug has no effext on my game, since I use framerate independant movement.


What is your formula?

I have float Position += float Speed * sf::RenderWindow::GetFrameTime(); and it still doesnt work.

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
VSync does not work properly!
« Reply #6 on: September 08, 2011, 01:41:58 pm »
Exactly!

I use

Code: [Select]
   float deltaTime = float(FrameTime) / 1000.f;
    float moveScale = moveSpeed * deltaTime;
    /* ... */
    pos += moveVect * moveScale;
    /* ... */
    Sprite.SetPosition(pos);


Where

Code: [Select]
unsigned int FrameTime = Window.GetFrameTime();
float moveSpeed = an arbitary value
sf::Vector3f pos = Sprite.GetPosition();
sf::Vector3f moveVect = the direction of the entity as a vector

Haikarainen

  • Guest
VSync does not work properly!
« Reply #7 on: September 08, 2011, 01:58:49 pm »
Quote from: "easy"
Exactly!

I use

Code: [Select]
   float deltaTime = float(FrameTime) / 1000.f;
    float moveScale = moveSpeed * deltaTime;
    /* ... */
    pos += moveVect * moveScale;
    /* ... */
    Sprite.SetPosition(pos);


Where

Code: [Select]
unsigned int FrameTime = Window.GetFrameTime();
float moveSpeed = an arbitary value
sf::Vector3f pos = Sprite.GetPosition();
sf::Vector3f moveVect = the direction of the entity as a vector


Hmm thats odd, what is your secret dude? Seems like everything you do works a little bit better than anything i attempt to do, regarding this thread and the tile-view thingy :P

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
VSync does not work properly!
« Reply #8 on: September 08, 2011, 02:46:27 pm »
Quote from: "Haikarainen"
Quote from: "easy"
Though I admit this bug has no effext on my game, since I use framerate independant movement.


What is your formula?

I have float Position += float Speed * sf::RenderWindow::GetFrameTime(); and it still doesnt work.
Shouldn't you have an "/ 1000" in there somewhere?

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
VSync does not work properly!
« Reply #9 on: September 08, 2011, 05:25:46 pm »
Quote from: "Haikarainen"
Hmm thats odd, what is your secret dude? Seems like everything you do works a little bit better than anything i attempt to do, regarding this thread and the tile-view thingy


Hehe, I guess nothing! I don't think our code is that different to mine as thePyro_13 has pointed out:

Quote from: "thePyro_13"
Shouldn't you have an "/ 1000" in there somewhere?


So basically I just divide "frame time" with 1000 to get the delta time. Ergo I don't know why you experience that choppy gameplay!

Are you sure that everything that can move/change over time is actually related to the "frame time" variable?

The way I do it, I practically don't use any clocks. Instead, I use Window.GetFrameTime everywhere to keep all the movements synchronized.

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
VSync does not work properly!
« Reply #10 on: September 10, 2011, 12:46:03 am »
Today I've compiled my game on Windows, and found the following possible bug:

VSync produces 200 FPS on an ASUS laptop with integrated video card on WindowsXP, and 40-60 FPS on a desktop machine set to 85Hz on Windows 7 with ATI Radeon video card.

I'm talking about SFML2 here.

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
VSync does not work properly!
« Reply #11 on: September 10, 2011, 01:06:42 am »
Vsync is more a graphics card prompt, not an enforced guarantee. You can have your card set to ignore it, enforce it even when the game doesn't say to and different cards are gonna handle it differently. Is it possible some of these 'problems' are just due to the graphics card not handling vsync how you'd expect or how it should?

Or the "timer" is somewhere ticking over or overflowing somewhere and that could be causing problems? Sometimes I'm tempted to give up and just label a bug as "rounding errors" xD

I guess the only way to tell would be to do tests with vsync turned on with a bunch of different libraries and compare-and-contrast :S Allegro5 is probably a good place to start for a quick-to-set-up check xD
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
VSync does not work properly!
« Reply #12 on: September 10, 2011, 03:33:06 pm »
True, true and true.

By the way, this is how I check FPS:

Code: [Select]
   unsigned int FrameTime = Window.GetFrameTime();
    lastFPS = currentFPS;
    currentFPS = (unsigned int)(1000.f / float(FrameTime));
    if (currentFPS != lastFPS)
    {
        std::ostringstream oss;
        oss << "FPS: " << currentFPS;
        FPSText.SetString(sf::String(oss.str()));
    }
    drawText(Window, FPSText, sf::Vector2f(10, ws.y - 35), sf::Color::White);

 

anything