Switch Nazara to C++20

This commit is contained in:
Lynix 2023-11-14 14:24:28 +01:00
parent 35b4da0d4b
commit e5789d1749
17 changed files with 51 additions and 57 deletions

View File

@ -40,7 +40,7 @@ namespace Nz
static void SetLogger(AbstractLogger* logger);
static void Write(std::string_view str);
template<typename... Args> static void Write(std::string_view str, Args&&... args);
template<typename... Args> static void Write(FormatString<Args...> fmt, 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, std::string_view /*string*/);

View File

@ -8,9 +8,9 @@
namespace Nz
{
template<typename... Args>
void Log::Write(std::string_view str, Args&&... args)
void Log::Write(FormatString<Args...> fmt, Args&&... args)
{
return Write(Format(str, std::forward<Args>(args)...));
return Write(Format(fmt, std::forward<Args>(args)...));
}
}

View File

@ -89,7 +89,7 @@ namespace Nz
}
else
{
File file(filePath.generic_u8string());
File file(filePath);
if (!file.Open(OpenMode::WriteOnly | OpenMode::Truncate))
{

View File

@ -30,7 +30,7 @@ namespace Nz
if constexpr (std::is_same_v<std::filesystem::path::value_type, wchar_t>)
m_handle = LoadLibraryExW(libraryPath.c_str(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0);
else
m_handle = LoadLibraryExW(ToWideString(libraryPath.generic_u8string()).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0);
m_handle = LoadLibraryExW(ToWideString(PathToString(libraryPath)).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0);
if (m_handle)
return true;

View File

@ -92,7 +92,7 @@ namespace Nz
if constexpr (std::is_same_v<std::filesystem::path::value_type, wchar_t>)
m_handle = CreateFileW(filePath.c_str(), access, shareMode, nullptr, openMode, 0, nullptr);
else
m_handle = CreateFileW(ToWideString(filePath.generic_u8string()).data(), access, shareMode, nullptr, openMode, 0, nullptr);
m_handle = CreateFileW(ToWideString(PathToString(filePath)).data(), access, shareMode, nullptr, openMode, 0, nullptr);
return m_handle != INVALID_HANDLE_VALUE;
}

View File

@ -174,13 +174,13 @@ namespace Nz
// The default police can make live one hardware atlas after the free of a module (which could be problematic)
// So, if the default police use a hardware atlas, we stole it.
// I don't like this solution, but I don't have any better
if (!defaultAtlas.unique())
if (defaultAtlas.use_count() > 1)
{
// Still at least one police use the atlas
// At least one police use the atlas
const std::shared_ptr<Font>& defaultFont = Font::GetDefault();
defaultFont->SetAtlas(nullptr);
if (!defaultAtlas.unique())
if (!defaultAtlas.use_count() > 1)
{
// Still not the only one to own it ? Then crap.
NazaraWarning("Default font atlas uses hardware storage and is still used");

View File

@ -167,19 +167,17 @@ namespace Nz
for (auto&& rendererImpl : implementations)
{
#ifndef NAZARA_RENDERER_EMBEDDEDBACKENDS
std::string fileNameStr = rendererImpl.fileName.generic_u8string();
DynLib implLib;
if (!implLib.Load(rendererImpl.fileName))
{
NazaraWarning("Failed to load " + fileNameStr + ": " + implLib.GetLastError());
NazaraWarningFmt("Failed to load {0}: {1}", rendererImpl.fileName, implLib.GetLastError());
continue;
}
CreateRendererImplFunc createRenderer = reinterpret_cast<CreateRendererImplFunc>(implLib.GetSymbol("NazaraRenderer_Instantiate"));
if (!createRenderer)
{
NazaraDebug("Skipped " + fileNameStr + " (symbol not found)");
NazaraDebug("Skipped {0} (NazaraRenderer_Instantiate symbol not found)", rendererImpl.fileName);
continue;
}
@ -194,7 +192,7 @@ namespace Nz
}
#ifndef NAZARA_RENDERER_EMBEDDEDBACKENDS
NazaraDebug("Loaded " + fileNameStr);
NazaraDebug("Loaded {0}", rendererImpl.fileName);
chosenLib = std::move(implLib);
#endif

View File

@ -89,7 +89,7 @@ namespace Nz
std::shared_ptr<Texture> texture = params.renderDevice->InstantiateTexture(texParams, image.GetConstPixels(), params.buildMipmaps);
texture->SetFilePath(image.GetFilePath());
if (std::string debugName = texture->GetFilePath().generic_u8string(); !debugName.empty())
if (std::string debugName = PathToString(texture->GetFilePath()); !debugName.empty())
texture->UpdateDebugName(debugName);
return texture;

View File

@ -22,7 +22,7 @@ namespace Nz
bool FontParams::IsValid() const
{
return true; // Rien à tester
return true; // Nothing to test
}
Font::Font() :
@ -37,29 +37,25 @@ namespace Nz
OnFontRelease(this);
Destroy();
SetAtlas({}); // On libère l'atlas proprement
SetAtlas({}); // Reset our atlas
}
void Font::ClearGlyphCache()
{
if (m_atlas)
{
if (m_atlas.unique())
m_atlas->Clear(); // Appellera OnAtlasCleared
if (m_atlas.use_count() == 1)
m_atlas->Clear(); // Will call OnAtlasCleared
else
{
// Au moins une autre police utilise cet atlas, on vire nos glyphes un par un
for (auto mapIt = m_glyphes.begin(); mapIt != m_glyphes.end(); ++mapIt)
// At least one font is using this atlas, remove our glyphes
for (auto&& [_, glyphMap] : m_glyphes)
{
GlyphMap& glyphMap = mapIt->second;
for (auto glyphIt = glyphMap.begin(); glyphIt != glyphMap.end(); ++glyphIt)
{
Glyph& glyph = glyphIt->second;
for (auto&& [_, glyph] : glyphMap)
m_atlas->Free(&glyph.atlasRect, &glyph.layerIndex, 1);
}
}
// Destruction des glyphes mémorisés et notification
// Free all cached glyphes
m_glyphes.clear();
OnFontGlyphCacheCleared(this);

View File

@ -89,7 +89,7 @@ namespace Nz
stream.Read(skin, 68*sizeof(char));
ParameterList matData;
matData.SetParameter(MaterialData::BaseColorTexturePath, (baseDir / skin).generic_u8string());
matData.SetParameter(MaterialData::BaseColorTexturePath, PathToString(baseDir / skin));
mesh->SetMaterialData(i, std::move(matData));
}

View File

@ -50,7 +50,7 @@ namespace Nz
sequence.firstFrame = 0;
sequence.frameCount = frameCount;
sequence.frameRate = frameRate;
sequence.name = stream.GetPath().filename().generic_u8string();
sequence.name = PathToString(stream.GetPath().filename());
animation->AddSequence(sequence);

View File

@ -212,7 +212,7 @@ namespace Nz
// Material
ParameterList matData;
matData.SetParameter(MaterialData::BaseColorTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
matData.SetParameter(MaterialData::BaseColorTexturePath, PathToString(baseDir / md5Mesh.shader));
mesh->SetMaterialData(i, std::move(matData));
@ -338,7 +338,7 @@ namespace Nz
// Material
ParameterList matData;
matData.SetParameter(MaterialData::BaseColorTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
matData.SetParameter(MaterialData::BaseColorTexturePath, PathToString(baseDir / md5Mesh.shader));
mesh->SetMaterialData(i, std::move(matData));
}

View File

@ -80,7 +80,7 @@ namespace Nz
if (!fullPath.is_absolute())
fullPath = baseDir / fullPath;
data.SetParameter(MaterialData::AlphaTexturePath, fullPath.generic_u8string());
data.SetParameter(MaterialData::AlphaTexturePath, PathToString(fullPath));
}
if (!mtlMat->diffuseMap.empty())
@ -89,7 +89,7 @@ namespace Nz
if (!fullPath.is_absolute())
fullPath = baseDir / fullPath;
data.SetParameter(MaterialData::BaseColorTexturePath, fullPath.generic_u8string());
data.SetParameter(MaterialData::BaseColorTexturePath, PathToString(fullPath));
}
if (!mtlMat->emissiveMap.empty())
@ -98,7 +98,7 @@ namespace Nz
if (!fullPath.is_absolute())
fullPath = baseDir / fullPath;
data.SetParameter(MaterialData::EmissiveTexturePath, fullPath.generic_u8string());
data.SetParameter(MaterialData::EmissiveTexturePath, PathToString(fullPath));
}
if (!mtlMat->normalMap.empty())
@ -107,7 +107,7 @@ namespace Nz
if (!fullPath.is_absolute())
fullPath = baseDir / fullPath;
data.SetParameter(MaterialData::NormalTexturePath, fullPath.generic_u8string());
data.SetParameter(MaterialData::NormalTexturePath, PathToString(fullPath));
}
if (!mtlMat->specularMap.empty())
@ -116,7 +116,7 @@ namespace Nz
if (!fullPath.is_absolute())
fullPath = baseDir / fullPath;
data.SetParameter(MaterialData::SpecularTexturePath, fullPath.generic_u8string());
data.SetParameter(MaterialData::SpecularTexturePath, PathToString(fullPath));
}
// If we either have an alpha value or an alpha map, let's configure the material for transparency

View File

@ -508,7 +508,7 @@ namespace Nz
if (!m_mtlLib.empty())
{
Emit("mtllib ");
EmitLine(m_mtlLib.generic_u8string());
EmitLine(PathToString(m_mtlLib));
EmitLine();
}

View File

@ -401,7 +401,7 @@ int main()
/*
Note: En C++11 il est possible d'insérer de l'Unicode de façon standard, quel que soit l'encodage du fichier,
via quelque chose de similaire à u8"Cha\u00CEne de caract\u00E8res".
via quelque chose de similaire à "Cha\u00CEne de caract\u00E8res".
Cependant, si le code source est encodé en UTF-8 (Comme c'est le cas dans ce fichier),
cela fonctionnera aussi comme ceci : "Chaîne de caractères".
*/

View File

@ -4,7 +4,7 @@
SCENARIO("String", "[CORE][STRING]")
{
std::string unicodeString(u8"\u00E0\u00E9\u00E7\u0153\u00C2\u5B98\u46E1");
std::string unicodeString("\u00E0\u00E9\u00E7\u0153\u00C2\u5B98\u46E1");
WHEN("Checking if string ends with")
{
@ -27,13 +27,13 @@ SCENARIO("String", "[CORE][STRING]")
CHECK_FALSE(Nz::EndsWith("Nazara Engine", "Nazara", Nz::CaseIndependent{}));
CHECK_FALSE(Nz::EndsWith("Nazara Engine", "Sir Nazara van Engine", Nz::CaseIndependent{}));
CHECK(Nz::EndsWith(u8"L'\u00CEle de R\u00E9", u8"", Nz::UnicodeAware{}));
CHECK(Nz::EndsWith(u8"L'\u00CEle de R\u00E9", u8"R\u00E9", Nz::UnicodeAware{}));
CHECK_FALSE(Nz::EndsWith(u8"L'\u00CEle de R\u00E9", u8"Long long j\u00F4hnson", Nz::UnicodeAware{}));
CHECK(Nz::EndsWith("L'\u00CEle de R\u00E9", "", Nz::UnicodeAware{}));
CHECK(Nz::EndsWith("L'\u00CEle de R\u00E9", "R\u00E9", Nz::UnicodeAware{}));
CHECK_FALSE(Nz::EndsWith("L'\u00CEle de R\u00E9", "Long long j\u00F4hnson", Nz::UnicodeAware{}));
CHECK(Nz::EndsWith(u8"L'\u00CEle de R\u00E9", u8"", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK(Nz::EndsWith(u8"L'\u00CEle de R\u00E9", u8"R\u00C9", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK_FALSE(Nz::EndsWith(u8"L'\u00CEle de R\u00E9", u8"Long long j\u00F4hnson", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK(Nz::EndsWith("L'\u00CEle de R\u00E9", "", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK(Nz::EndsWith("L'\u00CEle de R\u00E9", "R\u00C9", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK_FALSE(Nz::EndsWith("L'\u00CEle de R\u00E9", "Long long j\u00F4hnson", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
}
WHEN("Converting string back and forth")
@ -47,11 +47,11 @@ SCENARIO("String", "[CORE][STRING]")
CHECK(Nz::GetWord({}, 0).empty());
CHECK(Nz::GetWord(" ", 0).empty());
std::string sentence = u8"\nSay hello\tto Nazara\u00A0Engine\n\t! "; //< \u00A0 is a No-Break Space
std::string sentence = "\nSay hello\tto Nazara\u00A0Engine\n\t! "; //< \u00A0 is a No-Break Space
CHECK(Nz::GetWord(sentence, 0) == "Say");
CHECK(Nz::GetWord(sentence, 1) == "hello");
CHECK(Nz::GetWord(sentence, 2) == "to");
CHECK(Nz::GetWord(sentence, 3) == u8"Nazara\u00A0Engine");
CHECK(Nz::GetWord(sentence, 3) == "Nazara\u00A0Engine");
CHECK(Nz::GetWord(sentence, 4) == "!");
CHECK(Nz::GetWord(sentence, 5).empty());
@ -124,21 +124,21 @@ SCENARIO("String", "[CORE][STRING]")
CHECK_FALSE(Nz::StartsWith("NAZARA Engine", "NavaRa", Nz::CaseIndependent{}));
CHECK_FALSE(Nz::StartsWith("NAZARA Engine", "Long long johnson", Nz::CaseIndependent{}));
CHECK(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"", Nz::UnicodeAware{}));
CHECK(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"L'\u00CEle", Nz::UnicodeAware{}));
CHECK_FALSE(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"Long long j\u00F4hnson", Nz::UnicodeAware{}));
CHECK(Nz::StartsWith("L'\u00CEle de R\u00E9", "", Nz::UnicodeAware{}));
CHECK(Nz::StartsWith("L'\u00CEle de R\u00E9", "L'\u00CEle", Nz::UnicodeAware{}));
CHECK_FALSE(Nz::StartsWith("L'\u00CEle de R\u00E9", "Long long j\u00F4hnson", Nz::UnicodeAware{}));
CHECK(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"l'\u00EEle", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK_FALSE(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"Long long j\u00F4hnson", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK(Nz::StartsWith("L'\u00CEle de R\u00E9", "", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK(Nz::StartsWith("L'\u00CEle de R\u00E9", "l'\u00EEle", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
CHECK_FALSE(Nz::StartsWith("L'\u00CEle de R\u00E9", "Long long j\u00F4hnson", Nz::CaseIndependent{}, Nz::UnicodeAware{}));
}
WHEN("Converting between lower and upper")
{
CHECK(Nz::ToLower("Nazara Engine") == "nazara engine");
CHECK(Nz::ToLower(u8"L'\u00CELE DE R\u00C9", Nz::UnicodeAware{}) == u8"l'\u00EEle de r\u00E9");
CHECK(Nz::ToLower("L'\u00CELE DE R\u00C9", Nz::UnicodeAware{}) == "l'\u00EEle de r\u00E9");
CHECK(Nz::ToUpper("Nazara Engine") == "NAZARA ENGINE");
CHECK(Nz::ToUpper(u8"l'\u00EEle de r\u00E9", Nz::UnicodeAware{}) == u8"L'\u00CELE DE R\u00C9");
CHECK(Nz::ToUpper("l'\u00EEle de r\u00E9", Nz::UnicodeAware{}) == "L'\u00CELE DE R\u00C9");
}
WHEN("Trimming strings")
@ -148,7 +148,7 @@ SCENARIO("String", "[CORE][STRING]")
CHECK(Nz::Trim("Nazara Engin", 'n', Nz::CaseIndependent{}) == "azara Engi");
CHECK(Nz::Trim(unicodeString, Nz::UnicodeAware{}) == unicodeString);
CHECK(Nz::Trim("\n\t" + unicodeString + "\t ", Nz::UnicodeAware{}) == unicodeString);
CHECK(Nz::Trim(unicodeString, U'\u46E1', Nz::UnicodeAware{}) == u8"\u00E0\u00E9\u00E7\u0153\u00C2\u5B98");
CHECK(Nz::Trim(unicodeString, U'\u46E1', Nz::UnicodeAware{}) == "\u00E0\u00E9\u00E7\u0153\u00C2\u5B98");
CHECK(Nz::Trim(unicodeString, Nz::Unicode::Category_Letter, Nz::UnicodeAware{}) == "");
}
}

View File

@ -378,8 +378,8 @@ set_defaultmode("debug")
add_includedirs("include")
add_sysincludedirs("thirdparty/include")
set_languages("c89", "cxx17")
set_encodings("utf-8")
set_languages("c89", "c++20")
set_rundir("./bin/$(plat)_$(arch)_$(mode)")
set_targetdir("./bin/$(plat)_$(arch)_$(mode)")
set_warnings("allextra")