graphics frame rate fixed
This commit is contained in:
parent
e41714c2bb
commit
29280949a8
7 changed files with 203 additions and 121 deletions
89
Graphics/private/GraphicApplication.cpp
Normal file
89
Graphics/private/GraphicApplication.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
|
||||
#include "GraphicApplication.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
Application::Application() :
|
||||
mApplicationModule("Application", nullptr, nullptr, mModuleDeps) {
|
||||
mInitialized = mApplicationModule.initialize();
|
||||
if (!mInitialized) return;
|
||||
|
||||
mWindow = Window::createWindow();
|
||||
|
||||
mDrawTimer.setDuration(1000.f / mDrawPerSecond);
|
||||
mProcTimer.setDuration(1000.f / mProcPerSecond);
|
||||
mPerSecondTimer.setDuration(1000.f);
|
||||
}
|
||||
|
||||
void Application::run() {
|
||||
Graphics graphics(mWindow);
|
||||
auto eventHandler = new EventHandler();
|
||||
|
||||
mWindow->setEventHandler(eventHandler);
|
||||
|
||||
mDrawTimer.reset();
|
||||
mProcTimer.reset();
|
||||
mPerSecondTimer.reset();
|
||||
|
||||
bool redrawNeeded = false;
|
||||
|
||||
while (!mWindow->shouldClose()) {
|
||||
if (mProcTimer.isTimeout()) {
|
||||
|
||||
mWindow->processEvents();
|
||||
|
||||
while (eventHandler->isEvents()) {
|
||||
eventHandler->processEvent();
|
||||
processFrame(eventHandler);
|
||||
|
||||
redrawNeeded = true;
|
||||
mFramesProcessed++;
|
||||
}
|
||||
|
||||
mProcTimer.wait();
|
||||
mProcTimer.reset();
|
||||
}
|
||||
|
||||
if (mDrawTimer.isTimeout()) {
|
||||
mDrawTimer.reset();
|
||||
|
||||
if (redrawNeeded) {
|
||||
graphics.drawBegin();
|
||||
|
||||
drawFrame(graphics.getCanvas());
|
||||
|
||||
graphics.drawEnd();
|
||||
|
||||
mWindow->draw();
|
||||
|
||||
redrawNeeded = false;
|
||||
mFramesDrawn++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mPerSecondTimer.isTimeout()) {
|
||||
mPerSecondTimer.reset();
|
||||
|
||||
mFramesProcessedPerSecond = mFramesProcessed;
|
||||
mFramesDrawnPerSecond = mFramesDrawn;
|
||||
|
||||
mFramesDrawn = 0;
|
||||
mFramesProcessed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
delete eventHandler;
|
||||
}
|
||||
|
||||
void Application::processFrame(EventHandler* eventHandler) {}
|
||||
|
||||
void Application::drawFrame(Canvas* canvas) {
|
||||
// ImGui::Text("Frames processed per second: %f", mFramesProcessedPerSecond);
|
||||
// ImGui::Text("Frames drawn per second: %f", mFramesDrawnPerSecond);
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
if (!mInitialized) return;
|
||||
Window::destroyWindow(mWindow);
|
||||
mApplicationModule.deinitialize();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue