From 845a9a7b9cc8c9d13b797333eb697820d3058c51 Mon Sep 17 00:00:00 2001 From: nhmall Date: Tue, 28 Apr 2026 12:09:55 -0400 Subject: [PATCH] a first try at a Qt idlecheckpoint implementation --- include/config.h | 1 + win/Qt/qt_bind.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++- win/Qt/qt_bind.h | 3 ++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index b54d073de..6eacad389 100644 --- a/include/config.h +++ b/include/config.h @@ -687,6 +687,7 @@ typedef unsigned char uchar; * will perform an update to the checkpoint file. * Currently has support in: * WIN32CON + * Qt */ /* #define IDLECHECKPOINT */ diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index fd55061e2..10e2c3d8f 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -70,6 +70,14 @@ static struct key_macro_rec { { 0, 0U, (const char *) 0, (const char *) 0 } }; +#ifdef IDLECHECKPOINT +#ifndef IDLECHECKPOINT_WAIT_TIME +#define IDLECHECKPOINT_WAIT_TIME 10 +#endif +static void qt_timer_fire(void); +QTimer *qt_input_timer; +#endif + static QPen *pen = (QPen *) 0; NetHackQtBind::NetHackQtBind(int& argc, char** argv) : @@ -309,6 +317,11 @@ public: void NetHackQtBind::qt_exit_nhwindows(const char *) { +#ifdef IDLECHECKPOINT + if (qt_input_timer) { + NetHackQtBind::free_qt_input_timer(); + } +#endif #if defined(QWS) // Avoids bug in SHARP SL5500 ((TApp*)qApp)->lwc(); @@ -653,11 +666,58 @@ QCoreApplication::exec: The event loop is already running return keybuffer.GetAscii(); } +#ifdef IDLECHECKPOINT +void +NetHackQtBind::free_qt_input_timer(void) +{ + if (qt_input_timer) { + if (qt_input_timer->isActive()) + qt_input_timer->stop(); + if (qt_input_timer) + delete qt_input_timer; + qt_input_timer = 0; + } +} + +static void +qt_timer_fire(void) +{ +#if defined(INSURANCE) + if (iflags.idlecheckpoint) { + /* no input for 30 seconds, so let's take + * advantage and do a game checkpoint, + * then resume the wait. + */ + save_currentstate(); + } + if (qt_input_timer->isActive()) + qt_input_timer->stop(); +#endif /* INSURANCE */ +} + +//void +//cancel_qt_input_timer(void) +//{ +// +//} +#endif /* IDLECHECKPOINT */ + int NetHackQtBind::qt_nh_poskey(coordxy *x, coordxy *y, int *mod) { if (main) main->fadeHighlighting(true); +#ifdef IDLECHECKPOINT + if (iflags.idlecheckpoint) { + if (!qt_input_timer) { + qt_input_timer = new QTimer(); + qt_input_timer->setSingleShot(true); + connect(qt_input_timer, &QTimer::timeout, &qt_timer_fire); + } + if (!qt_input_timer->isActive()) + qt_input_timer->start(IDLECHECKPOINT_WAIT_TIME * 1000); + } +#endif // Process events until a key or map-click arrives. // while (keybuffer.Empty() && clickbuffer.Empty()) { @@ -672,12 +732,20 @@ int NetHackQtBind::qt_nh_poskey(coordxy *x, coordxy *y, int *mod) main->fadeHighlighting(false); if (!keybuffer.Empty()) { - return keybuffer.GetAscii(); +#ifdef IDLECHECKPOINT + if (qt_input_timer->isActive()) + qt_input_timer->stop(); +#endif + return keybuffer.GetAscii(); } else { *x=clickbuffer.NextX(); *y=clickbuffer.NextY(); *mod=clickbuffer.NextMod(); clickbuffer.Get(); +#ifdef IDLECHECKPOINT + if (qt_input_timer->isActive()) + qt_input_timer->stop(); +#endif return 0; } } diff --git a/win/Qt/qt_bind.h b/win/Qt/qt_bind.h index d0c71759c..45336c29f 100644 --- a/win/Qt/qt_bind.h +++ b/win/Qt/qt_bind.h @@ -106,6 +106,9 @@ public: static void qtsound_ambience(int32_t, int32_t, int32_t); static void qtsound_verbal(char *text, int32_t gender, int32_t tone, int32_t vol, int32_t moreinfo); #endif +#ifdef IDLECHECKPOINT + static void free_qt_input_timer(void); +#endif private: virtual bool notify(QObject *receiver, QEvent *event);