Use fmt store instead of ToString fallback

Thanks to @jonathanpoelen for the idea
This commit is contained in:
SirLynix
2023-08-14 23:47:00 +02:00
committed by Jérôme Leclercq
parent a741672a51
commit ab8bac2575
10 changed files with 118 additions and 243 deletions

View File

@@ -0,0 +1,53 @@
// 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/Format.hpp>
#include <fmt/args.h>
#include <fmt/format.h>
#include <fmt/std.h>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
namespace Detail
{
thread_local fmt::dynamic_format_arg_store<fmt::format_context> s_formatStore;
void ClearFormatStore()
{
s_formatStore.clear();
}
std::string FormatFromStore(std::string_view str)
{
return fmt::vformat(str, s_formatStore);
}
#define NAZARA_FORMAT_IMPLEM(Type) \
template<> NAZARA_CORE_API void PushFormatArgImpl(Type const& value) \
{ \
s_formatStore.push_back(value); \
}
NAZARA_FORMAT_IMPLEM(std::filesystem::path);
NAZARA_FORMAT_IMPLEM(std::string);
NAZARA_FORMAT_IMPLEM(std::string_view);
NAZARA_FORMAT_IMPLEM(const char*);
NAZARA_FORMAT_IMPLEM(short);
NAZARA_FORMAT_IMPLEM(int);
NAZARA_FORMAT_IMPLEM(long);
NAZARA_FORMAT_IMPLEM(long long);
NAZARA_FORMAT_IMPLEM(unsigned short);
NAZARA_FORMAT_IMPLEM(unsigned int);
NAZARA_FORMAT_IMPLEM(unsigned long);
NAZARA_FORMAT_IMPLEM(unsigned long long);
NAZARA_FORMAT_IMPLEM(float);
NAZARA_FORMAT_IMPLEM(double);
NAZARA_FORMAT_IMPLEM(long double);
#undef NAZARA_FORMAT_IMPLEM
}
#undef NAZARA_TO_STRING_CPP_SPEC
}

View File

@@ -1,61 +0,0 @@
// 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

@@ -495,7 +495,6 @@ namespace Nz
bool VulkanSwapchain::SetupRenderPass()
{
NazaraError("Test");
std::optional<PixelFormat> colorFormat = FromVulkan(m_surfaceFormat.format);
if (!colorFormat)
{