refactor: add window::stop() and remove quit flag

Added `window::stop()` (sets GLFW close flag). Updated
signal/timer handlers and Q key check to call it instead of
using a separate `quit` bool in main().

This encapsulates the close state in the window class (no
more external flag + manual checks). The render loop is now
simpler.

(The process_signals lambda and ASIO duration timer are
retained.)
This commit is contained in:
2026-05-05 23:45:46 +02:00
parent 3f78d0978d
commit c3860cc1d3
3 changed files with 13 additions and 7 deletions
+6 -7
View File
@@ -50,10 +50,9 @@ auto main(int argc, char const* argv[]) -> int {
// signal handling + optional duration timer (via ASIO)
asio::io_context io;
asio::signal_set signals(io, SIGINT, SIGTERM);
bool quit = false;
signals.async_wait([&](auto, auto) {
quit = true;
win.stop();
io.stop();
});
@@ -61,9 +60,9 @@ auto main(int argc, char const* argv[]) -> int {
if (max_duration_seconds > 0.0f) {
duration_timer.expires_after(std::chrono::milliseconds(
static_cast<long long>(max_duration_seconds * 1000.0f)));
duration_timer.async_wait([&](auto ec) {
duration_timer.async_wait([&win](auto ec) {
if (!ec) {
quit = true;
win.stop();
}
});
}
@@ -78,11 +77,11 @@ auto main(int argc, char const* argv[]) -> int {
while (!win.should_close()) {
process_signals();
auto now = std::chrono::steady_clock::now();
if (quit || glfwGetKey(win.raw(), GLFW_KEY_Q) == GLFW_PRESS) {
break;
if (glfwGetKey(win.raw(), GLFW_KEY_Q) == GLFW_PRESS) {
win.stop();
}
auto now = std::chrono::steady_clock::now();
auto dt = std::chrono::duration<float>(now - prev).count();
prev = now;