Minor improvements

This commit is contained in:
Lynix 2024-01-29 18:34:46 +01:00
parent 0191256493
commit 2b88f50c21
19 changed files with 34 additions and 41 deletions

View File

@ -146,4 +146,3 @@ namespace Nz
}
#include <Nazara/Core/DebugOff.hpp>
#include "ApplicationBase.hpp"

View File

@ -18,7 +18,7 @@ namespace Nz
ModuleBase<T>::ModuleBase(std::string moduleName, T* pointer, NoLog) :
m_moduleName(std::move(moduleName))
{
NazaraAssert(T::s_instance == nullptr, "only one instance of " + m_moduleName + " can exist at a given time");
NazaraAssertFmt(T::s_instance == nullptr, "only one instance of {} can exist at a given time", m_moduleName);
T::s_instance = pointer;
}

View File

@ -37,7 +37,7 @@ namespace Nz
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::IsExtensionSupported(std::string_view extension) const
{
NazaraAssert(extension.size() >= 2 || extension.front() != '.', "extension should start with a .");
NazaraAssertFmt(extension.size() >= 2 || extension.front() != '.', "extension should start with a . (got {})", extension);
for (const auto& saverPtr : m_savers)
{

View File

@ -36,7 +36,7 @@ namespace Nz
virtual void BuildElement(ElementRendererRegistry& registry, const ElementData& elementData, std::size_t passIndex, std::vector<RenderElementOwner>& elements) const = 0;
inline const Boxf& GetAABB() const;
virtual const std::shared_ptr<MaterialInstance>& GetMaterial(std::size_t i) const = 0;
virtual const std::shared_ptr<MaterialInstance>& GetMaterial(std::size_t materialIndex) const = 0;
virtual std::size_t GetMaterialCount() const = 0;
inline int GetRenderLayer() const;

View File

@ -35,7 +35,7 @@ namespace Nz
inline void Clear();
inline const Color& GetColor() const;
const std::shared_ptr<MaterialInstance>& GetMaterial(std::size_t i = 0) const override;
const std::shared_ptr<MaterialInstance>& GetMaterial(std::size_t materialIndex = 0) const override;
std::size_t GetMaterialCount() const override;
inline Orientation GetOrientation() const;
inline const Vector2f& GetOrigin() const;

View File

@ -43,7 +43,7 @@ namespace Nz
inline auto LinearSlicedSprite::GetSection(std::size_t sectionIndex) const -> const Section&
{
NazaraAssert(sectionIndex < m_sectionCount, "out of range section");
NazaraAssertFmt(sectionIndex < m_sectionCount, "section index ouf of range ({0} >= {1})", sectionIndex, m_sectionCount);
return m_sections[sectionIndex];
}
@ -71,7 +71,7 @@ namespace Nz
inline void LinearSlicedSprite::RemoveSection(std::size_t sectionIndex)
{
NazaraAssert(sectionIndex < m_sectionCount, "out of range section");
NazaraAssertFmt(sectionIndex < m_sectionCount, "section index ouf of range ({0} >= {1})", sectionIndex, m_sectionCount);
if (m_sectionCount >= sectionIndex + 1)
std::move(m_sections.begin() + sectionIndex + 1, m_sections.begin() + m_sectionCount, m_sections.begin() + sectionIndex);
@ -102,7 +102,7 @@ namespace Nz
inline void LinearSlicedSprite::SetSection(std::size_t sectionIndex, float size, float textureCoord)
{
NazaraAssert(sectionIndex < m_sectionCount, "out of range section");
NazaraAssertFmt(sectionIndex < m_sectionCount, "section index ouf of range ({0} >= {1})", sectionIndex, m_sectionCount);
auto& section = m_sections[sectionIndex];
section.size = size;
@ -113,7 +113,7 @@ namespace Nz
inline void LinearSlicedSprite::SetSectionSize(std::size_t sectionIndex, float size)
{
NazaraAssert(sectionIndex < m_sectionCount, "out of range section");
NazaraAssertFmt(sectionIndex < m_sectionCount, "section index ouf of range ({0} >= {1})", sectionIndex, m_sectionCount);
auto& section = m_sections[sectionIndex];
section.size = size;
@ -123,7 +123,7 @@ namespace Nz
inline void LinearSlicedSprite::SetSectionTextureCoord(std::size_t sectionIndex, float textureCoord)
{
NazaraAssert(sectionIndex < m_sectionCount, "out of range section");
NazaraAssertFmt(sectionIndex < m_sectionCount, "section index ouf of range ({0} >= {1})", sectionIndex, m_sectionCount);
auto& section = m_sections[sectionIndex];
section.textureCoord = textureCoord;
@ -133,7 +133,7 @@ namespace Nz
inline void LinearSlicedSprite::SetSize(float size)
{
NazaraAssert(size >= 0.f, "size must be positive");
NazaraAssertFmt(size >= 0.f, "size must be positive (got {0})", size);
m_size = size;

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <cassert>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
@ -14,8 +14,8 @@ namespace Nz
inline void Model::SetMaterial(std::size_t subMeshIndex, std::shared_ptr<MaterialInstance> material)
{
assert(subMeshIndex < m_submeshes.size());
assert(material);
NazaraAssertFmt(subMeshIndex < m_submeshes.size(), "submesh index out of range ({0} >= {1})", subMeshIndex, m_submeshes.size());
NazaraAssert(material, "invalid material");
if (m_submeshes[subMeshIndex].material != material)
{

View File

@ -31,7 +31,7 @@ namespace Nz
inline const Color& GetColor() const;
inline const Corner& GetBottomRightCorner() const;
const std::shared_ptr<MaterialInstance>& GetMaterial(std::size_t i = 0) const override;
const std::shared_ptr<MaterialInstance>& GetMaterial(std::size_t materialIndex = 0) const override;
std::size_t GetMaterialCount() const override;
inline const Vector2f& GetOrigin() const;
inline const Vector2f& GetSize() const;

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <cassert>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
@ -70,7 +70,7 @@ namespace Nz
inline void SlicedSprite::SetMaterial(std::shared_ptr<MaterialInstance> material)
{
assert(material);
NazaraAssert(material, "invalid material");
if (m_material != material)
{

View File

@ -120,7 +120,7 @@ namespace Nz
inline void Tilemap::EnableTile(const Vector2ui& tilePos, const Rectf& coords, const Color& color, std::size_t materialIndex)
{
NazaraAssert(tilePos.x < m_mapSize.x&& tilePos.y < m_mapSize.y, "Tile position is out of bounds");
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
NazaraAssertFmt(materialIndex < m_layers.size(), "material index out of bounds ({0} >= {1})", materialIndex, m_layers.size());
std::size_t tileIndex = tilePos.y * m_mapSize.x + tilePos.x;
Tile& tile = m_tiles[tilePos.y * m_mapSize.x + tilePos.x];
@ -168,7 +168,7 @@ namespace Nz
*/
inline void Tilemap::EnableTile(const Vector2ui& tilePos, const Rectui& rect, const Color& color, std::size_t materialIndex)
{
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
NazaraAssertFmt(materialIndex < m_layers.size(), "material index out of bounds ({0} >= {1})", materialIndex, m_layers.size());
Vector2ui textureSize(GetTextureSize(materialIndex));
float invWidth = 1.f / textureSize.x;
@ -194,7 +194,7 @@ namespace Nz
*/
inline void Tilemap::EnableTiles(const Rectf& coords, const Color& color, std::size_t materialIndex)
{
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
NazaraAssertFmt(materialIndex < m_layers.size(), "material index out of bounds ({0} >= {1})", materialIndex, m_layers.size());
for (Layer& layer : m_layers)
layer.enabledTiles.Reset();
@ -231,7 +231,7 @@ namespace Nz
*/
inline void Tilemap::EnableTiles(const Rectui& rect, const Color& color, std::size_t materialIndex)
{
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
NazaraAssertFmt(materialIndex < m_layers.size(), "material index out of bounds ({0} >= {1})", materialIndex, m_layers.size());
Vector2ui textureSize(GetTextureSize(materialIndex));
float invWidth = 1.f / textureSize.x;
@ -257,7 +257,7 @@ namespace Nz
inline void Tilemap::EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectf& coords, const Color& color, std::size_t materialIndex)
{
NazaraAssert(tilesPos || tileCount == 0, "Invalid tile position array with a non-zero tileCount");
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
NazaraAssertFmt(materialIndex < m_layers.size(), "material index out of bounds ({0} >= {1})", materialIndex, m_layers.size());
for (std::size_t i = 0; i < tileCount; ++i)
{
@ -316,7 +316,7 @@ namespace Nz
*/
inline void Tilemap::EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectui& rect, const Color& color, std::size_t materialIndex)
{
NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds");
NazaraAssertFmt(materialIndex < m_layers.size(), "material index out of bounds ({0} >= {1})", materialIndex, m_layers.size());
Vector2ui textureSize(GetTextureSize(materialIndex));
float invWidth = 1.f / textureSize.x;

View File

@ -640,7 +640,7 @@ namespace Nz
template<typename T>
constexpr T& Box<T>::operator[](std::size_t i)
{
NazaraAssert(i < 6, "Index out of range");
NazaraAssertFmt(i < 6, "index out of range ({0} >= 6)", i);
return *(&x+i);
}
@ -656,7 +656,7 @@ namespace Nz
template<typename T>
constexpr const T& Box<T>::operator[](std::size_t i) const
{
NazaraAssert(i < 6, "Index out of range");
NazaraAssertFmt(i < 6, "index out of range ({0} >= 6)", i);
return *(&x+i);
}

View File

@ -262,4 +262,3 @@ namespace Nz
}
#include <Nazara/Widgets/DebugOff.hpp>
#include "AbstractTextAreaWidget.hpp"

View File

@ -7,6 +7,7 @@
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <NazaraUtils/CallOnExit.hpp>
#include <array>
#include <cstring>
#include <Nazara/Core/Debug.hpp>

View File

@ -39,7 +39,6 @@ namespace Nz
{
NAZARA_USE_ANONYMOUS_NAMESPACE
// std::thread::native_handle returns a void* with MSVC instead of a HANDLE
return PlatformImpl::GetThreadName(GetHandle(thread));
}
@ -52,7 +51,6 @@ namespace Nz
{
NAZARA_USE_ANONYMOUS_NAMESPACE
// std::thread::native_handle returns a void* with MSVC instead of a HANDLE
PlatformImpl::SetThreadName(GetHandle(thread), name);
}
}

View File

@ -47,11 +47,9 @@ namespace Nz
elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox));
}
const std::shared_ptr<MaterialInstance>& LinearSlicedSprite::GetMaterial(std::size_t i) const
const std::shared_ptr<MaterialInstance>& LinearSlicedSprite::GetMaterial(std::size_t materialIndex) const
{
assert(i == 0);
NazaraUnused(i);
NazaraAssertFmt(materialIndex == 0, "material index out of range ({0} >= 1)", materialIndex);
return m_material;
}

View File

@ -79,7 +79,7 @@ namespace Nz
const std::shared_ptr<MaterialInstance>& Model::GetMaterial(std::size_t subMeshIndex) const
{
assert(subMeshIndex < m_submeshes.size());
NazaraAssertFmt(subMeshIndex < m_submeshes.size(), "material index out of range ({0} >= {1})", subMeshIndex, m_submeshes.size());
const auto& subMeshData = m_submeshes[subMeshIndex];
return subMeshData.material;
}
@ -91,7 +91,7 @@ namespace Nz
const std::vector<RenderPipelineInfo::VertexBufferData>& Model::GetVertexBufferData(std::size_t subMeshIndex) const
{
assert(subMeshIndex < m_submeshes.size());
NazaraAssertFmt(subMeshIndex < m_submeshes.size(), "submesh index out of range ({0} >= {1})", subMeshIndex, m_submeshes.size());
const auto& subMeshData = m_submeshes[subMeshIndex];
return subMeshData.vertexBufferData;
}

View File

@ -42,11 +42,9 @@ namespace Nz
elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox));
}
const std::shared_ptr<MaterialInstance>& SlicedSprite::GetMaterial(std::size_t i) const
const std::shared_ptr<MaterialInstance>& SlicedSprite::GetMaterial(std::size_t materialIndex) const
{
assert(i == 0);
NazaraUnused(i);
NazaraAssertFmt(materialIndex == 0, "material index out of range ({0} >= 1)", materialIndex);
return m_material;
}

View File

@ -25,14 +25,14 @@ namespace Nz
*/
Tilemap::Tilemap(const Vector2ui& mapSize, const Vector2f& tileSize, std::size_t materialCount) :
m_layers(materialCount),
m_tiles(mapSize.x* mapSize.y),
m_tiles(mapSize.x * mapSize.y),
m_origin(0.f, 0.f),
m_tileSize(tileSize),
m_mapSize(mapSize),
m_isometricModeEnabled(false),
m_shouldRebuildVertices(false)
{
NazaraAssert(m_tiles.size() != 0U, "Invalid map size");
NazaraAssert(m_tiles.size() != 0U, "invalid map size");
NazaraAssert(m_tileSize.x > 0 && m_tileSize.y > 0, "Invalid tile size");
NazaraAssert(m_layers.size() != 0U, "Invalid material count");

View File

@ -12,7 +12,7 @@ namespace Nz::GL
WGLLoader::WGLLoader(const Renderer::Config& config) :
m_baseContext(nullptr, *this)
{
if (!m_opengl32Lib.Load("opengl32" NAZARA_DYNLIB_EXTENSION))
if (!m_opengl32Lib.Load("opengl32.dll"))
throw std::runtime_error("Failed to load opengl32 library, is OpenGL installed on your system?");
if (!m_gdi32Lib.Load("gdi32.dll"))