Replace float/UInt64 durations by a more precise Time class (#388)

Improve Clock class with atomic RestartIfOver method and allows to choose required precision
This commit is contained in:
Jérôme Leclercq
2022-12-29 21:31:46 +01:00
committed by GitHub
parent 1de5f65536
commit dd421a6385
84 changed files with 1278 additions and 663 deletions

View File

@@ -62,6 +62,29 @@ namespace Nz
return pitch;
}
Time OpenALSource::GetPlayingOffset() const
{
GetDevice().MakeContextCurrent();
#ifdef AL_SOFT_source_latency
if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency))
{
// alGetSourcedvSOFT has extra precision thanks to double
ALdouble playingOffset;
m_library.alGetSourcedvSOFT(m_sourceId, AL_SEC_OFFSET, &playingOffset);
return Time::Seconds(playingOffset);
}
else
#endif
{
ALfloat playingOffset;
m_library.alGetSourcefv(m_sourceId, AL_SEC_OFFSET, &playingOffset);
return Time::Seconds(playingOffset);
}
}
Vector3f OpenALSource::GetPosition() const
{
GetDevice().MakeContextCurrent();
@@ -94,14 +117,14 @@ namespace Nz
m_library.alGetSourcei64vSOFT(m_sourceId, AL_SAMPLE_OFFSET_LATENCY_SOFT, values.data());
offsetWithLatency.sampleOffset = ((values[0] & 0xFFFFFFFF00000000) >> 32) * 1'000;
offsetWithLatency.sourceLatency = values[1] / 1'000;
offsetWithLatency.sourceLatency = Time::Nanoseconds(values[1] / 1'000);
}
else
#endif
{
offsetWithLatency.sampleOffset = GetSampleOffset() * 1'000;
offsetWithLatency.sourceLatency = 0;
offsetWithLatency.sourceLatency = Time::Zero();
}
return offsetWithLatency;
@@ -239,6 +262,19 @@ namespace Nz
m_library.alSourcef(m_sourceId, AL_PITCH, pitch);
}
void OpenALSource::SetPlayingOffset(Time offset)
{
GetDevice().MakeContextCurrent();
#ifdef AL_SOFT_source_latency
if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency))
// alGetSourcedvSOFT has extra precision thanks to double
m_library.alSourcedSOFT(m_sourceId, AL_SEC_OFFSET, offset.AsSeconds<ALdouble>());
else
#endif
m_library.alSourcef(m_sourceId, AL_SEC_OFFSET, offset.AsSeconds<ALfloat>());
}
void OpenALSource::SetPosition(const Vector3f& position)
{
GetDevice().MakeContextCurrent();