From 094d87272335948cff7415be52c673e7bf1211a8 Mon Sep 17 00:00:00 2001 From: tomch Date: Tue, 27 Mar 2007 20:46:14 +0000 Subject: [PATCH] A more elegant exit from the 'restart' loop (when SysClk fails to init) --- source/Applewin.cpp | 71 ++++++++++++++++++++++----------------------- source/Frame.cpp | 2 +- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index f7c494d4..669c0ccc 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -288,53 +288,50 @@ void EnterMessageLoop () { MSG message; - PeekMessage( &message, NULL, 0, 0, PM_NOREMOVE); + PeekMessage(&message, NULL, 0, 0, PM_NOREMOVE); while (message.message!=WM_QUIT) { -// while (GetMessage(&message,0,0,0)) - if (PeekMessage( &message, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&message); - DispatchMessage(&message); - - while ((g_nAppMode == MODE_RUNNING) || (g_nAppMode == MODE_STEPPING)) + if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { - if (PeekMessage(&message,0,0,0,PM_REMOVE)) + TranslateMessage(&message); + DispatchMessage(&message); + + while ((g_nAppMode == MODE_RUNNING) || (g_nAppMode == MODE_STEPPING)) { - if (message.message == WM_QUIT) - return; - TranslateMessage(&message); - DispatchMessage(&message); - } - else if (g_nAppMode == MODE_STEPPING) - DebugContinueStepping(); - else - { - ContinueExecution(); - if (g_nAppMode != MODE_DEBUG) - if (g_bFullSpeed) - ContinueExecution(); + if (PeekMessage(&message,0,0,0,PM_REMOVE)) + { + if (message.message == WM_QUIT) + return; + + TranslateMessage(&message); + DispatchMessage(&message); + } + else if (g_nAppMode == MODE_STEPPING) + { + DebugContinueStepping(); + } + else + { + ContinueExecution(); + if (g_nAppMode != MODE_DEBUG) + { + if (g_bFullSpeed) + ContinueExecution(); + } + } } } - } - else - { - if (g_nAppMode == MODE_DEBUG) + else { - DebuggerUpdate(); - } - else if (g_nAppMode == MODE_LOGO) - { - Sleep(100); // Stop process hogging CPU + if (g_nAppMode == MODE_DEBUG) + DebuggerUpdate(); + else if (g_nAppMode == MODE_LOGO) + Sleep(100); // Stop process hogging CPU } } } -// while (PeekMessage(&message,0,0,0,PM_REMOVE)) -// ; // intentional null statement -} - //=========================================================================== void GetProgramDirectory () { GetModuleFileName((HINSTANCE)0,g_sProgramDir,MAX_PATH); @@ -619,9 +616,9 @@ int APIENTRY WinMain (HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) //----- // Initialize COM + // . NB. DSInit() is done when g_hFrameWindow is created (WM_CREATE) CoInitialize( NULL ); bool bSysClkOK = SysClk_InitTimer(); -// DSInit(); // Done when g_hFrameWindow is created (WM_CREATE) // DO ONE-TIME INITIALIZATION g_hInstance = passinstance; @@ -663,7 +660,7 @@ int APIENTRY WinMain (HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) if (!bSysClkOK) { MessageBox(g_hFrameWindow, "DirectX failed to create SystemClock instance", TEXT("AppleWin Error"), MB_OK); - break; + PostMessage(g_hFrameWindow, WM_DESTROY, 0, 0); // Close everything down } tfe_init(); diff --git a/source/Frame.cpp b/source/Frame.cpp index 9cce5fdd..ef9f16ed 100644 --- a/source/Frame.cpp +++ b/source/Frame.cpp @@ -529,7 +529,7 @@ LRESULT CALLBACK FrameWndProc ( VideoDestroy(); MB_Destroy(); DeleteGdiObjects(); - PostQuitMessage(0); + PostQuitMessage(0); // Post WM_QUIT message to the thread's message queue break; case WM_DISPLAYCHANGE: