mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +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 str(s) #s
|
||||
|
||||
#define VERSION 1,2,0,3
|
||||
#define VERSION 1,2,0,4
|
||||
|
||||
1 VERSIONINFO
|
||||
FILEVERSION VERSION
|
||||
|
@ -98,7 +98,7 @@ typedef struct IDirectDrawImpl
|
||||
char shader[MAX_PATH];
|
||||
BOOL wine;
|
||||
int sleep;
|
||||
LONG resetDirect3D9;
|
||||
LONG displayModeChanged;
|
||||
LONG minimized;
|
||||
|
||||
} IDirectDrawImpl;
|
||||
|
23
src/main.c
23
src/main.c
@ -38,9 +38,8 @@ void mouse_unlock();
|
||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||
#endif
|
||||
|
||||
extern HMODULE hD3D9;
|
||||
extern D3DPRESENT_PARAMETERS D3dpp;
|
||||
extern BOOL UseDirect3D9;
|
||||
extern BOOL D3D9_Enabled;
|
||||
extern HMODULE D3D9_hModule;
|
||||
|
||||
IDirectDrawImpl *ddraw = NULL;
|
||||
|
||||
@ -241,7 +240,7 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This)
|
||||
if(!ddraw->windowed)
|
||||
{
|
||||
ChangeDisplaySettings(&This->mode, 0);
|
||||
InterlockedExchange(&ddraw->resetDirect3D9, TRUE);
|
||||
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||
}
|
||||
|
||||
return DD_OK;
|
||||
@ -527,15 +526,14 @@ void ToggleFullscreen()
|
||||
SetWindowPos(ddraw->hWnd, HWND_TOPMOST, 0, 0, ddraw->render.width, ddraw->render.height, SWP_SHOWWINDOW);
|
||||
LastSetWindowPosTick = timeGetTime();
|
||||
|
||||
D3dpp.Windowed = FALSE;
|
||||
InterlockedExchange(&ddraw->resetDirect3D9, TRUE);
|
||||
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||
}
|
||||
mouse_lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
mouse_unlock();
|
||||
D3dpp.Windowed = TRUE;
|
||||
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||
if(ChangeDisplaySettings(&ddraw->mode, 0) == DISP_CHANGE_SUCCESSFUL)
|
||||
{
|
||||
if (!ddraw->border)
|
||||
@ -557,11 +555,8 @@ void ToggleFullscreen()
|
||||
|
||||
ddraw->windowed = TRUE;
|
||||
ddraw->windowed_init = TRUE;
|
||||
InterlockedExchange(&ddraw->resetDirect3D9, TRUE);
|
||||
InterlockedExchange(&ddraw->displayModeChanged, TRUE);
|
||||
}
|
||||
else
|
||||
D3dpp.Windowed = FALSE;
|
||||
|
||||
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 */
|
||||
if (!ddraw->windowed)
|
||||
{
|
||||
if (!UseDirect3D9)
|
||||
if (!D3D9_Enabled)
|
||||
ShowWindow(ddraw->hWnd, SW_MINIMIZE);
|
||||
|
||||
ChangeDisplaySettings(&ddraw->mode, 0);
|
||||
@ -1256,10 +1251,10 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
||||
LPDIRECT3D9 d3d = NULL;
|
||||
|
||||
// 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 *)(UINT))GetProcAddress(hD3D9, "Direct3DCreate9");
|
||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
||||
|
||||
if (D3DCreate9 && (d3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||
d3d->lpVtbl->Release(d3d);
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
typedef struct CUSTOMVERTEX { float x, y, z, rhw, u, v; } CUSTOMVERTEX;
|
||||
|
||||
HMODULE hD3D9;
|
||||
D3DPRESENT_PARAMETERS D3dpp;
|
||||
BOOL UseDirect3D9;
|
||||
BOOL D3D9_Enabled;
|
||||
HMODULE D3D9_hModule;
|
||||
|
||||
static D3DPRESENT_PARAMETERS D3dpp;
|
||||
static LPDIRECT3D9 D3d;
|
||||
static LPDIRECT3DDEVICE9 D3ddev;
|
||||
static LPDIRECT3DVERTEXBUFFER9 D3dvb;
|
||||
@ -38,8 +38,8 @@ DWORD WINAPI render_d3d9_main(void)
|
||||
{
|
||||
Sleep(500);
|
||||
|
||||
UseDirect3D9 = CreateDirect3D();
|
||||
if (UseDirect3D9)
|
||||
D3D9_Enabled = CreateDirect3D();
|
||||
if (D3D9_Enabled)
|
||||
{
|
||||
SetMaxFPS();
|
||||
|
||||
@ -48,7 +48,7 @@ DWORD WINAPI render_d3d9_main(void)
|
||||
|
||||
ReleaseDirect3D();
|
||||
|
||||
if (!UseDirect3D9)
|
||||
if (!D3D9_Enabled)
|
||||
{
|
||||
ShowDriverWarning = TRUE;
|
||||
ddraw->renderer = render_soft_main;
|
||||
@ -63,13 +63,13 @@ static BOOL CreateDirect3D()
|
||||
if (!ReleaseDirect3D())
|
||||
return FALSE;
|
||||
|
||||
if (!hD3D9)
|
||||
hD3D9 = LoadLibrary("d3d9.dll");
|
||||
if (!D3D9_hModule)
|
||||
D3D9_hModule = LoadLibrary("d3d9.dll");
|
||||
|
||||
if (hD3D9)
|
||||
if (D3D9_hModule)
|
||||
{
|
||||
IDirect3D9 *(WINAPI *D3DCreate9)(UINT) =
|
||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(hD3D9, "Direct3DCreate9");
|
||||
(IDirect3D9 *(WINAPI *)(UINT))GetProcAddress(D3D9_hModule, "Direct3DCreate9");
|
||||
|
||||
if (D3DCreate9 && (D3d = D3DCreate9(D3D_SDK_VERSION)))
|
||||
{
|
||||
@ -217,8 +217,8 @@ static void SetMaxFPS()
|
||||
|
||||
static void Render()
|
||||
{
|
||||
DWORD tick_start = 0;
|
||||
DWORD tick_end = 0;
|
||||
DWORD tickStart = 0;
|
||||
DWORD tickEnd = 0;
|
||||
BOOL active = TRUE;
|
||||
|
||||
while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, 200) != WAIT_FAILED)
|
||||
@ -237,7 +237,7 @@ static void Render()
|
||||
#endif
|
||||
|
||||
if (MaxFPS > 0)
|
||||
tick_start = timeGetTime();
|
||||
tickStart = timeGetTime();
|
||||
|
||||
EnterCriticalSection(&ddraw->cs);
|
||||
|
||||
@ -297,17 +297,17 @@ static void Render()
|
||||
LeaveCriticalSection(&ddraw->cs);
|
||||
|
||||
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;
|
||||
ReleaseDirect3D();
|
||||
Sleep(200);
|
||||
ShowWindow(ddraw->hWnd, SW_SHOWMINNOACTIVE);
|
||||
}
|
||||
else if (InterlockedExchange(&ddraw->resetDirect3D9, FALSE))
|
||||
{
|
||||
Reset();
|
||||
|
||||
if (minimized)
|
||||
ShowWindow(ddraw->hWnd, SW_SHOWMINNOACTIVE);
|
||||
}
|
||||
else if (hr == D3DERR_DEVICENOTRESET && D3dpp.Windowed)
|
||||
{
|
||||
@ -328,10 +328,10 @@ static void Render()
|
||||
|
||||
if (MaxFPS > 0)
|
||||
{
|
||||
tick_end = timeGetTime();
|
||||
tickEnd = timeGetTime();
|
||||
|
||||
if (tick_end - tick_start < FrameLength)
|
||||
Sleep(FrameLength - (tick_end - tick_start));
|
||||
if (tickEnd - tickStart < FrameLength)
|
||||
Sleep(FrameLength - (tickEnd - tickStart));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user