Skip to content

Commit

Permalink
Update shared components from DirectXTK (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Dec 12, 2024
1 parent 494c108 commit a49f715
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 218 deletions.
4 changes: 0 additions & 4 deletions Audio/SoundStreamInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,7 @@ HRESULT SoundStreamInstance::Impl::PlayBuffers() noexcept
if (mPackets[j].state == State::PENDING)
{
DWORD cb = 0;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
const BOOL result = GetOverlappedResultEx(async, &mPackets[j].request, &cb, 0, FALSE);
#else
const BOOL result = GetOverlappedResult(async, &mPackets[j].request, &cb, FALSE);
#endif
if (result)
{
mPackets[j].state = State::READY;
Expand Down
10 changes: 0 additions & 10 deletions Audio/WAVFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,20 +540,10 @@ namespace
return E_INVALIDARG;

// open the file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(
szFileName,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
szFileName,
GENERIC_READ, FILE_SHARE_READ,
nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr)));
#endif

if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down
100 changes: 3 additions & 97 deletions Audio/WaveBankReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,23 +526,13 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
return HRESULT_FROM_WIN32(GetLastError());
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
CREATEFILE2_EXTENDED_PARAMETERS params = { sizeof(CREATEFILE2_EXTENDED_PARAMETERS), 0, 0, 0, {}, nullptr };
params.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
params.dwFileFlags = FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN;
ScopedHandle hFile(safe_handle(CreateFile2(
szFileName,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
&params)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
szFileName,
GENERIC_READ, FILE_SHARE_READ,
nullptr,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN,
nullptr)));
#endif

if (!hFile)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand All @@ -552,29 +542,15 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
OVERLAPPED request = {};
request.hEvent = m_event.get();

bool wait = false;
if (!ReadFile(hFile.get(), &m_header, sizeof(m_header), nullptr, &request))
{
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
}

DWORD bytes;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
std::ignore = wait;

BOOL result = GetOverlappedResultEx(hFile.get(), &request, &bytes, INFINITE, FALSE);
#else
if (wait)
{
std::ignore = WaitForSingleObject(m_event.get(), INFINITE);
}

BOOL result = GetOverlappedResult(hFile.get(), &request, &bytes, FALSE);
#endif

if (!result || (bytes != sizeof(m_header)))
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -602,26 +578,14 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
request.Offset = m_header.Segments[HEADER::SEGIDX_BANKDATA].dwOffset;
request.hEvent = m_event.get();

