diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index 0adaff290..74a794ea1 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -1063,16 +1063,16 @@ int main() window.EnableEventPolling(true); - Nz::Clock updateClock; - Nz::Clock secondClock; + Nz::MillisecondClock updateClock; + Nz::MillisecondClock fpsClock; unsigned int fps = 0; std::size_t totalFrameCount = 0; Nz::Mouse::SetRelativeMouseMode(true); - float elapsedTime = 0.f; - Nz::UInt64 time = Nz::GetElapsedMicroseconds(); + Nz::Time elapsedTime = Nz::Time::Zero(); + Nz::Time time = Nz::GetElapsedNanoseconds(); auto ComputeLightAnimationSpeed = [](const Nz::Vector3f& position) { @@ -1095,9 +1095,9 @@ int main() while (window.IsOpen()) { - Nz::UInt64 now = Nz::GetElapsedMicroseconds(); + Nz::Time now = Nz::GetElapsedNanoseconds(); if (lightAnimation) - elapsedTime += (now - time) / 1'000'000.f; + elapsedTime += now - time; time = now; Nz::WindowEvent event; @@ -1129,13 +1129,14 @@ int main() { if (event.key.scancode == Nz::Keyboard::Scancode::Space) { + float elapsedSeconds = elapsedTime.AsSeconds(); float rotationSpeed = ComputeLightAnimationSpeed(viewerPos); auto& spotLight = spotLights.emplace_back(); spotLight.color = Nz::Color(0.4f, 0.4f, 1.f); spotLight.radius = 5.f; - spotLight.position = AnimateLightPosition(viewerPos, rotationSpeed, -elapsedTime); - spotLight.direction = AnimateLightDirection(camQuat * Nz::Vector3f::Forward(), rotationSpeed, -elapsedTime); + spotLight.position = AnimateLightPosition(viewerPos, rotationSpeed, -elapsedSeconds); + spotLight.direction = AnimateLightDirection(camQuat * Nz::Vector3f::Forward(), rotationSpeed, -elapsedSeconds); lightUpdate = true; } @@ -1163,10 +1164,9 @@ int main() } } - if (updateClock.GetMilliseconds() > 1000 / 60) + if (std::optional deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60))) { - float cameraSpeed = 2.f * updateClock.GetSeconds(); - updateClock.Restart(); + float cameraSpeed = 2.f * deltaTime->AsSeconds(); if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z)) viewerPos += camQuat * Nz::Vector3f::Forward() * cameraSpeed; @@ -1465,7 +1465,9 @@ int main() modelInstance2.OnTransfer(frame, builder); planeInstance.OnTransfer(frame, builder); - Nz::EulerAnglesf flareRotation(0.f, 0.f, elapsedTime * 10.f); + float elapsedSeconds = elapsedTime.AsSeconds(); + + Nz::EulerAnglesf flareRotation(0.f, 0.f, elapsedSeconds * 10.f); flareInstance.UpdateWorldMatrix(Nz::Matrix4f::Transform(viewerPos + flarePosition, flareRotation)); flareInstance.OnTransfer(frame, builder); @@ -1481,8 +1483,8 @@ int main() { float rotationSpeed = ComputeLightAnimationSpeed(spotLight.position); - Nz::Vector3f position = AnimateLightPosition(spotLight.position, rotationSpeed, elapsedTime); - Nz::Vector3f direction = AnimateLightDirection(spotLight.direction, rotationSpeed, elapsedTime); + Nz::Vector3f position = AnimateLightPosition(spotLight.position, rotationSpeed, elapsedSeconds); + Nz::Vector3f direction = AnimateLightDirection(spotLight.direction, rotationSpeed, elapsedSeconds); Nz::AccessByOffset(lightDataPtr, colorOffset) = Nz::Vector3f(spotLight.color.r, spotLight.color.g, spotLight.color.b); Nz::AccessByOffset(lightDataPtr, positionOffset) = position; @@ -1565,23 +1567,10 @@ int main() fps++; totalFrameCount++; - if (secondClock.GetMilliseconds() >= 1000) // Toutes les secondes + if (fpsClock.RestartIfOver(Nz::Time::Second())) { - // Et on insère ces données dans le titre de la fenêtre window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS"); - - /* - Note: En C++11 il est possible d'insérer de l'Unicode de façon standard, quel que soit l'encodage du fichier, - via quelque chose de similaire à u8"Cha\u00CEne de caract\u00E8res". - Cependant, si le code source est encodé en UTF-8 (Comme c'est le cas dans ce fichier), - cela fonctionnera aussi comme ceci : "Chaîne de caractères". - */ - - // Et on réinitialise le compteur de FPS fps = 0; - - // Et on relance l'horloge pour refaire ça dans une seconde - secondClock.Restart(); } } diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp index 0498da58a..901521ac5 100644 --- a/examples/DopplerEffect/main.cpp +++ b/examples/DopplerEffect/main.cpp @@ -53,17 +53,17 @@ int main() sound.Play(); // La boucle du programme (Pour déplacer le son) - Nz::Clock clock; + Nz::MillisecondClock clock; while (sound.GetStatus() == Nz::SoundStatus::Playing) { // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement - int sleepTime = int(1000/60 - clock.GetMilliseconds()); // 60 FPS + Nz::Time sleepTime = Nz::Time::TickDuration(60) - clock.GetElapsedTime(); // 60 FPS - if (sleepTime > 0) - std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); + if (sleepTime > Nz::Time::Millisecond()) + std::this_thread::sleep_for(sleepTime.AsDuration()); // On bouge la source du son en fonction du temps depuis chaque mise à jour - Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); + Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.GetElapsedTime().AsSeconds(); sound.SetPosition(pos); std::cout << "Sound position: " << pos << std::endl; diff --git a/examples/PhysicallyBasedRendering/main.cpp b/examples/PhysicallyBasedRendering/main.cpp index 41007a4b0..63fb12a17 100644 --- a/examples/PhysicallyBasedRendering/main.cpp +++ b/examples/PhysicallyBasedRendering/main.cpp @@ -104,8 +104,8 @@ int main() window.EnableEventPolling(true); - Nz::Clock updateClock; - Nz::Clock secondClock; + Nz::MillisecondClock updateClock; + Nz::MillisecondClock fpsClock; unsigned int fps = 0; Nz::Mouse::SetRelativeMouseMode(true); @@ -161,10 +161,9 @@ int main() } } - if (updateClock.GetMilliseconds() > 1000 / 60) + if (std::optional deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60))) { - float cameraSpeed = 2.f * updateClock.GetSeconds(); - updateClock.Restart(); + float cameraSpeed = 2.f * deltaTime->AsSeconds(); if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z)) viewerPos += camQuat * Nz::Vector3f::Forward() * cameraSpeed; @@ -209,23 +208,10 @@ int main() // On incrémente le compteur de FPS improvisé fps++; - if (secondClock.GetMilliseconds() >= 1000) // Toutes les secondes + if (fpsClock.RestartIfOver(Nz::Time::Second())) { - // Et on insère ces données dans le titre de la fenêtre window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS"); - - /* - Note: En C++11 il est possible d'insérer de l'Unicode de façon standard, quel que soit l'encodage du fichier, - via quelque chose de similaire à u8"Cha\u00CEne de caract\u00E8res". - Cependant, si le code source est encodé en UTF-8 (Comme c'est le cas dans ce fichier), - cela fonctionnera aussi comme ceci : "Chaîne de caractères". - */ - - // Et on réinitialise le compteur de FPS fps = 0; - - // Et on relance l'horloge pour refaire ça dans une seconde - secondClock.Restart(); } } diff --git a/examples/Physics2DDemo/main.cpp b/examples/Physics2DDemo/main.cpp index 6b278693c..c35aeabf5 100644 --- a/examples/Physics2DDemo/main.cpp +++ b/examples/Physics2DDemo/main.cpp @@ -68,8 +68,8 @@ int main() texParams.renderDevice = device; texParams.loadFormat = Nz::PixelFormat::RGBA8; - std::shared_ptr material = Nz::Graphics::Instance()->GetDefaultMaterials().phongMaterial->Instantiate(); - material->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "box.png", texParams)); + std::shared_ptr spriteMaterial = Nz::Graphics::Instance()->GetDefaultMaterials().phongMaterial->Instantiate(); + spriteMaterial->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "box.png", texParams)); for (std::size_t y = 0; y < 30; ++y) { @@ -77,7 +77,7 @@ int main() { entt::entity spriteEntity = registry.create(); { - std::shared_ptr sprite = std::make_shared(material); + std::shared_ptr sprite = std::make_shared(spriteMaterial); sprite->SetSize({ 32.f, 32.f }); sprite->SetOrigin({ 0.5f, 0.5f }); @@ -97,10 +97,10 @@ int main() tilemap->SetOrigin({ 0.5f, 0.5f }); for (std::size_t i = 0; i < 18; ++i) { - std::shared_ptr material = Nz::Graphics::Instance()->GetDefaultMaterials().basicTransparent->Clone(); - material->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "tiles" / (std::to_string(i + 1) + ".png"), texParams)); + std::shared_ptr tileMaterial = Nz::Graphics::Instance()->GetDefaultMaterials().basicTransparent->Clone(); + tileMaterial->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "tiles" / (std::to_string(i + 1) + ".png"), texParams)); - tilemap->SetMaterial(i, material); + tilemap->SetMaterial(i, tileMaterial); } for (unsigned int y = 0; y < 20; ++y) @@ -122,14 +122,12 @@ int main() window.EnableEventPolling(true); - Nz::Clock updateClock; - Nz::Clock secondClock; + Nz::MillisecondClock secondClock; unsigned int fps = 0; //Nz::Mouse::SetRelativeMouseMode(true); float elapsedTime = 0.f; - Nz::UInt64 time = Nz::GetElapsedMicroseconds(); Nz::PidController headingController(0.5f, 0.f, 0.05f); Nz::PidController upController(1.f, 0.f, 0.1f); @@ -137,10 +135,6 @@ int main() bool showColliders = false; while (window.IsOpen()) { - Nz::UInt64 now = Nz::GetElapsedMicroseconds(); - elapsedTime = (now - time) / 1'000'000.f; - time = now; - Nz::WindowEvent event; while (window.PollEvent(&event)) { @@ -165,13 +159,10 @@ int main() fps++; - if (secondClock.GetMilliseconds() >= 1000) + if (secondClock.RestartIfOver(Nz::Time::Second())) { window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS" + " - " + Nz::NumberToString(registry.alive()) + " entities"); - fps = 0; - - secondClock.Restart(); } } diff --git a/examples/PhysicsDemo/main.cpp b/examples/PhysicsDemo/main.cpp index f2a167180..951a1dda9 100644 --- a/examples/PhysicsDemo/main.cpp +++ b/examples/PhysicsDemo/main.cpp @@ -198,25 +198,18 @@ int main() window.EnableEventPolling(true); - Nz::Clock updateClock; - Nz::Clock secondClock; + Nz::MillisecondClock updateClock; + Nz::MillisecondClock fpsClock; unsigned int fps = 0; Nz::Mouse::SetRelativeMouseMode(true); - float elapsedTime = 0.f; - Nz::UInt64 time = Nz::GetElapsedMicroseconds(); - Nz::PidController headingController(0.3f, 0.f, 0.1f); Nz::PidController upController(1.f, 0.f, 0.1f); bool showColliders = false; while (window.IsOpen()) { - Nz::UInt64 now = Nz::GetElapsedMicroseconds(); - elapsedTime = (now - time) / 1'000'000.f; - time = now; - Nz::WindowEvent event; while (window.PollEvent(&event)) { @@ -286,8 +279,10 @@ int main() } } - if (updateClock.GetMilliseconds() > 1000 / 60) + if (std::optional deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60))) { + float elapsedTime = deltaTime->AsSeconds(); + auto spaceshipView = registry.view(); for (auto&& [entity, node, _] : spaceshipView.each()) { @@ -338,13 +333,10 @@ int main() fps++; - if (secondClock.GetMilliseconds() >= 1000) + if (fpsClock.RestartIfOver(Nz::Time::Second())) { window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS" + " - " + Nz::NumberToString(registry.alive()) + " entities"); - fps = 0; - - secondClock.Restart(); } } diff --git a/examples/Showcase/main.cpp b/examples/Showcase/main.cpp index 29b15722d..77e45cbed 100644 --- a/examples/Showcase/main.cpp +++ b/examples/Showcase/main.cpp @@ -357,12 +357,11 @@ int main() window.EnableEventPolling(true); - Nz::Clock fpsClock, updateClock; + Nz::MillisecondClock fpsClock, updateClock; float incr = 0.f; unsigned int currentFrame = 0; unsigned int nextFrame = 1; Nz::EulerAnglesf camAngles = Nz::EulerAnglesf(-30.f, 0.f, 0.f); - Nz::UInt64 lastTime = Nz::GetElapsedMicroseconds(); Nz::UInt64 fps = 0; bool paused = false; @@ -409,9 +408,9 @@ int main() } } - if (updateClock.GetMilliseconds() > 1000 / 60) + if (std::optional deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60))) { - float updateTime = updateClock.Restart() / 1'000'000.f; + float updateTime = deltaTime->AsSeconds(); /*auto& playerBody = registry.get(playerEntity); @@ -533,12 +532,9 @@ int main() fps++; - if (fpsClock.GetMilliseconds() >= 1000) + if (fpsClock.RestartIfOver(Nz::Time::Second())) { - fpsClock.Restart(); - window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS" + " - " + Nz::NumberToString(registry.alive()) + " entities"); - fps = 0; } } diff --git a/examples/WidgetDemo/main.cpp b/examples/WidgetDemo/main.cpp index bfe8b9b3c..aeb78a9e2 100644 --- a/examples/WidgetDemo/main.cpp +++ b/examples/WidgetDemo/main.cpp @@ -127,19 +127,11 @@ int main() mainWindow.EnableEventPolling(true); - Nz::Clock updateClock; - Nz::Clock secondClock; + Nz::MillisecondClock fpsClock; unsigned int fps = 0; - float elapsedTime = 0.f; - Nz::UInt64 time = Nz::GetElapsedMicroseconds(); - while (mainWindow.IsOpen()) { - Nz::UInt64 now = Nz::GetElapsedMicroseconds(); - elapsedTime = (now - time) / 1'000'000.f; - time = now; - Nz::WindowEvent event; while (mainWindow.PollEvent(&event)) { @@ -158,13 +150,10 @@ int main() fps++; - if (secondClock.GetMilliseconds() >= 1000) + if (fpsClock.RestartIfOver(Nz::Time::Second())) { mainWindow.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS" + " - " + Nz::NumberToString(registry.alive()) + " entities"); - fps = 0; - - secondClock.Restart(); } } diff --git a/include/Nazara/Audio/AudioSource.hpp b/include/Nazara/Audio/AudioSource.hpp index c46cfd1c6..23831ac2a 100644 --- a/include/Nazara/Audio/AudioSource.hpp +++ b/include/Nazara/Audio/AudioSource.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace Nz @@ -34,6 +35,7 @@ namespace Nz virtual float GetAttenuation() const = 0; virtual float GetMinDistance() const = 0; virtual float GetPitch() const = 0; + virtual Time GetPlayingOffset() const = 0; virtual Vector3f GetPosition() const = 0; virtual UInt32 GetSampleOffset() const = 0; virtual OffsetWithLatency GetSampleOffsetAndLatency() const = 0; @@ -53,6 +55,7 @@ namespace Nz virtual void SetBuffer(std::shared_ptr audioBuffer) = 0; virtual void SetMinDistance(float minDistance) = 0; virtual void SetPitch(float pitch) = 0; + virtual void SetPlayingOffset(Time offset) = 0; virtual void SetPosition(const Vector3f& position) = 0; virtual void SetSampleOffset(UInt32 offset) = 0; virtual void SetVelocity(const Vector3f& velocity) = 0; @@ -70,7 +73,7 @@ namespace Nz struct OffsetWithLatency { UInt64 sampleOffset; - UInt64 sourceLatency; + Time sourceLatency; }; private: diff --git a/include/Nazara/Audio/DummyAudioBuffer.hpp b/include/Nazara/Audio/DummyAudioBuffer.hpp index 9d47a13d3..821b48ba7 100644 --- a/include/Nazara/Audio/DummyAudioBuffer.hpp +++ b/include/Nazara/Audio/DummyAudioBuffer.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Nz { @@ -23,7 +24,7 @@ namespace Nz ~DummyAudioBuffer() = default; AudioFormat GetAudioFormat() const; - UInt32 GetDuration() const; + Time GetDuration() const; UInt64 GetSampleCount() const override; UInt64 GetSize() const override; UInt32 GetSampleRate() const override; diff --git a/include/Nazara/Audio/DummyAudioSource.hpp b/include/Nazara/Audio/DummyAudioSource.hpp index 6848c4c27..474aade17 100644 --- a/include/Nazara/Audio/DummyAudioSource.hpp +++ b/include/Nazara/Audio/DummyAudioSource.hpp @@ -30,6 +30,7 @@ namespace Nz float GetAttenuation() const override; float GetMinDistance() const override; float GetPitch() const override; + Time GetPlayingOffset() const override; Vector3f GetPosition() const override; UInt32 GetSampleOffset() const override; OffsetWithLatency GetSampleOffsetAndLatency() const override; @@ -49,6 +50,7 @@ namespace Nz void SetBuffer(std::shared_ptr audioBuffer) override; void SetMinDistance(float minDistance) override; void SetPitch(float pitch) override; + void SetPlayingOffset(Time offset) override; void SetPosition(const Vector3f& position) override; void SetSampleOffset(UInt32 offset) override; void SetVelocity(const Vector3f& velocity) override; @@ -65,11 +67,11 @@ namespace Nz private: void RequeueBuffers(); - UInt64 UpdateTime() const; + Time UpdateTime() const; mutable std::vector> m_queuedBuffers; mutable std::vector> m_processedBuffers; - mutable Clock m_playClock; + mutable MillisecondClock m_playClock; mutable SoundStatus m_status; Vector3f m_position; Vector3f m_velocity; diff --git a/include/Nazara/Audio/DummyAudioSource.inl b/include/Nazara/Audio/DummyAudioSource.inl index 762e0eead..66826a927 100644 --- a/include/Nazara/Audio/DummyAudioSource.inl +++ b/include/Nazara/Audio/DummyAudioSource.inl @@ -9,7 +9,7 @@ namespace Nz { inline DummyAudioSource::DummyAudioSource(std::shared_ptr device) : AudioSource(std::move(device)), - m_playClock(0, true), + m_playClock(Time::Zero(), true), m_status(SoundStatus::Stopped), m_position(Vector3f::Zero()), m_velocity(Vector3f::Zero()), diff --git a/include/Nazara/Audio/Music.hpp b/include/Nazara/Audio/Music.hpp index 123e7e845..092432755 100644 --- a/include/Nazara/Audio/Music.hpp +++ b/include/Nazara/Audio/Music.hpp @@ -22,7 +22,7 @@ namespace Nz { class AudioBuffer; - class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter + class NAZARA_AUDIO_API Music final : public Resource, public SoundEmitter { public: Music(); @@ -36,11 +36,12 @@ namespace Nz void EnableLooping(bool loop) override; - UInt32 GetDuration() const override; + Time GetDuration() const override; AudioFormat GetFormat() const; - UInt32 GetPlayingOffset() const override; + Time GetPlayingOffset() const; UInt64 GetSampleCount() const; - UInt32 GetSampleRate() const; + UInt64 GetSampleOffset() const override; + UInt32 GetSampleRate() const override; SoundStatus GetStatus() const override; bool IsLooping() const override; @@ -52,7 +53,7 @@ namespace Nz void Pause() override; void Play() override; - void SetPlayingOffset(UInt32 offset); + void SeekToSampleOffset(UInt64 offset); void Stop() override; diff --git a/include/Nazara/Audio/OpenALSource.hpp b/include/Nazara/Audio/OpenALSource.hpp index 73afff99d..0eaf30e36 100644 --- a/include/Nazara/Audio/OpenALSource.hpp +++ b/include/Nazara/Audio/OpenALSource.hpp @@ -34,6 +34,7 @@ namespace Nz float GetAttenuation() const override; float GetMinDistance() const override; float GetPitch() const override; + Time GetPlayingOffset() const override; Vector3f GetPosition() const override; UInt32 GetSampleOffset() const override; OffsetWithLatency GetSampleOffsetAndLatency() const override; @@ -53,6 +54,7 @@ namespace Nz void SetBuffer(std::shared_ptr audioBuffer) override; void SetMinDistance(float minDistance) override; void SetPitch(float pitch) override; + void SetPlayingOffset(Time offset) override; void SetPosition(const Vector3f& position) override; void SetSampleOffset(UInt32 offset) override; void SetVelocity(const Vector3f& velocity) override; diff --git a/include/Nazara/Audio/Sound.hpp b/include/Nazara/Audio/Sound.hpp index f9362582a..9f1572d4e 100644 --- a/include/Nazara/Audio/Sound.hpp +++ b/include/Nazara/Audio/Sound.hpp @@ -14,7 +14,7 @@ namespace Nz { - class NAZARA_AUDIO_API Sound : public SoundEmitter + class NAZARA_AUDIO_API Sound final : public SoundEmitter { public: using SoundEmitter::SoundEmitter; @@ -27,8 +27,10 @@ namespace Nz void EnableLooping(bool loop) override; const std::shared_ptr& GetBuffer() const; - UInt32 GetDuration() const override; - UInt32 GetPlayingOffset() const override; + Time GetDuration() const override; + Time GetPlayingOffset() const override; + UInt64 GetSampleOffset() const override; + UInt32 GetSampleRate() const override; SoundStatus GetStatus() const override; bool IsLooping() const override; @@ -42,7 +44,8 @@ namespace Nz void Play() override; void SetBuffer(std::shared_ptr soundBuffer); - void SetPlayingOffset(UInt32 offset); + + void SeekToSampleOffset(UInt64 offset) override; void Stop() override; diff --git a/include/Nazara/Audio/SoundBuffer.hpp b/include/Nazara/Audio/SoundBuffer.hpp index ba45b0423..20a35cb54 100644 --- a/include/Nazara/Audio/SoundBuffer.hpp +++ b/include/Nazara/Audio/SoundBuffer.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,7 @@ namespace Nz const std::shared_ptr& GetAudioBuffer(AudioDevice* device); - inline UInt32 GetDuration() const; + inline Time GetDuration() const; inline AudioFormat GetFormat() const; inline const Int16* GetSamples() const; inline UInt64 GetSampleCount() const; @@ -76,7 +77,7 @@ namespace Nz std::unordered_map m_audioBufferByDevice; std::unique_ptr m_samples; AudioFormat m_format; - UInt32 m_duration; + Time m_duration; UInt32 m_sampleRate; UInt64 m_sampleCount; }; diff --git a/include/Nazara/Audio/SoundBuffer.inl b/include/Nazara/Audio/SoundBuffer.inl index afa95e570..7cd04d96b 100644 --- a/include/Nazara/Audio/SoundBuffer.inl +++ b/include/Nazara/Audio/SoundBuffer.inl @@ -10,10 +10,8 @@ namespace Nz /*! * \brief Gets the duration of the sound buffer * \return Duration of the sound buffer in milliseconds - * - * \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined */ - inline UInt32 SoundBuffer::GetDuration() const + inline Time SoundBuffer::GetDuration() const { return m_duration; } diff --git a/include/Nazara/Audio/SoundEmitter.hpp b/include/Nazara/Audio/SoundEmitter.hpp index 2e74b3c82..05b6837a7 100644 --- a/include/Nazara/Audio/SoundEmitter.hpp +++ b/include/Nazara/Audio/SoundEmitter.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -32,11 +33,13 @@ namespace Nz void EnableSpatialization(bool spatialization); float GetAttenuation() const; - virtual UInt32 GetDuration() const = 0; + virtual Time GetDuration() const = 0; float GetMinDistance() const; float GetPitch() const; - virtual UInt32 GetPlayingOffset() const = 0; + virtual Time GetPlayingOffset() const = 0; Vector3f GetPosition() const; + virtual UInt64 GetSampleOffset() const = 0; + virtual UInt32 GetSampleRate() const = 0; Vector3f GetVelocity() const; virtual SoundStatus GetStatus() const = 0; float GetVolume() const; @@ -48,6 +51,9 @@ namespace Nz virtual void Pause() = 0; virtual void Play() = 0; + virtual void SeekToPlayingOffset(Time offset); + virtual void SeekToSampleOffset(UInt64 offset) = 0; + void SetAttenuation(float attenuation); void SetMinDistance(float minDistance); void SetPitch(float pitch); diff --git a/include/Nazara/Audio/SoundStream.hpp b/include/Nazara/Audio/SoundStream.hpp index 1a22c5962..e6116f75d 100644 --- a/include/Nazara/Audio/SoundStream.hpp +++ b/include/Nazara/Audio/SoundStream.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace Nz @@ -35,7 +36,7 @@ namespace Nz SoundStream() = default; virtual ~SoundStream(); - virtual UInt32 GetDuration() const = 0; + virtual Time GetDuration() const = 0; virtual AudioFormat GetFormat() const = 0; virtual std::mutex& GetMutex() = 0; virtual UInt64 GetSampleCount() const = 0; diff --git a/include/Nazara/Core/Clock.hpp b/include/Nazara/Core/Clock.hpp index 8e68068c4..b5c4cc0ee 100644 --- a/include/Nazara/Core/Clock.hpp +++ b/include/Nazara/Core/Clock.hpp @@ -9,40 +9,46 @@ #include #include +#include +#include namespace Nz { - class NAZARA_CORE_API Clock + template + class Clock { public: - Clock(UInt64 startingValue = 0, bool paused = false); + Clock(Time startingValue = Time::Zero(), bool paused = false); Clock(const Clock& clock) = default; - Clock(Clock&& clock) = default; + Clock(Clock&& clock) noexcept = default; ~Clock() = default; - float GetSeconds() const; - UInt64 GetMicroseconds() const; - UInt64 GetMilliseconds() const; + Time GetElapsedTime() const; bool IsPaused() const; void Pause(); - UInt64 Restart(UInt64 startingValue = 0, bool paused = false); + + Time Restart(Time startingPoint = Time::Zero(), bool paused = false); + std::optional