mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 15:22:16 +00:00
Cast OpenAL IDs to/from void*
This commit is contained in:
parent
906b828d87
commit
fb07f7ef07
1 changed files with 26 additions and 24 deletions
|
@ -95,6 +95,9 @@ EXTERN_CVAR (Bool, snd_waterreverb)
|
|||
EXTERN_CVAR (Bool, snd_pitched)
|
||||
|
||||
|
||||
#define MAKE_PTRID(x) ((void*)(uintptr_t)(x))
|
||||
#define GET_PTRID(x) ((uint32)(uintptr_t)(x))
|
||||
|
||||
#define foreach(type, name, vec) \
|
||||
for(std::vector<type>::iterator (name) = (vec).begin(), \
|
||||
(_end_##name) = (vec).end(); \
|
||||
|
@ -810,7 +813,7 @@ void OpenALSoundRenderer::SetSfxVolume(float volume)
|
|||
{
|
||||
if(schan->SysChannel != NULL)
|
||||
{
|
||||
ALuint source = *((ALuint*)schan->SysChannel);
|
||||
ALuint source = GET_PTRID(schan->SysChannel);
|
||||
volume = SfxVolume;
|
||||
|
||||
alcSuspendContext(Context);
|
||||
|
@ -836,7 +839,7 @@ unsigned int OpenALSoundRenderer::GetMSLength(SoundHandle sfx)
|
|||
{
|
||||
if(sfx.data)
|
||||
{
|
||||
ALuint buffer = *((ALuint*)sfx.data);
|
||||
ALuint buffer = GET_PTRID(sfx.data);
|
||||
if(alIsBuffer(buffer))
|
||||
{
|
||||
ALint bits, channels, freq, size;
|
||||
|
@ -855,7 +858,7 @@ unsigned int OpenALSoundRenderer::GetSampleLength(SoundHandle sfx)
|
|||
{
|
||||
if(sfx.data)
|
||||
{
|
||||
ALuint buffer = *((ALuint*)sfx.data);
|
||||
ALuint buffer = GET_PTRID(sfx.data);
|
||||
ALint bits, channels, size;
|
||||
alGetBufferi(buffer, AL_BITS, &bits);
|
||||
alGetBufferi(buffer, AL_CHANNELS, &channels);
|
||||
|
@ -939,7 +942,7 @@ SoundHandle OpenALSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int length, int fre
|
|||
warned = true;
|
||||
}
|
||||
|
||||
retval.data = new ALuint(buffer);
|
||||
retval.data = MAKE_PTRID(buffer);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -987,7 +990,7 @@ SoundHandle OpenALSoundRenderer::LoadSound(BYTE *sfxdata, int length)
|
|||
return retval;
|
||||
}
|
||||
|
||||
retval.data = new ALuint(buffer);
|
||||
retval.data = MAKE_PTRID(buffer);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -996,14 +999,15 @@ void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
|
|||
if(!sfx.data)
|
||||
return;
|
||||
|
||||
ALuint buffer = GET_PTRID(sfx.data);
|
||||
FSoundChan *schan = Channels;
|
||||
while(schan)
|
||||
{
|
||||
if(schan->SysChannel)
|
||||
{
|
||||
ALint bufID = 0;
|
||||
alGetSourcei(*((ALuint*)schan->SysChannel), AL_BUFFER, &bufID);
|
||||
if(bufID == *((ALint*)sfx.data))
|
||||
alGetSourcei(GET_PTRID(schan->SysChannel), AL_BUFFER, &bufID);
|
||||
if((ALuint)bufID == buffer)
|
||||
{
|
||||
FSoundChan *next = schan->NextChan;
|
||||
StopChannel(schan);
|
||||
|
@ -1014,9 +1018,8 @@ void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
|
|||
schan = schan->NextChan;
|
||||
}
|
||||
|
||||
alDeleteBuffers(1, ((ALuint*)sfx.data));
|
||||
alDeleteBuffers(1, &buffer);
|
||||
getALError();
|
||||
delete ((ALuint*)sfx.data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1052,8 +1055,8 @@ FISoundChannel *OpenALSoundRenderer::StartSound(SoundHandle sfx, float vol, int
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ALuint buffer = *((ALuint*)sfx.data);
|
||||
ALuint &source = *std::find(Sources.begin(), Sources.end(), FreeSfx.back());
|
||||
ALuint buffer = GET_PTRID(sfx.data);
|
||||
ALuint source = FreeSfx.back();
|
||||
alSource3f(source, AL_POSITION, 0.f, 0.f, 0.f);
|
||||
alSource3f(source, AL_VELOCITY, 0.f, 0.f, 0.f);
|
||||
alSource3f(source, AL_DIRECTION, 0.f, 0.f, 0.f);
|
||||
|
@ -1120,8 +1123,8 @@ FISoundChannel *OpenALSoundRenderer::StartSound(SoundHandle sfx, float vol, int
|
|||
FreeSfx.pop_back();
|
||||
|
||||
FISoundChannel *chan = reuse_chan;
|
||||
if(!chan) chan = S_GetChannel(&source);
|
||||
else chan->SysChannel = &source;
|
||||
if(!chan) chan = S_GetChannel(MAKE_PTRID(source));
|
||||
else chan->SysChannel = MAKE_PTRID(source);
|
||||
|
||||
chan->Rolloff.RolloffType = ROLLOFF_Linear;
|
||||
chan->Rolloff.MaxDistance = 1000.f;
|
||||
|
@ -1156,11 +1159,11 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener
|
|||
float rolloffFactor, gain;
|
||||
bool manualGain = true;
|
||||
|
||||
ALuint buffer = *((ALuint*)sfx.data);
|
||||
ALuint buffer = GET_PTRID(sfx.data);
|
||||
ALint channels = 1;
|
||||
alGetBufferi(buffer, AL_CHANNELS, &channels);
|
||||
|
||||
ALuint &source = *std::find(Sources.begin(), Sources.end(), FreeSfx.back());
|
||||
ALuint source = FreeSfx.back();
|
||||
alSource3f(source, AL_POSITION, pos[0], pos[1], -pos[2]);
|
||||
alSource3f(source, AL_VELOCITY, vel[0], vel[1], -vel[2]);
|
||||
alSource3f(source, AL_DIRECTION, 0.f, 0.f, 0.f);
|
||||
|
@ -1262,8 +1265,8 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener
|
|||
FreeSfx.pop_back();
|
||||
|
||||
FISoundChannel *chan = reuse_chan;
|
||||
if(!chan) chan = S_GetChannel(&source);
|
||||
else chan->SysChannel = &source;
|
||||
if(!chan) chan = S_GetChannel(MAKE_PTRID(source));
|
||||
else chan->SysChannel = MAKE_PTRID(source);
|
||||
|
||||
chan->Rolloff = *rolloff;
|
||||
chan->DistanceScale = distscale;
|
||||
|
@ -1280,8 +1283,7 @@ void OpenALSoundRenderer::ChannelVolume(FISoundChannel *chan, float volume)
|
|||
|
||||
alcSuspendContext(Context);
|
||||
|
||||
ALuint source = *((ALuint*)chan->SysChannel);
|
||||
|
||||
ALuint source = GET_PTRID(chan->SysChannel);
|
||||
if(chan->ManualGain)
|
||||
volume *= GetRolloff(&chan->Rolloff, sqrt(chan->DistanceSqr));
|
||||
alSourcef(source, AL_GAIN, SfxVolume * volume);
|
||||
|
@ -1292,7 +1294,7 @@ void OpenALSoundRenderer::StopChannel(FISoundChannel *chan)
|
|||
if(chan == NULL || chan->SysChannel == NULL)
|
||||
return;
|
||||
|
||||
ALuint source = *((ALuint*)chan->SysChannel);
|
||||
ALuint source = GET_PTRID(chan->SysChannel);
|
||||
// Release first, so it can be properly marked as evicted if it's being
|
||||
// forcefully killed
|
||||
S_ChannelEnded(chan);
|
||||
|
@ -1318,7 +1320,7 @@ unsigned int OpenALSoundRenderer::GetPosition(FISoundChannel *chan)
|
|||
return 0;
|
||||
|
||||
ALint pos;
|
||||
alGetSourcei(*((ALuint*)chan->SysChannel), AL_SAMPLE_OFFSET, &pos);
|
||||
alGetSourcei(GET_PTRID(chan->SysChannel), AL_SAMPLE_OFFSET, &pos);
|
||||
if(getALError() == AL_NO_ERROR)
|
||||
return pos;
|
||||
return 0;
|
||||
|
@ -1409,7 +1411,7 @@ void OpenALSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FISoundCh
|
|||
|
||||
alcSuspendContext(Context);
|
||||
|
||||
ALuint source = *((ALuint*)chan->SysChannel);
|
||||
ALuint source = GET_PTRID(chan->SysChannel);
|
||||
alSource3f(source, AL_POSITION, pos[0], pos[1], -pos[2]);
|
||||
alSource3f(source, AL_VELOCITY, vel[0], vel[1], -vel[2]);
|
||||
|
||||
|
@ -1576,7 +1578,7 @@ float OpenALSoundRenderer::GetAudibility(FISoundChannel *chan)
|
|||
if(chan == NULL || chan->SysChannel == NULL)
|
||||
return 0.f;
|
||||
|
||||
ALuint source = *((ALuint*)chan->SysChannel);
|
||||
ALuint source = GET_PTRID(chan->SysChannel);
|
||||
ALfloat volume = 0.f;
|
||||
|
||||
if(!chan->ManualGain)
|
||||
|
@ -1691,7 +1693,7 @@ void OpenALSoundRenderer::PurgeStoppedSources()
|
|||
FSoundChan *schan = Channels;
|
||||
while(schan)
|
||||
{
|
||||
if(schan->SysChannel != NULL && *i == *((ALuint*)schan->SysChannel))
|
||||
if(schan->SysChannel != NULL && *i == GET_PTRID(schan->SysChannel))
|
||||
{
|
||||
StopChannel(schan);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue