From f039e3c6687e2e967a0902dc2426d6d4153d5d92 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 26 Oct 2014 03:36:49 +0300 Subject: [PATCH 1/3] precompiled for msvc fix --- neo/CMakeLists.txt | 10 ++++++---- neo/idlib/CMakeLists.txt | 26 ++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 062a9fa5..51ba3ba1 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -1272,19 +1272,21 @@ if(MSVC) list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/renderer/jobs/staticshadowvolume/StaticShadowVolume.cpp) list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/renderer/jobs/ShadowShared.cpp) list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/renderer/RenderLog.cpp) + list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/framework/precompiled.cpp) + - foreach( src_file ${RBDOOM3_PRECOMPILED_SOURCES} ) - #message(STATUS "/Yuprecompiled.h for ${src_file}") set_source_files_properties( - ${src_file} + ${RBDOOM3_PRECOMPILED_SOURCES} PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h" + OBJECT_DEPENDS "precompiled.pch" + ) - endforeach() set_source_files_properties(framework/precompiled.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h" + OBJECT_OUTPUTS "precompiled.pch" ) list(APPEND RBDOOM3_SOURCES ${WIN32_RESOURCES}) diff --git a/neo/idlib/CMakeLists.txt b/neo/idlib/CMakeLists.txt index 0fcbfbfc..72845fbd 100644 --- a/neo/idlib/CMakeLists.txt +++ b/neo/idlib/CMakeLists.txt @@ -84,23 +84,21 @@ list(REMOVE_ITEM ID_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/geometry/Ren list(REMOVE_ITEM ID_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/SoftwareCache.cpp) if(MSVC) - - #set_target_properties(idlib PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h") - - foreach( src_file ${ID_PRECOMPILED_SOURCES} ) - #message(STATUS "/Yuprecompiled.h for ${src_file}") - set_source_files_properties( - ${src_file} - PROPERTIES - COMPILE_FLAGS "/Yuprecompiled.h" - ) - endforeach() - - set_source_files_properties(precompiled.cpp + list(REMOVE_ITEM ID_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.cpp) + + #set_target_properties(idlib PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h") + set_source_files_properties(precompiled.cpp PROPERTIES COMPILE_FLAGS "/Ycprecompiled.h" + OBJECT_OUTPUTS "precompiled.pch" ) - + set_source_files_properties( + ${ID_PRECOMPILED_SOURCES} + PROPERTIES + COMPILE_FLAGS "/Yuprecompiled.h" + OBJECT_DEPENDS "precompiled.pch" + ) + add_library(idlib ${ID_SOURCES_ALL} ${ID_INCLUDES_ALL}) else() foreach( src_file ${ID_PRECOMPILED_SOURCES} ) From aab81a225f2c2ef89b51df62ccc2c9161becbae0 Mon Sep 17 00:00:00 2001 From: palmalcheg Date: Mon, 27 Oct 2014 04:39:10 +0200 Subject: [PATCH 2/3] sound for WinRT --- neo/CMakeLists.txt | 3 +- neo/sound/XAudio2/XA2_SoundHardware.cpp | 134 +++++++++++++++++++++--- neo/sound/snd_local.h | 18 +++- 3 files changed, 139 insertions(+), 16 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 51ba3ba1..33b1df3d 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -157,7 +157,8 @@ elseif(MSVC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS - -D_MBCS + -D_MBCS + -DUSE_WINRT #-DUSE_OPENAL -DUSE_EXCEPTIONS) diff --git a/neo/sound/XAudio2/XA2_SoundHardware.cpp b/neo/sound/XAudio2/XA2_SoundHardware.cpp index b70d1d7b..57efc810 100644 --- a/neo/sound/XAudio2/XA2_SoundHardware.cpp +++ b/neo/sound/XAudio2/XA2_SoundHardware.cpp @@ -258,18 +258,124 @@ void idSoundHardware_XAudio2::Init() // Register the sound engine callback pXAudio2->RegisterForCallbacks( &soundEngineCallback ); soundEngineCallback.hardware = this; - -// RB: not available on Windows 8 SDK + UINT32 deviceCount = 0; + DWORD outputSampleRate = 44100; // Max( (DWORD)XAUDIO2FX_REVERB_MIN_FRAMERATE, Min( (DWORD)XAUDIO2FX_REVERB_MAX_FRAMERATE, deviceDetails.OutputFormat.Format.nSamplesPerSec ) ); + + // RB: not available on Windows 8 SDK #if defined(USE_WINRT) //(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) - // FIXME - - idLib::Warning( "No audio devices found" ); - pXAudio2->Release(); - pXAudio2 = NULL; - return; -#else - UINT32 deviceCount = 0; + IMMDeviceEnumerator *immDevEnum = nullptr; + IMMDeviceCollection *immDevCollection = nullptr; + IMMDevice *immDev = nullptr; + std::vector vAudioDevices; + + HRESULT hResult = CoCreateInstance( + __uuidof(MMDeviceEnumerator), NULL, + CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**) &immDevEnum); + + if (FAILED(hResult)) { + idLib::Warning( "Failed to get audio enumerator" ); + pXAudio2->Release(); + pXAudio2 = NULL; + return; + } + + hResult = immDevEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &immDevCollection); + if (FAILED(hResult)) { + idLib::Warning( "Failed to get audio endpoints" ); + pXAudio2->Release(); + pXAudio2 = NULL; + return; + } + + hResult = immDevCollection->GetCount(&deviceCount); + if (FAILED(hResult)) { + idLib::Warning( "No audio devices found" ); + pXAudio2->Release(); + pXAudio2 = NULL; + return; + } + + for (UINT i = 0; i < deviceCount; i++) { + IPropertyStore *propStore = nullptr; + PROPVARIANT varName; + PROPVARIANT varId; + + PropVariantInit(&varId); + PropVariantInit(&varName); + + hResult = immDevCollection->Item(i, &immDev); + if (SUCCEEDED(hResult)) { + hResult = immDev->OpenPropertyStore(STGM_READ, &propStore); + } + if (SUCCEEDED(hResult)) { + hResult = propStore->GetValue(PKEY_AudioEndpoint_Path, &varId); + } + + if (SUCCEEDED(hResult)) { + hResult = propStore->GetValue(PKEY_Device_FriendlyName, &varName); + } + + if (SUCCEEDED(hResult)) { + assert(varId.vt == VT_LPWSTR); + assert(varName.vt == VT_LPWSTR); + + // Now save somewhere the device display name & id + AudioDevice ad; + ad.name = varName.pwszVal; + ad.id = varId.pwszVal; + + vAudioDevices.push_back(ad); + } + + PropVariantClear(&varName); + PropVariantClear(&varId); + + if (propStore != nullptr) { + propStore->Release(); + } + + if (immDev != nullptr) { + immDev->Release(); + } + } + + + immDevCollection->Release(); + immDevEnum->Release(); + + int preferredDevice = s_device.GetInteger(); + if (!vAudioDevices.empty()) { + if (SUCCEEDED(pXAudio2->CreateMasteringVoice(&pMasterVoice, + XAUDIO2_DEFAULT_CHANNELS, + outputSampleRate, + 0, + vAudioDevices.at(0).id.c_str(), + NULL, + AudioCategory_GameEffects))) + { + XAUDIO2_VOICE_DETAILS deviceDetails; + pMasterVoice->GetVoiceDetails(&deviceDetails); + + pMasterVoice->SetVolume(DBtoLinear(s_volume_dB.GetFloat())); + + outputChannels = deviceDetails.InputChannels; + DWORD win8_channelMask; + pMasterVoice->GetChannelMask(&win8_channelMask); + + channelMask = (unsigned int)win8_channelMask; + idLib::Printf( "Using device %s\n", vAudioDevices.at(0).name ); + + } + else { + idLib::Warning("Failed to create master voice"); + pXAudio2->Release(); + pXAudio2 = NULL; + return; + } + } + +#else if( pXAudio2->GetDeviceCount( &deviceCount ) != S_OK || deviceCount == 0 ) { idLib::Warning( "No audio devices found" ); @@ -322,8 +428,7 @@ void idSoundHardware_XAudio2::Init() return; } - DWORD outputSampleRate = 44100; // Max( (DWORD)XAUDIO2FX_REVERB_MIN_FRAMERATE, Min( (DWORD)XAUDIO2FX_REVERB_MAX_FRAMERATE, deviceDetails.OutputFormat.Format.nSamplesPerSec ) ); - + if( FAILED( pXAudio2->CreateMasteringVoice( &pMasterVoice, XAUDIO2_DEFAULT_CHANNELS, outputSampleRate, 0, preferredDevice, NULL ) ) ) { idLib::Warning( "Failed to create master voice" ); @@ -335,7 +440,9 @@ void idSoundHardware_XAudio2::Init() outputChannels = deviceDetails.OutputFormat.Format.nChannels; channelMask = deviceDetails.OutputFormat.dwChannelMask; - + +#endif // #if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) + idSoundVoice::InitSurround( outputChannels, channelMask ); #if defined(USE_DOOMCLASSIC) @@ -409,7 +516,6 @@ void idSoundHardware_XAudio2::Init() { freeVoices[i] = &voices[i]; } -#endif // #if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) // RB end } diff --git a/neo/sound/snd_local.h b/neo/sound/snd_local.h index cf372c08..208b8fba 100644 --- a/neo/sound/snd_local.h +++ b/neo/sound/snd_local.h @@ -137,7 +137,23 @@ ID_INLINE_EXTERN ALCenum CheckALCErrors_( ALCdevice* device, const char* filenam #define OPERATION_SET 1 // RB: not available on Windows 8 SDK -#if !defined(USE_WINRT) // (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) +#if defined(USE_WINRT) // (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) +#include +#include // For the pkey defines to be properly instantiated. +#include +#include "functiondiscoverykeys_devpkey.h" +#include +#include + +DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_Path, 0x9c119480, 0xddc2, 0x4954, 0xa1, 0x50, 0x5b, 0xd2, 0x40, 0xd4, 0x54, 0xad, 1); + +#pragma comment(lib,"xaudio2.lib") + +struct AudioDevice { + std::wstring name; + std::wstring id; +}; +#else #include #endif // RB end From 27387e664b1d1c86187cb12f6fb067f31605df20 Mon Sep 17 00:00:00 2001 From: palmalcheg Date: Mon, 27 Oct 2014 22:20:20 +0200 Subject: [PATCH 3/3] cmake definition on winrt detection, log device info --- neo/CMakeLists.txt | 7 +++++-- neo/sound/XAudio2/XA2_SoundHardware.cpp | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 33b1df3d..48c3a01c 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -158,9 +158,12 @@ elseif(MSVC) -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_MBCS - -DUSE_WINRT - #-DUSE_OPENAL + #-DUSE_OPENAL -DUSE_EXCEPTIONS) + ## Check for Version ## + if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.2 ) # Windows 8 + add_definitions(-DUSE_WINRT) + endif() if(NOT CMAKE_CL_64) add_definitions(-D_USE_32BIT_TIME_T) diff --git a/neo/sound/XAudio2/XA2_SoundHardware.cpp b/neo/sound/XAudio2/XA2_SoundHardware.cpp index 57efc810..1e4731c4 100644 --- a/neo/sound/XAudio2/XA2_SoundHardware.cpp +++ b/neo/sound/XAudio2/XA2_SoundHardware.cpp @@ -365,7 +365,6 @@ void idSoundHardware_XAudio2::Init() channelMask = (unsigned int)win8_channelMask; idLib::Printf( "Using device %s\n", vAudioDevices.at(0).name ); - } else { idLib::Warning("Failed to create master voice");