Improve Config's "Do Benchmark" behaviour when HW config changes.

This commit is contained in:
tomch 2012-07-08 12:21:15 +00:00
parent f5ec940189
commit 595b429796
6 changed files with 96 additions and 72 deletions

View File

@ -8,7 +8,6 @@ public:
CConfigNeedingRestart(UINT bEnableTheFreezesF8Rom = false) :
m_Apple2Type(g_Apple2Type),
m_bEnhanceDisk(enhancedisk),
m_bDoBenchmark(false),
m_uSaveLoadStateMsg(0)
{
m_bEnableHDD = HD_CardIsEnabled();
@ -25,7 +24,6 @@ public:
m_bEnhanceDisk = other.m_bEnhanceDisk;
m_bEnableHDD = other.m_bEnableHDD;
m_bEnableTheFreezesF8Rom = other.m_bEnableTheFreezesF8Rom;
m_bDoBenchmark = other.m_bDoBenchmark;
m_uSaveLoadStateMsg = other.m_uSaveLoadStateMsg;
return *this;
}
@ -37,7 +35,6 @@ public:
m_bEnhanceDisk == other.m_bEnhanceDisk &&
m_bEnableHDD == other.m_bEnableHDD &&
m_bEnableTheFreezesF8Rom == other.m_bEnableTheFreezesF8Rom &&
m_bDoBenchmark == other.m_bDoBenchmark &&
m_uSaveLoadStateMsg == other.m_uSaveLoadStateMsg;
}
@ -51,6 +48,5 @@ public:
BOOL m_bEnhanceDisk;
bool m_bEnableHDD;
UINT m_bEnableTheFreezesF8Rom;
bool m_bDoBenchmark;
UINT m_uSaveLoadStateMsg;
};

View File

@ -74,7 +74,9 @@ BOOL CPageConfig::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM
break;
case IDC_BENCHMARK:
m_PropertySheetHelper.GetConfigNew().m_bDoBenchmark = true;
if (!IsOkToBenchmark(hWnd, m_PropertySheetHelper.IsConfigChanged()))
break;
m_PropertySheetHelper.SetDoBenchmark();
PropSheet_PressButton(GetParent(hWnd), PSBTN_OK);
break;
@ -261,3 +263,30 @@ void CPageConfig::ui_tfe_settings_dialog(HWND hwnd)
{
DialogBox(g_hInstance, (LPCTSTR)IDD_TFE_SETTINGS_DIALOG, hwnd, CPageConfigTfe::DlgProc);
}
bool CPageConfig::IsOkToBenchmark(HWND hWnd, const bool bConfigChanged)
{
if (bConfigChanged)
{
if (MessageBox(hWnd,
TEXT("The hardware configuration has changed. Benchmarking will lose these changes.\n\n")
TEXT("Are you sure you want to do this?"),
TEXT("Benchmarks"),
MB_ICONQUESTION | MB_OKCANCEL | MB_SETFOREGROUND) == IDCANCEL)
return false;
}
if (g_nAppMode == MODE_LOGO)
return true;
if (MessageBox(hWnd,
TEXT("Running the benchmarks will reset the state of ")
TEXT("the emulated machine, causing you to lose any ")
TEXT("unsaved work.\n\n")
TEXT("Are you sure you want to do this?"),
TEXT("Benchmarks"),
MB_ICONQUESTION | MB_YESNO | MB_SETFOREGROUND) == IDNO)
return false;
return true;
}

View File

@ -29,6 +29,7 @@ private:
eApple2Type GetApple2Type(DWORD NewMenuItem);
void EnableTrackbar(HWND hWnd, BOOL enable);
void ui_tfe_settings_dialog(HWND hwnd);
bool IsOkToBenchmark(HWND hWnd, const bool bConfigChanged);
static CPageConfig* ms_this;
static const TCHAR m_ComputerChoices[];

View File

