Affichage des FPS
This commit is contained in:
parent
735464f3ba
commit
16652236a0
3 changed files with 34 additions and 3 deletions
|
@ -8,13 +8,16 @@ class Ecran {
|
||||||
|
|
||||||
static std::string message;
|
static std::string message;
|
||||||
|
|
||||||
|
static bool fps;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Fenêtre
|
// Fenêtre
|
||||||
static sf::RenderWindow window;
|
static sf::RenderWindow window;
|
||||||
|
|
||||||
Ecran(const uint width = 800, const uint height = 800,
|
Ecran(const uint width = 800, const uint height = 800,
|
||||||
const std::string name = "Projet"); // constructor
|
const std::string name = "Projet",
|
||||||
~Ecran(); // destructor
|
const bool printFps = false); // constructor
|
||||||
|
~Ecran(); // destructor
|
||||||
|
|
||||||
void afficher(
|
void afficher(
|
||||||
/* Fonction appellée à chaque image */
|
/* Fonction appellée à chaque image */
|
||||||
|
@ -44,4 +47,9 @@ public:
|
||||||
static void cleanMessage() {
|
static void cleanMessage() {
|
||||||
message = "";
|
message = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change l'état de l'affichage des FPS
|
||||||
|
static void toggleFps() {
|
||||||
|
fps = !fps;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
#include "../includes/Ecran.hpp"
|
#include "../includes/Ecran.hpp"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
sf::RenderWindow Ecran::window;
|
sf::RenderWindow Ecran::window;
|
||||||
|
|
||||||
std::string Ecran::message = "";
|
std::string Ecran::message = "";
|
||||||
|
|
||||||
Ecran::Ecran(const uint w, const uint h, const std::string n) {
|
bool Ecran::fps = false;
|
||||||
|
|
||||||
|
Ecran::Ecran(const uint w, const uint h, const std::string n, const bool pf) {
|
||||||
// Création de la fenêtre SFML
|
// Création de la fenêtre SFML
|
||||||
window.create(sf::VideoMode(w, h + bottomTxtPadding), n,
|
window.create(sf::VideoMode(w, h + bottomTxtPadding), n,
|
||||||
sf::Style::Titlebar | sf::Style::Close);
|
sf::Style::Titlebar | sf::Style::Close);
|
||||||
|
|
||||||
|
fps = pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ecran::~Ecran() {}
|
Ecran::~Ecran() {}
|
||||||
|
@ -24,6 +31,9 @@ void Ecran::afficher(
|
||||||
text.setPosition(3, hauteur());
|
text.setPosition(3, hauteur());
|
||||||
text.setFillColor(sf::Color::White);
|
text.setFillColor(sf::Color::White);
|
||||||
|
|
||||||
|
sf::Clock fpsClock;
|
||||||
|
sf::Clock printFpsclock;
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event)) {
|
while (window.pollEvent(event)) {
|
||||||
|
@ -49,5 +59,17 @@ void Ecran::afficher(
|
||||||
window.draw(text);
|
window.draw(text);
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
|
|
||||||
|
// Affichage des FPS
|
||||||
|
if (fps) {
|
||||||
|
float currentTime = fpsClock.restart().asSeconds();
|
||||||
|
|
||||||
|
// Toutes les 2 secondes
|
||||||
|
if (printFpsclock.getElapsedTime().asSeconds() >= 2.f) {
|
||||||
|
std::cout << " " << std::fixed << std::setprecision(2)
|
||||||
|
<< 1.f / currentTime << std::endl;
|
||||||
|
printFpsclock.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ void help(char const *progName) {
|
||||||
|
|
||||||
int main(int argc, char const *argv[]) {
|
int main(int argc, char const *argv[]) {
|
||||||
Ecran e;
|
Ecran e;
|
||||||
|
Ecran::toggleFps();
|
||||||
|
|
||||||
// Interface cli
|
// Interface cli
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
|
|
Reference in a new issue