mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-28 15:55:39 +00:00
Adjusts the OpenAL device listing query to ensure more reliable results.
This commit is contained in:
parent
cb63b382ff
commit
e47fe2b1f3
3 changed files with 41 additions and 44 deletions
|
|
@ -33,10 +33,11 @@
|
||||||
#include <al/alc.h>
|
#include <al/alc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init call
|
* Init call
|
||||||
*/
|
*/
|
||||||
ALDeviceList::ALDeviceList( const OPENALFNTABLE &oalft )
|
ALDeviceList::ALDeviceList( const OPENALFNTABLE& oalft )
|
||||||
{
|
{
|
||||||
VECTOR_SET_ASSOCIATION( vDeviceInfo );
|
VECTOR_SET_ASSOCIATION( vDeviceInfo );
|
||||||
|
|
||||||
|
|
@ -44,8 +45,9 @@ ALDeviceList::ALDeviceList( const OPENALFNTABLE &oalft )
|
||||||
char *devices;
|
char *devices;
|
||||||
int index;
|
int index;
|
||||||
const char *defaultDeviceName;
|
const char *defaultDeviceName;
|
||||||
|
const char *actualDeviceName;
|
||||||
|
|
||||||
dMemcpy( &ALFunction, &oalft, sizeof( OPENALFNTABLE ) );
|
dMemcpy( &ALFunction, &oalft, sizeof(OPENALFNTABLE) );
|
||||||
|
|
||||||
// DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support
|
// DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support
|
||||||
vDeviceInfo.clear();
|
vDeviceInfo.clear();
|
||||||
|
|
@ -66,44 +68,48 @@ ALDeviceList::ALDeviceList( const OPENALFNTABLE &oalft )
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
// go through device list (each device terminated with a single NULL, list terminated with double NULL)
|
// go through device list (each device terminated with a single NULL, list terminated with double NULL)
|
||||||
while (*devices != 0) {
|
while (*devices != '\0') {
|
||||||
if (String::compare(defaultDeviceName, devices) == 0) {
|
if (String::compare(defaultDeviceName, devices) == 0) {
|
||||||
defaultDeviceIndex = index;
|
defaultDeviceIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bNewName = true;
|
ALCdevice* device = ALFunction.alcOpenDevice(devices);
|
||||||
for (int i = 0; i < GetNumDevices(); i++) {
|
if (device)
|
||||||
if (String::compare(GetDeviceName(i), devices) == 0) {
|
|
||||||
bNewName = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((bNewName) && (devices != NULL) && (dStrlen(devices) > 0))
|
|
||||||
{
|
{
|
||||||
dMemset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO));
|
ALCcontext* ctx = ALFunction.alcCreateContext(device, nullptr);
|
||||||
ALDeviceInfo.bSelected = true;
|
|
||||||
dStrncpy(ALDeviceInfo.strInternalDeviceName, devices, sizeof(ALDeviceInfo.strInternalDeviceName));
|
if (ctx)
|
||||||
char deviceExternal[256];
|
|
||||||
dStrcpy(deviceExternal, devices, 256);
|
|
||||||
char* openFind = dStrchr(deviceExternal, '(');
|
|
||||||
if (openFind)
|
|
||||||
{
|
{
|
||||||
char* deviceName = openFind + 1;
|
ALFunction.alcMakeContextCurrent(ctx);
|
||||||
char* closeFind = dStrchr(deviceName, ')');
|
actualDeviceName = ALFunction.alcGetString(device, ALC_DEVICE_SPECIFIER);
|
||||||
if (closeFind)
|
bool bNewName = true;
|
||||||
(*closeFind) = '\0';
|
|
||||||
|
|
||||||
dStrncpy(ALDeviceInfo.strDeviceName, deviceName, sizeof(ALDeviceInfo.strDeviceName));
|
if (actualDeviceName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < GetNumDevices(); i++) {
|
||||||
|
if (String::compare(GetDeviceName(i), devices) == 0) {
|
||||||
|
bNewName = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((bNewName) && (actualDeviceName != NULL) && (dStrlen(actualDeviceName) > 0))
|
||||||
|
{
|
||||||
|
dMemset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO));
|
||||||
|
ALDeviceInfo.bSelected = true;
|
||||||
|
dStrncpy(ALDeviceInfo.strDeviceName, actualDeviceName, sizeof(ALDeviceInfo.strDeviceName));
|
||||||
|
char deviceExternal[256];
|
||||||
|
dStrcpy(deviceExternal, devices, 256);
|
||||||
|
|
||||||
|
vDeviceInfo.push_back(ALDeviceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
ALFunction.alcMakeContextCurrent(nullptr);
|
||||||
|
ALFunction.alcDestroyContext(ctx);
|
||||||
}
|
}
|
||||||
else
|
ALFunction.alcCloseDevice(device);
|
||||||
{
|
|
||||||
dStrncpy(ALDeviceInfo.strDeviceName, devices, sizeof(ALDeviceInfo.strDeviceName));
|
|
||||||
}
|
|
||||||
|
|
||||||
vDeviceInfo.push_back(ALDeviceInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
devices += dStrlen(devices) + 1;
|
devices += dStrlen(devices) + 1;
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -129,14 +135,6 @@ int ALDeviceList::GetNumDevices()
|
||||||
/*
|
/*
|
||||||
* Returns the device name at an index in the complete device list
|
* Returns the device name at an index in the complete device list
|
||||||
*/
|
*/
|
||||||
const char *ALDeviceList::GetInternalDeviceName(int index)
|
|
||||||
{
|
|
||||||
if (index < GetNumDevices())
|
|
||||||
return vDeviceInfo[index].strInternalDeviceName;
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* ALDeviceList::GetDeviceName(int index)
|
const char* ALDeviceList::GetDeviceName(int index)
|
||||||
{
|
{
|
||||||
if (index < GetNumDevices())
|
if (index < GetNumDevices())
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ public:
|
||||||
~ALDeviceList ();
|
~ALDeviceList ();
|
||||||
S32 GetNumDevices();
|
S32 GetNumDevices();
|
||||||
const char *GetDeviceName(S32 index);
|
const char *GetDeviceName(S32 index);
|
||||||
const char *GetInternalDeviceName(S32 index);
|
|
||||||
void GetDeviceVersion(S32 index, S32 *major, S32 *minor);
|
void GetDeviceVersion(S32 index, S32 *major, S32 *minor);
|
||||||
U32 GetMaxNumSources(S32 index);
|
U32 GetMaxNumSources(S32 index);
|
||||||
bool IsExtensionSupported(S32 index, SFXALCaps caps);
|
bool IsExtensionSupported(S32 index, SFXALCaps caps);
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ void SFXALProvider::init()
|
||||||
{
|
{
|
||||||
ALDeviceInfo* info = new ALDeviceInfo;
|
ALDeviceInfo* info = new ALDeviceInfo;
|
||||||
|
|
||||||
info->internalName = String( mALDL->GetInternalDeviceName( i ) );
|
//info->internalName = String( mALDL->GetInternalDeviceName( i ) );
|
||||||
info->name = String( mALDL->GetDeviceName( i ) );
|
info->name = String( mALDL->GetDeviceName( i ) );
|
||||||
|
|
||||||
mDeviceInfo.push_back( info );
|
mDeviceInfo.push_back( info );
|
||||||
|
|
@ -114,14 +114,14 @@ SFXALProvider::~SFXALProvider()
|
||||||
delete mALDL;
|
delete mALDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SFXDevice *SFXALProvider::createDevice( const String& deviceName, bool useHardware, S32 maxBuffers )
|
SFXDevice* SFXALProvider::createDevice(const String& deviceName, bool useHardware, S32 maxBuffers)
|
||||||
{
|
{
|
||||||
ALDeviceInfo *info = dynamic_cast< ALDeviceInfo* >
|
ALDeviceInfo* info = dynamic_cast<ALDeviceInfo*>
|
||||||
( _findDeviceInfo( deviceName) );
|
(_findDeviceInfo(deviceName));
|
||||||
|
|
||||||
// Do we find one to create?
|
// Do we find one to create?
|
||||||
if (info)
|
if (info)
|
||||||
return new SFXALDevice(this, mOpenAL, info->internalName, useHardware, maxBuffers);
|
return new SFXALDevice(this, mOpenAL, info->name, useHardware, maxBuffers);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue