Random code cleanup

This commit is contained in:
SirLynix 2023-06-05 18:05:16 +02:00
parent 1a55b550fb
commit b9c1559d97
10 changed files with 31 additions and 46 deletions

View File

@ -14,8 +14,6 @@
#include <Nazara/Math/Vector3.hpp>
#include <limits>
///TODO: Inherit SoundEmitter from Node
namespace Nz
{
class AudioDevice;

View File

@ -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<ALsizei>(sampleCount * sizeof(Int16)), static_cast<ALsizei>(sampleRate));
m_library.alBufferData(m_bufferId, alFormat, samples, SafeCast<ALsizei>(sampleCount * sizeof(Int16)), SafeCast<ALsizei>(sampleRate));
if (ALenum lastError = m_library.alGetError(); lastError != AL_NO_ERROR)
{

View File

@ -73,7 +73,7 @@ namespace Nz
if (libraryPath.extension() != NAZARA_DYNLIB_EXTENSION)
libraryPath += NAZARA_DYNLIB_EXTENSION;
auto impl = std::make_unique<DynLibImpl>(this);
auto impl = std::make_unique<DynLibImpl>();
if (!impl->Load(libraryPath, &m_lastError))
{
NazaraError("Failed to load library: " + m_lastError);

View File

@ -3,17 +3,11 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Posix/DynLibImpl.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <dlfcn.h>
#include <Nazara/Core/Debug.hpp>
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;
}
}

View File

@ -8,6 +8,7 @@
#define NAZARA_CORE_POSIX_DYNLIBIMPL_HPP
#include <Nazara/Core/DynLib.hpp>
#include <NazaraUtils/MovablePtr.hpp>
#include <filesystem>
#include <string>
@ -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<void> m_handle;
};
}

View File

@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Win32/DynLibImpl.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <memory>
@ -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<DynLibFunc>(GetProcAddress(m_handle, symbol));
DynLibFunc sym = reinterpret_cast<DynLibFunc>(::GetProcAddress(m_handle, symbol));
if (!sym)
*errorMessage = Error::GetLastSystemError();

View File

@ -9,27 +9,28 @@
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <NazaraUtils/MovablePtr.hpp>
#include <filesystem>
#include <windows.h>
#include <Windows.h>
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<std::remove_pointer_t<HMODULE>> m_handle;
};
}

View File

@ -44,7 +44,7 @@ namespace Nz
}
RenderPipelineInfo renderPipelineInfo;
static_cast<RenderStates&>(renderPipelineInfo).operator=(m_pipelineInfo); // Not the line I'm the most proud of
static_cast<RenderStates&>(renderPipelineInfo).operator=(m_pipelineInfo);
renderPipelineInfo.pipelineLayout = m_pipelineInfo.pipelineLayout;

View File

@ -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");
}
}
}

View File

@ -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();