Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinMain 92% #313

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/GameErrorContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
115 changes: 56 additions & 59 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand Down
Loading