Skip to content

Commit f6ef046

Browse files
authored
Optimize rendering performance by adding idle state handling and continuous render check (#5)
1 parent 1a95ae6 commit f6ef046

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/BinXray/UI/Application.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ bool Application::initialize(HINSTANCE hInstance) {
233233
int Application::run() {
234234
MSG msg = {};
235235
while (m_running && msg.message != WM_QUIT) {
236+
// If nothing requires continuous rendering, sleep until the OS
237+
// delivers an input/paint/timer message. This drops CPU and GPU
238+
// utilization to near-zero when the application is idle.
239+
if (!needsContinuousRender()) {
240+
::MsgWaitForMultipleObjects(0, nullptr, FALSE, INFINITE, QS_ALLINPUT);
241+
}
242+
236243
while (::PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE)) {
237244
::TranslateMessage(&msg);
238245
::DispatchMessage(&msg);
@@ -468,6 +475,16 @@ void Application::invalidateSeek() {
468475
}
469476
}
470477

478+
bool Application::needsContinuousRender() const noexcept {
479+
// Auto-rotation advances yaw every frame.
480+
if (m_3dModeEnabled && m_3dAutoRotate) return true;
481+
// Async file load needs polling each frame.
482+
if (m_isLoadingFile) return true;
483+
// Pending data recomputation.
484+
if (m_matrixDirty) return true;
485+
return false;
486+
}
487+
471488
void Application::updateSeekFromPlot(float originX, float originY, float plotSize) {
472489
if (!m_seek.seekEnabled || m_seek.frozen) {
473490
return;

src/BinXray/UI/Application.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class Application {
9090
void updateSeekFromPlot(float originX, float originY, float plotSize);
9191
void invalidateSeek();
9292

93+
/// True when ongoing animation or async work requires per-frame rendering.
94+
[[nodiscard]] bool needsContinuousRender() const noexcept;
95+
9396
// ---- D3D11 lifecycle ----------------------------------------------------
9497
bool createDeviceD3D(HWND hWnd);
9598
void cleanupDeviceD3D();

src/BinXray/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#define BXR_VERSION_MAJOR 0
66
#define BXR_VERSION_MINOR 4
7-
#define BXR_VERSION_PATCH 1
7+
#define BXR_VERSION_PATCH 2
88
#define BXR_VERSION_BUILD 0
99

1010
#define BXR_VERSION_FILEVERSION BXR_VERSION_MAJOR, BXR_VERSION_MINOR, BXR_VERSION_PATCH, BXR_VERSION_BUILD

0 commit comments

Comments
 (0)