diff --git a/FPSCounter.cpp b/FPSCounter.cpp index 61144c3..5fd25eb 100644 --- a/FPSCounter.cpp +++ b/FPSCounter.cpp @@ -10,6 +10,7 @@ public: auto currentTime = std::chrono::high_resolution_clock::now(); std::chrono::duration elapsed = currentTime - lastTime; + // Aktualizujemy FPS co 1 sekundê if (elapsed.count() >= 1.0) { double fps = frameCount / elapsed.count(); std::cout << "FPS: " << fps << std::endl; diff --git a/main.cpp b/main.cpp index 6f94d21..8f2c5e7 100644 --- a/main.cpp +++ b/main.cpp @@ -85,19 +85,24 @@ std::time_t monitormodehelper; FPSCounter fpsCounter; static const int targetFPS = 144; // Celowany FPS //Fps counter + void LimitFPS(int targetFPS) { - static auto lastTime = std::chrono::high_resolution_clock::now(); - auto currentTime = std::chrono::high_resolution_clock::now(); + static auto lastTime = std::chrono::steady_clock::now(); + auto currentTime = std::chrono::steady_clock::now(); std::chrono::duration elapsed = currentTime - lastTime; - // JeÅ›li upÅ‚ynęło za maÅ‚o czasu, aby osiÄ…gnąć target FPS, czekamy + // Obliczamy czas na jednÄ… klatkÄ™ double frameTime = 1.0 / targetFPS; // Czas na jednÄ… klatkÄ™ w sekundach - if (elapsed.count() < frameTime) { - std::this_thread::sleep_for(std::chrono::duration(frameTime - elapsed.count())); + double timeToWait = frameTime - elapsed.count(); // Obliczamy czas do czekania + + if (timeToWait > 0.0) { + // JeÅ›li czas do czekania jest wiÄ™kszy niż 0, to Å›pimy przez tÄ™ wartość + std::this_thread::sleep_for(std::chrono::duration(timeToWait)); } - lastTime = std::chrono::high_resolution_clock::now(); + lastTime = currentTime; // Zaktualizuj czas dla nastÄ™pnej iteracji } + bool Kolizja = false; bool keyWPressed = false; bool keySPressed = false; @@ -851,6 +856,7 @@ void SetupRC() { void RenderScene(void) { + //float normal[3]; // Storage for calculated surface normal // Save the matrix state and do the rotations @@ -913,7 +919,7 @@ void RenderScene(void) { glTranslatef(Foward, 0.0f, Sides); // Translacja Å‚azika na jego pozycjÄ™ glRotatef(Rotation, 0.0f, 1.0f, 0.0f); // Obrót Å‚azika wokół wÅ‚asnej osi glColor3f(1.0, 0.0, 0.0); // Czerwony kolor dla Å‚azika - + fpsCounter.update(); user.draw(); UpdateRover(fences); glPopMatrix(); @@ -933,7 +939,7 @@ void RenderScene(void) { //glColor3f(0.0, 1.0, 0.0); //mapa.draw(); //glColor3f(0.0, 0.0, 0.0); - fpsCounter.update(); + // Zamiana buforów (double buffering) @@ -1243,11 +1249,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //break; // Limit FPS - LimitFPS(targetFPS); + // Uaktualniaj FPS + LimitFPS(targetFPS); // Ogranicz FPS - // Update FPS counter - if (monitormode) fpsCounter.update(); - break; + case WM_QUERYNEWPALETTE: // If the palette was created.