graphics frame rate fixed

This commit is contained in:
Ilusha 2024-03-19 16:39:18 +03:00 committed by Ilya Shurupov
parent 16af8dc809
commit fb374e71e4
7 changed files with 203 additions and 121 deletions

View file

@ -60,11 +60,27 @@ namespace tp {
~EventHandler();
public: // Event Poster Interface
void postEvent(InputID inputID, InputEvent inputEvent); // Record event
// Record event
void postEvent(InputID inputID, InputEvent inputEvent) {
mMutex.lock();
mEventQueue.pushBack({ inputID, inputEvent });
mMutex.unlock();
}
public: // User interface
bool isEvents() { return false; }
void processEvent() {}
bool isEvents() {
mMutex.lock();
auto res = mEventQueue.length();
mMutex.unlock();
return res;
}
void processEvent() {
mMutex.lock();
mEventQueue.popFront();
mMutex.unlock();
}
const Vec2F& getPointer() const;
@ -78,7 +94,7 @@ namespace tp {
std::mutex mMutex = {};
// Store thread protected queue of posted events
List<InputEvent> mEventQueue;
List<std::pair<InputID, InputEvent>> mEventQueue;
// input states
Vec2F mPointer;

View file

@ -0,0 +1,41 @@
#pragma once
#include "Window.hpp"
#include "Graphics.hpp"
#include "Timing.hpp"
namespace tp {
class Application {
public:
Application();
void run();
virtual void processFrame(EventHandler* eventHandler);
virtual void drawFrame(Canvas* canvas);
virtual ~Application();
protected:
ModuleManifest* mModuleDeps[2] = { &gModuleGraphics, nullptr };
ModuleManifest mApplicationModule;
Window* mWindow = nullptr;
bool mInitialized = false;
ualni mDrawPerSecond = 60;
ualni mProcPerSecond = 160;
Timer mDrawTimer;
Timer mProcTimer;
Timer mPerSecondTimer;
halnf mFramesProcessedPerSecond = 0;
halnf mFramesDrawnPerSecond = 0;
halnf mFramesProcessed = 0;
halnf mFramesDrawn = 0;
};
}

View file

@ -146,5 +146,7 @@ namespace tp {
MOUSE_DOWN = 507,
LAST_KEY_CODE = 508,
WINDOW_RESIZE = 1000,
};
}

View file

@ -29,8 +29,12 @@ namespace tp {
[[nodiscard]] bool shouldClose() const;
[[nodiscard]] const Vec2F& getSize() const;
void checkAxisUpdates();
private:
Vec2F mSize;
Vec2F mPointerPos;
Context* mContext;
EventHandler* mEventHandler = nullptr;
};