SFML community forums

Help => Window => Topic started by: GameBear on July 27, 2016, 06:20:52 pm

Title: program slows down during fullscreen
Post by: GameBear on July 27, 2016, 06:20:52 pm
So, I have this game that im currently working on
(link in spoiler:
(click to show/hide)

the normal screen size for this game is 800 by 600.
it uses sf::view (400 by 300 pixels) and sf::window
it uses a flexible timestep
it runs fine using only 3-6& cpu and few %memory

but if i toggle fullscreen to true (or if i start in full screen) it slows down a lot.
but also, the animation gets slower still and thus out of sync.
(eg, walking becomes sliding)

toggeling fullscreen back off again solves the problem instantly...
I've tried running as administrator and searching with all my google'fu but no solution so far.

the toggleFullscreen code is:

void Window::ToggleFullScreen() {
        m_isFullscreen = !m_isFullscreen;
        Destroy();
        Create();
}

if it has any interest the animation code is called right after the units have updated their current location and status.

void Agent::animate() {
        _currentFrame+= (_speed / 160);
        if (_aniAtt) {
                if (_currentFrame > _attFrames) _currentFrame = 0;
                _animation = 3;
        }
        else if (_aniJump) {
                if (_yVel < 0) _currentFrame = 0;
                else _currentFrame = 1;
                _animation = 2;
        }
        else if (_aniWalk) {
                if (_currentFrame > _walkFrames) _currentFrame = 0;
                _animation = 1;
        }
        //standing
        else{
                if (_currentFrame > _standFrames) _currentFrame = 0;
                _animation = 0;
        }
        if (_dirLeft) _animation += 6;
}

_animation corresponds to a specific row and _current frame to the column in a texture.
a sprite is set to the corresponding coordinates and then rendered to the window.
_speed is the movement speed of the characters.

again, the cpu, memory and gpu usage remains roughly the same, and never exceeds 12% but both the program in general slows down and the animation, the animation just more than the rest.

any suggestions?
Title: Re: program slows down during fullscreen
Post by: Arcade on July 27, 2016, 08:07:25 pm
Does your game take the framerate into account during time/movement calculations? For example does your game use a fixed timestep in the main game loop? How often do you call Agent::animate()?
Title: Re: program slows down during fullscreen
Post by: GameBear on July 27, 2016, 08:35:11 pm
The framerate is a flexible fixed timestep. animate is called each time the game loop is called.

:

targetTime = 0;
if(clock() > targetTime) {
  targetTime += (1000/targetUPS);
  doGameLoop();
  animate();
}



*target time is an int
*targetUPS = target updates per second.

so if the character moves, his animation should update.

rendering is done sepperatly.

my targetUPS is normaly set to 60, so an update should happen no more than once per 0.016 seconds.
a normal update including animate() takes 0.003 to 0.008 seconds, so there is time to spare...
Title: Re: program slows down during fullscreen
Post by: Hapax on July 27, 2016, 10:08:26 pm
This still only updates up to once per cycle?
It might be worth trying to change the if to a while to allow it to catch up.
Title: Re: program slows down during fullscreen
Post by: GameBear on July 28, 2016, 12:00:28 am
A sorry.
a writing mistake...

The line "targetTime = 0;" is called upon initialization. so only once.

Thus the game will catch up. Eg:
(click to show/hide)

This is why i use a flexible time step, this way you avoid delta time and you avoid updating out of sync (mostly) the downside is that you must update target time each time you pause/pause, to avoid (clock() is 10000 target time is 16 = to many repetitions)

But no, this is not the error i'm experiencing, since animate() and the game functions are both called within the same main loop, they should update 1 time each right after each other, but for some reason the game function seems to be called multiple times :S
Title: Re: program slows down during fullscreen
Post by: Hapax on July 28, 2016, 12:54:53 am
It takes a number of frames to catch up, though. Using a while allows it to step through each step until it's caught up before wasting time rendering out-of-date frames on the way (7-10 could be done in one cycle).

A varying time step is likely to be the cause of your animation not scaling. Are you multiplying/scaling the animation and movement by the amount of time passed since the last update?