diff --git a/include/Nazara/Audio/SoundEmitter.hpp b/include/Nazara/Audio/SoundEmitter.hpp index 060d975c3..2cc1e526c 100644 --- a/include/Nazara/Audio/SoundEmitter.hpp +++ b/include/Nazara/Audio/SoundEmitter.hpp @@ -14,8 +14,6 @@ #include #include -///TODO: Inherit SoundEmitter from Node - namespace Nz { class AudioDevice; diff --git a/src/Nazara/Audio/OpenALBuffer.cpp b/src/Nazara/Audio/OpenALBuffer.cpp index 45b5c0f90..2d49b0036 100644 --- a/src/Nazara/Audio/OpenALBuffer.cpp +++ b/src/Nazara/Audio/OpenALBuffer.cpp @@ -74,8 +74,7 @@ namespace Nz // We empty the error stack while (m_library.alGetError() != AL_NO_ERROR); - // TODO: Use SafeCast - m_library.alBufferData(m_bufferId, alFormat, samples, static_cast(sampleCount * sizeof(Int16)), static_cast(sampleRate)); + m_library.alBufferData(m_bufferId, alFormat, samples, SafeCast(sampleCount * sizeof(Int16)), SafeCast(sampleRate)); if (ALenum lastError = m_library.alGetError(); lastError != AL_NO_ERROR) { diff --git a/src/Nazara/Core/DynLib.cpp b/src/Nazara/Core/DynLib.cpp index 1e8ce737d..0aa765bde 100644 --- a/src/Nazara/Core/DynLib.cpp +++ b/src/Nazara/Core/DynLib.cpp @@ -73,7 +73,7 @@ namespace Nz if (libraryPath.extension() != NAZARA_DYNLIB_EXTENSION) libraryPath += NAZARA_DYNLIB_EXTENSION; - auto impl = std::make_unique(this); + auto impl = std::make_unique(); if (!impl->Load(libraryPath, &m_lastError)) { NazaraError("Failed to load library: " + m_lastError); diff --git a/src/Nazara/Core/Posix/DynLibImpl.cpp b/src/Nazara/Core/Posix/DynLibImpl.cpp index b08f5c5b8..ae128c181 100644 --- a/src/Nazara/Core/Posix/DynLibImpl.cpp +++ b/src/Nazara/Core/Posix/DynLibImpl.cpp @@ -3,17 +3,11 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include namespace Nz { - DynLibImpl::DynLibImpl(DynLib*) : - m_handle(nullptr) - { - } - DynLibImpl::~DynLibImpl() { if (m_handle) @@ -22,25 +16,19 @@ namespace Nz DynLibFunc DynLibImpl::GetSymbol(const char* symbol, std::string* errorMessage) const { - /* - Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction. - Nous devons donc utiliser des techniques diaboliques venant du malin lui-même.. :D - Au moins ce n'est pas aussi terrible qu'un const_cast - -Lynix - */ - union - { - DynLibFunc func; - void* pointer; - } converter; - dlerror(); // Clear error flag - converter.pointer = dlsym(m_handle, symbol); - if (!converter.pointer) + void* ptr = dlsym(m_handle, symbol); + if (!ptr) *errorMessage = dlerror(); - return converter.func; + static_assert(sizeof(DynLibFunc) == sizeof(void*)); + + // poor man's std::bit_cast + DynLibFunc funcPtr; + std::memcpy(&funcPtr, &ptr, sizeof(funcPtr)); + + return funcPtr; } bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage) @@ -48,12 +36,12 @@ namespace Nz dlerror(); // Clear error flag m_handle = dlopen(libraryPath.generic_u8string().data(), RTLD_LAZY | RTLD_GLOBAL); - if (m_handle) - return true; - else + if (!m_handle) { *errorMessage = dlerror(); return false; } + + return true; } } diff --git a/src/Nazara/Core/Posix/DynLibImpl.hpp b/src/Nazara/Core/Posix/DynLibImpl.hpp index 73f4a8c1e..93e6f0885 100644 --- a/src/Nazara/Core/Posix/DynLibImpl.hpp +++ b/src/Nazara/Core/Posix/DynLibImpl.hpp @@ -8,6 +8,7 @@ #define NAZARA_CORE_POSIX_DYNLIBIMPL_HPP #include +#include #include #include @@ -18,14 +19,19 @@ namespace Nz class DynLibImpl { public: - DynLibImpl(DynLib* m_parent); + DynLibImpl() = default; + DynLibImpl(const DynLibImpl&) = delete; + DynLibImpl(DynLibImpl&&) noexcept = default; ~DynLibImpl(); DynLibFunc GetSymbol(const char* symbol, std::string* errorMessage) const; bool Load(const std::filesystem::path& libraryPath, std::string* errorMessage); + DynLibImpl& operator=(const DynLibImpl&) = delete; + DynLibImpl& operator=(DynLibImpl&&) noexcept = default; + private: - void* m_handle; + MovablePtr m_handle; }; } diff --git a/src/Nazara/Core/Win32/DynLibImpl.cpp b/src/Nazara/Core/Win32/DynLibImpl.cpp index e2e40a5c3..9a9079653 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.cpp +++ b/src/Nazara/Core/Win32/DynLibImpl.cpp @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include @@ -11,11 +10,6 @@ namespace Nz { - DynLibImpl::DynLibImpl(DynLib*) : - m_handle(nullptr) - { - } - DynLibImpl::~DynLibImpl() { if (m_handle) @@ -24,7 +18,7 @@ namespace Nz DynLibFunc DynLibImpl::GetSymbol(const char* symbol, std::string* errorMessage) const { - DynLibFunc sym = reinterpret_cast(GetProcAddress(m_handle, symbol)); + DynLibFunc sym = reinterpret_cast(::GetProcAddress(m_handle, symbol)); if (!sym) *errorMessage = Error::GetLastSystemError(); diff --git a/src/Nazara/Core/Win32/DynLibImpl.hpp b/src/Nazara/Core/Win32/DynLibImpl.hpp index bff2eb989..d4ac15327 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.hpp +++ b/src/Nazara/Core/Win32/DynLibImpl.hpp @@ -9,27 +9,28 @@ #include #include +#include #include -#include +#include namespace Nz { class DynLibImpl { public: - DynLibImpl(DynLib* m_parent); + DynLibImpl() = default; DynLibImpl(const DynLibImpl&) = delete; - DynLibImpl(DynLibImpl&&) = delete; ///TODO? + DynLibImpl(DynLibImpl&&) noexcept = default; ~DynLibImpl(); DynLibFunc GetSymbol(const char* symbol, std::string* errorMessage) const; bool Load(const std::filesystem::path& libraryPath, std::string* errorMessage); DynLibImpl& operator=(const DynLibImpl&) = delete; - DynLibImpl& operator=(DynLibImpl&&) = delete; ///TODO? + DynLibImpl& operator=(DynLibImpl&&) noexcept = default; private: - HMODULE m_handle; + MovablePtr> m_handle; }; } diff --git a/src/Nazara/Graphics/MaterialPipeline.cpp b/src/Nazara/Graphics/MaterialPipeline.cpp index 14939d28d..917f1a17b 100644 --- a/src/Nazara/Graphics/MaterialPipeline.cpp +++ b/src/Nazara/Graphics/MaterialPipeline.cpp @@ -44,7 +44,7 @@ namespace Nz } RenderPipelineInfo renderPipelineInfo; - static_cast(renderPipelineInfo).operator=(m_pipelineInfo); // Not the line I'm the most proud of + static_cast(renderPipelineInfo).operator=(m_pipelineInfo); renderPipelineInfo.pipelineLayout = m_pipelineInfo.pipelineLayout; diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index ff3466dc5..9820c248d 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -22,7 +22,7 @@ namespace Nz else { // TODO: Implement GPU to CPU - throw std::runtime_error("buffer is not mappable not implemented"); + throw std::runtime_error("buffer is not mappable: not implemented"); } } } diff --git a/src/Nazara/Utility/Components/SharedSkeletonComponent.cpp b/src/Nazara/Utility/Components/SharedSkeletonComponent.cpp index 5f71867e1..2e866aeec 100644 --- a/src/Nazara/Utility/Components/SharedSkeletonComponent.cpp +++ b/src/Nazara/Utility/Components/SharedSkeletonComponent.cpp @@ -82,7 +82,6 @@ namespace Nz if (jointCount == 0) return; - // TODO: This will trigger a lot of invalidation which can be avoided const Joint* referenceJoints = m_referenceSkeleton->GetJoints(); Joint* attachedJoints = m_attachedSkeleton.GetJoints();