@ -71,30 +71,11 @@ Design:
- so this can just discard any config changes
- if any config change, then show msg box to say they won't be applied
. Benchmark button
- Action it immediately (yes).
- But apply or discard config changes?
- Could discard & show msg box like Load/Save State (for consistency)
- Action it immediately.
- If config has changed:
- Prompt to either do benchmark (and lose new config) or cancel benchmark (and drop back to Configuration dialog).
*/
// NB. This used to be in FrameWndProc() for case WM_USER_RESTART:
// - but this is too late to cancel, since new configurations have already been changed.
bool CPropertySheetHelper::IsOkToRestart(HWND hWnd)
{
if (g_nAppMode == MODE_LOGO)
return true;
if (MessageBox(hWnd,
TEXT("Restarting the emulator will reset the state ")
"of the emulated machine, causing you to lose any "
"unsaved work.\n\n"
"Are you sure you want to do this?",
TEXT(REG_CONFIG),
MB_ICONQUESTION | MB_OKCANCEL | MB_SETFOREGROUND) == IDCANCEL)
return false;
return true;
}
void CPropertySheetHelper::FillComboBox(HWND window, int controlid, LPCTSTR choices, int currentchoice)
{
_ASSERT(choices);
@ -283,16 +264,23 @@ void CPropertySheetHelper::PostMsgAfterClose(HWND hWnd, PAGETYPE page)
//
UINT uAfterClose = 0;
if (m_ConfigNew.m_uSaveLoadStateMsg)
if (m_ConfigNew.m_uSaveLoadStateMsg && IsOkToSaveLoadState(hWnd, IsConfigChanged()))
{
// Drop any state change, and do load/save state
// Drop any config change, and do load/save state
PostMessage(g_hFrameWindow, m_ConfigNew.m_uSaveLoadStateMsg, 0, 0);
return;
}
if (m_bDoBenchmark)
{
// Drop any config change, and do benchmark
PostMessage(g_hFrameWindow, WM_USER_BENCHMARK, 0, 0); // NB. doesn't do WM_USER_RESTART
return;
}
if (m_ConfigNew != m_ConfigOld)
UINT uAfterClose = 0;
if (IsConfigChanged())
{
if (!CheckChangesForRestart(hWnd))
{
@ -306,11 +294,6 @@ void CPropertySheetHelper::PostMsgAfterClose(HWND hWnd, PAGETYPE page)
uAfterClose = WM_USER_RESTART;
}
if (m_ConfigNew.m_bDoBenchmark)
{
uAfterClose = WM_USER_BENCHMARK; // which implies WM_USER_RESTART (actually it doesn't)
}
if (uAfterClose)
PostMessage(g_hFrameWindow, uAfterClose, 0, 0);
}
@ -335,7 +318,7 @@ void CPropertySheetHelper::ApplyNewConfig(void)
if (CONFIG_CHANGED(m_Apple2Type))
{
SaveComputerType(m_ConfigNew.m_Apple2Type);
g_Apple2Type = m_ConfigNew.m_Apple2Type; // Is this necessary?
//g_Apple2Type = m_ConfigNew.m_Apple2Type; // Is this necessary?
}
if (CONFIG_CHANGED(m_Slot[4]))
@ -344,14 +327,14 @@ void CPropertySheetHelper::ApplyNewConfig(void)
if (CONFIG_CHANGED(m_Slot[5]))
SetSlot5(m_ConfigNew.m_Slot[5]);
if (m_ConfigNew.m_Slot[4] == CT_MockingboardC || m_ConfigNew.m_Slot[4] == CT_Phasor)
{
MB_SetSoundcardType(m_ConfigNew.m_Slot[4]); // Is this necessary?
}
else
{
MB_SetSoundcardType(CT_Empty); // Is this necessary?
}
//if (m_ConfigNew.m_Slot[4] == CT_MockingboardC || m_ConfigNew.m_Slot[4] == CT_Phasor)
//{
// MB_SetSoundcardType(m_ConfigNew.m_Slot[4]); // Is this necessary?
//}
//else
//{
// MB_SetSoundcardType(CT_Empty); // Is this necessary?
//}
if (CONFIG_CHANGED(m_bEnhanceDisk))
REGSAVE(TEXT(REGVALUE_ENHANCE_DISK_SPEED), m_ConfigNew.m_bEnhanceDisk);
@ -359,13 +342,13 @@ void CPropertySheetHelper::ApplyNewConfig(void)
if (CONFIG_CHANGED(m_bEnableHDD))
{
REGSAVE(TEXT(REGVALUE_HDD_ENABLED), m_ConfigNew.m_bEnableHDD ? 1 : 0);
HD_SetEnabled(m_ConfigNew.m_bEnableHDD); // Is this necessary?
//HD_SetEnabled(m_ConfigNew.m_bEnableHDD); // Is this necessary?
}
if (CONFIG_CHANGED(m_bEnableTheFreezesF8Rom))
{
REGSAVE(TEXT(REGVALUE_THE_FREEZES_F8_ROM), m_ConfigNew.m_bEnableTheFreezesF8Rom);
sg_PropertySheet.SetTheFreezesF8Rom(m_ConfigNew.m_bEnableTheFreezesF8Rom); // Is this necessary?
//sg_PropertySheet.SetTheFreezesF8Rom(m_ConfigNew.m_bEnableTheFreezesF8Rom); // Is this necessary?
}
}
@ -380,8 +363,8 @@ void CPropertySheetHelper::SaveCurrentConfig(void)
m_ConfigOld.m_bEnableTheFreezesF8Rom = sg_PropertySheet.GetTheFreezesF8Rom();
// Reset flags each time:
m_ConfigOld.m_bDoBenchmark = false;
m_ConfigOld.m_uSaveLoadStateMsg = 0;
m_bDoBenchmark = false;
// Setup ConfigNew
m_ConfigNew = m_ConfigOld;
@ -398,6 +381,38 @@ void CPropertySheetHelper::RestoreCurrentConfig(void)
sg_PropertySheet.SetTheFreezesF8Rom(m_ConfigOld.m_bEnableTheFreezesF8Rom);
}
bool CPropertySheetHelper::IsOkToSaveLoadState(HWND hWnd, const bool bConfigChanged)
{
if (bConfigChanged)
{
if (MessageBox(hWnd,
TEXT("The hardware configuration has changed. Save/Load state will lose these changes.\n\n")
TEXT("Are you sure you want to do this?"),
TEXT(REG_CONFIG),
MB_ICONQUESTION | MB_OKCANCEL | MB_SETFOREGROUND) == IDCANCEL)
return false;
}
return true;
}
bool CPropertySheetHelper::IsOkToRestart(HWND hWnd)
{
if (g_nAppMode == MODE_LOGO)
return true;
if (MessageBox(hWnd,
TEXT("Restarting the emulator will reset the state ")
TEXT("of the emulated machine, causing you to lose any ")
TEXT("unsaved work.\n\n")
TEXT("Are you sure you want to do this?"),
TEXT(REG_CONFIG),
MB_ICONQUESTION | MB_OKCANCEL | MB_SETFOREGROUND) == IDCANCEL)
return false;
return true;
}
bool CPropertySheetHelper::HardwareConfigChanged(HWND hWnd)
{
std::string strMsg("The emulator needs to restart as the hardware configuration has changed:\n");
@ -424,19 +439,6 @@ bool CPropertySheetHelper::HardwareConfigChanged(HWND hWnd)
strMsgMain += ". F8 ROM changed (The Freeze's F8 Rom)\n";
}
if (strMsgMain.empty())
{
if (CONFIG_CHANGED(m_bDoBenchmark))
strMsg = "The emulator needs to restart to perform the benchmark.\n";
else
_ASSERT(0);
}
else
{
if (CONFIG_CHANGED(m_bDoBenchmark))
strMsgMain += ". Benchmark\n";
}
std::string strMsgPost("\n");
strMsgPost += "This change will not take effect until the next time you restart the emulator.\n\n";
strMsgPost += "Would you like to restart the emulator now?";

