mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
release d3d9 on alt+enter
This commit is contained in:
parent
12655fa5a3
commit
bbe8fa11d8
2
ddraw.rc
2
ddraw.rc
@ -2,7 +2,7 @@
|
|||||||
#define vxstr(a,b,c,d) str(a##.##b##.##c##.##d)
|
#define vxstr(a,b,c,d) str(a##.##b##.##c##.##d)
|
||||||
#define str(s) #s
|
#define str(s) #s
|
||||||
|
|
||||||
#define VERSION 1,2,0,3
|
#define VERSION 1,2,0,4
|
||||||
|
|
||||||
1 VERSIONINFO
|
1 VERSIONINFO
|
||||||
FILEVERSION VERSION
|
FILEVERSION VERSION
|
||||||
|
@ -98,7 +98,7 @@ typedef struct IDirectDrawImpl
|
|||||||
char shader[MAX_PATH];
|
char shader[MAX_PATH];
|
||||||
BOOL wine;
|
BOOL wine;
|
||||||
int sleep;
|
int sleep;
|
||||||
LONG resetDirect3D9;
|
LONG displayModeChanged;
|
||||||
LONG minimized;
|
LONG minimized;
|
||||||
|
|
||||||
} IDirectDrawImpl;
|
} IDirectDrawImpl;
|
||||||
|
23
src/main.c
23
src/main.c
@ -38,9 +38,8 @@ void mouse_unlock();
|
|||||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern HMODULE hD3D9;
|
extern BOOL D3D9_Enabled;
|
||||||
extern D3DPRESENT_PARAMETERS D3dpp;
|
extern HMODULE D3D9_hModule;
|
||||||
extern BOOL UseDirect3D9;
|
|
||||||
|
|
||||||
IDirectDrawImpl *ddraw = NULL;
|
IDirectDrawImpl *ddraw = NULL;
|
||||||
|
|
||||||
@ -241,7 +240,7 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
|||||||
if(!ddraw->windowed)
|
if(!ddraw->windowed)
|
||||||
{
|
{
|
||||||
ChangeDisplaySettings(&This->mode, 0);
|
ChangeDisplaySettings(&This->mode, 0);
|
||||||
InterlockedExchange(&ddraw->resetDirect3D9, TRUE);
|
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
@ -527,15 +526,14 @@ void ToggleFullscreen()
|
|||||||
SetWindowPos(ddraw->hWnd, HWND_TOPMOST, 0, 0, ddraw->render.width, ddraw->render.height, SWP_SHOWWINDOW);
|
SetWindowPos(ddraw->hWnd, HWND_TOPMOST, 0, 0, ddraw->render.width, ddraw->render.height, SWP_SHOWWINDOW);
|
||||||
LastSetWindowPosTick = timeGetTime();
|
LastSetWindowPosTick = timeGetTime();
|
||||||
|
|
||||||
D3dpp.Windowed = FALSE;
|
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||||
InterlockedExchange(&ddraw->resetDirect3D9, TRUE);
|
|
||||||
}
|
}
|
||||||
mouse_lock();
|
mouse_lock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mouse_unlock();
|
mouse_unlock();
|
||||||
D3dpp.Windowed = TRUE;
|
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||||
if(ChangeDisplaySettings(&ddraw->mode, 0) == DISP_CHANGE_SUCCESSFUL)
|
if(ChangeDisplaySettings(&ddraw->mode, 0) == DISP_CHANGE_SUCCESSFUL)
|
||||||
{
|
{
|
||||||
if (!ddraw->border)
|
if (!ddraw->border)
|
||||||
@ -557,11 +555,8 @@ void ToggleFullscreen()
|
|||||||
|
|
||||||
ddraw->windowed = TRUE;
|
ddraw->windowed = TRUE;
|
||||||
ddraw->windowed_init = TRUE;
|
ddraw->windowed_init = TRUE;
|
||||||
InterlockedExchange(&ddraw->resetDirect3D9, TRUE);
|
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
D3dpp.Windowed = FALSE;
|
|
||||||
|
|
||||||
mouse_lock();
|
mouse_lock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -650,7 +645,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
/* minimize our window on defocus when in fullscreen */
|
/* minimize our window on defocus when in fullscreen */
|
||||||
if (!ddraw->windowed)
|
if (!ddraw->windowed)
|
||||||
{
|
{
|
||||||
if (!UseDirect3D9)
|
if (!D3D9_Enabled)
|
||||||
ShowWindow(ddraw->hWnd, SW_MINIMIZE);
|
ShowWindow(ddraw->hWnd, SW_MINIMIZE);
|
||||||
|
|
||||||
ChangeDisplaySettings(&ddraw->mode, 0);
|
ChangeDisplaySettings(&ddraw->mode, 0);
|
||||||
@ -1256,10 +1251,10 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
LPDIRECT3D9 d3d = NULL;
|
LPDIRECT3D9 d3d = NULL;
|
||||||
|
|
||||||
// Win XP/Vista/7 use Direct3D 9 - Win 8/10 and wine use OpenGL
|
// Win XP/Vista/7 use Direct3D 9 - Win 8/10 and wine use OpenGL
|
||||||
if (!This->wine && (major < 6 || (major == 6 && minor == 1)) && (hD3D9 = LoadLibrary("d3d9.dll")))
|
if (!This->wine && (major < 6 || (major == 6 && minor == 1)) && (D3D9_hModule = LoadLibrary("d3d9.dll")))
|
||||||
{
|
{
|
||||||
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
||||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(hD3D9, "Direct3DCreate9");
|
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
||||||
|
|
||||||
if (D3DCreate9 && (d3d = D3DCreate9(D3D_SDK_VERSION)))
|
if (D3DCreate9 && (d3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||||
d3d->lpVtbl->Release(d3d);
|
d3d->lpVtbl->Release(d3d);
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
typedef struct CUSTOMVERTEX { float x, y, z, rhw, u, v; } CUSTOMVERTEX;
|
typedef struct CUSTOMVERTEX { float x, y, z, rhw, u, v; } CUSTOMVERTEX;
|
||||||
|
|
||||||
HMODULE hD3D9;
|
BOOL D3D9_Enabled;
|
||||||
D3DPRESENT_PARAMETERS D3dpp;
|
HMODULE D3D9_hModule;
|
||||||
BOOL UseDirect3D9;
|
|
||||||
|
|
||||||
|
static D3DPRESENT_PARAMETERS D3dpp;
|
||||||
static LPDIRECT3D9 D3d;
|
static LPDIRECT3D9 D3d;
|
||||||
static LPDIRECT3DDEVICE9 D3ddev;
|
static LPDIRECT3DDEVICE9 D3ddev;
|
||||||
static LPDIRECT3DVERTEXBUFFER9 D3dvb;
|
static LPDIRECT3DVERTEXBUFFER9 D3dvb;
|
||||||
@ -38,8 +38,8 @@ DWORD WINAPI render_d3d9_main(void)
|
|||||||
{
|
{
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
|
|
||||||
UseDirect3D9 = CreateDirect3D();
|
D3D9_Enabled = CreateDirect3D();
|
||||||
if (UseDirect3D9)
|
if (D3D9_Enabled)
|
||||||
{
|
{
|
||||||
SetMaxFPS();
|
SetMaxFPS();
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ DWORD WINAPI render_d3d9_main(void)
|
|||||||
|
|
||||||
ReleaseDirect3D();
|
ReleaseDirect3D();
|
||||||
|
|
||||||
if (!UseDirect3D9)
|
if (!D3D9_Enabled)
|
||||||
{
|
{
|
||||||
ShowDriverWarning = TRUE;
|
ShowDriverWarning = TRUE;
|
||||||
ddraw->renderer = render_soft_main;
|
ddraw->renderer = render_soft_main;
|
||||||
@ -63,13 +63,13 @@ static BOOL CreateDirect3D()
|
|||||||
if (!ReleaseDirect3D())
|
if (!ReleaseDirect3D())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!hD3D9)
|
if (!D3D9_hModule)
|
||||||
hD3D9 = LoadLibrary("d3d9.dll");
|
D3D9_hModule = LoadLibrary("d3d9.dll");
|
||||||
|
|
||||||
if (hD3D9)
|
if (D3D9_hModule)
|
||||||
{
|
{
|
||||||
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
||||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(hD3D9, "Direct3DCreate9");
|
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
||||||
|
|
||||||
if (D3DCreate9 && (D3d = D3DCreate9(D3D_SDK_VERSION)))
|
if (D3DCreate9 && (D3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||||
{
|
{
|
||||||
@ -217,8 +217,8 @@ static void SetMaxFPS()
|
|||||||
|
|
||||||
static void Render()
|
static void Render()
|
||||||
{
|
{
|
||||||
DWORD tick_start = 0;
|
DWORD tickStart = 0;
|
||||||
DWORD tick_end = 0;
|
DWORD tickEnd = 0;
|
||||||
BOOL active = TRUE;
|
BOOL active = TRUE;
|
||||||
|
|
||||||
while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, 200) != WAIT_FAILED)
|
while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, 200) != WAIT_FAILED)
|
||||||
@ -237,7 +237,7 @@ static void Render()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (MaxFPS > 0)
|
if (MaxFPS > 0)
|
||||||
tick_start = timeGetTime();
|
tickStart = timeGetTime();
|
||||||
|
|
||||||
EnterCriticalSection(&ddraw->cs);
|
EnterCriticalSection(&ddraw->cs);
|
||||||
|
|
||||||
@ -297,17 +297,17 @@ static void Render()
|
|||||||
LeaveCriticalSection(&ddraw->cs);
|
LeaveCriticalSection(&ddraw->cs);
|
||||||
|
|
||||||
HRESULT hr = D3ddev->lpVtbl->TestCooperativeLevel(D3ddev);
|
HRESULT hr = D3ddev->lpVtbl->TestCooperativeLevel(D3ddev);
|
||||||
|
LONG modeChanged = InterlockedExchange(&ddraw->displayModeChanged, FALSE);
|
||||||
|
LONG minimized = InterlockedExchangeAdd(&ddraw->minimized, 0);
|
||||||
|
|
||||||
if (InterlockedExchangeAdd(&ddraw->minimized, 0))
|
if (minimized || modeChanged)
|
||||||
{
|
{
|
||||||
active = FALSE;
|
active = FALSE;
|
||||||
ReleaseDirect3D();
|
ReleaseDirect3D();
|
||||||
Sleep(200);
|
Sleep(200);
|
||||||
ShowWindow(ddraw->hWnd, SW_SHOWMINNOACTIVE);
|
|
||||||
}
|
if (minimized)
|
||||||
else if (InterlockedExchange(&ddraw->resetDirect3D9, FALSE))
|
ShowWindow(ddraw->hWnd, SW_SHOWMINNOACTIVE);
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
}
|
||||||
else if (hr == D3DERR_DEVICENOTRESET && D3dpp.Windowed)
|
else if (hr == D3DERR_DEVICENOTRESET && D3dpp.Windowed)
|
||||||
{
|
{
|
||||||
@ -328,10 +328,10 @@ static void Render()
|
|||||||
|
|
||||||
if (MaxFPS > 0)
|
if (MaxFPS > 0)
|
||||||
{
|
{
|
||||||
tick_end = timeGetTime();
|
tickEnd = timeGetTime();
|
||||||
|
|
||||||
if (tick_end - tick_start < FrameLength)
|
if (tickEnd - tickStart < FrameLength)
|
||||||
Sleep(FrameLength - (tick_end - tick_start));
|
Sleep(FrameLength - (tickEnd - tickStart));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user