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