View File

@ -8,7 +8,8 @@ public:
CPropertySheetHelper() :
m_LastPage(PG_CONFIG),
m_bmPages(0),
m_bSSNewFilename(false)
m_bSSNewFilename(false),
m_bDoBenchmark(false)
{}
virtual ~CPropertySheetHelper(){}
@ -34,8 +35,11 @@ public:
void ClearSSNewDirectory(void) { m_szSSNewDirectory[0] = 0; }
// const CConfigNeedingRestart& GetConfigOld(void) { return m_ConfigOld; }
CConfigNeedingRestart& GetConfigNew(void) { return m_ConfigNew; }
bool IsConfigChanged(void) { return m_ConfigNew != m_ConfigOld; }
void SetDoBenchmark(void) { m_bDoBenchmark = true; }
private:
bool IsOkToSaveLoadState(HWND hWnd, const bool bConfigChanged);
bool IsOkToRestart(HWND hWnd);
void SaveComputerType(eApple2Type NewApple2Type);
bool HardwareConfigChanged(HWND hWnd);
@ -53,4 +57,5 @@ private:
char m_szSSNewFilename[MAX_PATH];
CConfigNeedingRestart m_ConfigOld;
CConfigNeedingRestart m_ConfigNew;
bool m_bDoBenchmark;
};

View File

@ -1320,15 +1320,6 @@ LRESULT CALLBACK FrameWndProc (
break;
case WM_USER_BENCHMARK: {
if (g_nAppMode != MODE_LOGO)
if (MessageBox(g_hFrameWindow,
TEXT("Running the benchmarks will reset the state of ")
TEXT("the emulated machine, causing you to lose any ")
TEXT("unsaved work.\n\n")
TEXT("Are you sure you want to do this?"),
TEXT("Benchmarks"),
MB_ICONQUESTION | MB_YESNO | MB_SETFOREGROUND) == IDNO)
break;
UpdateWindow(window);
ResetMachineState();
g_nAppMode = MODE_LOGO;