Allow error message to be formatted

This commit is contained in:
SirLynix 2023-08-14 23:16:37 +02:00 committed by Jérôme Leclercq
parent 25957c4b7f
commit a741672a51
119 changed files with 707 additions and 490 deletions

View File

@ -105,7 +105,7 @@ namespace Nz
using Param = std::decay_t<decltype(arg)>;
if constexpr (std::is_base_of_v<VirtualDirectory::DirectoryEntry, Param>)
{
NazaraError(std::string(assetPath) + " is a directory");
NazaraError("{} is a directory", assetPath);
return false;
}
else if constexpr (std::is_same_v<Param, VirtualDirectory::FileEntry>)
@ -136,7 +136,7 @@ namespace Nz
using Param = std::decay_t<decltype(arg)>;
if constexpr (std::is_base_of_v<VirtualDirectory::DirectoryEntry, Param>)
{
NazaraError(std::string(assetPath) + " is a directory");
NazaraError("{} is a directory", assetPath);
return false;
}
else if constexpr (std::is_same_v<Param, VirtualDirectory::FileEntry>)

View File

@ -30,14 +30,10 @@ namespace Nz
enum class ErrorMode
{
None,
Silent,
SilentDisabled,
ThrowException,
ThrowExceptionDisabled,
Max = ThrowExceptionDisabled
Max = ThrowException
};
template<>
@ -48,6 +44,8 @@ namespace Nz
using ErrorModeFlags = Flags<ErrorMode>;
constexpr ErrorModeFlags ErrorMode_Default = {};
enum class ErrorType
{
AssertFailed,

View File

@ -10,17 +10,18 @@
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/ToString.hpp>
#include <string>
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
#define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType::AssertFailed, err, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION)
#define NazaraAssert(a, ...) if NAZARA_UNLIKELY(!(a)) Nz::Error::Trigger(Nz::ErrorType::AssertFailed, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION, __VA_ARGS__)
#else
#define NazaraAssert(a, err) for (;;) break
#define NazaraAssert(a, ...) for (;;) break
#endif
#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType::Normal, err, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION)
#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType::Internal, err, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION)
#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType::Warning, err, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION)
#define NazaraError(...) Nz::Error::Trigger(Nz::ErrorType::Normal, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION, __VA_ARGS__)
#define NazaraInternalError(...) Nz::Error::Trigger(Nz::ErrorType::Internal, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION, __VA_ARGS__)
#define NazaraWarning(...) Nz::Error::Trigger(Nz::ErrorType::Warning, __LINE__, __FILE__, NAZARA_PRETTY_FUNCTION, __VA_ARGS__)
namespace Nz
{
@ -30,25 +31,22 @@ namespace Nz
Error() = delete;
~Error() = delete;
static constexpr std::string_view GetCurrentFileRelativeToEngine(std::string_view file);
static ErrorModeFlags GetFlags();
static std::string GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
static std::string GetLastError(std::string_view* file = nullptr, unsigned int* line = nullptr, std::string_view* function = nullptr);
static unsigned int GetLastSystemErrorCode();
static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode());
static void SetFlags(ErrorModeFlags flags);
static void Trigger(ErrorType type, std::string error);
static void Trigger(ErrorType type, std::string error, unsigned int line, const char* file, const char* function);
template<typename... Args> static void Trigger(ErrorType type, std::string_view error, Args&&... args);
template<typename... Args> static void Trigger(ErrorType type, unsigned int line, std::string_view file, std::string_view function, std::string_view error, Args&&... args);
private:
static const char* GetCurrentFileRelativeToEngine(const char* file);
static ErrorModeFlags s_flags;
static std::string s_lastError;
static const char* s_lastErrorFunction;
static const char* s_lastErrorFile;
static unsigned int s_lastErrorLine;
static void TriggerInternal(ErrorType type, std::string error, unsigned int line, std::string_view file, std::string_view function);
};
}
#include <Nazara/Core/Error.inl>
#endif // NAZARA_CORE_ERROR_HPP

View File

@ -0,0 +1,29 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
namespace Nz
{
constexpr std::string_view Error::GetCurrentFileRelativeToEngine(std::string_view file)
{
if (std::size_t offset = file.find("NazaraEngine/"); offset != file.npos)
return file.substr(offset);
if (std::size_t offset = file.find("NazaraEngine\\"); offset != file.npos)
return file.substr(offset);
return file;
}
template<typename... Args>
void Error::Trigger(ErrorType type, std::string_view error, Args&&... args)
{
return TriggerInternal(type, Format(error, std::forward<Args>(args)...), 0, {}, {});
}
template<typename... Args>
void Error::Trigger(ErrorType type, unsigned int line, std::string_view file, std::string_view function, std::string_view error, Args&&... args)
{
return TriggerInternal(type, Format(error, std::forward<Args>(args)...), line, GetCurrentFileRelativeToEngine(file), function);
}
}

View File

@ -16,14 +16,14 @@ namespace Nz
class NAZARA_CORE_API ErrorFlags
{
public:
ErrorFlags(ErrorModeFlags flags, bool replace = false);
ErrorFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags = {});
ErrorFlags(const ErrorFlags&) = delete;
ErrorFlags(ErrorFlags&&) = delete;
~ErrorFlags();
ErrorModeFlags GetPreviousFlags() const;
void SetFlags(ErrorModeFlags flags, bool replace = false);
void SetFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags = {});
ErrorFlags& operator=(const ErrorFlags&) = delete;
ErrorFlags& operator=(ErrorFlags&&) = delete;

View File

@ -15,12 +15,12 @@
#include <string>
#ifdef NAZARA_DEBUG
#define NazaraDebug(txt) NazaraNotice(txt)
#define NazaraDebug(...) NazaraNotice(__VA_ARGS__)
#else
#define NazaraDebug(txt)
#define NazaraDebug(...)
#endif
#define NazaraNotice(txt) Nz::Log::Write(txt)
#define NazaraNotice(...) Nz::Log::Write(__VA_ARGS__)
namespace Nz
{
@ -39,7 +39,8 @@ namespace Nz
static void SetLogger(AbstractLogger* logger);
static void Write(std::string_view string);
static void Write(std::string_view str);
template<typename... Args> static void Write(std::string_view str, Args&&... args);
static void WriteError(ErrorType type, std::string_view error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
NazaraStaticSignal(OnLogWrite, const std::string_view& /*string*/);
@ -54,4 +55,6 @@ namespace Nz
};
}
#include <Nazara/Core/Log.inl>
#endif // NAZARA_CORE_LOG_HPP

View File

@ -0,0 +1,17 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/ToString.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
template<typename... Args>
void Log::Write(std::string_view str, Args&&... args)
{
return Write(Format(str, std::forward<Args>(args)...));
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -35,7 +35,7 @@ namespace Nz
{
std::shared_ptr<Type> ref = Query(name);
if (!ref)
NazaraError("Object \"" + name + "\" is not present");
NazaraError("Object \"{}\" is not present", name);
return ref;
}

View File

@ -66,7 +66,7 @@ namespace Nz
std::string ext = ToLower(PathToString(filePath.extension()));
if (ext.empty())
{
NazaraError("Failed to get file extension from \"" + PathToString(filePath) + '"');
NazaraError("failed to get file extension from \"{0}\"", filePath);
return nullptr;
}
@ -93,7 +93,7 @@ namespace Nz
{
if (!file.Open(OpenMode::ReadOnly))
{
NazaraError("failed to load resource: unable to open \"" + PathToString(filePath) + '"');
NazaraError("failed to load resource: unable to open \"{0}\"", filePath);
return nullptr;
}
}
@ -121,9 +121,9 @@ namespace Nz
}
if (found)
NazaraError("failed to load resource from file \"" + PathToString(filePath) + "\": all loaders failed");
NazaraError("failed to load resource from file \"{0}}\": all loaders failed", filePath);
else
NazaraError("failed to load resource from file \"" + PathToString(filePath) + "\": no loader found for extension \"" + ext + '"');
NazaraError("failed to load resource from file \"{0}}\": no loader found for extension \"{1}\"", ext);
return nullptr;
}
@ -139,9 +139,9 @@ namespace Nz
template<typename Type, typename Parameters>
std::shared_ptr<Type> ResourceLoader<Type, Parameters>::LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters) const
{
NazaraAssert(data, "Invalid data pointer");
NazaraAssert(size, "No data to load");
NazaraAssert(parameters.IsValid(), "Invalid parameters");
NazaraAssert(data, "invalid data pointer");
NazaraAssert(size, "no data to load");
NazaraAssert(parameters.IsValid(), "invalid parameters");
MemoryView stream(data, size);

View File

@ -50,11 +50,11 @@ namespace Nz
std::shared_ptr<Type> resource = m_loader.LoadFromFile(absolutePath, GetDefaultParameters());
if (!resource)
{
NazaraError("Failed to load resource from file: " + PathToString(absolutePath));
NazaraError("failed to load resource from file: {0}", absolutePath);
return std::shared_ptr<Type>();
}
NazaraDebug("Loaded resource from file " + PathToString(absolutePath));
NazaraDebug("loaded resource from file {0}", absolutePath);
it = m_resources.insert(std::make_pair(absolutePath, resource)).first;
}

View File

@ -69,7 +69,7 @@ namespace Nz
std::string extension = ToLower(PathToString(filePath.extension()));
if (extension.empty())
{
NazaraError("Failed to get file extension from \"" + PathToString(filePath) + '"');
NazaraError("failed to get file extension from \"{0}\"", filePath);
return false;
}
@ -93,7 +93,7 @@ namespace Nz
if (!file.Open(OpenMode::WriteOnly | OpenMode::Truncate))
{
NazaraError("failed to save to file: unable to open \"" + PathToString(filePath) + "\" in write mode");
NazaraError("failed to save to file: unable to open \"{0}\" in write mode", filePath);
return false;
}
@ -107,7 +107,7 @@ namespace Nz
if (found)
NazaraError("failed to save resource: all savers failed");
else
NazaraError("failed to save resource: no saver found for extension \"" + extension + '"');
NazaraError("failed to save resource: no saver found for extension \"extension\"", extension);
return false;
}
@ -152,7 +152,7 @@ namespace Nz
if (found)
NazaraError("failed to save resource: all savers failed");
else
NazaraError("failed to save resource: no saver found for format \"" + format + '"');
NazaraError("failed to save resource: no saver found for format \"{0}\"", format);
return false;
}

View File

@ -0,0 +1,90 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_TOSTRING_HPP
#define NAZARA_CORE_TOSTRING_HPP
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/Config.hpp>
#include <NazaraUtils/Algorithm.hpp>
#include <filesystem>
#include <string>
namespace Nz
{
template<typename... Args> std::string Format(std::string_view str, Args&&... args);
template<typename T> decltype(auto) ToString(T&& value);
template<typename T>
struct ToStringFormatter
{
static_assert(AlwaysFalse<T>(), "ToStringFormatter is not implemented for this type");
};
template<>
struct NAZARA_CORE_API ToStringFormatter<std::filesystem::path>
{
static std::string Format(const std::filesystem::path& path);
};
template<>
struct ToStringFormatter<std::string>
{
static const std::string& Format(const std::string& value);
static std::string Format(std::string&& value);
};
template<>
struct ToStringFormatter<std::string_view>
{
static std::string Format(std::string_view value);
};
template<>
struct ToStringFormatter<const char*>
{
static std::string_view Format(const char* value);
template<std::size_t N> static std::string_view Format(const char(&str)[N]);
};
// Specializations declared in .inl
#define NAZARA_TO_STRING_INLINE_SPEC(Type) \
template<> \
struct ToStringFormatter<Type> \
{ \
static std::string Format(Type value); \
}
NAZARA_TO_STRING_INLINE_SPEC(short);
NAZARA_TO_STRING_INLINE_SPEC(int);
NAZARA_TO_STRING_INLINE_SPEC(long);
NAZARA_TO_STRING_INLINE_SPEC(long long);
NAZARA_TO_STRING_INLINE_SPEC(unsigned short);
NAZARA_TO_STRING_INLINE_SPEC(unsigned int);
NAZARA_TO_STRING_INLINE_SPEC(unsigned long);
NAZARA_TO_STRING_INLINE_SPEC(unsigned long long);
#undef NAZARA_TO_STRING_INLINE_SPEC
// Specializations declared in .cpp
#define NAZARA_TO_STRING_CPP_SPEC(Type) \
template<> \
struct NAZARA_CORE_API ToStringFormatter<Type> \
{ \
static std::string Format(Type value); \
}
NAZARA_TO_STRING_CPP_SPEC(float);
NAZARA_TO_STRING_CPP_SPEC(double);
NAZARA_TO_STRING_CPP_SPEC(long double);
#undef NAZARA_TO_STRING_CPP_SPEC
}
#include <Nazara/Core/ToString.inl>
#endif // NAZARA_CORE_TOSTRING_HPP

View File

@ -0,0 +1,88 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifdef NAZARA_BUILD
#include <fmt/format.h>
#include <fmt/std.h>
#endif
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
namespace Detail
{
NAZARA_CORE_API std::string FormatFallback(std::string_view str);
NAZARA_CORE_API std::string FormatFallback(std::string_view str, std::string_view param1);
NAZARA_CORE_API std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2);
NAZARA_CORE_API std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2, std::string_view param3);
NAZARA_CORE_API std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2, std::string_view param3, std::string_view param4);
NAZARA_CORE_API std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2, std::string_view param3, std::string_view param4, std::string_view param5);
}
template<typename ...Args>
std::string Format(std::string_view str, Args&&... args)
{
#ifdef NAZARA_BUILD
return fmt::format(str, std::forward<Args>(args)...);
#else
return Detail::FormatFallback(str, ToString(args)...);
#endif
}
template<typename T>
decltype(auto) ToString(T&& value)
{
return ToStringFormatter<std::decay_t<T>>::Format(std::forward<T>(value));
}
inline const std::string& ToStringFormatter<std::string>::Format(const std::string& value)
{
return value;
}
inline std::string ToStringFormatter<std::string>::Format(std::string&& value)
{
return value;
}
inline std::string ToStringFormatter<std::string_view>::Format(std::string_view value)
{
return std::string(value);
}
inline std::string_view ToStringFormatter<const char*>::Format(const char* value)
{
return std::string_view(value);
}
template<std::size_t N>
inline std::string_view ToStringFormatter<const char*>::Format(const char(&str)[N])
{
return std::string_view(str, N);
}
#define NAZARA_TO_STRING_STD_SPEC(Type) \
inline std::string ToStringFormatter<Type>::Format(Type value) \
{ \
return std::to_string(value); \
}
NAZARA_TO_STRING_STD_SPEC(short);
NAZARA_TO_STRING_STD_SPEC(int);
NAZARA_TO_STRING_STD_SPEC(long);
NAZARA_TO_STRING_STD_SPEC(long long);
NAZARA_TO_STRING_STD_SPEC(unsigned short);
NAZARA_TO_STRING_STD_SPEC(unsigned int);
NAZARA_TO_STRING_STD_SPEC(unsigned long);
NAZARA_TO_STRING_STD_SPEC(unsigned long long);
#undef NAZARA_TO_STRING_STD_SPEC
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -73,7 +73,7 @@ namespace Nz
case nzsl::ImageType::Cubemap: return ImageType::Cubemap;
}
NazaraError("invalid image type 0x" + NumberToString(UnderlyingCast(imageType), 16));
NazaraError("invalid image type 0x{0}", NumberToString(UnderlyingCast(imageType), 16));
return ImageType::E2D;
}
}

View File

@ -53,7 +53,7 @@ namespace Nz
std::size_t propertyIndex = FindTextureProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no texture property named " + std::string(propertyName));
NazaraError("material has no texture property named \"{0}\"", propertyName);
return nullptr;
}
@ -79,7 +79,7 @@ namespace Nz
std::size_t propertyIndex = FindTextureProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no texture property named " + std::string(propertyName));
NazaraError("material has no texture property named \"{0}\"", propertyName);
return nullptr;
}
@ -97,7 +97,7 @@ namespace Nz
std::size_t propertyIndex = FindValueProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no value property named " + std::string(propertyName));
NazaraError("material has no value property named \"{0}\"", propertyName);
return nullptr;
}
@ -128,7 +128,7 @@ namespace Nz
std::size_t propertyIndex = FindTextureProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no texture property named " + std::string(propertyName));
NazaraError("material has no texture property named \"{0}\"", propertyName);
return;
}
@ -140,7 +140,7 @@ namespace Nz
std::size_t propertyIndex = FindTextureProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no texture property named " + std::string(propertyName));
NazaraError("material has no texture property named \"{0}\"", propertyName);
return;
}
@ -152,7 +152,7 @@ namespace Nz
std::size_t propertyIndex = FindTextureProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no texture property named " + std::string(propertyName));
NazaraError("material has no texture property named \"{0}\"", propertyName);
return;
}
@ -164,7 +164,7 @@ namespace Nz
std::size_t propertyIndex = FindValueProperty(propertyName);
if (propertyIndex == MaterialSettings::InvalidPropertyIndex)
{
NazaraError("material has no value property named " + std::string(propertyName));
NazaraError("material has no value property named \"{0}\"", propertyName);
return;
}

View File

@ -363,7 +363,7 @@ namespace Nz
}
// If we arrive here, the extent is invalid
NazaraError("Invalid extent type (From) (0x" + NumberToString(UnderlyingCast(from.extent), 16) + ')');
NazaraError("Invalid extent type (From) ({0:#x})", UnderlyingCast(from.extent));
return Null();
}
@ -390,13 +390,13 @@ namespace Nz
}
// If we arrive here, the extent is invalid
NazaraError("Invalid extent type (From) (0x" + NumberToString(UnderlyingCast(from.extent), 16) + ')');
NazaraError("Invalid extent type (From) ({0:#x})", UnderlyingCast(from.extent));
return Null();
}
}
// If we arrive here, the extent is invalid
NazaraError("Invalid extent type (To) (0x" + NumberToString(UnderlyingCast(to.extent), 16) + ')');
NazaraError("Invalid extent type (To) ({0:#x})", UnderlyingCast(to.extent));
return Null();
}

View File

@ -7,12 +7,12 @@
#ifndef NAZARA_MATH_BOX_HPP
#define NAZARA_MATH_BOX_HPP
#include <NazaraUtils/EnumArray.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <NazaraUtils/EnumArray.hpp>
#include <string>
namespace Nz

View File

@ -305,7 +305,7 @@ namespace Nz
return Vector3<T>(x + width, y + height, z + depth);
}
NazaraError("Corner not handled (0x" + NumberToString(UnderlyingCast(corner), 16) + ')');
NazaraError("Corner not handled ({0:#x})", UnderlyingCast(corner));
return Vector3<T>();
}

View File

@ -116,7 +116,7 @@ namespace Nz
return false;
}
NazaraError("Invalid intersection side (0x" + NumberToString(UnderlyingCast(side), 16) + ')');
NazaraError("Invalid intersection side ({0:#x})", UnderlyingCast(side));
return false;
}
@ -127,7 +127,7 @@ namespace Nz
return false;
}
NazaraError("Invalid extent type (0x" + NumberToString(UnderlyingCast(volume.extent), 16) + ')');
NazaraError("Invalid extent type ({0:#x})", UnderlyingCast(volume.extent));
return false;
}
@ -281,7 +281,7 @@ namespace Nz
return IntersectionSide::Outside;
}
NazaraError("Invalid intersection side (0x" + NumberToString(UnderlyingCast(side), 16) + ')');
NazaraError("Invalid intersection side ({0:#x})", UnderlyingCast(side));
return IntersectionSide::Outside;
}
@ -292,7 +292,7 @@ namespace Nz
return IntersectionSide::Outside;
}
NazaraError("Invalid extent type (0x" + NumberToString(UnderlyingCast(volume.extent), 16) + ')');
NazaraError("Invalid extent type ({0:#x})", UnderlyingCast(volume.extent));
return IntersectionSide::Outside;
}

View File

@ -221,22 +221,11 @@ namespace Nz
* \param to Target plane
* \param interpolation Factor of interpolation
*
* \remark interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
* \remark With NAZARA_DEBUG, a NazaraError is thrown and Plane() is returned
*
* \see Lerp
*/
template<typename T>
constexpr Plane<T> Plane<T>::Lerp(const Plane& from, const Plane& to, T interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < T(0.0) || interpolation > T(1.0))
{
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
return Plane();
}
#endif
Plane plane;
plane.distance = Nz::Lerp(from.distance, to.distance, interpolation);
plane.normal = Vector3<T>::Lerp(from.normal, to.normal, interpolation);

View File

@ -603,14 +603,6 @@ namespace Nz
template<typename T>
constexpr Quaternion<T> Quaternion<T>::Lerp(const Quaternion& from, const Quaternion& to, T interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < T(0.0) || interpolation > T(1.0))
{
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
return Zero();
}
#endif
Quaternion interpolated;
interpolated.w = Nz::Lerp(from.w, to.w, interpolation);
interpolated.x = Nz::Lerp(from.x, to.x, interpolation);
@ -717,22 +709,11 @@ namespace Nz
* \param to Target quaternion
* \param interpolation Factor of interpolation
*
* \remark interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
* \remark With NAZARA_DEBUG, a NazaraError is thrown and Zero() is returned
*
* \see Lerp
*/
template<typename T>
Quaternion<T> Quaternion<T>::Slerp(const Quaternion& from, const Quaternion& to, T interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < T(0.0) || interpolation > T(1.0))
{
NazaraError("Interpolation must be in range [0..1] (Got " + std::to_string(interpolation) + ')');
return Zero();
}
#endif
Quaternion q;
T cosOmega = from.DotProduct(to);

View File

@ -200,7 +200,7 @@ namespace Nz
return false;
}
NazaraError("Invalid extent type (0x" + NumberToString(UnderlyingCast(volume.extent), 16) + ')');
NazaraError("Invalid extent type ({0:#x})", UnderlyingCast(volume.extent));
return false;
}

View File

@ -7,9 +7,9 @@
#ifndef NAZARA_MATH_RECT_HPP
#define NAZARA_MATH_RECT_HPP
#include <NazaraUtils/EnumArray.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <NazaraUtils/EnumArray.hpp>
#include <string>
namespace Nz

View File

@ -246,7 +246,7 @@ namespace Nz
return Vector2<T>(x + width, y);
}
NazaraError("Corner not handled (0x" + NumberToString(UnderlyingCast(corner), 16) + ')');
NazaraError("Corner not handled ({0:#x})", UnderlyingCast(corner));
return Vector2<T>();
}

View File

@ -478,22 +478,11 @@ namespace Nz
* \param to Target sphere
* \param interpolation Factor of interpolation
*
* \remark interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
* \remark With NAZARA_DEBUG, a NazaraError is thrown and Zero() is returned
*
* \see Lerp
*/
template<typename T>
constexpr Sphere<T> Sphere<T>::Lerp(const Sphere& from, const Sphere& to, T interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < T(0.0) || interpolation > T(1.0))
{
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
return Zero();
}
#endif
Sphere sphere;
sphere.x = Nz::Lerp(from.x, to.x, interpolation);
sphere.y = Nz::Lerp(from.y, to.y, interpolation);

View File

