[Scummvm-git-logs] scummvm master -> 6dd4811df98cc863bf57c2debfcfa73135e2953f
dreammaster
noreply at scummvm.org
Tue Dec 16 05:30:04 UTC 2025
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
da1dfe342a BAGEL: MFC: Simplification of quit handling
6dd4811df9 BAGEL: Simplify the quit event handling
Commit: da1dfe342a9d615699e5044060f76ab9dc377017
https://github.com/scummvm/scummvm/commit/da1dfe342a9d615699e5044060f76ab9dc377017
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2025-12-16T16:29:46+11:00
Commit Message:
BAGEL: MFC: Simplification of quit handling
Changed paths:
engines/bagel/hodjnpodj/metagame/bgen/bgb.cpp
engines/bagel/hodjnpodj/metagame/demo/hodjpodj_demo.cpp
engines/bagel/hodjnpodj/metagame/frame/hodjpodj.cpp
engines/bagel/hodjnpodj/metagame/frame/movytmpl.cpp
engines/bagel/hodjnpodj/metagame/gtl/gtlmgm.cpp
engines/bagel/mfc/libs/event_loop.cpp
engines/bagel/mfc/libs/event_loop.h
engines/bagel/mfc/libs/events.cpp
engines/bagel/mfc/win_app.cpp
diff --git a/engines/bagel/hodjnpodj/metagame/bgen/bgb.cpp b/engines/bagel/hodjnpodj/metagame/bgen/bgb.cpp
index 7c3e1a4c378..fc7f8647d4b 100644
--- a/engines/bagel/hodjnpodj/metagame/bgen/bgb.cpp
+++ b/engines/bagel/hodjnpodj/metagame/bgen/bgb.cpp
@@ -784,7 +784,7 @@ bool CBgbMgr::AnimateSprite(CBgbObject *pBgbSprite, CPoint cOldPosition, CPoint
// delay 30 ms
if (!lpMetaGameStruct->m_bScrolling)
Sleep(30);
- if (app->isQuitting())
+ if (app->shouldQuit())
break;
}
diff --git a/engines/bagel/hodjnpodj/metagame/demo/hodjpodj_demo.cpp b/engines/bagel/hodjnpodj/metagame/demo/hodjpodj_demo.cpp
index 87c54253f6b..279ddf3d41b 100644
--- a/engines/bagel/hodjnpodj/metagame/demo/hodjpodj_demo.cpp
+++ b/engines/bagel/hodjnpodj/metagame/demo/hodjpodj_demo.cpp
@@ -245,7 +245,7 @@ void CHodjPodjDemoWindow::OnParentNotify(unsigned int msg, LPARAM lParam) {
LPARAM nGameReturn;
// Ignore messages during app shutdown
- if (AfxGetApp()->isQuitting())
+ if (AfxGetApp()->shouldQuit())
return;
switch (msg) {
diff --git a/engines/bagel/hodjnpodj/metagame/frame/hodjpodj.cpp b/engines/bagel/hodjnpodj/metagame/frame/hodjpodj.cpp
index b571c6447b4..68ab07ef012 100644
--- a/engines/bagel/hodjnpodj/metagame/frame/hodjpodj.cpp
+++ b/engines/bagel/hodjnpodj/metagame/frame/hodjpodj.cpp
@@ -1597,7 +1597,7 @@ void CHodjPodjWindow::OnParentNotify(unsigned int msg, LPARAM lParam) {
LPARAM nGameReturn;
// Ignore messages during app shutdown
- if (AfxGetApp()->isQuitting())
+ if (AfxGetApp()->shouldQuit())
return;
switch (msg) {
diff --git a/engines/bagel/hodjnpodj/metagame/frame/movytmpl.cpp b/engines/bagel/hodjnpodj/metagame/frame/movytmpl.cpp
index 998598fd771..cadccbbedb1 100644
--- a/engines/bagel/hodjnpodj/metagame/frame/movytmpl.cpp
+++ b/engines/bagel/hodjnpodj/metagame/frame/movytmpl.cpp
@@ -107,10 +107,7 @@ bool CMovieWindow::PlayMovie() {
decoder.stop();
- if (event.type == Common::EVENT_QUIT ||
- event.type == Common::EVENT_RETURN_TO_LAUNCHER)
- app->quit();
- else
+ if (!g_engine->shouldQuit())
m_pParent->PostMessage(WM_COMMAND, MOVIE_OVER);
return true;
diff --git a/engines/bagel/hodjnpodj/metagame/gtl/gtlmgm.cpp b/engines/bagel/hodjnpodj/metagame/gtl/gtlmgm.cpp
index 01564a74766..c95ffa74714 100644
--- a/engines/bagel/hodjnpodj/metagame/gtl/gtlmgm.cpp
+++ b/engines/bagel/hodjnpodj/metagame/gtl/gtlmgm.cpp
@@ -214,7 +214,7 @@ bool CGtlData::ProcessMove(CNode FAR *lpTargetNode)
// as long as the computer's on the move, then compute move and
// play it
- while (!AfxGetApp()->isQuitting() && (m_xpCurXodj != nullptr) && (m_xpCurXodj->m_bComputer) && (m_bGameOver == false) && (bExitMetaDLL == false)) {
+ while (!AfxGetApp()->shouldQuit() && (m_xpCurXodj != nullptr) && (m_xpCurXodj->m_bComputer) && (m_bGameOver == false) && (bExitMetaDLL == false)) {
if (((m_xpCurXodj->m_bHodj) && (lpMetaGameStruct->m_cHodj.m_bHaveMishMosh)) ||
((m_xpCurXodj->m_bHodj == false) && (lpMetaGameStruct->m_cPodj.m_bHaveMishMosh)))
@@ -293,7 +293,7 @@ bool CGtlData::MoveCharToNode(CNode FAR *lpTargetNode)
// path, and lpiShortPath[1] contains the total weight.
// The remaining array elements contain the path nodes.
for (iK = 3 ; _metaGame && !bDone && iK <= lpiShortPath[0] ; ++iK) {
- if (app->isQuitting())
+ if (app->shouldQuit())
break;
lpNextNode = m_lpNodes + lpiShortPath[iK] ;
diff --git a/engines/bagel/mfc/libs/event_loop.cpp b/engines/bagel/mfc/libs/event_loop.cpp
index 2cb75ada5ac..9457b37451d 100644
--- a/engines/bagel/mfc/libs/event_loop.cpp
+++ b/engines/bagel/mfc/libs/event_loop.cpp
@@ -39,8 +39,10 @@ void EventLoop::runEventLoop() {
if (activeWin->_modalResult != DEFAULT_MODAL_RESULT)
break;
- if (!GetMessage(msg))
+ if (!GetMessage(msg)) {
+ activeWin->_modalResult = -9999;
break;
+ }
CWnd *mainWnd = GetActiveWindow();
if (msg.message != WM_NULL && mainWnd && !mainWnd->PreTranslateMessage(&msg)) {
@@ -51,7 +53,7 @@ void EventLoop::runEventLoop() {
}
void EventLoop::SetActiveWindow(CWnd *wnd) {
- assert(_quitFlag == QUIT_NONE);
+ assert(!shouldQuit());
if (wnd == GetActiveWindow())
// Already the active window
return;
@@ -101,17 +103,7 @@ void EventLoop::checkMessages() {
if (_activeWindows.empty())
return;
- if (isQuitting()) {
- // If for some reason the previous messages added in handleQuit
- // didn't close all the windows, keep closing the remaining top window
- if (_messages.empty() && !_activeWindows.empty())
- _messages.push(MSG(_activeWindows.top()->m_hWnd, WM_CLOSE, 0, 0));
-
- if (_activeWindows.empty())
- _quitFlag = QUIT_QUIT;
- return;
-
- } else if (_messages.empty() && _idleCtr >= 0) {
+ if (_messages.empty() && _idleCtr >= 0) {
if (!OnIdle(_idleCtr))
// OnIdle returning false means disabling permanently
_idleCtr = -1;
@@ -209,7 +201,7 @@ bool EventLoop::GetMessage(MSG &msg) {
msg.message = WM_NULL;
}
- return _quitFlag != QUIT_QUIT;
+ return !shouldQuit();
}
void EventLoop::setMessageWnd(Common::Event &ev, HWND &hWnd) {
@@ -349,7 +341,7 @@ bool EventLoop::PeekMessage(LPMSG lpMsg, HWND hWnd,
bool EventLoop::PostMessage(HWND hWnd, unsigned int Msg,
WPARAM wParam, LPARAM lParam) {
- if (isQuitting())
+ if (shouldQuit())
return false;
if (!hWnd && Msg == WM_PARENTNOTIFY)
// Hodj minigame launched directly without metagame,
@@ -375,39 +367,12 @@ void EventLoop::TranslateMessage(LPMSG lpMsg) {
void EventLoop::DispatchMessage(LPMSG lpMsg) {
CWnd *wnd = CWnd::FromHandle(lpMsg->hwnd);
- if (lpMsg->message == WM_QUIT) {
- lpMsg->hwnd = nullptr;
- handleQuit();
- }
-
if (wnd) {
wnd->SendMessage(lpMsg->message,
lpMsg->wParam, lpMsg->lParam);
}
}
-void EventLoop::handleQuit() {
- _quitFlag = QUIT_QUITTING;
-
- // For a shutdown, go backwards through the windows,
- // and flag any open dialogs with a modal result
- // so they close, and a WM_CLOSE to any non-dialogs
- for (int i = _activeWindows.size() - 1; i >= 0; --i) {
- CWnd *wnd = _activeWindows[i];
- CDialog *d = dynamic_cast<CDialog *>(wnd);
-
- if (d) {
- d->_modalResult = -999;
- } else {
- MSG closeMsg;
- closeMsg.hwnd = wnd->m_hWnd;
- closeMsg.message = WM_CLOSE;
-
- _messages.push(closeMsg);
- }
- }
-}
-
bool EventLoop::isMouseMsg(const Common::Event &ev) const {
return ev.type == Common::EVENT_MOUSEMOVE ||
ev.type == Common::EVENT_LBUTTONDOWN ||
@@ -426,6 +391,14 @@ bool EventLoop::isJoystickMsg(const Common::Event &ev) const {
ev.type == Common::EVENT_JOYBUTTON_UP;
}
+bool EventLoop::shouldQuit() const {
+ return g_engine->shouldQuit();
+}
+
+void EventLoop::quit() {
+ g_engine->quitGame();
+}
+
void EventLoop::SetCapture(HWND hWnd) {
_captureWin = hWnd;
}
diff --git a/engines/bagel/mfc/libs/event_loop.h b/engines/bagel/mfc/libs/event_loop.h
index a58f1fb700b..2ab06f1e4c9 100644
--- a/engines/bagel/mfc/libs/event_loop.h
+++ b/engines/bagel/mfc/libs/event_loop.h
@@ -103,12 +103,6 @@ private:
KeybindProc _keybindProc = nullptr;
FocusChangeProc _focusChangeProc = nullptr;
-protected:
- enum QuitFlag {
- QUIT_NONE, QUIT_QUITTING, QUIT_QUIT
- };
- QuitFlag _quitFlag = QUIT_NONE;
-
private:
/**
* Get any pending event
@@ -161,8 +155,6 @@ private:
*/
void checkForFrameUpdate();
- void handleQuit();
-
public:
EventLoop() {}
virtual ~EventLoop() {}
@@ -212,19 +204,13 @@ public:
/**
* Returns whether the app should quit.
- * It does not use g_engine->shouldQuit(),
- * since messages need to be processed to
- * cleanly shut down any active windows
*/
- bool shouldQuit() const {
- return _quitFlag == QUIT_QUIT;
- }
- bool isQuitting() const {
- return _quitFlag != QUIT_NONE;
- }
- void quit() {
- _quitFlag = QUIT_QUITTING;
- }
+ bool shouldQuit() const;
+
+ /**
+ * Quit the game
+ */
+ void quit();
void SetCapture(HWND hWnd);
void ReleaseCapture();
diff --git a/engines/bagel/mfc/libs/events.cpp b/engines/bagel/mfc/libs/events.cpp
index 6f80446e3c8..9ffd716425a 100644
--- a/engines/bagel/mfc/libs/events.cpp
+++ b/engines/bagel/mfc/libs/events.cpp
@@ -169,6 +169,7 @@ bool EventQueue::peekMessage(MSG *lpMsg, HWND hWnd,
const MSG &msg = _queue[i];
if ((hWnd == nullptr || hWnd == msg.hwnd) &&
((wMsgFilterMin == 0 && wMsgFilterMax == 0) ||
+ (msg.message == WM_QUIT) ||
(msg.message >= wMsgFilterMin && msg.message <= wMsgFilterMax))) {
// Found a matching message
*lpMsg = msg;
diff --git a/engines/bagel/mfc/win_app.cpp b/engines/bagel/mfc/win_app.cpp
index 6d7e82c6c37..c73f57f7e06 100644
--- a/engines/bagel/mfc/win_app.cpp
+++ b/engines/bagel/mfc/win_app.cpp
@@ -70,8 +70,6 @@ CWinApp::~CWinApp() {
m_pmapHGDIOBJ = nullptr;
_activeApp = _priorWinApp;
- if (_activeApp && Engine::shouldQuit())
- _activeApp->_quitFlag = QUIT_QUITTING;
}
bool CWinApp::InitApplication() {
@@ -152,7 +150,7 @@ bool CWinApp::SaveAllModified() {
}
int CWinApp::Run() {
- if (isQuitting())
+ if (shouldQuit())
return 0;
// Ensure app has been initialized
Commit: 6dd4811df98cc863bf57c2debfcfa73135e2953f
https://github.com/scummvm/scummvm/commit/6dd4811df98cc863bf57c2debfcfa73135e2953f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2025-12-16T16:29:47+11:00
Commit Message:
BAGEL: Simplify the quit event handling
Previously the quit code was mess, with a multi-state quit mode.
This was prone to getting out of sync, resulting in assert
errors, or the game not quitting unless the ScummVM window 'x'
icon was clicked multiple times, or even not at all.
This new simplified version seems to be working okay when quitting
from various windows and dialogs.
Changed paths:
engines/bagel/mfc/libs/event_loop.cpp
diff --git a/engines/bagel/mfc/libs/event_loop.cpp b/engines/bagel/mfc/libs/event_loop.cpp
index 9457b37451d..f6e1f521353 100644
--- a/engines/bagel/mfc/libs/event_loop.cpp
+++ b/engines/bagel/mfc/libs/event_loop.cpp
@@ -39,10 +39,8 @@ void EventLoop::runEventLoop() {
if (activeWin->_modalResult != DEFAULT_MODAL_RESULT)
break;
- if (!GetMessage(msg)) {
- activeWin->_modalResult = -9999;
+ if (!GetMessage(msg))
break;
- }
CWnd *mainWnd = GetActiveWindow();
if (msg.message != WM_NULL && mainWnd && !mainWnd->PreTranslateMessage(&msg)) {
@@ -161,6 +159,12 @@ void EventLoop::checkMessages() {
MAKELPARAM(HTCLIENT, msg.message)
);
}
+ } else if (msg.message == WM_QUIT) {
+ // Add a window message close message as well
+ MSG cmsg;
+ cmsg.message = WM_CLOSE;
+ cmsg.hwnd = hWnd;
+ _messages.push(cmsg);
}
}
@@ -196,12 +200,14 @@ bool EventLoop::GetMessage(MSG &msg) {
}
} else if (msg.message != WM_QUIT) {
msg.message = WM_NULL;
+ } else {
+ debug(1, "Got WM_QUIT message..");
}
} else {
msg.message = WM_NULL;
}
- return !shouldQuit();
+ return !((msg.message == WM_QUIT) || (shouldQuit() && _messages.empty()));
}
void EventLoop::setMessageWnd(Common::Event &ev, HWND &hWnd) {
@@ -348,7 +354,7 @@ bool EventLoop::PostMessage(HWND hWnd, unsigned int Msg,
// so we can ignore the WM_PARENTNOTIFY on closure
return false;
- assert(hWnd || Msg == WM_QUIT);
+ assert(hWnd);
_messages.push(MSG(hWnd, Msg, wParam, lParam));
return true;
}
More information about the Scummvm-git-logs
mailing list