diff --git a/src/GameErrorContext.hpp b/src/GameErrorContext.hpp index ac5a1ec0..2f329470 100644 --- a/src/GameErrorContext.hpp +++ b/src/GameErrorContext.hpp @@ -30,10 +30,11 @@ class GameErrorContext { } - void RstContext() + void ResetContext() { m_BufferEnd = m_Buffer; - m_Buffer[0] = '\0'; + m_BufferEnd[0] = '\0'; + // TODO: check if it should be m_Buffer[0] above. } void Flush(); diff --git a/src/main.cpp b/src/main.cpp index c2737d11..ae839722 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,13 +19,14 @@ using namespace th06; +#pragma var_order(renderResult, msg, testCoopLevelRes, testResetRes, waste1, waste2, waste3, waste4, waste5, waste6, ) int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { i32 renderResult = 0; i32 testCoopLevelRes; i32 testResetRes; MSG msg; - AnmManager *anm; + i32 waste1, waste2, waste3, waste4, waste5, waste6; if (utils::CheckForRunningGameInstance()) { @@ -55,68 +56,65 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL SystemParametersInfo(SPI_SETLOWPOWERACTIVE, 0, NULL, SPIF_SENDCHANGE); SystemParametersInfo(SPI_SETPOWEROFFACTIVE, 0, NULL, SPIF_SENDCHANGE); - for (;;) +restart: + GameWindow::CreateGameWindow(hInstance); + + if (GameWindow::InitD3dRendering()) { - GameWindow::CreateGameWindow(hInstance); + g_GameErrorContext.Flush(); + return 1; + } - if (GameWindow::InitD3dRendering()) - { - g_GameErrorContext.Flush(); - return 1; - } + g_SoundPlayer.InitializeDSound(g_GameWindow.window); + Controller::GetJoystickCaps(); + Controller::ResetKeyboard(); + + g_AnmManager = new AnmManager(); - g_SoundPlayer.InitializeDSound(g_GameWindow.window); - Controller::GetJoystickCaps(); - Controller::ResetKeyboard(); + if (Supervisor::RegisterChain() != ZUN_SUCCESS) + { + goto stop; + } + if (!g_Supervisor.cfg.windowed) + { + ShowCursor(FALSE); + } - anm = new AnmManager(); - g_AnmManager = anm; + g_GameWindow.curFrame = 0; - if (Supervisor::RegisterChain() != ZUN_SUCCESS) - { - goto exit; - } - if (!g_Supervisor.cfg.windowed) + while (!g_GameWindow.isAppClosing) + { + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - ShowCursor(FALSE); + TranslateMessage(&msg); + DispatchMessage(&msg); } - - g_GameWindow.curFrame = 0; - - while (!g_GameWindow.isAppClosing) + else { - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + testCoopLevelRes = g_Supervisor.d3dDevice->TestCooperativeLevel(); + if (testCoopLevelRes == D3D_OK) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - else - { - testCoopLevelRes = g_Supervisor.d3dDevice->TestCooperativeLevel(); - if (testCoopLevelRes == D3D_OK) + renderResult = g_GameWindow.Render(); + if (renderResult != 0) { - renderResult = g_GameWindow.Render(); - if (renderResult != 0) - { - break; - } + goto stop; } - else if (testCoopLevelRes == D3DERR_DEVICENOTRESET) + } + else if (testCoopLevelRes == D3DERR_DEVICENOTRESET) + { + g_AnmManager->ReleaseSurfaces(); + testResetRes = g_Supervisor.d3dDevice->Reset(&g_Supervisor.presentParameters); + if (testResetRes != 0) { - g_AnmManager->ReleaseSurfaces(); - testResetRes = g_Supervisor.d3dDevice->Reset(&g_Supervisor.presentParameters); - if (testResetRes != 0) - { - break; - } - GameWindow::InitD3dDevice(); - g_Supervisor.unk198 = 3; + goto stop; } + GameWindow::InitD3dDevice(); + g_Supervisor.unk198 = 3; } } - break; } +stop: g_Chain.Release(); g_SoundPlayer.Release(); @@ -134,29 +132,28 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL if (renderResult == 2) { - g_GameErrorContext.RstContext(); + g_GameErrorContext.ResetContext(); + GameErrorContext::Log(&g_GameErrorContext, TH_ERR_OPTION_CHANGED_RESTART); if (!g_Supervisor.cfg.windowed) { ShowCursor(TRUE); } + goto restart; } - else - { - FileSystem::WriteDataToFile(TH_CONFIG_FILE, &g_Supervisor.cfg, sizeof(g_Supervisor.cfg)); - SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, g_GameWindow.screenSaveActive, NULL, SPIF_SENDCHANGE); - SystemParametersInfo(SPI_SETLOWPOWERACTIVE, g_GameWindow.lowPowerActive, NULL, SPIF_SENDCHANGE); - SystemParametersInfo(SPI_SETPOWEROFFACTIVE, g_GameWindow.powerOffActive, NULL, SPIF_SENDCHANGE); - if (g_Supervisor.d3dIface != NULL) - { - g_Supervisor.d3dIface->Release(); - g_Supervisor.d3dIface = NULL; - } + FileSystem::WriteDataToFile(TH_CONFIG_FILE, &g_Supervisor.cfg, sizeof(g_Supervisor.cfg)); + SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, g_GameWindow.screenSaveActive, NULL, SPIF_SENDCHANGE); + SystemParametersInfo(SPI_SETLOWPOWERACTIVE, g_GameWindow.lowPowerActive, NULL, SPIF_SENDCHANGE); + SystemParametersInfo(SPI_SETPOWEROFFACTIVE, g_GameWindow.powerOffActive, NULL, SPIF_SENDCHANGE); + + if (g_Supervisor.d3dIface != NULL) + { + g_Supervisor.d3dIface->Release(); + g_Supervisor.d3dIface = NULL; } -exit: ShowCursor(TRUE); g_GameErrorContext.Flush(); return 0;