@ -42,7 +42,7 @@ namespace Nz
default: break;
}
NazaraError("Unhandled PixelFormat 0x" + NumberToString(UnderlyingCast(pixelFormat), 16));
NazaraError("unhandled PixelFormat {0:#x})", UnderlyingCast(pixelFormat));
return {};
}
@ -57,7 +57,7 @@ namespace Nz
case BlendEquation::Subtract: return GL_FUNC_SUBTRACT;
}
NazaraError("Unhandled BlendEquation 0x" + NumberToString(UnderlyingCast(blendEquation), 16));
NazaraError("unhandled BlendEquation {0:#x})", UnderlyingCast(blendEquation));
return {};
}
@ -81,7 +81,7 @@ namespace Nz
case BlendFunc::Zero: return GL_ZERO;
}
NazaraError("Unhandled BlendFunc 0x" + NumberToString(UnderlyingCast(blendFunc), 16));
NazaraError("unhandled BlendFunc {0:#x})", UnderlyingCast(blendFunc));
return {};
}
@ -94,7 +94,7 @@ namespace Nz
case FaceFilling::Point: return GL_POINT;
}
NazaraError("Unhandled FaceFilling 0x" + NumberToString(UnderlyingCast(side), 16));
NazaraError("unhandled FaceFilling {0:#x})", UnderlyingCast(side));
return {};
}
@ -110,7 +110,7 @@ namespace Nz
case FaceCulling::FrontAndBack: return GL_FRONT_AND_BACK;
}
NazaraError("Unhandled FaceSide 0x" + NumberToString(UnderlyingCast(side), 16));
NazaraError("unhandled FaceSide {0:#x})", UnderlyingCast(side));
return {};
}
@ -122,7 +122,7 @@ namespace Nz
case FrontFace::CounterClockwise: return GL_CCW;
}
NazaraError("Unhandled FrontFace 0x" + NumberToString(UnderlyingCast(face), 16));
NazaraError("unhandled FrontFace {0:#x})", UnderlyingCast(face));
return {};
}
@ -135,7 +135,7 @@ namespace Nz
case IndexType::U32: return GL_UNSIGNED_INT;
}
NazaraError("Unhandled IndexType 0x" + NumberToString(UnderlyingCast(indexType), 16));
NazaraError("unhandled IndexType {0:#x})", UnderlyingCast(indexType));
return {};
}
@ -151,7 +151,7 @@ namespace Nz
case PrimitiveMode::TriangleFan: return GL_TRIANGLE_FAN;
}
NazaraError("Unhandled PrimitiveMode 0x" + NumberToString(UnderlyingCast(primitiveMode), 16));
NazaraError("unhandled PrimitiveMode {0:#x})", UnderlyingCast(primitiveMode));
return {};
}
@ -169,7 +169,7 @@ namespace Nz
case RendererComparison::NotEqual: return GL_NOTEQUAL;
}
NazaraError("Unhandled RendererComparison 0x" + NumberToString(UnderlyingCast(comparison), 16));
NazaraError("unhandled RendererComparison {0:#x})", UnderlyingCast(comparison));
return {};
}
@ -181,7 +181,7 @@ namespace Nz
case SamplerFilter::Nearest: return GL_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(filter), 16));
NazaraError("unhandled SamplerFilter {0:#x})", UnderlyingCast(filter));
return {};
}
@ -197,7 +197,7 @@ namespace Nz
case SamplerMipmapMode::Nearest: return GL_LINEAR_MIPMAP_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16));
NazaraError("unhandled SamplerFilter {0:#x})", UnderlyingCast(mipmapFilter));
return {};
}
@ -209,12 +209,12 @@ namespace Nz
case SamplerMipmapMode::Nearest: return GL_NEAREST_MIPMAP_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16));
NazaraError("unhandled SamplerFilter {0:#x})", UnderlyingCast(mipmapFilter));
return {};
}
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(minFilter), 16));
NazaraError("unhandled SamplerFilter {0:#x})", UnderlyingCast(minFilter));
return {};
}
@ -227,7 +227,7 @@ namespace Nz
case SamplerWrap::Repeat: return GL_REPEAT;
}
NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(wrapMode), 16));
NazaraError("unhandled SamplerWrap {0:#x})", UnderlyingCast(wrapMode));
return {};
}
@ -240,7 +240,7 @@ namespace Nz
case nzsl::ShaderStageType::Vertex: return GL_VERTEX_SHADER;
}
NazaraError("Unhandled nzsl::ShaderStageType 0x" + NumberToString(UnderlyingCast(stageType), 16));
NazaraError("unhandled nzsl::ShaderStageType {0:#x})", UnderlyingCast(stageType));
return {};
}
@ -258,7 +258,7 @@ namespace Nz
case StencilOperation::Zero: return GL_ZERO;
}
NazaraError("Unhandled StencilOperation 0x" + NumberToString(UnderlyingCast(stencilOp), 16));
NazaraError("unhandled StencilOperation {0:#x})", UnderlyingCast(stencilOp));
return {};
}
@ -271,7 +271,7 @@ namespace Nz
case TextureAccess::WriteOnly: return GL_WRITE_ONLY;
}
NazaraError("Unhandled TextureAccess 0x" + NumberToString(UnderlyingCast(textureAccess), 16));
NazaraError("unhandled TextureAccess {0:#x})", UnderlyingCast(textureAccess));
return {};
}
@ -290,7 +290,7 @@ namespace Nz
case GL::BufferTarget::Uniform: return GL_UNIFORM_BUFFER;
}
NazaraError("Unhandled GL::BufferTarget 0x" + NumberToString(UnderlyingCast(bufferTarget), 16));
NazaraError("unhandled GL::BufferTarget {0:#x})", UnderlyingCast(bufferTarget));
return {};
}
@ -310,7 +310,7 @@ namespace Nz
case GL::TextureTarget::Target3D: return GL_TEXTURE_3D;
}
NazaraError("Unhandled GL::TextureTarget 0x" + NumberToString(UnderlyingCast(textureTarget), 16));
NazaraError("unhandled GL::TextureTarget {0:#x})", UnderlyingCast(textureTarget));
return {};
}
}

View File

@ -14,14 +14,14 @@ namespace Nz
inline Window::Window(VideoMode mode, const std::string& title, WindowStyleFlags style) :
Window()
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
Create(mode, title, style);
}
inline Window::Window(WindowHandle handle) :
Window()
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
Create(handle);
}

View File

@ -53,7 +53,7 @@ namespace Nz
inline void MTLParser::Error(const std::string& message)
{
NazaraError(message + " at line #" + std::to_string(m_lineCount));
NazaraError("{0} at line #{1}", message, m_lineCount);
}
inline void MTLParser::Flush() const
@ -64,7 +64,7 @@ namespace Nz
inline void MTLParser::Warning(const std::string& message)
{
NazaraWarning(message + " at line #" + std::to_string(m_lineCount));
NazaraWarning("{0} at line #{1}", message, m_lineCount);
}
inline void MTLParser::UnrecognizedLine(bool error)

View File

@ -153,7 +153,7 @@ namespace Nz
inline void OBJParser::Error(const std::string& message)
{
NazaraError(message + " at line #" + std::to_string(m_lineCount));
NazaraError("{0} at line #{1}", message, m_lineCount);
}
inline void OBJParser::Flush() const
@ -164,7 +164,7 @@ namespace Nz
inline void OBJParser::Warning(const std::string& message)
{
NazaraWarning(message + " at line #" + std::to_string(m_lineCount));
NazaraWarning("{0} at line #{1}", message, m_lineCount);
}
inline bool OBJParser::UnrecognizedLine(bool error)

View File

@ -159,7 +159,7 @@ namespace Nz
return m_position;
}
NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')');
NazaraError("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
return Vector3f();
}
@ -181,7 +181,7 @@ namespace Nz
return m_rotation;
}
NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')');
NazaraError("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
return Quaternionf();
}
@ -197,7 +197,7 @@ namespace Nz
return m_scale;
}
NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')');
NazaraError("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
return Vector3f();
}

View File

@ -200,13 +200,13 @@ namespace Nz
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func)
{
NazaraError("Pixel format conversion from " + std::string(GetName(srcFormat)) + " to " + std::string(GetName(dstFormat)) + " is not supported");
NazaraError("pixel format conversion from {0} to {1} is not supported", GetName(srcFormat), GetName(dstFormat));
return false;
}
if (!func(reinterpret_cast<const UInt8*>(start), reinterpret_cast<const UInt8*>(end), reinterpret_cast<UInt8*>(dst)))
{
NazaraError("Pixel format conversion from " + std::string(GetName(srcFormat)) + " to " + std::string(GetName(dstFormat)) + " failed");
NazaraError("pixel format conversion from {0} to {1} failed", GetName(srcFormat), GetName(dstFormat));
return false;
}

View File

@ -55,7 +55,7 @@ namespace Nz
case AttachmentLoadOp::Load: return VK_ATTACHMENT_LOAD_OP_LOAD;
}
NazaraError("Unhandled AttachmentLoadOp 0x" + NumberToString(UnderlyingCast(loadOp), 16));
NazaraError("unhandled AttachmentLoadOp {0:#x})", UnderlyingCast(loadOp));
return {};
}
@ -67,7 +67,7 @@ namespace Nz
case AttachmentStoreOp::Store: return VK_ATTACHMENT_STORE_OP_STORE;
}
NazaraError("Unhandled AttachmentStoreOp 0x" + NumberToString(UnderlyingCast(storeOp), 16));
NazaraError("unhandled AttachmentStoreOp {0:#x})", UnderlyingCast(storeOp));
return {};
}
@ -82,7 +82,7 @@ namespace Nz
case BlendEquation::Subtract: return VK_BLEND_OP_SUBTRACT;
}
NazaraError("Unhandled BlendEquation 0x" + NumberToString(UnderlyingCast(blendEquation), 16));
NazaraError("unhandled BlendEquation {0:#x})", UnderlyingCast(blendEquation));
return {};
}
@ -106,7 +106,7 @@ namespace Nz
case BlendFunc::Zero: return VK_BLEND_FACTOR_ZERO;
}
NazaraError("Unhandled BlendFunc 0x" + NumberToString(UnderlyingCast(blendFunc), 16));
NazaraError("unhandled BlendFunc {0:#x})", UnderlyingCast(blendFunc));
return {};
}
@ -121,7 +121,7 @@ namespace Nz
case BufferType::Upload: return VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
}
NazaraError("Unhandled BufferType 0x" + NumberToString(UnderlyingCast(bufferType), 16));
NazaraError("unhandled BufferType {0:#x})", UnderlyingCast(bufferType));
return 0;
}
@ -144,7 +144,7 @@ namespace Nz
case ComponentType::Int4: return VK_FORMAT_R32G32B32A32_SINT;
}
NazaraError("Unhandled ComponentType 0x" + NumberToString(UnderlyingCast(componentType), 16));
NazaraError("unhandled ComponentType {0:#x})", UnderlyingCast(componentType));
return VK_FORMAT_UNDEFINED;
}
@ -158,7 +158,7 @@ namespace Nz
case FaceCulling::FrontAndBack: return VK_CULL_MODE_FRONT_AND_BACK;
}
NazaraError("Unhandled FaceSide 0x" + NumberToString(UnderlyingCast(faceSide), 16));
NazaraError("unhandled FaceSide {0:#x})", UnderlyingCast(faceSide));
return VK_CULL_MODE_BACK_BIT;
}
@ -171,7 +171,7 @@ namespace Nz
case FaceFilling::Point: return VK_POLYGON_MODE_POINT;
}
NazaraError("Unhandled FaceFilling 0x" + NumberToString(UnderlyingCast(faceFilling), 16));
NazaraError("unhandled FaceFilling {0:#x})", UnderlyingCast(faceFilling));
return VK_POLYGON_MODE_FILL;
}
@ -183,7 +183,7 @@ namespace Nz
case FrontFace::CounterClockwise: return VK_FRONT_FACE_COUNTER_CLOCKWISE;
}
NazaraError("Unhandled FrontFace 0x" + NumberToString(UnderlyingCast(frontFace), 16));
NazaraError("unhandled FrontFace {0:#x})", UnderlyingCast(frontFace));
return {};
}
@ -196,7 +196,7 @@ namespace Nz
case IndexType::U32: return VK_INDEX_TYPE_UINT32;
}
NazaraError("Unhandled IndexType 0x" + NumberToString(UnderlyingCast(indexType), 16));
NazaraError("unhandled IndexType {0:#x})", UnderlyingCast(indexType));
return {};
}
@ -222,7 +222,7 @@ namespace Nz
case MemoryAccess::VertexBufferRead: return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
}
NazaraError("Unhandled MemoryAccess 0x" + NumberToString(UnderlyingCast(memoryAccess), 16));
NazaraError("unhandled MemoryAccess {0:#x})", UnderlyingCast(memoryAccess));
return {};
}
@ -256,7 +256,7 @@ namespace Nz
case PipelineStage::BottomOfPipe: return VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
}
NazaraError("Unhandled PipelineStage 0x" + NumberToString(UnderlyingCast(pipelineStage), 16));
NazaraError("unhandled PipelineStage {0:#x})", UnderlyingCast(pipelineStage));
return {};
}
@ -299,7 +299,7 @@ namespace Nz
default: break;
}
NazaraError("Unhandled PixelFormat 0x" + NumberToString(UnderlyingCast(pixelFormat), 16));
NazaraError("unhandled PixelFormat {0:#x})", UnderlyingCast(pixelFormat));
return VK_FORMAT_UNDEFINED;
}
@ -316,7 +316,7 @@ namespace Nz
case PixelFormatContent::Stencil: return VK_IMAGE_ASPECT_STENCIL_BIT;
}
NazaraError("Unhandled PixelFormatContent 0x" + NumberToString(UnderlyingCast(pixelFormatContent), 16));
NazaraError("unhandled PixelFormatContent {0:#x})", UnderlyingCast(pixelFormatContent));
return VK_IMAGE_ASPECT_COLOR_BIT;
}
@ -330,7 +330,7 @@ namespace Nz
case PresentMode::VerticalSync: return VK_PRESENT_MODE_FIFO_KHR;
}
NazaraError("Unhandled PresentMode 0x" + NumberToString(UnderlyingCast(presentMode), 16));
NazaraError("unhandled PresentMode {0:#x})", UnderlyingCast(presentMode));
return VK_PRESENT_MODE_FIFO_KHR;
}
@ -346,7 +346,7 @@ namespace Nz
case PrimitiveMode::TriangleFan: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
}
NazaraError("Unhandled PrimitiveMode 0x" + NumberToString(UnderlyingCast(primitiveMode), 16));
NazaraError("unhandled PrimitiveMode {0:#x})", UnderlyingCast(primitiveMode));
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
}
@ -364,7 +364,7 @@ namespace Nz
case RendererComparison::Always: return VK_COMPARE_OP_ALWAYS;
}
NazaraError("Unhandled RendererComparison 0x" + NumberToString(UnderlyingCast(comparison), 16));
NazaraError("unhandled RendererComparison {0:#x})", UnderlyingCast(comparison));
return VK_COMPARE_OP_NEVER;
}
@ -376,7 +376,7 @@ namespace Nz
case SamplerFilter::Nearest: return VK_FILTER_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(samplerFilter), 16));
NazaraError("unhandled SamplerFilter {0:#x})", UnderlyingCast(samplerFilter));
return VK_FILTER_NEAREST;
}
@ -388,7 +388,7 @@ namespace Nz
case SamplerMipmapMode::Nearest: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
NazaraError("Unhandled SamplerMipmapMode 0x" + NumberToString(UnderlyingCast(samplerMipmap), 16));
NazaraError("unhandled SamplerMipmapMode {0:#x})", UnderlyingCast(samplerMipmap));
return VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
@ -401,7 +401,7 @@ namespace Nz
case SamplerWrap::Repeat: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}
NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(samplerWrap), 16));
NazaraError("unhandled SamplerWrap {0:#x})", UnderlyingCast(samplerWrap));
return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}
@ -415,7 +415,7 @@ namespace Nz
case ShaderBindingType::UniformBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
}
NazaraError("Unhandled ShaderBindingType 0x" + NumberToString(UnderlyingCast(bindingType), 16));
NazaraError("unhandled ShaderBindingType {0:#x})", UnderlyingCast(bindingType));
return VK_DESCRIPTOR_TYPE_SAMPLER;
}
@ -428,7 +428,7 @@ namespace Nz
case nzsl::ShaderStageType::Vertex: return VK_SHADER_STAGE_VERTEX_BIT;
}
NazaraError("Unhandled nzsl::ShaderStageType 0x" + NumberToString(UnderlyingCast(stageType), 16));
NazaraError("unhandled nzsl::ShaderStageType {0:#x})", UnderlyingCast(stageType));
return {};
}
@ -455,7 +455,7 @@ namespace Nz
case StencilOperation::Zero: return VK_STENCIL_OP_ZERO;
}
NazaraError("Unhandled StencilOperation 0x" + NumberToString(UnderlyingCast(stencilOp), 16));
NazaraError("unhandled StencilOperation {0:#x})", UnderlyingCast(stencilOp));
return {};
}
@ -474,7 +474,7 @@ namespace Nz
case TextureLayout::Undefined: return VK_IMAGE_LAYOUT_UNDEFINED;
}
NazaraError("Unhandled TextureLayout 0x" + NumberToString(UnderlyingCast(textureLayout), 16));
NazaraError("unhandled TextureLayout {0:#x})", UnderlyingCast(textureLayout));
return {};
}
@ -491,7 +491,7 @@ namespace Nz
case TextureUsage::TransferDestination: return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
}
NazaraError("Unhandled TextureUsage 0x" + NumberToString(UnderlyingCast(textureLayout), 16));
NazaraError("unhandled TextureUsage {0:#x})", UnderlyingCast(textureLayout));
return {};
}
@ -512,7 +512,7 @@ namespace Nz
case VertexInputRate::Vertex: return VK_VERTEX_INPUT_RATE_VERTEX;
}
NazaraError("Unhandled VertexInputRate 0x" + NumberToString(UnderlyingCast(inputRate), 16));
NazaraError("unhandled VertexInputRate {0:#x})", UnderlyingCast(inputRate));
return {};
}

View File

@ -36,7 +36,7 @@ namespace Nz
m_lastErrorCode = m_pool->GetDevice()->vkBeginCommandBuffer(m_handle, &info);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to begin command buffer: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to begin command buffer: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -321,7 +321,7 @@ namespace Nz
m_lastErrorCode = m_pool->GetDevice()->vkEndCommandBuffer(m_handle);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to end command buffer: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to end command buffer: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -23,7 +23,7 @@ namespace Nz::Vk
inline const Device::QueueList& Device::GetEnabledQueues(UInt32 familyQueue) const
{
NazaraAssert(familyQueue < m_enabledQueuesInfos.size(), "Invalid family queue");
NazaraAssert(familyQueue < m_enabledQueuesInfos.size(), "invalid family queue {0}", familyQueue);
return *m_queuesByFamily[familyQueue];
}
@ -62,7 +62,7 @@ namespace Nz::Vk
{
PFN_vkVoidFunction func;
{
ErrorFlags errFlags(ErrorMode::ThrowExceptionDisabled);
ErrorFlags errFlags({}, ~ErrorMode::ThrowException);
func = m_instance.GetDeviceProcAddr(m_device, name);
}
@ -71,7 +71,7 @@ namespace Nz::Vk
if (allowInstanceFallback)
return m_instance.GetProcAddr(name);
NazaraError("Failed to get " + std::string(name) + " address");
NazaraError("failed to get {0} address", name);
}
return func;
@ -126,7 +126,7 @@ namespace Nz::Vk
m_lastErrorCode = vkDeviceWaitIdle(m_device);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to wait for device idle: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to wait for device idle: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -40,7 +40,7 @@ namespace Nz
typeMask <<= 1;
}
NazaraError("Failed to find a memory type suitable for typeBits: " + NumberToString(typeBits) + " and properties: 0x" + NumberToString(properties, 16));
NazaraError("failed to find a memory type suitable for typeBits: {0} and properties: 0x{1}", typeBits, NumberToString(properties, 16));
return false;
}
@ -62,7 +62,7 @@ namespace Nz
m_lastErrorCode = m_device->vkFlushMappedMemoryRanges(*m_device, 1, &memoryRange);
if (m_lastErrorCode != VK_SUCCESS)
{
NazaraError("Failed to flush memory: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to flush memory: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -85,7 +85,7 @@ namespace Nz
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &mappedPtr);
if (m_lastErrorCode != VK_SUCCESS)
{
NazaraError("Failed to map device memory: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to map device memory: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -40,7 +40,7 @@ namespace Nz::Vk
m_lastErrorCode = C::CreateHelper(*m_device, &createInfo, allocator, &m_handle);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan device object: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to create Vulkan device object: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -25,7 +25,7 @@ namespace Nz
m_lastErrorCode = m_device->vkResetFences(*m_device, 1U, &m_handle);
if (m_lastErrorCode != VK_SUCCESS)
{
NazaraError("Failed to reset fence: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to reset fence: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -42,7 +42,7 @@ namespace Nz
m_lastErrorCode = m_device->vkWaitForFences(*m_device, 1U, &m_handle, VK_TRUE, timeout);
if (m_lastErrorCode != VK_SUCCESS && m_lastErrorCode != VK_TIMEOUT)
{
NazaraError("Failed to wait for fence: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to wait for fence: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -14,7 +14,7 @@ namespace Nz
m_lastErrorCode = m_device->vkBindImageMemory(*m_device, m_handle, memory, offset);
if (m_lastErrorCode != VK_SUCCESS)
{
NazaraError("Failed to bind image memory: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to bind image memory: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -50,7 +50,7 @@ namespace Nz::Vk
{
PFN_vkVoidFunction func = vkGetDeviceProcAddr(device, name);
if (!func)
NazaraError("Failed to get " + std::string(name) + " address");
NazaraError("failed to get {0} address", name);
return func;
}
@ -69,7 +69,7 @@ namespace Nz::Vk
{
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
if (!func)
NazaraError("Failed to get " + std::string(name) + " address");
NazaraError("failed to get {0} address", name);
return func;
}
@ -120,7 +120,7 @@ namespace Nz::Vk
m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to get physical device image format properties: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to get physical device image format properties: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -39,7 +39,7 @@ namespace Nz
m_lastErrorCode = C::CreateHelper(*m_instance, &createInfo, allocator, &m_handle);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan instance object: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to create Vulkan instance object: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -74,7 +74,7 @@ namespace Nz
m_lastErrorCode = result;
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan pipeline: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to create Vulkan pipeline: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -135,7 +135,7 @@ namespace Nz
m_lastErrorCode = m_device->vkQueueSubmit(m_handle, submitCount, submits, signalFence);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to submit queue: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to submit queue: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -147,7 +147,7 @@ namespace Nz
m_lastErrorCode = m_device->vkQueueWaitIdle(m_handle);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to wait for queue: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to wait for queue: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -177,7 +177,7 @@ namespace Nz::Vk
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query surface capabilities: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -191,7 +191,7 @@ namespace Nz::Vk
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0)
{
NazaraError("Failed to query format count: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query format count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -200,7 +200,7 @@ namespace Nz::Vk
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query formats: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query formats: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -223,7 +223,7 @@ namespace Nz::Vk
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query present modes: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query present modes: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -236,7 +236,7 @@ namespace Nz::Vk
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query surface capabilities: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -291,7 +291,7 @@ namespace Nz::Vk
{
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to create Vulkan surface: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}

View File

@ -22,7 +22,7 @@ namespace Nz
default:
{
NazaraError("Failed to acquire next swapchain image: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to acquire next swapchain image: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
}
@ -37,7 +37,7 @@ namespace Nz
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || imageCount == 0)
{
NazaraError("Failed to query swapchain image count: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query swapchain image count: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -45,7 +45,7 @@ namespace Nz
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, images.data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query swapchain images: " + TranslateVulkanError(m_lastErrorCode));
NazaraError("failed to query swapchain images: {0}", TranslateVulkanError(m_lastErrorCode));
return false;
}
@ -78,7 +78,7 @@ namespace Nz
if (!m_images[i].view.Create(*m_device, imageViewCreateInfo))
{
NazaraError("Failed to create image view for image #" + NumberToString(i));
NazaraError("failed to create image view for image #{0}", i);
return false;
}
}

View File

@ -82,7 +82,7 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod
}
else
{
ErrorFlags errFlags(ErrorMode::ThrowExceptionDisabled, true);
ErrorFlags errFlags({}, ~ErrorMode::ThrowException);
///TODO: Move to File::DecodeOpenMode
OpenModeFlags openModeEnum = 0;
@ -107,7 +107,7 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod
}
else
{
NazaraError(std::string("Unhandled/Invalid openmode: ") + openMode + std::string(" for file ") + filePath);
NazaraError("unhandled/invalid openmode: {0} for file {1}", openMode, filePath);
return nullptr;
}

View File

@ -157,7 +157,7 @@ bool FindSkeletonRoot(SceneInfo& sceneInfo, const aiNode* node)
auto range = sceneInfo.nodeByName.equal_range(node->mName.C_Str());
if (std::distance(range.first, range.second) != 1)
{
NazaraError("failed to identify skeleton root node: " + std::to_string(std::distance(range.first, range.second)) + " node(s) matched");
NazaraError("failed to identify skeleton root node: {0} node(s) matched", std::distance(range.first, range.second));
return false;
}
@ -265,7 +265,7 @@ Nz::Result<std::shared_ptr<Nz::Animation>, Nz::ResourceLoadingError> LoadAnimati
if (!scene)
{
NazaraError("Assimp failed to import file: " + std::string(aiGetErrorString()));
NazaraError("Assimp failed to import file: {0}", aiGetErrorString());
return Nz::Err(Nz::ResourceLoadingError::DecodingError);
}
@ -308,7 +308,7 @@ Nz::Result<std::shared_ptr<Nz::Animation>, Nz::ResourceLoadingError> LoadAnimati
std::size_t jointIndex = parameters.skeleton->GetJointIndex(nodeAnim->mNodeName.C_Str());
if (jointIndex == Nz::Skeleton::InvalidJointIndex)
{
NazaraError("animation references joint " + std::string(nodeAnim->mNodeName.C_Str()) + " which is not part of the skeleton");
NazaraError("animation references joint {0} which is not part of the skeleton", nodeAnim->mNodeName.C_Str());
continue;
}
@ -815,7 +815,7 @@ Nz::Result<std::shared_ptr<Nz::Mesh>, Nz::ResourceLoadingError> LoadMesh(Nz::Str
if (!scene)
{
NazaraError("Assimp failed to import file: " + std::string(aiGetErrorString()));
NazaraError("Assimp failed to import file: {0}", aiGetErrorString());
return Nz::Err(Nz::ResourceLoadingError::DecodingError);
}

View File

@ -98,13 +98,13 @@ namespace
if (int errCode = avformat_open_input(&m_formatContext, "", nullptr, nullptr); errCode != 0)
{
NazaraError("failed to open input: " + ErrorToString(errCode));
NazaraError("failed to open input: {0}", ErrorToString(errCode));
return Nz::Err(Nz::ResourceLoadingError::Unrecognized);
}
if (int errCode = avformat_find_stream_info(m_formatContext, nullptr); errCode != 0)
{
NazaraError("failed to find stream info: " + ErrorToString(errCode));
NazaraError("failed to find stream info: {0}", ErrorToString(errCode));
return Nz::Err(Nz::ResourceLoadingError::Unrecognized);
}
@ -150,7 +150,7 @@ namespace
return false;
}
NazaraError("failed to read frame: " + ErrorToString(errCode));
NazaraError("failed to read frame: {0}", ErrorToString(errCode));
return false;
}
@ -159,7 +159,7 @@ namespace
if (int errCode = avcodec_send_packet(m_codecContext, &packet); errCode < 0)
{
NazaraError("failed to send packet: " + ErrorToString(errCode));
NazaraError("failed to send packet: {0}", ErrorToString(errCode));
return false;
}
@ -168,7 +168,7 @@ namespace
if (errCode == AVERROR(EAGAIN))
continue;
NazaraError("failed to receive frame: " + ErrorToString(errCode));
NazaraError("failed to receive frame: {0}", ErrorToString(errCode));
return false;
}
@ -236,13 +236,13 @@ namespace
if (int errCode = avcodec_parameters_to_context(m_codecContext, codecParameters); errCode < 0)
{
NazaraError("failed to copy codec params to codec context: " + ErrorToString(errCode));
NazaraError("failed to copy codec params to codec context: {0}", ErrorToString(errCode));
return Nz::Err(Nz::ResourceLoadingError::Internal);
}
if (int errCode = avcodec_open2(m_codecContext, m_codec, nullptr); errCode < 0)
{
NazaraError("could not open codec: " + ErrorToString(errCode));
NazaraError("could not open codec: {0}", ErrorToString(errCode));
return Nz::Err(Nz::ResourceLoadingError::Internal);
}
@ -260,7 +260,7 @@ namespace
if (int errCode = av_frame_get_buffer(m_rgbaFrame, 0); errCode < 0)
{
NazaraError("failed to open input: " + ErrorToString(errCode));
NazaraError("failed to open input: {0}", ErrorToString(errCode));
return Nz::Err(Nz::ResourceLoadingError::Internal);
}
@ -286,7 +286,7 @@ namespace
std::unique_ptr<Nz::File> file = std::make_unique<Nz::File>();
if (!file->Open(filePath, Nz::OpenMode::ReadOnly))
{
NazaraError("Failed to open stream from file: " + Nz::Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Nz::Error::GetLastError());
return false;
}
m_ownedStream = std::move(file);

View File

@ -72,7 +72,7 @@ namespace Nz
if (!config.allowDummyDevice)
throw;
NazaraError(std::string("failed to open default OpenAL device: ") + e.what());
NazaraError("failed to open default OpenAL device: {0}", e.what());
}
}

View File

@ -65,7 +65,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(wav.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(wav.channels));
NazaraError("unexpected channel count: {0}", wav.channels);
return Err(ResourceLoadingError::Unsupported);
}
@ -138,7 +138,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("failed to open stream from file: " + Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
return Err(ResourceLoadingError::FailedToOpenFile);
}
@ -166,7 +166,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(m_decoder.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(m_decoder.channels));
NazaraError("unexpected channel count: {0}", m_decoder.channels);
return Err(ResourceLoadingError::Unsupported);
}

View File

@ -229,7 +229,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(channelCount);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(channelCount));
NazaraError("unexpected channel count: {0}", channelCount);
return Err(ResourceLoadingError::Unsupported);
}
@ -298,7 +298,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("failed to open stream from file: " + Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
return Err(ResourceLoadingError::FailedToOpenFile);
}
@ -351,7 +351,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(m_channelCount);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(m_channelCount));
NazaraError("unexpected channel count: {0}", m_channelCount);
return Err(ResourceLoadingError::Unrecognized);
}

View File

@ -103,7 +103,7 @@ namespace Nz
if (readBytes < 0)
{
NazaraError("an error occurred while reading file: " + VorbisErrToString(readBytes));
NazaraError("an error occurred while reading file: {0}", VorbisErrToString(readBytes));
return 0;
}
@ -139,7 +139,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(info->channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(info->channels));
NazaraError("unexpected channel count: {0}", info->channels);
return Err(ResourceLoadingError::Unsupported);
}
@ -217,7 +217,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("failed to open stream from file: " + Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
return Err(ResourceLoadingError::FailedToOpenFile);
}
@ -249,7 +249,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(info->channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(info->channels));
NazaraError("unexpected channel count: {0}", info->channels);
return Err(ResourceLoadingError::Unsupported);
}

View File

@ -96,7 +96,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(info.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(info.channels));
NazaraError("unexpected channel count: {0}", info.channels);
return Err(ResourceLoadingError::Unsupported);
}
@ -163,7 +163,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("failed to open stream from file: " + Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
return Err(ResourceLoadingError::FailedToOpenFile);
}
@ -208,7 +208,7 @@ namespace Nz
std::optional<AudioFormat> formatOpt = GuessAudioFormat(m_decoder.info.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(m_decoder.info.channels));
NazaraError("unexpected channel count: {0}", m_decoder.info.channels);
return Err(ResourceLoadingError::Unsupported);
}

View File

@ -78,7 +78,7 @@ namespace Nz
if (ALenum lastError = m_library.alGetError(); lastError != AL_NO_ERROR)
{
NazaraError("failed to reset OpenAL buffer: " + std::to_string(lastError));
NazaraError("failed to reset OpenAL buffer: {0}", std::to_string(lastError));
return false;
}

View File

@ -65,6 +65,8 @@ namespace Nz
for (const char* libname : libs)
{
ErrorFlags disableError(ErrorMode::Silent, ~ErrorMode::ThrowException);
if (!m_library.Load(libname))
continue;
@ -84,6 +86,8 @@ namespace Nz
}
catch (const std::exception& e)
{
ErrorFlags disableSilent({}, ~ErrorMode::Silent);
NazaraWarning(std::string("failed to load ") + libname + ": " + e.what());
continue;
}

View File

@ -147,7 +147,7 @@ namespace Nz
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromFile(filePath, params);
if (!buffer)
{
NazaraError("Failed to load buffer from file (" + filePath.generic_u8string() + ')');
NazaraError("Failed to load buffer from file ({0})", filePath);
return false;
}
@ -170,7 +170,7 @@ namespace Nz
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromMemory(data, size, params);
if (!buffer)
{
NazaraError("Failed to load buffer from memory (" + PointerToString(data) + ')');
NazaraError("failed to load buffer from memory ({0})", PointerToString(data));
return false;
}

View File

@ -108,7 +108,7 @@ namespace Nz
return std::make_shared<BulletSphereCollider3D>(primitive.sphere.size);
}
NazaraError("Primitive type not handled (0x" + NumberToString(UnderlyingCast(primitive.type), 16) + ')');
NazaraError("Primitive type not handled ({0:#x})", UnderlyingCast(primitive.type));
return std::shared_ptr<BulletCollider3D>();
}

View File

@ -76,7 +76,7 @@ namespace Nz
return std::make_unique<WhirlpoolHasher>();
}
NazaraInternalError("Hash type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
NazaraInternalError("Hash type not handled ({0:#x})", UnderlyingCast(type));
return nullptr;
}
}

View File

@ -76,7 +76,7 @@ namespace Nz
auto impl = std::make_unique<DynLibImpl>();
if (!impl->Load(libraryPath, &m_lastError))
{
NazaraError("Failed to load library: " + m_lastError);
NazaraError("failed to load library: {0}", m_lastError);
return false;
}

View File

@ -6,6 +6,7 @@
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <NazaraUtils/CallOnExit.hpp>
#include <NazaraUtils/EnumArray.hpp>
#include <cstdlib>
#include <stdexcept>
@ -20,6 +21,22 @@
namespace Nz
{
namespace NAZARA_ANONYMOUS_NAMESPACE
{
constexpr EnumArray<ErrorType, std::string_view> s_errorTypes = {
"Assert failed: ", // ErrorType::AssertFailed
"Internal error: ", // ErrorType::Internal
"Error: ", // ErrorType::Normal
"Warning: " // ErrorType::Warning
};
thread_local ErrorModeFlags s_flags;
thread_local std::string s_lastError = "no error";
thread_local std::string_view s_lastErrorFunction;
thread_local std::string_view s_lastErrorFile;
thread_local unsigned int s_lastErrorLine = 0;
}
/*!
* \ingroup core
* \class Nz::Error
@ -33,6 +50,8 @@ namespace Nz
ErrorModeFlags Error::GetFlags()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_flags;
}
@ -45,8 +64,10 @@ namespace Nz
* \param function Optional argument to set last error function
*/
std::string Error::GetLastError(const char** file, unsigned int* line, const char** function)
std::string Error::GetLastError(std::string_view* file, unsigned int* line, std::string_view* function)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (file)
*file = s_lastErrorFile;
@ -118,90 +139,39 @@ namespace Nz
void Error::SetFlags(ErrorModeFlags flags)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
s_flags = flags;
}
/*!
* \brief Checks if the error should trigger
*
* \param type ErrorType of the error
* \param error Message of the error
*
* \remark Produces a std::abort on AssertFailed with NAZARA_CORE_EXIT_ON_ASSERT_FAILURE defined
* \remark Produces a std::runtime_error on AssertFailed or throwing exception
*/
void Error::Trigger(ErrorType type, std::string error)
void Error::TriggerInternal(ErrorType type, std::string error, unsigned int line, std::string_view file, std::string_view function)
{
if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0 || (s_flags & ErrorMode::SilentDisabled) != 0)
Log::WriteError(type, error);
NAZARA_USE_ANONYMOUS_NAMESPACE
s_lastError = std::move(error);
s_lastErrorFile = "";
s_lastErrorFunction = "";
s_lastErrorLine = 0;
if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0)
{
if (line == 0 && file.empty())
Log::Write("{}{}", s_errorTypes[type], error);
else
Log::Write("{}{} ({}:{}: {})", s_errorTypes[type], error, file, line, function);
}
if (type != ErrorType::Warning)
{
s_lastError = std::move(error);
s_lastErrorFile = file;
s_lastErrorFunction = function;
s_lastErrorLine = line;
}
#if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE
if (type == ErrorType::AssertFailed)
std::abort();
#endif
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning &&
(s_flags & ErrorMode::ThrowException) != 0 && (s_flags & ErrorMode::ThrowExceptionDisabled) == 0))
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning && s_flags.Test(ErrorMode::ThrowException)))
throw std::runtime_error(s_lastError);
}
/*!
* \brief Checks if the error should trigger
*
* \param type ErrorType of the error
* \param error Message of the error
* \param line Line of the error
* \param file File of the error
* \param function Function of the error
*
* \remark Produces a std::abort on AssertFailed with NAZARA_CORE_EXIT_ON_ASSERT_FAILURE defined
* \remark Produces a std::runtime_error on AssertFailed or throwing exception
*/
void Error::Trigger(ErrorType type, std::string error, unsigned int line, const char* file, const char* function)
{
file = GetCurrentFileRelativeToEngine(file);
if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0 || (s_flags & ErrorMode::SilentDisabled) != 0)
Log::WriteError(type, error, line, file, function);
s_lastError = std::move(error);
s_lastErrorFile = file;
s_lastErrorFunction = function;
s_lastErrorLine = line;
#if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE
if (type == ErrorType::AssertFailed)
std::abort();
#endif
if (type == ErrorType::AssertFailed || (type != ErrorType::Warning &&
(s_flags & ErrorMode::ThrowException) != 0 && (s_flags & ErrorMode::ThrowExceptionDisabled) == 0))
throw std::runtime_error(s_lastError);
}
const char* Error::GetCurrentFileRelativeToEngine(const char* file)
{
if (const char* ptr = std::strstr(file, "NazaraEngine/"))
return ptr;
if (const char* ptr = std::strstr(file, "NazaraEngine\\"))
return ptr;
return file;
}
ErrorModeFlags Error::s_flags = ErrorMode::None;
std::string Error::s_lastError;
const char* Error::s_lastErrorFunction = "";
const char* Error::s_lastErrorFile = "";
unsigned int Error::s_lastErrorLine = 0;
}
#if defined(NAZARA_PLATFORM_WINDOWS)

View File

@ -21,10 +21,10 @@ namespace Nz
* \param replace Replace the entirely the old flag if true, else do a "OR"
*/
ErrorFlags::ErrorFlags(ErrorModeFlags flags, bool replace) :
ErrorFlags::ErrorFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags) :
m_previousFlags(Error::GetFlags())
{
SetFlags(flags, replace);
SetFlags(orFlags, andFlags);
}
/*!
@ -51,11 +51,12 @@ namespace Nz
* \param flags Flags for the error
* \param replace Replace the entirely the old flag if true, else do a "OR"
*/
void ErrorFlags::SetFlags(ErrorModeFlags flags, bool replace)
void ErrorFlags::SetFlags(ErrorModeFlags orFlags, ErrorModeFlags andFlags)
{
if (!replace)
flags |= m_previousFlags;
ErrorModeFlags newFlags = m_previousFlags;
newFlags |= orFlags;
newFlags &= andFlags;
Error::SetFlags(flags);
Error::SetFlags(newFlags);
}
}

View File

@ -192,7 +192,7 @@ namespace Nz
if (!impl->Open(m_filePath, openMode))
{
ErrorFlags flags(ErrorMode::Silent); // Silent by default
NazaraError("failed to open \"" + m_filePath.generic_u8string() + "\": " + Error::GetLastSystemError());
NazaraError("failed to open \"{0}\": {1}", m_filePath, Error::GetLastSystemError());
return false;
}
@ -243,7 +243,7 @@ namespace Nz
std::unique_ptr<FileImpl> impl = std::make_unique<FileImpl>(this);
if (!impl->Open(filePath, m_openMode))
{
NazaraError("Failed to open new file; " + Error::GetLastSystemError());
NazaraError("failed to open new file; {0}", Error::GetLastSystemError());
return false;
}
@ -281,7 +281,7 @@ namespace Nz
File file(path);
if (!file.Open(OpenMode::ReadOnly | OpenMode::Unbuffered)) //< unbuffered since we will read all the file at once
{
NazaraError("failed to open \"" + path.generic_u8string() + '"');
NazaraError("failed to open \"{0}\"", path);
return std::nullopt;
}
@ -301,7 +301,7 @@ namespace Nz
File file(path);
if (!file.Open(OpenMode::WriteOnly | OpenMode::Unbuffered)) //< unbuffered since we will write all the file at once
{
NazaraError("failed to open \"" + path.generic_u8string() + '"');
NazaraError("failed to open \"{0}\"", path);
return false;
}

View File

@ -613,7 +613,7 @@ namespace Nz
break;
default:
NazaraError("Split heuristic out of enum (0x" + NumberToString(method, 16) + ')');
NazaraError("Split heuristic out of enum ({0:#x})", UnderlyingCast(method));
splitHorizontal = true;
}
@ -658,7 +658,7 @@ namespace Nz
return ScoreWorstShortSideFit(width, height, freeRect);
}
NazaraError("Rect choice heuristic out of enum (0x" + NumberToString(rectChoice, 16) + ')');
NazaraError("Rect choice heuristic out of enum ({0:#x})", UnderlyingCast(rectChoice));
return std::numeric_limits<int>::max();
}
}

View File

@ -46,7 +46,7 @@ namespace Nz
void FileImpl::Flush()
{
if (fsync(m_fileDescriptor) == -1)
NazaraError("Unable to flush file: " + Error::GetLastSystemError());
NazaraError("Unable to flush file: {0}", Error::GetLastSystemError());
}
UInt64 FileImpl::GetCursorPos() const
@ -81,7 +81,7 @@ namespace Nz
int fileDescriptor = Open_def(filePath.generic_u8string().data(), flags, permissions);
if (fileDescriptor == -1)
{
NazaraError("Failed to open \"" + filePath.generic_u8string() + "\" : " + Error::GetLastSystemError());
NazaraError("Failed to open \"{0}\": {1}", filePath, Error::GetLastSystemError());
return false;
}
@ -161,7 +161,7 @@ namespace Nz
break;
default:
NazaraInternalError("Cursor position not handled (0x" + NumberToString(UnderlyingCast(pos), 16) + ')');
NazaraInternalError("Cursor position not handled ({0:#x})", UnderlyingCast(pos));
return false;
}

View File

@ -202,7 +202,7 @@ namespace Nz
}
catch (utf8::exception& e)
{
NazaraError("UTF-8 error: " + std::string(e.what()));
NazaraError("UTF-8 error: {0}", e.what());
}
catch (std::exception& e)
{

View File

@ -0,0 +1,61 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/ToString.hpp>
#include <fmt/format.h>
#include <fmt/std.h>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
namespace Detail
{
std::string FormatFallback(std::string_view str)
{
return fmt::format(str);
}
std::string FormatFallback(std::string_view str, std::string_view param1)
{
return fmt::format(str, param1);
}
std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2)
{
return fmt::format(str, param1, param2);
}
std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2, std::string_view param3)
{
return fmt::format(str, param1, param2, param3);
}
std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2, std::string_view param3, std::string_view param4)
{
return fmt::format(str, param1, param2, param3, param4);
}
std::string FormatFallback(std::string_view str, std::string_view param1, std::string_view param2, std::string_view param3, std::string_view param4, std::string_view param5)
{
return fmt::format(str, param1, param2, param3, param4, param5);
}
}
std::string ToStringFormatter<std::filesystem::path>::Format(const std::filesystem::path& path)
{
return path.generic_u8string();
}
#define NAZARA_TO_STRING_FMT_SPEC(Type) \
std::string ToStringFormatter<Type>::Format(Type value) \
{ \
return fmt::format("{}", value); \
}
NAZARA_TO_STRING_FMT_SPEC(float);
NAZARA_TO_STRING_FMT_SPEC(double);
NAZARA_TO_STRING_FMT_SPEC(long double);
#undef NAZARA_TO_STRING_CPP_SPEC
}

View File

@ -43,7 +43,7 @@ namespace Nz
void FileImpl::Flush()
{
if (!FlushFileBuffers(m_handle))
NazaraError("Unable to flush file: " + Error::GetLastSystemError());
NazaraError("Unable to flush file: {0}", Error::GetLastSystemError());
}
UInt64 FileImpl::GetCursorPos() const
@ -153,7 +153,7 @@ namespace Nz
break;
default:
NazaraInternalError("Cursor position not handled (0x" + NumberToString(UnderlyingCast(pos), 16) + ')');
NazaraInternalError("Cursor position not handled ({0:#x})", UnderlyingCast(pos));
return false;
}
@ -177,13 +177,13 @@ namespace Nz
if (!SetCursorPos(CursorPosition::AtBegin, size))
{
NazaraError("Failed to set file size: failed to move cursor position: " + Error::GetLastSystemError());
NazaraError("failed to set file size: failed to move cursor position: {0}", Error::GetLastSystemError());
return false;
}
if (!SetEndOfFile(m_handle))
{
NazaraError("Failed to set file size: " + Error::GetLastSystemError());
NazaraError("failed to set file size: {0}", Error::GetLastSystemError());
return false;
}

View File

@ -51,7 +51,7 @@ namespace Nz
}
catch (const std::exception& e)
{
NazaraError(std::string("Failed to instantiate texture: ") + e.what());
NazaraError("failed to instantiate texture: {0}", e.what());
return nullptr;
}
@ -62,7 +62,7 @@ namespace Nz
if (!newTexture->Copy(oldTexture, Boxui(0, 0, 0, oldSize.x, oldSize.y, oldSize.z)))
{
NazaraError("Failed to update texture");
NazaraError("failed to update texture");
return nullptr;
}
}

View File

@ -35,11 +35,7 @@ namespace Nz
if (textureProperty.type != textureData.imageType)
{
// TODO: Use EnumToString to show image type as string
NazaraError("unmatching texture type: material property is of type " +
std::to_string(UnderlyingCast(textureProperty.type)) +
" but shader sampler is of type " +
std::to_string(UnderlyingCast(textureData.imageType)));
NazaraError("unmatching texture type: material property is of type {0} but shader sampler is of type {1}", UnderlyingCast(textureProperty.type), UnderlyingCast(textureData.imageType));
return;
}
@ -54,7 +50,7 @@ namespace Nz
m_optionHash = optionData->hash;
}
else
NazaraError("option " + m_optionName + " is not a boolean option (got " + ToString(optionData->type) + ")");
NazaraError("option {0} is not a boolean option (got {1})", m_optionName, nzsl::Ast::ToString(optionData->type));
}
}

View File

@ -66,14 +66,14 @@ namespace Nz
const auto& arrayType = std::get<nzsl::Ast::ArrayType>(*varType);
const auto& innerType = arrayType.containedType->type;
if (!IsSamplerType(innerType))
throw std::runtime_error("unexpected type " + ToString(innerType) + " in array " + ToString(arrayType));
throw std::runtime_error("unexpected type " + nzsl::Ast::ToString(innerType) + " in array " + nzsl::Ast::ToString(arrayType));
arraySize = arrayType.length;
bindingType = ShaderBindingType::Sampler;
varType = &innerType;
}
else
throw std::runtime_error("unexpected type " + ToString(varType));
throw std::runtime_error("unexpected type " + nzsl::Ast::ToString(varType));
// TODO: Get more precise shader stage type
m_pipelineLayoutInfo.bindings.push_back({

View File

@ -35,7 +35,7 @@ namespace Nz
nzsl::Ast::ModulePtr newShaderModule = resolver->Resolve(name);
if (!newShaderModule)
{
NazaraError("failed to retrieve updated shader module " + name);
NazaraError("failed to retrieve updated shader module {0}", name);
return;
}
@ -45,7 +45,7 @@ namespace Nz
}
catch (const std::exception& e)
{
NazaraError("failed to retrieve updated shader module " + name + ": " + e.what());
NazaraError("failed to retrieve updated shader module {0}: {1}", name, e.what());
return;
}

View File

@ -101,7 +101,7 @@ namespace Nz
return std::make_shared<JoltSphereCollider3D>(primitive.sphere.size);
}
NazaraError("Primitive type not handled (0x" + NumberToString(UnderlyingCast(primitive.type), 16) + ')');
NazaraError("Primitive type not handled ({0:#x})", UnderlyingCast(primitive.type));
return std::shared_ptr<JoltCollider3D>();
}

View File

