Fixes and improvements to the graphics module

This commit is contained in:
IlyaShurupov 2024-07-17 09:40:49 +03:00
parent 2fb319840c
commit e3757770c8
19 changed files with 161 additions and 55 deletions

View file

@ -1,6 +1,8 @@
#include "GraphicApplication.hpp"
#include "imgui.h"
using namespace tp;
Application::Application() {
@ -12,7 +14,7 @@ Application::Application() {
mPerSecondTimer.setDuration(1000.f);
}
void Application::run() {
void Application::runDefaultLoop() {
auto eventHandler = new EventHandler();
mWindow->setEventHandler(eventHandler);
@ -25,8 +27,8 @@ void Application::run() {
// proc first frame by default
{
mWindow->processEvents();
processFrame(eventHandler);
mWindow->processEvents(false);
processFrame(eventHandler, 0);
mGraphics->drawBegin();
drawFrame(mGraphics->getCanvas());
@ -34,17 +36,33 @@ void Application::run() {
mWindow->draw();
}
time_ms prevProcTime = get_time();
bool isForcedNewFrame = true;
while (!mWindow->shouldClose()) {
mWindow->processEvents();
mWindow->processEvents(!isForcedNewFrame);
updateGlobalTime();
if (mProcTimer.isTimeout() || eventHandler->isEvents()) {
if (mProcTimer.isTimeout() || eventHandler->isEvents() || isForcedNewFrame) {
while ((eventHandler->isEvents() || isForcedNewFrame)) {
while (eventHandler->isEvents()) {
eventHandler->processEvent();
processFrame(eventHandler);
time_ms currentTime = get_time();
processFrame(eventHandler, halnf(currentTime - prevProcTime));
prevProcTime = currentTime;
redrawNeeded = true;
mFramesProcessed++;
isForcedNewFrame = forceNewFrame();
if (isForcedNewFrame) {
// mWindow->processEvents();
break;
}
}
mProcTimer.wait();
@ -82,13 +100,46 @@ void Application::run() {
delete eventHandler;
}
void Application::processFrame(EventHandler* eventHandler) {}
void Application::runDebugLoop() {
auto eventHandler = new EventHandler();
mWindow->setEventHandler(eventHandler);
time_ms prevProcTime = get_time();
while (!mWindow->shouldClose()) {
mWindow->processEvents();
eventHandler->processAllEvent();
time_ms currentTime = get_time();
processFrame(eventHandler, halnf(currentTime - prevProcTime));
prevProcTime = currentTime;
mGraphics->drawBegin();
drawFrame(mGraphics->getCanvas());
mGraphics->drawEnd();
mWindow->draw();
}
delete eventHandler;
}
void Application::run() {
runDefaultLoop();
// runDebugLoop();
}
void Application::processFrame(EventHandler* eventHandler, halnf deltaTime) {}
void Application::drawFrame(Canvas* canvas) {
// ImGui::Text("Frames processed per second: %f", mFramesProcessedPerSecond);
// ImGui::Text("Frames drawn per second: %f", mFramesDrawnPerSecond);
}
void Application::drawDebug() {
ImGui::Text("Frames processed per second: %f", this->mFramesProcessedPerSecond);
ImGui::Text("Frames drawn per second: %f", this->mFramesDrawnPerSecond);
}
Application::~Application() {
delete mGraphics;
Window::destroyWindow(mWindow);