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

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