wait = false;
if (!ReadFile(hFile.get(), &m_data, sizeof(m_data), nullptr, &request))
{
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
result = GetOverlappedResultEx(hFile.get(), &request, &bytes, INFINITE, FALSE);
#else
if (wait)
{
std::ignore = WaitForSingleObject(m_event.get(), INFINITE);
}

result = GetOverlappedResult(hFile.get(), &request, &bytes, FALSE);
#endif

if (!result || (bytes != sizeof(m_data)))
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -688,26 +652,14 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
request.Offset = m_header.Segments[HEADER::SEGIDX_ENTRYNAMES].dwOffset;
request.hEvent = m_event.get();

wait = false;
if (!ReadFile(hFile.get(), temp.get(), namesBytes, nullptr, &request))
{
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
result = GetOverlappedResultEx(hFile.get(), &request, &bytes, INFINITE, FALSE);
#else
if (wait)
{
std::ignore = WaitForSingleObject(m_event.get(), INFINITE);
}

result = GetOverlappedResult(hFile.get(), &request, &bytes, FALSE);
#endif

if (!result || (namesBytes != bytes))
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -741,26 +693,14 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
request.Offset = m_header.Segments[HEADER::SEGIDX_ENTRYMETADATA].dwOffset;
request.hEvent = m_event.get();

wait = false;
if (!ReadFile(hFile.get(), m_entries.get(), metadataBytes, nullptr, &request))
{
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
result = GetOverlappedResultEx(hFile.get(), &request, &bytes, INFINITE, FALSE);
#else
if (wait)
{
std::ignore = WaitForSingleObject(m_event.get(), INFINITE);
}

result = GetOverlappedResult(hFile.get(), &request, &bytes, FALSE);
#endif

if (!result || (metadataBytes != bytes))
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -794,26 +734,14 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
request.Offset = m_header.Segments[HEADER::SEGIDX_SEEKTABLES].dwOffset;
request.hEvent = m_event.get();

wait = false;
if (!ReadFile(hFile.get(), m_seekData.get(), seekLen, nullptr, &request))
{
const DWORD error = GetLastError();
if (error != ERROR_IO_PENDING)
return HRESULT_FROM_WIN32(error);
wait = true;
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
result = GetOverlappedResultEx(hFile.get(), &request, &bytes, INFINITE, FALSE);
#else
if (wait)
{
std::ignore = WaitForSingleObject(m_event.get(), INFINITE);
}

result = GetOverlappedResult(hFile.get(), &request, &bytes, FALSE);
#endif

if (!result || (seekLen != bytes))
{
return HRESULT_FROM_WIN32(GetLastError());
Expand All @@ -840,25 +768,13 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
// If streaming, reopen without buffering
hFile.reset();

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
CREATEFILE2_EXTENDED_PARAMETERS params2 = { sizeof(CREATEFILE2_EXTENDED_PARAMETERS), 0, 0, 0, {}, nullptr };
params2.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
params2.dwFileFlags = FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING;
m_async = CreateFile2(szFileName,
GENERIC_READ,
FILE_SHARE_READ,
OPEN_EXISTING,
m_async = CreateFile2(
szFileName,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
&params2);
#else
m_async = CreateFileW(szFileName,
GENERIC_READ,
FILE_SHARE_READ,
nullptr,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING,
nullptr);
#endif

if (m_async == INVALID_HANDLE_VALUE)
{
return HRESULT_FROM_WIN32(GetLastError());
Expand Down Expand Up @@ -942,13 +858,7 @@ void WaveBankReader::Impl::Close() noexcept
if (m_request.hEvent)
{
DWORD bytes;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
std::ignore = GetOverlappedResultEx(m_async, &m_request, &bytes, INFINITE, FALSE);
#else
std::ignore = WaitForSingleObject(m_request.hEvent, INFINITE);

std::ignore = GetOverlappedResult(m_async, &m_request, &bytes, FALSE);
#endif
}

CloseHandle(m_async);
Expand Down Expand Up @@ -1279,12 +1189,8 @@ bool WaveBankReader::Impl::UpdatePrepared() noexcept
if (m_request.hEvent)
{

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
DWORD bytes;
const BOOL result = GetOverlappedResultEx(m_async, &m_request, &bytes, 0, FALSE);
#else
const bool result = HasOverlappedIoCompleted(&m_request);
#endif
if (result)
{
m_prepared = true;
Expand Down
4 changes: 1 addition & 3 deletions Inc/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@

#if defined(USING_XAUDIO2_REDIST) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || defined(_XBOX_ONE)
#define USING_XAUDIO2_9
#elif (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
#elif (_WIN32_WINNT >= 0x0603 /*_WIN32_WINNT_WINBLUE*/)
#define USING_XAUDIO2_8
#elif (_WIN32_WINNT >= 0x0601 /*_WIN32_WINNT_WIN7*/)
#error Windows 7 SP1 requires the XAudio2Redist NuGet package https://aka.ms/xaudio2redist
#else
#error DirectX Tool Kit for Audio not supported on this platform
#endif
Expand Down
4 changes: 0 additions & 4 deletions Inc/GamePad.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@

#elif defined(USING_XINPUT)
#ifdef _MSC_VER
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/ )
#pragma comment(lib,"xinput.lib")
#else
#pragma comment(lib,"xinput9_1_0.lib")
#endif
#endif
#endif

Expand Down
10 changes: 0 additions & 10 deletions Src/BinaryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,10 @@ HRESULT BinaryReader::ReadEntireFile(
*dataSize = 0;

// Open the file.
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile(safe_handle(CreateFile2(
fileName,
GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
nullptr)));
#else
ScopedHandle hFile(safe_handle(CreateFileW(
fileName,
GENERIC_READ, FILE_SHARE_READ,
nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr)));
#endif

if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());

Expand Down
Loading

0 comments on commit a49f715

Please sign in to comment.