So, I have this game that im currently working on
(link in spoiler:
http://en.sfml-dev.org/forums/index.php?topic=20589.0
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?
A sorry.
a writing mistake...
The line "targetTime = 0;" is called upon initialization. so only once.
Thus the game will catch up. Eg:
1 Run: clock() is 3, targetTime is 0 // loop, add 16 to target time.
2 Run: clock() is 12, targetTime is 16 // do not loop
3 Run: clock() is 18, targetTime is 16 // loop, add 16 to target time.
4 Run: clock() is 22, targetTime is 32 // do not loop
5 Run: clock() is 31, targetTime is 32 // do not loop
6 Run: clock() is 33, targetTime is 32 // loop, add 16 to target time. <- something happens and the loop is slow
7 Run: clock() is 90, targetTime is 48 // loop, add 16 to target time.
8 Run: clock() is 94, targetTime is 64 // loop, add 16 to target time.
9 Run: clock() is 98, targetTime is 80 // loop, add 16 to target time.
10 Run: clock() is 101, targetTime is 96 // loop, add 16 to target time.
11 Run: clock() is 108, targetTime is 112 // do not loop <-- the loop has cough up again
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