mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
fixes resolution changes during run time with d3d9 and opengl renderers
This commit is contained in:
parent
202e4eb869
commit
5477e5139a
72
src/main.c
72
src/main.c
@ -285,8 +285,11 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
|||||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
LeaveCriticalSection(&This->cs);
|
LeaveCriticalSection(&This->cs);
|
||||||
|
|
||||||
WaitForSingleObject(This->render.thread, INFINITE);
|
if (This->render.thread)
|
||||||
This->render.thread = NULL;
|
{
|
||||||
|
WaitForSingleObject(This->render.thread, INFINITE);
|
||||||
|
This->render.thread = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (This->renderer == render_d3d9_main)
|
if (This->renderer == render_d3d9_main)
|
||||||
Direct3D9_Release();
|
Direct3D9_Release();
|
||||||
@ -316,6 +319,18 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
|
|||||||
{
|
{
|
||||||
printf("DirectDraw::SetDisplayMode(This=%p, width=%d, height=%d, bpp=%d)\n", This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp);
|
printf("DirectDraw::SetDisplayMode(This=%p, width=%d, height=%d, bpp=%d)\n", This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp);
|
||||||
|
|
||||||
|
if (This->render.thread)
|
||||||
|
{
|
||||||
|
EnterCriticalSection(&This->cs);
|
||||||
|
This->render.run = FALSE;
|
||||||
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
|
LeaveCriticalSection(&This->cs);
|
||||||
|
|
||||||
|
WaitForSingleObject(This->render.thread, INFINITE);
|
||||||
|
This->render.thread = NULL;
|
||||||
|
Sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
if (!This->mode.dmPelsWidth)
|
if (!This->mode.dmPelsWidth)
|
||||||
{
|
{
|
||||||
This->mode.dmSize = sizeof(DEVMODE);
|
This->mode.dmSize = sizeof(DEVMODE);
|
||||||
@ -486,34 +501,31 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
|
|||||||
This->render.viewport.x = This->render.width / 2 - This->render.viewport.width / 2;
|
This->render.viewport.x = This->render.width / 2 - This->render.viewport.width / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(This->windowed)
|
if (This->windowed)
|
||||||
{
|
{
|
||||||
if(!This->windowed_init)
|
if (!This->border)
|
||||||
{
|
{
|
||||||
if (!This->border)
|
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
|
||||||
{
|
|
||||||
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
|
|
||||||
|
|
||||||
if (ddraw->wine)
|
|
||||||
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) | WS_MINIMIZEBOX);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* center the window with correct dimensions */
|
if (ddraw->wine)
|
||||||
int x = (WindowPosX != -32000) ? WindowPosX : (This->mode.dmPelsWidth / 2) - (This->render.width / 2);
|
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) | WS_MINIMIZEBOX);
|
||||||
int y = (WindowPosY != -32000) ? WindowPosY : (This->mode.dmPelsHeight / 2) - (This->render.height / 2);
|
|
||||||
RECT dst = { x, y, This->render.width+x, This->render.height+y };
|
|
||||||
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
|
|
||||||
SetWindowPos(ddraw->hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
|
||||||
MoveWindow(This->hWnd, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), TRUE);
|
|
||||||
This->windowed_init = TRUE;
|
|
||||||
|
|
||||||
if (This->renderer == render_d3d9_main)
|
|
||||||
InitDirect3D9();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowLong(This->hWnd, GWL_STYLE, GetWindowLong(This->hWnd, GWL_STYLE) | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* center the window with correct dimensions */
|
||||||
|
int x = (WindowPosX != -32000) ? WindowPosX : (This->mode.dmPelsWidth / 2) - (This->render.width / 2);
|
||||||
|
int y = (WindowPosY != -32000) ? WindowPosY : (This->mode.dmPelsHeight / 2) - (This->render.height / 2);
|
||||||
|
RECT dst = { x, y, This->render.width + x, This->render.height + y };
|
||||||
|
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
|
||||||
|
SetWindowPos(ddraw->hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||||
|
MoveWindow(This->hWnd, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), TRUE);
|
||||||
|
This->windowed_init = TRUE;
|
||||||
|
|
||||||
|
if (This->renderer == render_d3d9_main)
|
||||||
|
InitDirect3D9();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -547,7 +559,6 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
|
|||||||
if(This->render.thread == NULL)
|
if(This->render.thread == NULL)
|
||||||
{
|
{
|
||||||
This->render.thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)This->renderer, NULL, 0, NULL);
|
This->render.thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)This->renderer, NULL, 0, NULL);
|
||||||
//SetThreadPriority(This->render.thread, THREAD_PRIORITY_BELOW_NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
@ -998,8 +1009,11 @@ ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
|||||||
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
ReleaseSemaphore(ddraw->render.sem, 1, NULL);
|
||||||
LeaveCriticalSection(&This->cs);
|
LeaveCriticalSection(&This->cs);
|
||||||
|
|
||||||
WaitForSingleObject(This->render.thread, INFINITE);
|
if (This->render.thread)
|
||||||
This->render.thread = NULL;
|
{
|
||||||
|
WaitForSingleObject(This->render.thread, INFINITE);
|
||||||
|
This->render.thread = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (This->renderer == render_d3d9_main)
|
if (This->renderer == render_d3d9_main)
|
||||||
Direct3D9_Release();
|
Direct3D9_Release();
|
||||||
|
@ -130,17 +130,13 @@ BOOL Direct3D9_Release()
|
|||||||
|
|
||||||
if (D3dDev)
|
if (D3dDev)
|
||||||
{
|
{
|
||||||
if (FAILED(D3dDev->lpVtbl->Release(D3dDev)))
|
D3dDev->lpVtbl->Release(D3dDev);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D3dDev = NULL;
|
D3dDev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (D3d)
|
if (D3d)
|
||||||
{
|
{
|
||||||
if (FAILED(D3d->lpVtbl->Release(D3d)))
|
D3d->lpVtbl->Release(D3d);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
D3d = NULL;
|
D3d = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,14 +197,12 @@ static void CreateSettingsIni()
|
|||||||
"sleep=10\n"
|
"sleep=10\n"
|
||||||
"\n"
|
"\n"
|
||||||
"[EMPIRES2]\n"
|
"[EMPIRES2]\n"
|
||||||
"renderer=gdi\n"
|
|
||||||
"hidemouse=false\n"
|
"hidemouse=false\n"
|
||||||
"border=false\n"
|
"border=false\n"
|
||||||
"posX=0\n"
|
"posX=0\n"
|
||||||
"posY=0\n"
|
"posY=0\n"
|
||||||
"\n"
|
"\n"
|
||||||
"[age2_x1]\n"
|
"[age2_x1]\n"
|
||||||
"renderer=gdi\n"
|
|
||||||
"hidemouse=false\n"
|
"hidemouse=false\n"
|
||||||
"border=false\n"
|
"border=false\n"
|
||||||
"posX=0\n"
|
"posX=0\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user