Skip to content

Commit a94ed4e

Browse files
committed
Remove some do...while loops for code clarity
1 parent dcae7bd commit a94ed4e

File tree

4 files changed

+425
-437
lines changed

4 files changed

+425
-437
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 8092
1+
#define BUILD_NUMBER 8093

d3d9/IDirect3D9Ex.cpp

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ template <typename T>
532532
HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, bool IsEx, D3DDISPLAYMODEEX* pFullscreenDisplayMode, T ppReturnedDeviceInterface)
533533
{
534534
// Hook WndProc before creating device
535-
HWND hWnd = (hFocusWindow && IsWindow(hFocusWindow) ? hFocusWindow :
535+
const HWND hWnd = (hFocusWindow && IsWindow(hFocusWindow) ? hFocusWindow :
536536
(pPresentationParameters && IsWindow(pPresentationParameters->hDeviceWindow) ? pPresentationParameters->hDeviceWindow : nullptr));
537537
WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc(hWnd);
538538

@@ -576,6 +576,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
576576

577577
// Check fullscreen
578578
bool ForceFullscreen = false;
579+
bool MultiSampleFlag = false;
579580

580581
// Setup presentation parameters
581582
D3DPRESENT_PARAMETERS d3dpp = {};
@@ -589,87 +590,88 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
589590
CopyMemory(p_d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
590591

591592
UpdatePresentParameter(p_d3dpp, hFocusWindow, DeviceDetails, IsEx, ForceFullscreen, true);
592-
}
593593

594-
bool MultiSampleFlag = false;
594+
// Check for AntiAliasing (doesn't work with FlipEx)
595+
if (Config.AntiAliasing)
596+
{
597+
if (IsEx && Config.FlipEx)
598+
{
599+
LOG_LIMIT(3, __FUNCTION__ << " Warning: AntiAliasing is not supported on FlipEx presentation mode!");
600+
}
601+
else
602+
{
603+
DWORD QualityLevels = 0;
595604

596-
// Check for AntiAliasing (doesn't work with FlipEx)
597-
if (Config.AntiAliasing && pPresentationParameters && !(IsEx && Config.FlipEx))
598-
{
599-
DWORD QualityLevels = 0;
605+
// Check AntiAliasing quality
606+
for (int x = min(D3DMULTISAMPLE_16_SAMPLES, Config.AntiAliasing); x > 0; x--)
607+
{
608+
D3DMULTISAMPLE_TYPE Samples = (D3DMULTISAMPLE_TYPE)x;
609+
D3DFORMAT BufferFormat = (d3dpp.BackBufferFormat) ? d3dpp.BackBufferFormat : D3DFMT_X8R8G8B8;
610+
D3DFORMAT StencilFormat = (d3dpp.AutoDepthStencilFormat) ? d3dpp.AutoDepthStencilFormat : D3DFMT_X8R8G8B8;
600611

601-
// Check AntiAliasing quality
602-
for (int x = min(D3DMULTISAMPLE_16_SAMPLES, Config.AntiAliasing); x > 0; x--)
603-
{
604-
D3DMULTISAMPLE_TYPE Samples = (D3DMULTISAMPLE_TYPE)x;
605-
D3DFORMAT BufferFormat = (d3dpp.BackBufferFormat) ? d3dpp.BackBufferFormat : D3DFMT_X8R8G8B8;
606-
D3DFORMAT StencilFormat = (d3dpp.AutoDepthStencilFormat) ? d3dpp.AutoDepthStencilFormat : D3DFMT_X8R8G8B8;
612+
if (SUCCEEDED(ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, BufferFormat, d3dpp.Windowed, Samples, &QualityLevels)) &&
613+
SUCCEEDED(ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, StencilFormat, d3dpp.Windowed, Samples, &QualityLevels)))
614+
{
615+
// Update Present Parameter for Multisample
616+
UpdatePresentParameterForMultisample(p_d3dpp, Samples, (QualityLevels > 0) ? QualityLevels - 1 : 0);
607617

608-
if (SUCCEEDED(ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, BufferFormat, d3dpp.Windowed, Samples, &QualityLevels)) &&
609-
SUCCEEDED(ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, StencilFormat, d3dpp.Windowed, Samples, &QualityLevels)))
610-
{
611-
// Update Present Parameter for Multisample
612-
UpdatePresentParameterForMultisample(p_d3dpp, Samples, (QualityLevels > 0) ? QualityLevels - 1 : 0);
618+
// Create Device
619+
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, p_d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
613620

614-
// Create Device
615-
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, p_d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
621+
// Check if device was created successfully
622+
if (SUCCEEDED(hr) && ppReturnedDeviceInterface)
623+
{
624+
MultiSampleFlag = true;
616625

617-
// Check if device was created successfully
618-
if (SUCCEEDED(hr) && ppReturnedDeviceInterface)
619-
{
620-
MultiSampleFlag = true;
626+
(*ppReturnedDeviceInterface)->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
621627

622-
(*ppReturnedDeviceInterface)->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
628+
LOG_LIMIT(3, "Setting MultiSample " << d3dpp.MultiSampleType << " Quality " << d3dpp.MultiSampleQuality);
623629

624-
LOG_LIMIT(3, "Setting MultiSample " << d3dpp.MultiSampleType << " Quality " << d3dpp.MultiSampleQuality);
630+
break;
631+
}
632+
}
633+
}
634+
if (FAILED(hr))
635+
{
636+
// Reset presentation parameters
637+
CopyMemory(p_d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
625638

626-
break;
639+
UpdatePresentParameter(p_d3dpp, hFocusWindow, DeviceDetails, IsEx, ForceFullscreen, false);
640+
641+
LOG_LIMIT(100, __FUNCTION__ << " Failed to enable AntiAliasing!");
627642
}
628643
}
629644
}
630-
if (FAILED(hr))
631-
{
632-
LOG_LIMIT(100, __FUNCTION__ << " Failed to enable AntiAliasing!");
633-
}
634-
}
635-
else if (Config.AntiAliasing && IsEx && Config.FlipEx)
636-
{
637-
LOG_LIMIT(3, __FUNCTION__ << " Warning: AntiAliasing is not supported on FlipEx presentation mode!");
638645
}
639646

640647
// Create Device
641648
if (FAILED(hr))
642649
{
643-
// Update presentation parameters
644-
if (pPresentationParameters)
645-
{
646-
CopyMemory(p_d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
647-
UpdatePresentParameter(p_d3dpp, hFocusWindow, DeviceDetails, IsEx, ForceFullscreen, false);
648-
}
649-
650-
// Create Device
651650
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, p_d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
652651
}
653652

654-
if (SUCCEEDED(hr) && pPresentationParameters)
653+
if (SUCCEEDED(hr))
655654
{
656-
GetFinalPresentParameter(p_d3dpp, DeviceDetails);
655+
if (pPresentationParameters)
656+
{
657+
GetFinalPresentParameter(p_d3dpp, DeviceDetails);
657658

658-
d3dpp.Windowed = DeviceDetails.AppRequestedWindowMode;
659+
d3dpp.Windowed = DeviceDetails.AppRequestedWindowMode;
659660

660-
if (MultiSampleFlag)
661-
{
662-
DeviceDetails.DeviceMultiSampleFlag = true;
663-
DeviceDetails.DeviceMultiSampleType = d3dpp.MultiSampleType;
664-
DeviceDetails.DeviceMultiSampleQuality = d3dpp.MultiSampleQuality;
665-
}
661+
if (MultiSampleFlag)
662+
{
663+
DeviceDetails.DeviceMultiSampleFlag = true;
664+
DeviceDetails.DeviceMultiSampleType = d3dpp.MultiSampleType;
665+
DeviceDetails.DeviceMultiSampleQuality = d3dpp.MultiSampleQuality;
666+
}
666667

667-
CopyMemory(pPresentationParameters, p_d3dpp, sizeof(D3DPRESENT_PARAMETERS));
668+
CopyMemory(pPresentationParameters, p_d3dpp, sizeof(D3DPRESENT_PARAMETERS));
668669

669-
// Adjust window style after device creation
670-
if (IsWindow(DeviceDetails.DeviceWindow))
671-
{
672-
AdjustWindowStyle(DeviceDetails.DeviceWindow);
670+
// Adjust window style after device creation
671+
if (IsWindow(DeviceDetails.DeviceWindow))
672+
{
673+
AdjustWindowStyle(DeviceDetails.DeviceWindow);
674+
}
673675
}
674676
}
675677

d3d9/IDirect3DDevice9Ex.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,16 +3388,16 @@ HRESULT m_IDirect3DDevice9Ex::ResetT(T func, D3DPRESENT_PARAMETERS* pPresentatio
33883388

33893389
ProxyInterface->EndScene(); // Required for some games when using WineD3D
33903390

3391-
HRESULT hr;
3391+
HRESULT hr = D3DERR_INVALIDCALL;
33923392

33933393
// Check if display needs to be reset
3394-
bool IsSettingWindowMode = (pPresentationParameters ? pPresentationParameters->Windowed != FALSE : false);
3395-
bool IsWindowModeChanging = (SHARED.IsWindowMode != IsSettingWindowMode);
3396-
bool IsResolutionChanging = pPresentationParameters ?
3394+
const bool IsSettingWindowMode = (pPresentationParameters ? pPresentationParameters->Windowed != FALSE : false);
3395+
const bool IsWindowModeChanging = (SHARED.IsWindowMode != IsSettingWindowMode);
3396+
const bool IsResolutionChanging = pPresentationParameters ?
33973397
(SHARED.BufferWidth != (LONG)pPresentationParameters->BackBufferWidth || SHARED.BufferHeight != (LONG)pPresentationParameters->BackBufferHeight) : false;
33983398

33993399
// Hook WndProc before creating device
3400-
HWND hWnd = (pPresentationParameters && IsWindow(pPresentationParameters->hDeviceWindow) ? pPresentationParameters->hDeviceWindow : SHARED.DeviceWindow);
3400+
const HWND hWnd = (pPresentationParameters && IsWindow(pPresentationParameters->hDeviceWindow) ? pPresentationParameters->hDeviceWindow : SHARED.DeviceWindow);
34013401
WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc(hWnd);
34023402

34033403
bool tmpFlag = false;
@@ -3417,6 +3417,7 @@ HRESULT m_IDirect3DDevice9Ex::ResetT(T func, D3DPRESENT_PARAMETERS* pPresentatio
34173417

34183418
// Check fullscreen
34193419
bool ForceFullscreen = false;
3420+
bool ClearMultiSampled = (pPresentationParameters != nullptr); // Don't clear if pPresentationParameters is null
34203421

34213422
// Setup presentation parameters
34223423
D3DPRESENT_PARAMETERS d3dpp = {};
@@ -3428,49 +3429,45 @@ HRESULT m_IDirect3DDevice9Ex::ResetT(T func, D3DPRESENT_PARAMETERS* pPresentatio
34283429
CopyMemory(p_d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
34293430

34303431
m_IDirect3D9Ex::UpdatePresentParameter(p_d3dpp, SHARED.DeviceWindow, SHARED, IsEx, ForceFullscreen, IsWindowModeChanging || IsResolutionChanging);
3431-
}
3432-
3433-
// Test for Multisample
3434-
if (SHARED.DeviceMultiSampleFlag && pPresentationParameters)
3435-
{
3436-
do {
34373432

3433+
// Test for Multisample
3434+
if (SHARED.DeviceMultiSampleFlag)
3435+
{
34383436
// Update Present Parameter for Multisample
34393437
m_IDirect3D9Ex::UpdatePresentParameterForMultisample(p_d3dpp, SHARED.DeviceMultiSampleType, SHARED.DeviceMultiSampleQuality);
34403438

34413439
// Reset device
34423440
hr = ResetT(func, p_d3dpp, pFullscreenDisplayMode);
34433441

34443442
// Check if device was reset successfully
3445-
if (SUCCEEDED(hr))
3443+
if (FAILED(hr))
34463444
{
3447-
break;
3448-
}
3449-
3450-
// Reset presentation parameters
3451-
CopyMemory(p_d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
3445+
// Reset presentation parameters
3446+
CopyMemory(p_d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
34523447

3453-
m_IDirect3D9Ex::UpdatePresentParameter(p_d3dpp, SHARED.DeviceWindow, SHARED, IsEx, ForceFullscreen, false);
3448+
m_IDirect3D9Ex::UpdatePresentParameter(p_d3dpp, SHARED.DeviceWindow, SHARED, IsEx, ForceFullscreen, false);
34543449

3455-
// Reset device
3456-
hr = ResetT(func, p_d3dpp, pFullscreenDisplayMode);
3457-
3458-
if (SUCCEEDED(hr))
3459-
{
3460-
LOG_LIMIT(3, __FUNCTION__ << " Disabling AntiAliasing...");
3461-
SHARED.DeviceMultiSampleFlag = false;
3462-
SHARED.DeviceMultiSampleType = D3DMULTISAMPLE_NONE;
3463-
SHARED.DeviceMultiSampleQuality = 0;
3464-
SHARED.SetSSAA = false;
3465-
SHARED.SetATOC = false;
3450+
ClearMultiSampled = true;
34663451
}
3467-
3468-
} while (false);
3452+
}
34693453
}
3470-
else
3454+
3455+
// Reset device
3456+
if (FAILED(hr))
34713457
{
34723458
// Reset device
34733459
hr = ResetT(func, p_d3dpp, pFullscreenDisplayMode);
3460+
3461+
// Clear multi-sampled variables
3462+
if (ClearMultiSampled)
3463+
{
3464+
LOG_LIMIT(3, __FUNCTION__ << " Disabling AntiAliasing...");
3465+
SHARED.DeviceMultiSampleFlag = false;
3466+
SHARED.DeviceMultiSampleType = D3DMULTISAMPLE_NONE;
3467+
SHARED.DeviceMultiSampleQuality = 0;
3468+
SHARED.SetSSAA = false;
3469+
SHARED.SetATOC = false;
3470+
}
34743471
}
34753472

34763473
ClearVars();

0 commit comments

Comments
 (0)