feat: console on new thread
This commit is contained in:
@@ -1,29 +1,40 @@
|
||||
#include <iostream>
|
||||
#pragma once // Zabezpieczenie przed wielokrotnym dołączeniem
|
||||
#include <chrono>
|
||||
|
||||
class FPSCounter {
|
||||
public:
|
||||
FPSCounter() : frameCount(0), lastTime(std::chrono::high_resolution_clock::now()) {}
|
||||
FPSCounter() :
|
||||
frameCount(0),
|
||||
currentFPS(0.0),
|
||||
currentFrameTime(0.0),
|
||||
lastTime(std::chrono::high_resolution_clock::now()) {
|
||||
}
|
||||
|
||||
void update() {
|
||||
// Zwraca true, jeśli minęła sekunda i zaktualizowano dane
|
||||
bool update() {
|
||||
frameCount++;
|
||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
||||
|
||||
// Aktualizujemy i wypisujemy TYLKO jeśli minęła co najmniej 1 sekunda
|
||||
if (elapsed.count() >= 1.0) {
|
||||
double fps = frameCount / elapsed.count();
|
||||
double msPerFrame = 1000.0 / fps;
|
||||
|
||||
std::cout << "FPS: " << (int)fps
|
||||
<< " | Czas klatki: " << msPerFrame << " ms" << std::endl;
|
||||
currentFPS = frameCount / elapsed.count();
|
||||
// Obliczamy czas klatki w ms
|
||||
currentFrameTime = 1000.0 / (currentFPS == 0 ? 1 : currentFPS);
|
||||
|
||||
frameCount = 0;
|
||||
lastTime = currentTime;
|
||||
return true; // Zgłaszamy, że dane się zmieniły
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- TEGO BRAKOWAŁO W TWOIM KODZIE ---
|
||||
double getFPS() const { return currentFPS; }
|
||||
double getFrameTime() const { return currentFrameTime; }
|
||||
|
||||
private:
|
||||
int frameCount;
|
||||
long long frameCount;
|
||||
double currentFPS; // Przechowuje ostatnio obliczone FPS
|
||||
double currentFrameTime; // Przechowuje czas klatki
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> lastTime;
|
||||
};
|
||||
Reference in New Issue
Block a user