@ -179,7 +179,7 @@ namespace Nz
{
SocketError errorCode;
if (!SocketImpl::SetBlocking(m_handle, m_isBlockingEnabled, &errorCode))
NazaraWarning("Failed to set socket blocking mode (0x" + NumberToString(UnderlyingCast(errorCode), 16) + ')');
NazaraWarning("failed to set socket blocking mode ({0:#x})", UnderlyingCast(errorCode));
}
/*!
@ -201,7 +201,7 @@ namespace Nz
{
SocketImpl::Close(handle);
NazaraError("Failed to open a dual-stack socket: " + std::string(ErrorToString(m_lastError)));
NazaraError("failed to open a dual-stack socket: {0}", std::string(ErrorToString(m_lastError)));
return false;
}

View File

@ -39,7 +39,7 @@ namespace Nz
if (!m_library.IsLoaded())
{
NazaraError("failed to load libcurl: " + m_library.GetLastError());
NazaraError("failed to load libcurl: {0}", m_library.GetLastError());
return false;
}

View File

@ -96,7 +96,7 @@ namespace Nz
if (peerId >= m_peers.size())
{
NazaraError("Insufficient peers");
NazaraError("insufficient peers");
return nullptr;
}
@ -168,7 +168,7 @@ namespace Nz
if (peerCount > ENetConstants::ENetProtocol_MaximumPeerId)
{
NazaraError("Peer count exceeds maximum peer count supported by protocol (" + NumberToString(ENetConstants::ENetProtocol_MaximumPeerId) + ")");
NazaraError("peer count exceeds maximum peer count supported by protocol ({0})", UnderlyingCast(ENetConstants::ENetProtocol_MaximumPeerId));
return false;
}
@ -338,7 +338,7 @@ namespace Nz
{
if (m_socket.Bind(address) != SocketState::Bound)
{
NazaraError("Failed to bind address " + address.ToString());
NazaraError("failed to bind address {0}", address.ToString());
return false;
}
}

View File

@ -94,7 +94,7 @@ namespace Nz
return m_ipv6 == LoopbackIpV6.m_ipv6; // Only compare the ip value
}
NazaraInternalError("Invalid protocol for IpAddress (0x" + NumberToString(UnderlyingCast(m_protocol), 16) + ')');
NazaraInternalError("Invalid protocol for IpAddress ({0:#x})", UnderlyingCast(m_protocol));
return false;
}

View File

@ -61,7 +61,7 @@ namespace Nz
if (epoll_ctl(m_handle, EPOLL_CTL_ADD, socket, &entry) != 0)
{
NazaraError("Failed to add socket to epoll structure (errno " + NumberToString(errno) + ": " + Error::GetLastSystemError() + ')');
NazaraError("failed to add socket to epoll structure (errno {0}: {1})", errno, Error::GetLastSystemError());
return false;
}

View File

@ -178,7 +178,7 @@ namespace Nz
}
default:
NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(UnderlyingCast(ipAddress.GetProtocol()), 16) + ')');
NazaraInternalError("Unhandled ip protocol ({0:#x})", UnderlyingCast(ipAddress.GetProtocol()));
break;
}
}

View File

@ -198,7 +198,7 @@ namespace Nz
if (waitError != SocketError::NoError)
{
if (waitError != SocketError::Interrupted) //< Do not log interrupted error
NazaraError("SocketPoller encountered an error (code: 0x" + NumberToString(UnderlyingCast(waitError), 16) + "): " + ErrorToString(waitError));
NazaraError("SocketPoller encountered an error (code: {0:#x}): {1}", UnderlyingCast(waitError), ErrorToString(waitError));
return 0;
}

View File

@ -187,7 +187,7 @@ namespace Nz
break;
}
NazaraInternalError("Unexpected socket state (0x" + NumberToString(UnderlyingCast(m_state), 16) + ')');
NazaraInternalError("Unexpected socket state ({0:#x})", UnderlyingCast(m_state));
return m_state;
}
@ -479,7 +479,7 @@ namespace Nz
break;
}
NazaraInternalError("Unhandled socket state (0x" + NumberToString(UnderlyingCast(m_state), 16) + ')');
NazaraInternalError("Unhandled socket state ({0:#x})", UnderlyingCast(m_state));
return m_state;
}
@ -516,10 +516,10 @@ namespace Nz
SocketError errorCode;
if (!SocketImpl::SetNoDelay(m_handle, m_isLowDelayEnabled, &errorCode))
NazaraWarning("Failed to set socket no delay mode (0x" + NumberToString(UnderlyingCast(errorCode), 16) + ')');
NazaraWarning("failed to set socket no delay mode ({0:#x})", UnderlyingCast(errorCode));
if (!SocketImpl::SetKeepAlive(m_handle, m_isKeepAliveEnabled, m_keepAliveTime, m_keepAliveInterval, &errorCode))
NazaraWarning("Failed to set socket keep alive mode (0x" + NumberToString(UnderlyingCast(errorCode), 16) + ')');
NazaraWarning("failed to set socket keep alive mode ({0:#x})", UnderlyingCast(errorCode));
m_peerAddress = IpAddress::Invalid;
m_openMode = OpenMode_ReadWrite;

View File

@ -160,7 +160,7 @@ namespace Nz
int errorCode = WSAStartup(MAKEWORD(2, 2), &s_WSA);
if (errorCode != 0)
{
NazaraError("Failed to initialize Windows Socket 2.2: " + Error::GetLastSystemError(errorCode));
NazaraError("failed to initialize Windows Socket 2.2: {0}", Error::GetLastSystemError(errorCode));
return false;
}

View File

@ -91,7 +91,7 @@ namespace Nz
fd_set& targetSet = (i == 0) ? m_readSockets : m_writeSockets;
if (targetSet.fd_count > FD_SETSIZE)
{
NazaraError("Socket count exceeding hard-coded FD_SETSIZE (" + NumberToString(FD_SETSIZE) + ")");
NazaraError("Socket count exceeding hard-coded FD_SETSIZE ({0})", FD_SETSIZE);
return false;
}

View File

@ -369,13 +369,13 @@ namespace Nz::GL
// Validate framebuffer completeness
if (GLenum checkResult = m_blitFramebuffers->drawFBO.Check(); checkResult != GL_FRAMEBUFFER_COMPLETE)
{
NazaraError("Blit draw FBO is incomplete: " + TranslateOpenGLError(checkResult));
NazaraError("Blit draw FBO is incomplete: {0}", TranslateOpenGLError(checkResult));
return false;
}
if (GLenum checkResult = m_blitFramebuffers->readFBO.Check(); checkResult != GL_FRAMEBUFFER_COMPLETE)
{
NazaraError("Blit read FBO is incomplete: " + TranslateOpenGLError(checkResult));
NazaraError("Blit read FBO is incomplete: {0}", TranslateOpenGLError(checkResult));
return false;
}
@ -707,7 +707,7 @@ namespace Nz::GL
{
hasAnyError = true;
NazaraError("OpenGL error: " + TranslateOpenGLError(lastError));
NazaraError("OpenGL error: {0}", TranslateOpenGLError(lastError));
}
m_didCollectErrors = true;

View File

@ -166,7 +166,7 @@ namespace Nz::GL
EGLint numConfig = 0;
if (m_loader.eglChooseConfig(m_display, configAttributes, configs, EGLint(maxConfigCount), &numConfig) != GL_TRUE)
{
NazaraError(std::string("failed to retrieve compatible EGL configurations: ") + EGLLoader::TranslateError(m_loader.eglGetError()));
NazaraError("failed to retrieve compatible EGL configurations: {0}", EGLLoader::TranslateError(m_loader.eglGetError()));
return false;
}
@ -267,7 +267,7 @@ namespace Nz::GL
if (!m_handle)
{
NazaraError(std::string("failed to create EGL context: ") + EGLLoader::TranslateError(m_loader.eglGetError()));
NazaraError("failed to create EGL context: {0}", EGLLoader::TranslateError(m_loader.eglGetError()));
return false;
}

View File

@ -25,7 +25,7 @@ namespace Nz::GL
HWNDHandle window(::CreateWindowA("STATIC", nullptr, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, GetModuleHandle(nullptr), nullptr));
if (!window)
{
NazaraError("failed to create dummy window: " + Error::GetLastSystemError());
NazaraError("failed to create dummy window: {0}", Error::GetLastSystemError());
return false;
}
@ -34,7 +34,7 @@ namespace Nz::GL
m_deviceContext = ::GetDC(window.get());
if (!m_deviceContext)
{
NazaraError("failed to retrieve dummy window device context: " + Error::GetLastSystemError());
NazaraError("failed to retrieve dummy window device context: {0}", Error::GetLastSystemError());
return false;
}
@ -54,7 +54,7 @@ namespace Nz::GL
m_deviceContext = ::GetDC(static_cast<HWND>(window.windows.window));
if (!m_deviceContext)
{
NazaraError("failed to retrieve window device context: " + Error::GetLastSystemError());
NazaraError("failed to retrieve window device context: {0}", Error::GetLastSystemError());
return false;
}
@ -208,7 +208,7 @@ namespace Nz::GL
if (!m_handle)
{
NazaraError("failed to create WGL context: " + Error::GetLastSystemError());
NazaraError("failed to create WGL context: {0}", Error::GetLastSystemError());
return false;
}
}
@ -217,7 +217,7 @@ namespace Nz::GL
m_handle = m_loader.wglCreateContext(m_deviceContext);
if (!m_handle)
{
NazaraError("failed to create WGL context: " + Error::GetLastSystemError());
NazaraError("failed to create WGL context: {0}", Error::GetLastSystemError());
return false;
}
@ -225,7 +225,7 @@ namespace Nz::GL
{
if (!m_loader.wglShareLists(shareContext->m_handle, m_handle))
{
NazaraError("failed to share context objects: " + Error::GetLastSystemError());
NazaraError("failed to share context objects: {0}", Error::GetLastSystemError());
return false;
}
}
@ -268,7 +268,7 @@ namespace Nz::GL
bool succeeded = m_loader.wglMakeCurrent(m_deviceContext, m_handle);
if (!succeeded)
{
NazaraError("failed to activate context: " + Error::GetLastSystemError());
NazaraError("failed to activate context: {0}", Error::GetLastSystemError());
return false;
}
@ -389,14 +389,14 @@ namespace Nz::GL
pixelFormat = m_loader.ChoosePixelFormat(m_deviceContext, &descriptor);
if (pixelFormat == 0)
{
NazaraError("Failed to choose pixel format: " + Error::GetLastSystemError());
NazaraError("failed to choose pixel format: {0}", Error::GetLastSystemError());
return false;
}
}
if (!m_loader.SetPixelFormat(m_deviceContext, pixelFormat, &descriptor))
{
NazaraError("Failed to choose pixel format: " + Error::GetLastSystemError());
NazaraError("failed to choose pixel format: {0}", Error::GetLastSystemError());
return false;
}

View File

@ -126,13 +126,13 @@ namespace Nz::GL
}
else
{
NazaraError(std::string("failed to create WebGL context: OpenGL is not supported"));
NazaraError("failed to create WebGL context: OpenGL is not supported");
return false;
}
if (m_handle <= 0)
{
NazaraError(std::string("failed to create Web context: ") + WebLoader::TranslateError(static_cast<EMSCRIPTEN_RESULT>(m_handle)));
NazaraError("failed to create Web context: {0}", WebLoader::TranslateError(static_cast<EMSCRIPTEN_RESULT>(m_handle)));
return false;
}

View File

@ -14,7 +14,7 @@ namespace Nz::GL
HWNDHandle window(::CreateWindowA("STATIC", nullptr, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, GetModuleHandle(nullptr), nullptr));
if (!window)
{
NazaraError("failed to create dummy window: " + Error::GetLastSystemError());
NazaraError("failed to create dummy window: {0}", Error::GetLastSystemError());
return false;
}
@ -47,7 +47,7 @@ namespace Nz::GL
/*HDC deviceContext = ::GetDC(windowHandle);
if (!deviceContext)
{
NazaraError("failed to retrieve window device context: " + Error::GetLastSystemError());
NazaraError("failed to retrieve window device context: {0}", Error::GetLastSystemError());
return false;
}

View File

@ -13,13 +13,13 @@ namespace Nz
Cursor::Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
Create(cursor, hotSpot, placeholder);
}
Cursor::Cursor(SystemCursor systemCursor)
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
Create(systemCursor);
}

View File

@ -12,7 +12,7 @@ namespace Nz
Icon::Icon(const Image& icon)
{
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
Create(icon);
}

View File

@ -55,7 +55,7 @@ namespace Nz
);
if (!m_surface)
NazaraError("failed to create SDL Surface for cursor: " + std::string(SDL_GetError()));
NazaraError("failed to create SDL Surface for cursor: {0}", std::string(SDL_GetError()));
m_cursor = SDL_CreateColorCursor(m_surface, hotSpot.x, hotSpot.y);
if (!m_cursor)
@ -63,7 +63,7 @@ namespace Nz
if (m_surface) //< Just in case exceptions were disabled
SDL_FreeSurface(m_surface);
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
NazaraError("failed to create SDL cursor: {0}", std::string(SDL_GetError()));
}
}
@ -77,7 +77,7 @@ namespace Nz
{
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
if (!m_cursor)
NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError()));
NazaraError("failed to create SDL cursor: {0}", std::string(SDL_GetError()));
}
}

View File

@ -28,7 +28,7 @@ namespace Nz
);
if (!m_icon)
NazaraError("failed to create SDL Surface for icon: " + std::string(SDL_GetError()));
NazaraError("failed to create SDL Surface for icon: {0}", std::string(SDL_GetError()));
}
IconImpl::~IconImpl()

View File

@ -91,7 +91,7 @@ namespace Nz
m_handle = SDL_CreateWindow(title.c_str(), x, y, width, height, winStyle);
if (!m_handle)
{
NazaraError("Failed to create window: " + Error::GetLastSystemError());
NazaraError("failed to create window: {0}", Error::GetLastSystemError());
return false;
}
@ -212,8 +212,8 @@ namespace Nz
if (SDL_GetWindowWMInfo(m_handle, &wmInfo) != SDL_TRUE)
{
#ifndef NAZARA_PLATFORM_WEB
ErrorFlags flags(ErrorMode::ThrowException, true);
NazaraError(std::string("failed to retrieve window manager info: ") + SDL_GetError());
ErrorFlags flags(ErrorMode::ThrowException);
NazaraError("failed to retrieve window manager info: {0}", SDL_GetError());
#endif
}
@ -261,7 +261,7 @@ namespace Nz
#if defined(NAZARA_PLATFORM_WEB)
handle.type = WindowBackend::Web;
#else
ErrorFlags flags(ErrorMode::ThrowException, true);
ErrorFlags flags(ErrorMode::ThrowException);
NazaraError("unhandled window subsystem");
#endif
}

View File

@ -16,7 +16,7 @@ namespace Nz
File file(sourcePath);
if (!file.Open(OpenMode::ReadOnly | OpenMode::Text))
{
NazaraError("Failed to open \"" + sourcePath.generic_u8string() + '"');
NazaraError("Failed to open \"{0}\"", sourcePath);
return {};
}

View File

@ -235,7 +235,7 @@ namespace Nz
if (auto it = renderAPIStr.find(value); it != renderAPIStr.end())
preferredAPI = it->second;
else
NazaraError("unknown render API \"" + std::string(value) + "\"");
NazaraError("unknown render API \"{0}\"", value);
}
if (parameters.GetParameter("render-api-validation", &value))
@ -251,7 +251,7 @@ namespace Nz
if (auto it = validationStr.find(value); it != validationStr.end())
validationLevel = it->second;
else
NazaraError("unknown validation level \"" + std::string(value) + "\"");
NazaraError("unknown validation level \"{0}\"", value);
}
}
}

View File

@ -68,7 +68,7 @@ namespace Nz
auto it = m_impl->sequenceMap.find(sequence.name);
if (it != m_impl->sequenceMap.end())
{
NazaraError("Sequence name \"" + sequence.name + "\" is already in use");
NazaraError("sequence name \"{0}\" is already in use", sequence.name);
return false;
}
#endif

View File

@ -29,7 +29,7 @@ namespace Nz
std::size_t jointIndex = skeletonComponent->FindJointByName(jointName);
if (jointIndex == Skeleton::InvalidJointIndex)
{
NazaraError("skeleton has no joint \"" + jointName + "\"");
NazaraError("skeleton has no joint \"{0}\"", jointName);
return;
}

View File

@ -83,7 +83,7 @@ namespace Nz
if (byteStream.Read(ptr, byteCount) != byteCount)
{
NazaraError("Failed to read level #" + NumberToString(i));
NazaraError("failed to read level #{0}", NumberToString(i));
return Nz::Err(ResourceLoadingError::DecodingError);
}
@ -234,14 +234,14 @@ namespace Nz
buf[3] = (header.format.fourCC >> 24) & 255;
buf[4] = '\0';
NazaraError("Unhandled format \"" + std::string(buf) + "\"");
NazaraError("unhandled format \"{0}\"", buf);
return false;
}
}
}
else
{
NazaraError("Invalid DDS file");
NazaraError("invalid DDS file");
return false;
}

View File

@ -320,7 +320,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("Failed to open stream from file: " + Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
return false;
}
m_ownedStream = std::move(file);

View File

@ -339,7 +339,7 @@ namespace Nz
}
else if (!hasGlobalColorTable)
{
NazaraError("corrupt gif (no color table for image #" + std::to_string(m_frames.size() - 1) + ")");
NazaraError("corrupt gif (no color table for image #{0}", m_frames.size() - 1);
return Err(ResourceLoadingError::DecodingError);
}
@ -347,7 +347,7 @@ namespace Nz
m_byteStream >> minimumCodeSize;
if (minimumCodeSize > 12)
{
NazaraError("unexpected LZW Minimum Code Size (" + std::to_string(minimumCodeSize) + ")");
NazaraError("unexpected LZW Minimum Code Size ({0})", minimumCodeSize);
return Err(ResourceLoadingError::DecodingError);
}
@ -410,7 +410,7 @@ namespace Nz
break;
default:
NazaraWarning("unrecognized extension label (unknown tag 0x" + NumberToString(label, 16) + ")");
NazaraWarning("unrecognized extension label (unknown tag {0:#x})", label);
break;
}
@ -419,7 +419,7 @@ namespace Nz
}
default:
NazaraError("corrupt gif (unknown tag 0x" + NumberToString(tag, 16) + ")");
NazaraError("corrupt gif (unknown tag {0:#x})", tag);
return Err(ResourceLoadingError::DecodingError);
}
}
@ -450,7 +450,7 @@ namespace Nz
std::unique_ptr<File> file = std::make_unique<File>();
if (!file->Open(filePath, OpenMode::ReadOnly))
{
NazaraError("Failed to open stream from file: " + Error::GetLastError());
NazaraError("failed to open stream from file: {0}", Error::GetLastError());
return false;
}
m_ownedStream = std::move(file);

View File

@ -208,26 +208,26 @@ namespace Nz
std::size_t frameCount = m_frames.size();
if (frameCount == 0)
{
NazaraError("Frame count is invalid or missing");
NazaraError("frame count is invalid or missing");
return false;
}
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
NazaraError("Joint count is invalid or missing");
NazaraError("joint count is invalid or missing");
return false;
}
if (m_frameIndex != frameCount)
{
NazaraError("Missing frame infos: [" + NumberToString(m_frameIndex) + ',' + NumberToString(frameCount) + ']');
NazaraError("missing frame infos: [{0},{1}]", m_frameIndex, frameCount);
return false;
}
if (m_frameRate == 0)
{
NazaraWarning("Framerate is either invalid or missing, assuming a default value of 24");
NazaraWarning("framerate is either invalid or missing, assuming a default value of 24");
m_frameRate = 24;
}
@ -264,7 +264,7 @@ namespace Nz
void MD5AnimParser::Error(const std::string& message)
{
NazaraError(message + " at line #" + NumberToString(m_lineCount));
NazaraError("{0} at line #{1}", message, m_lineCount);
}
bool MD5AnimParser::ParseBaseframe()

View File

@ -211,7 +211,7 @@ namespace Nz
void MD5MeshParser::Error(const std::string& message)
{
NazaraError(message + " at line #" + std::to_string(m_lineCount));
NazaraError("{0} at line #1", message, m_lineCount);
}
bool MD5MeshParser::ParseJoints()

Some files were not shown because too many files have changed in this diff Show More