Hello.
Im trying to run my main loop at a static 60 fps, but sometimes it decides to limit the fps to 50. I guess this problem could be caused by many reasons, I have checked my cpu speed and seems to be running at full clockspeed. Any ideas?
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "model.h"
#include <iostream>
int main() {
sf::RenderWindow window(sf::VideoMode(1024, 768), "Azyrium");
Model * model = new Model();
sf::Clock clock;
sf::View view2;
view2.setSize(1920,1080);
view2.setCenter(960,540);
window.setView(view2);
while (window.isOpen()) {
clock.restart();
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
else if (event.type == sf::Event::KeyPressed || event.type == sf::Event::KeyReleased ) {
model->handleInput(event);
}
}
model->updateGame();
window.clear();
model->drawGame(window);
window.display();
while (clock.getElapsedTime().asMicroseconds() < 16667) {
sf::sleep(sf::microseconds(16667-clock.getElapsedTime().asMicroseconds()));
std::cout << 1/((double)(clock.getElapsedTime().asMicroseconds())/1000000 ) << std::endl;
}
}
delete model;
return 0;
}
Main loop.