Skip to content

Commit

Permalink
Avoid some manual Set/UnsetALContext calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Apr 16, 2023
1 parent 85aadb8 commit 4fdb5b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/dsoal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ bool load_openal()
LOAD_FUNCPTR(alcGetThreadContext);
LOAD_FUNCPTR(EAXSet);
LOAD_FUNCPTR(EAXGet);
LOAD_FUNCPTR(alDeferUpdatesSOFT);
LOAD_FUNCPTR(alProcessUpdatesSOFT);
LOAD_FUNCPTR(alBufferStorageSOFT);
LOAD_FUNCPTR(alMapBufferSOFT);
LOAD_FUNCPTR(alUnmapBufferSOFT);
Expand Down
4 changes: 0 additions & 4 deletions src/dsoal.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ inline PFNALCSETTHREADCONTEXTPROC palcSetThreadContext{};
inline PFNALCGETTHREADCONTEXTPROC palcGetThreadContext{};
inline LPEAXSET pEAXSet{};
inline LPEAXGET pEAXGet{};
inline LPALDEFERUPDATESSOFT palDeferUpdatesSOFT{};
inline LPALPROCESSUPDATESSOFT palProcessUpdatesSOFT{};
inline LPALBUFFERSTORAGESOFT palBufferStorageSOFT{};
inline LPALMAPBUFFERSOFT palMapBufferSOFT{};
inline LPALUNMAPBUFFERSOFT palUnmapBufferSOFT{};
Expand Down Expand Up @@ -393,8 +391,6 @@ inline LPALFLUSHMAPPEDBUFFERSOFT palFlushMappedBufferSOFT{};
#define alcGetThreadContext palcGetThreadContext
#define EAXSet pEAXSet
#define EAXGet pEAXGet
#define alDeferUpdatesSOFT palDeferUpdatesSOFT
#define alProcessUpdatesSOFT palProcessUpdatesSOFT
#define alBufferStorageSOFT palBufferStorageSOFT
#define alMapBufferSOFT palMapBufferSOFT
#define alUnmapBufferSOFT palUnmapBufferSOFT
Expand Down
36 changes: 16 additions & 20 deletions src/primarybuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Initialize(IDirectSound *directSound, c
mDeferred = mImmediate;
mDirty.reset();

SetALContext(mContext);
ALSection alsection{mContext};
setParams(mDeferred, ~0llu);
UnsetALContext();

return DS_OK;
}
Expand Down Expand Up @@ -453,10 +452,9 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::SetVolume(LONG volume) noexcept
if(!(mFlags&DSBCAPS_CTRLVOLUME))
return DSERR_CONTROLUNAVAIL;

SetALContext(mContext);
ALSection alsection{mContext};
mVolume = volume;
alListenerf(AL_GAIN, mB_to_gain(static_cast<float>(volume)));
UnsetALContext();

return DS_OK;
}
Expand Down Expand Up @@ -721,9 +719,10 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetAllParameters(const DS3D
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
alcSuspendContext(self->mContext);
self->setParams(*listener, ~0ull);
UnsetALContext();
alcProcessContext(self->mContext);
}

return E_NOTIMPL;
Expand All @@ -748,11 +747,10 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetDistanceFactor(D3DVALUE
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
self->mImmediate.flDistanceFactor = distanceFactor;
alSpeedOfSound(343.3f/distanceFactor);
alGetError();
UnsetALContext();
}

return S_OK;
Expand All @@ -777,11 +775,10 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetDopplerFactor(D3DVALUE d
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
self->mImmediate.flDopplerFactor = dopplerFactor;
alDopplerFactor(dopplerFactor);
alGetError();
UnsetALContext();
}

return S_OK;
Expand All @@ -805,7 +802,7 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetOrientation(D3DVALUE xFr
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
self->mImmediate.vOrientFront.x = xFront;
self->mImmediate.vOrientFront.y = yFront;
self->mImmediate.vOrientFront.z = zFront;
Expand All @@ -816,7 +813,6 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetOrientation(D3DVALUE xFr
const ALfloat ori[6]{xFront, yFront, -zFront, xTop, yTop, -zTop};
alListenerfv(AL_ORIENTATION, ori);
alGetError();
UnsetALContext();
}

return S_OK;
Expand All @@ -837,14 +833,13 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetPosition(D3DVALUE x, D3D
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
self->mImmediate.vPosition.x = x;
self->mImmediate.vPosition.y = y;
self->mImmediate.vPosition.z = z;

alListener3f(AL_POSITION, x, y, -z);
alGetError();
UnsetALContext();
}

return S_OK;
Expand All @@ -869,11 +864,12 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetRolloffFactor(D3DVALUE r
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
alcSuspendContext(self->mContext);
self->mImmediate.flRolloffFactor = rolloffFactor;
// TODO: Set all 3D secondary buffers' rolloff factor
alGetError();
UnsetALContext();
alcProcessContext(self->mContext);
}

return S_OK;
Expand All @@ -894,14 +890,13 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::SetVelocity(D3DVALUE x, D3D
}
else
{
SetALContext(self->mContext);
ALSection alsection{self->mContext};
self->mImmediate.vVelocity.x = x;
self->mImmediate.vVelocity.y = y;
self->mImmediate.vVelocity.z = z;

alListener3f(AL_VELOCITY, x, y, -z);
alGetError();
UnsetALContext();
}

return S_OK;
Expand All @@ -913,7 +908,8 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::CommitDeferredSettings() no

auto self = impl_from_base();
std::lock_guard lock{self->mMutex};
SetALContext(self->mContext);
ALSection alsection{self->mContext};
alcSuspendContext(self->mContext);

if(auto flags = std::exchange(self->mDirty, 0); flags.any())
{
Expand All @@ -924,7 +920,7 @@ HRESULT STDMETHODCALLTYPE PrimaryBuffer::Listener3D::CommitDeferredSettings() no
// TODO: Commit all 3D secondary buffers' properties

alGetError();
UnsetALContext();
alcProcessContext(self->mContext);
return DS_OK;
}
#undef PREFIX

0 comments on commit 4fdb5b2

Please sign in to comment.