From dfe6b2ddcf0cfad52fd1298d372d50193af1e6d7 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Tue, 30 May 2023 12:32:37 +0200 Subject: [PATCH] Make use of the new EnumMap class --- include/Nazara/Audio/OpenALDevice.hpp | 7 +- include/Nazara/Audio/OpenALDevice.inl | 4 +- include/Nazara/Core/HardwareInfo.hpp | 3 +- include/Nazara/Core/HardwareInfo.inl | 2 +- include/Nazara/Graphics/Enums.hpp | 2 - include/Nazara/Graphics/Graphics.hpp | 4 +- include/Nazara/Graphics/Material.hpp | 2 +- include/Nazara/Graphics/Material.inl | 2 +- include/Nazara/Graphics/Sprite.hpp | 2 +- include/Nazara/Graphics/Sprite.inl | 18 ++-- include/Nazara/Math/Frustum.hpp | 5 +- include/Nazara/Math/Frustum.inl | 96 ++++++++++--------- include/Nazara/Math/OrientedBox.hpp | 3 +- include/Nazara/Math/OrientedBox.inl | 73 +++++--------- .../Nazara/OpenGLRenderer/Wrapper/Context.hpp | 7 +- .../Nazara/OpenGLRenderer/Wrapper/Context.inl | 2 +- include/Nazara/Platform/Cursor.hpp | 3 +- include/Nazara/Platform/Cursor.inl | 2 +- include/Nazara/Renderer/DebugDrawer.inl | 31 +++--- include/Nazara/Utility/PixelFormat.hpp | 7 +- include/Nazara/Utility/PixelFormat.inl | 24 ++--- include/Nazara/Utility/VertexDeclaration.hpp | 3 +- include/Nazara/Utility/VertexDeclaration.inl | 3 +- .../Nazara/VulkanRenderer/Wrapper/Device.hpp | 5 +- .../Nazara/VulkanRenderer/Wrapper/Device.inl | 2 +- src/Nazara/Audio/OpenALDevice.cpp | 18 ++-- src/Nazara/Core/AbstractLogger.cpp | 7 +- src/Nazara/Core/HardwareInfo.cpp | 91 +++++++++--------- src/Nazara/Core/StdLogger.cpp | 15 ++- src/Nazara/Graphics/Graphics.cpp | 18 ++-- src/Nazara/Graphics/LinearSlicedSprite.cpp | 2 +- src/Nazara/Graphics/Material.cpp | 14 +-- src/Nazara/Graphics/MaterialInstance.cpp | 2 +- src/Nazara/Graphics/SlicedSprite.cpp | 2 +- src/Nazara/Graphics/Sprite.cpp | 2 +- src/Nazara/Graphics/SubmeshRenderer.cpp | 6 +- src/Nazara/Graphics/Tilemap.cpp | 14 +-- src/Nazara/Network/Posix/SocketImpl.cpp | 15 ++- src/Nazara/Network/Win32/SocketImpl.cpp | 13 ++- src/Nazara/OpenGLRenderer/Wrapper/Context.cpp | 72 +++++++------- src/Nazara/Platform/Cursor.cpp | 8 +- src/Nazara/Platform/SDL2/CursorImpl.cpp | 8 +- src/Nazara/Renderer/Renderer.cpp | 5 +- src/Nazara/Utility/PixelFormat.cpp | 40 ++++---- src/Nazara/Utility/VertexDeclaration.cpp | 56 +++++------ src/Nazara/VulkanRenderer/Wrapper/Device.cpp | 13 ++- 46 files changed, 354 insertions(+), 379 deletions(-) diff --git a/include/Nazara/Audio/OpenALDevice.hpp b/include/Nazara/Audio/OpenALDevice.hpp index ab14769ac..7512f59e4 100644 --- a/include/Nazara/Audio/OpenALDevice.hpp +++ b/include/Nazara/Audio/OpenALDevice.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,6 @@ namespace Nz Max = SourceLatency }; - constexpr std::size_t OpenALExtensionCount = static_cast(OpenALExtension::Max) + 1; - class NAZARA_AUDIO_API OpenALDevice : public AudioDevice { friend OpenALLibrary; @@ -72,8 +71,8 @@ namespace Nz OpenALDevice& operator=(OpenALDevice&&) = delete; private: - std::array m_audioFormatValues; - std::array m_extensionStatus; + EnumMap m_audioFormatValues; + EnumMap m_extensionStatus; std::string m_renderer; std::string m_vendor; OpenALLibrary& m_library; diff --git a/include/Nazara/Audio/OpenALDevice.inl b/include/Nazara/Audio/OpenALDevice.inl index a8cd7c625..47f80b026 100644 --- a/include/Nazara/Audio/OpenALDevice.inl +++ b/include/Nazara/Audio/OpenALDevice.inl @@ -9,12 +9,12 @@ namespace Nz { inline bool OpenALDevice::IsExtensionSupported(OpenALExtension extension) const { - return m_extensionStatus[UnderlyingCast(extension)]; + return m_extensionStatus[extension]; } inline ALenum OpenALDevice::TranslateAudioFormat(AudioFormat format) const { - return m_audioFormatValues[UnderlyingCast(format)]; + return m_audioFormatValues[format]; } } diff --git a/include/Nazara/Core/HardwareInfo.hpp b/include/Nazara/Core/HardwareInfo.hpp index ccf87d2ea..9a56104ed 100644 --- a/include/Nazara/Core/HardwareInfo.hpp +++ b/include/Nazara/Core/HardwareInfo.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -41,8 +42,8 @@ namespace Nz void FetchCPUInfo(); void FetchMemoryInfo(); - std::array m_cpuCapabilities; std::array m_cpuBrandString; + EnumMap m_cpuCapabilities; ProcessorVendor m_cpuVendor; unsigned int m_cpuThreadCount; UInt64 m_systemTotalMemory; diff --git a/include/Nazara/Core/HardwareInfo.inl b/include/Nazara/Core/HardwareInfo.inl index 0042f06b1..a8885bc45 100644 --- a/include/Nazara/Core/HardwareInfo.inl +++ b/include/Nazara/Core/HardwareInfo.inl @@ -29,7 +29,7 @@ namespace Nz inline bool HardwareInfo::HasCapability(ProcessorCap capability) const { - return m_cpuCapabilities[UnderlyingCast(capability)]; + return m_cpuCapabilities[capability]; } } diff --git a/include/Nazara/Graphics/Enums.hpp b/include/Nazara/Graphics/Enums.hpp index e0cda00ce..3631357cd 100644 --- a/include/Nazara/Graphics/Enums.hpp +++ b/include/Nazara/Graphics/Enums.hpp @@ -102,8 +102,6 @@ namespace Nz Max = ViewerDataUbo }; - - constexpr std::size_t PredefinedShaderBindingCount = static_cast(EngineShaderBinding::Max) + 1; } #endif // NAZARA_GRAPHICS_ENUMS_HPP diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index fac0ed941..548671722 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -78,8 +78,8 @@ namespace Nz struct DefaultTextures { - std::array, ImageTypeCount> depthTextures; - std::array, ImageTypeCount> whiteTextures; + EnumMap> depthTextures; + EnumMap> whiteTextures; }; private: diff --git a/include/Nazara/Graphics/Material.hpp b/include/Nazara/Graphics/Material.hpp index 55bee0d62..dc4a28290 100644 --- a/include/Nazara/Graphics/Material.hpp +++ b/include/Nazara/Graphics/Material.hpp @@ -90,7 +90,6 @@ namespace Nz }; private: - std::array m_engineShaderBindings; std::shared_ptr m_renderPipelineLayout; std::unordered_map m_optionValues; std::unordered_map m_textureByTag; @@ -98,6 +97,7 @@ namespace Nz std::vector m_textures; std::vector m_uniformBlocks; mutable std::weak_ptr m_defaultInstance; + EnumMap m_engineShaderBindings; MaterialSettings m_settings; ShaderReflection m_reflection; }; diff --git a/include/Nazara/Graphics/Material.inl b/include/Nazara/Graphics/Material.inl index a733f8b79..bcdf82df3 100644 --- a/include/Nazara/Graphics/Material.inl +++ b/include/Nazara/Graphics/Material.inl @@ -26,7 +26,7 @@ namespace Nz inline UInt32 Material::GetEngineBindingIndex(EngineShaderBinding shaderBinding) const { - return m_engineShaderBindings[UnderlyingCast(shaderBinding)]; + return m_engineShaderBindings[shaderBinding]; } inline const std::shared_ptr& Material::GetRenderPipelineLayout() const diff --git a/include/Nazara/Graphics/Sprite.hpp b/include/Nazara/Graphics/Sprite.hpp index 1849337eb..c17e81f7a 100644 --- a/include/Nazara/Graphics/Sprite.hpp +++ b/include/Nazara/Graphics/Sprite.hpp @@ -50,7 +50,7 @@ namespace Nz private: inline void UpdateVertices(); - std::array m_cornerColor; + EnumMap m_cornerColor; std::array m_vertices; std::shared_ptr m_material; Color m_color; diff --git a/include/Nazara/Graphics/Sprite.inl b/include/Nazara/Graphics/Sprite.inl index bb3a51d48..efac2d719 100644 --- a/include/Nazara/Graphics/Sprite.inl +++ b/include/Nazara/Graphics/Sprite.inl @@ -14,7 +14,7 @@ namespace Nz inline const Color& Sprite::GetCornerColor(RectCorner corner) const { - return m_cornerColor[UnderlyingCast(corner)]; + return m_cornerColor[corner]; } inline const Vector2f& Sprite::GetOrigin() const @@ -41,7 +41,7 @@ namespace Nz inline void Sprite::SetCornerColor(RectCorner corner, const Color& color) { - m_cornerColor[UnderlyingCast(corner)] = color; + m_cornerColor[corner] = color; UpdateVertices(); } @@ -90,18 +90,18 @@ namespace Nz { VertexStruct_XYZ_Color_UV* vertices = m_vertices.data(); - std::array cornerExtent; - cornerExtent[UnderlyingCast(RectCorner::LeftBottom)] = Vector2f(0.f, 0.f); - cornerExtent[UnderlyingCast(RectCorner::RightBottom)] = Vector2f(1.f, 0.f); - cornerExtent[UnderlyingCast(RectCorner::LeftTop)] = Vector2f(0.f, 1.f); - cornerExtent[UnderlyingCast(RectCorner::RightTop)] = Vector2f(1.f, 1.f); + EnumMap cornerExtent; + cornerExtent[RectCorner::LeftBottom] = Vector2f(0.f, 0.f); + cornerExtent[RectCorner::RightBottom] = Vector2f(1.f, 0.f); + cornerExtent[RectCorner::LeftTop] = Vector2f(0.f, 1.f); + cornerExtent[RectCorner::RightTop] = Vector2f(1.f, 1.f); Vector3f originShift = m_origin * m_size; for (RectCorner corner : { RectCorner::LeftBottom, RectCorner::RightBottom, RectCorner::LeftTop, RectCorner::RightTop }) { - vertices->color = m_color * m_cornerColor[UnderlyingCast(corner)]; - vertices->position = Vector3f(m_size * cornerExtent[UnderlyingCast(corner)], 0.f) - originShift; + vertices->color = m_color * m_cornerColor[corner]; + vertices->position = Vector3f(m_size * cornerExtent[corner], 0.f) - originShift; vertices->uv = m_textureCoords.GetCorner(corner); vertices++; diff --git a/include/Nazara/Math/Frustum.hpp b/include/Nazara/Math/Frustum.hpp index fdec4a7f7..dc23ab208 100644 --- a/include/Nazara/Math/Frustum.hpp +++ b/include/Nazara/Math/Frustum.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -27,7 +28,7 @@ namespace Nz { public: Frustum() = default; - explicit Frustum(const std::array, FrustumPlaneCount>& planes); + explicit Frustum(const EnumMap>& planes); template explicit Frustum(const Frustum& frustum); Frustum(const Frustum& frustum) = default; ~Frustum() = default; @@ -63,7 +64,7 @@ namespace Nz friend bool Unserialize(SerializationContext& context, Frustum* frustum, TypeTag>); private: - std::array, FrustumPlaneCount> m_planes; + EnumMap> m_planes; }; using Frustumd = Frustum; diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index df1288c3a..15f58fae1 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -30,7 +31,7 @@ namespace Nz * \param planes Frustum of type U to convert to type T */ template - Frustum::Frustum(const std::array, FrustumPlaneCount>& planes) : + Frustum::Frustum(const EnumMap>& planes) : m_planes(planes) { } @@ -44,8 +45,8 @@ namespace Nz template Frustum::Frustum(const Frustum& frustum) { - for (std::size_t i = 0; i < FrustumPlaneCount; ++i) - m_planes[i].Set(frustum.m_planes[i]); + for (auto&& [planeEnum, plane] : m_planes) + plane = Frustum(frustum.GetPlane(planeEnum)); } /*! @@ -129,9 +130,9 @@ namespace Nz bool Frustum::Contains(const Box& box) const { // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ - for (unsigned int i = 0; i < FrustumPlaneCount; i++) + for (const auto& plane : m_planes) { - if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0)) + if (plane.Distance(box.GetPositiveVertex(plane.normal)) < T(0.0)) return false; } @@ -161,9 +162,9 @@ namespace Nz template bool Frustum::Contains(const Sphere& sphere) const { - for (unsigned int i = 0; i < FrustumPlaneCount; i++) + for (const auto& plane : m_planes) { - if (m_planes[i].Distance(sphere.GetPosition()) < -sphere.radius) + if (plane.Distance(sphere.GetPosition()) < -sphere.radius) return false; } @@ -180,9 +181,9 @@ namespace Nz template bool Frustum::Contains(const Vector3& point) const { - for (unsigned int i = 0; i < FrustumPlaneCount; ++i) + for (const auto& plane : m_planes) { - if (m_planes[i].Distance(point) < T(0.0)) + if (plane.Distance(point) < T(0.0)) return false; } @@ -200,12 +201,12 @@ namespace Nz template bool Frustum::Contains(const Vector3* points, std::size_t pointCount) const { - for (std::size_t i = 0; i < FrustumPlaneCount; ++i) + for (const auto& plane : m_planes) { std::size_t j; for (j = 0; j < pointCount; j++ ) { - if (m_planes[i].Distance(points[j]) > T(0.0)) + if (plane.Distance(points[j]) > T(0.0)) break; } @@ -228,8 +229,8 @@ namespace Nz template const Plane& Frustum::GetPlane(FrustumPlane plane) const { - NazaraAssert(UnderlyingCast(plane) < FrustumPlaneCount, "invalid plane"); - return m_planes[UnderlyingCast(plane)]; + NazaraAssert(plane <= FrustumPlane::Max, "invalid plane"); + return m_planes[plane]; } /*! @@ -292,11 +293,11 @@ namespace Nz // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ IntersectionSide side = IntersectionSide::Inside; - for (std::size_t i = 0; i < FrustumPlaneCount; i++) + for (const auto& plane : m_planes) { - if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0)) + if (plane.Distance(box.GetPositiveVertex(plane.normal)) < T(0.0)) return IntersectionSide::Outside; - else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < T(0.0)) + else if (plane.Distance(box.GetNegativeVertex(plane.normal)) < T(0.0)) side = IntersectionSide::Intersecting; } @@ -329,9 +330,9 @@ namespace Nz // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-points-and-spheres/ IntersectionSide side = IntersectionSide::Inside; - for (std::size_t i = 0; i < FrustumPlaneCount; i++) + for (const auto& plane : m_planes) { - T distance = m_planes[i].Distance(sphere.GetPosition()); + T distance = plane.Distance(sphere.GetPosition()); if (distance < -sphere.radius) return IntersectionSide::Outside; else if (distance < sphere.radius) @@ -354,12 +355,12 @@ namespace Nz { std::size_t c = 0; - for (std::size_t i = 0; i < FrustumPlaneCount; ++i) + for (const auto& plane : m_planes) { std::size_t j; for (j = 0; j < pointCount; j++ ) { - if (m_planes[i].Distance(points[j]) > T(0.0)) + if (plane.Distance(points[j]) > T(0.0)) break; } @@ -418,25 +419,26 @@ namespace Nz Vector3 fc = eye + f * zFar; // Computing the frustum - std::array, BoxCornerCount> corners; - corners[UnderlyingCast(BoxCorner::FarLeftBottom)] = fc - u * farH - s * farW; - corners[UnderlyingCast(BoxCorner::FarLeftTop)] = fc + u * farH - s * farW; - corners[UnderlyingCast(BoxCorner::FarRightTop)] = fc + u * farH + s * farW; - corners[UnderlyingCast(BoxCorner::FarRightBottom)] = fc - u * farH + s * farW; + EnumMap> corners; + corners[BoxCorner::FarLeftBottom] = fc - u * farH - s * farW; + corners[BoxCorner::FarLeftTop] = fc + u * farH - s * farW; + corners[BoxCorner::FarRightTop] = fc + u * farH + s * farW; + corners[BoxCorner::FarRightBottom] = fc - u * farH + s * farW; - corners[UnderlyingCast(BoxCorner::NearLeftBottom)] = nc - u * nearH - s * nearW; - corners[UnderlyingCast(BoxCorner::NearLeftTop)] = nc + u * nearH - s * nearW; - corners[UnderlyingCast(BoxCorner::NearRightTop)] = nc + u * nearH + s * nearW; - corners[UnderlyingCast(BoxCorner::NearRightBottom)] = nc - u * nearH + s * nearW; + corners[BoxCorner::NearLeftBottom] = nc - u * nearH - s * nearW; + corners[BoxCorner::NearLeftTop] = nc + u * nearH - s * nearW; + corners[BoxCorner::NearRightTop] = nc + u * nearH + s * nearW; + corners[BoxCorner::NearRightBottom] = nc - u * nearH + s * nearW; // Construction of frustum's planes - std::array, FrustumPlaneCount> planes; - planes[UnderlyingCast(FrustumPlane::Bottom)] = Plane(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)]); - planes[UnderlyingCast(FrustumPlane::Far)] = Plane(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)]); - planes[UnderlyingCast(FrustumPlane::Left)] = Plane(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)]); - planes[UnderlyingCast(FrustumPlane::Near)] = Plane(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], corners[UnderlyingCast(BoxCorner::NearRightBottom)]); - planes[UnderlyingCast(FrustumPlane::Right)] = Plane(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::NearRightTop)], corners[UnderlyingCast(BoxCorner::FarRightBottom)]); - planes[UnderlyingCast(FrustumPlane::Top)] = Plane(corners[UnderlyingCast(BoxCorner::NearRightTop)], corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)]); + + EnumMap> planes; + planes[FrustumPlane::Bottom] = Plane(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearRightBottom], corners[BoxCorner::FarRightBottom]); + planes[FrustumPlane::Far] = Plane(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarLeftTop], corners[BoxCorner::FarLeftBottom]); + planes[FrustumPlane::Left] = Plane(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearLeftBottom], corners[BoxCorner::FarLeftBottom]); + planes[FrustumPlane::Near] = Plane(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearRightTop], corners[BoxCorner::NearRightBottom]); + planes[FrustumPlane::Right] = Plane(corners[BoxCorner::NearRightBottom], corners[BoxCorner::NearRightTop], corners[BoxCorner::FarRightBottom]); + planes[FrustumPlane::Top] = Plane(corners[BoxCorner::NearRightTop], corners[BoxCorner::NearLeftTop], corners[BoxCorner::FarLeftTop]); return Frustum(planes); } @@ -454,7 +456,7 @@ namespace Nz T plane[4]; T invLength; - std::array, FrustumPlaneCount> planes; + EnumMap> planes; // Extract the numbers for the RIGHT plane plane[0] = viewProjMatrix[3] - viewProjMatrix[0]; @@ -469,7 +471,7 @@ namespace Nz plane[2] *= invLength; plane[3] *= -invLength; - planes[UnderlyingCast(FrustumPlane::Right)] = Plane(plane); + planes[FrustumPlane::Right] = Plane(plane); // Extract the numbers for the LEFT plane plane[0] = viewProjMatrix[3] + viewProjMatrix[0]; @@ -484,7 +486,7 @@ namespace Nz plane[2] *= invLength; plane[3] *= -invLength; - planes[UnderlyingCast(FrustumPlane::Left)] = Plane(plane); + planes[FrustumPlane::Left] = Plane(plane); // Extract the BOTTOM plane plane[0] = viewProjMatrix[3] + viewProjMatrix[1]; @@ -499,7 +501,7 @@ namespace Nz plane[2] *= invLength; plane[3] *= -invLength; - planes[UnderlyingCast(FrustumPlane::Bottom)] = Plane(plane); + planes[FrustumPlane::Bottom] = Plane(plane); // Extract the TOP plane plane[0] = viewProjMatrix[3] - viewProjMatrix[1]; @@ -514,7 +516,7 @@ namespace Nz plane[2] *= invLength; plane[3] *= -invLength; - planes[UnderlyingCast(FrustumPlane::Top)] = Plane(plane); + planes[FrustumPlane::Top] = Plane(plane); // Extract the FAR plane plane[0] = viewProjMatrix[3] - viewProjMatrix[2]; @@ -529,7 +531,7 @@ namespace Nz plane[2] *= invLength; plane[3] *= -invLength; - planes[UnderlyingCast(FrustumPlane::Far)] = Plane(plane); + planes[FrustumPlane::Far] = Plane(plane); // Extract the NEAR plane plane[0] = viewProjMatrix[3] + viewProjMatrix[2]; @@ -544,7 +546,7 @@ namespace Nz plane[2] *= invLength; plane[3] *= -invLength; - planes[UnderlyingCast(FrustumPlane::Near)] = Plane(plane); + planes[FrustumPlane::Near] = Plane(plane); return Frustum(planes); } @@ -559,9 +561,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const Frustum& frustum, TypeTag>) { - for (unsigned int i = 0; i < FrustumPlaneCount; ++i) + for (const auto& plane : frustum.m_planes) { - if (!Serialize(context, frustum.m_planes[i])) + if (!Serialize(context, plane)) return false; } @@ -578,9 +580,9 @@ namespace Nz template bool Unserialize(SerializationContext& context, Frustum* frustum, TypeTag>) { - for (unsigned int i = 0; i < FrustumPlaneCount; ++i) + for (auto& plane : frustum->m_planes) { - if (!Unserialize(context, &frustum->m_planes[i])) + if (!Unserialize(context, &plane)) return false; } diff --git a/include/Nazara/Math/OrientedBox.hpp b/include/Nazara/Math/OrientedBox.hpp index 489c45daf..d99546304 100644 --- a/include/Nazara/Math/OrientedBox.hpp +++ b/include/Nazara/Math/OrientedBox.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Nz @@ -53,7 +54,7 @@ namespace Nz Box localBox; private: - Vector3 m_corners[BoxCornerCount]; + EnumMap> m_corners; }; using OrientedBoxd = OrientedBox; diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index 21b64e483..a2c4a6340 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -43,8 +43,8 @@ namespace Nz OrientedBox::OrientedBox(const OrientedBox& orientedBox) : localBox(orientedBox.localBox) { - for (unsigned int i = 0; i < BoxCornerCount; ++i) - m_corners[i] = Vector3(orientedBox(i)); + for (auto&& [cornerEnum, corner] : m_corners.iter_kv()) + corner = Vector3(orientedBox.GetCorner(cornerEnum)); } /*! @@ -59,23 +59,14 @@ namespace Nz template const Vector3& OrientedBox::GetCorner(BoxCorner corner) const { - #ifdef NAZARA_DEBUG - if (UnderlyingCast(corner) > BoxCornerCount) - { - NazaraError("Corner not handled (0x" + NumberToString(UnderlyingCast(corner), 16) + ')'); - - static Vector3 dummy; - return dummy; - } - #endif - - return m_corners[UnderlyingCast(corner)]; + NazaraAssert(corner <= BoxCorner::Max, "invalid corner"); + return m_corners[corner]; } template const Vector3* OrientedBox::GetCorners() const { - return &m_corners[0]; + return &m_corners.front(); } /*! @@ -112,8 +103,8 @@ namespace Nz template void OrientedBox::Update(const Matrix4& transformMatrix) { - for (unsigned int i = 0; i < BoxCornerCount; ++i) - m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast(i))); + for (auto&& [corner, pos] : m_corners.iter_kv()) + pos = transformMatrix.Transform(localBox.GetCorner(corner)); } /*! @@ -125,8 +116,8 @@ namespace Nz template void OrientedBox::Update(const Vector3& translation) { - for (unsigned int i = 0; i < BoxCornerCount; ++i) - m_corners[i] = localBox.GetCorner(static_cast(i)) + translation; + for (auto&& [corner, pos] : m_corners.iter_kv()) + pos = localBox.GetCorner(corner) + translation; } /*! @@ -140,18 +131,8 @@ namespace Nz template Vector3& OrientedBox::operator()(unsigned int i) { - #if NAZARA_MATH_SAFE - if (i >= BoxCornerCount) - { - std::ostringstream ss; - ss << "Index out of range: (" << i << " >= " << BoxCornerCount << ")"; - - NazaraError(ss.str()); - throw std::out_of_range(ss.str()); - } - #endif - - return m_corners[i]; + NazaraAssert(i < m_corners.size(), "corner out of range"); + return m_corners[static_cast(i)]; } /*! @@ -165,18 +146,8 @@ namespace Nz template const Vector3& OrientedBox::operator()(unsigned int i) const { -#if NAZARA_MATH_SAFE - if (i >= BoxCornerCount) - { - std::ostringstream ss; - ss << "Index out of range: (" << i << " >= " << BoxCornerCount << ")"; - - NazaraError(ss.str()); - throw std::out_of_range(ss.str()); - } -#endif - - return m_corners[i]; + NazaraAssert(i < m_corners.size(), "corner out of range"); + return m_corners[static_cast(i)]; } /*! @@ -282,16 +253,16 @@ namespace Nz * \param orientedBox The orientedBox to output */ template - std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox) + std::ostream& operator<<(std::ostream& out, const OrientedBox& orientedBox) { - return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftBottom) << ",\n" - << " FLT: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftTop) << ",\n" - << " FRB: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightBottom) << ",\n" - << " FRT: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightTop) << ",\n" - << " NLB: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftBottom) << ",\n" - << " NLT: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftTop) << ",\n" - << " NRB: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightBottom) << ",\n" - << " NRT: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightTop) << ")\n"; + return out << "OrientedBox(FLB: " << orientedBox.GetCorner(BoxCorner::FarLeftBottom) << ",\n" + << " FLT: " << orientedBox.GetCorner(BoxCorner::FarLeftTop) << ",\n" + << " FRB: " << orientedBox.GetCorner(BoxCorner::FarRightBottom) << ",\n" + << " FRT: " << orientedBox.GetCorner(BoxCorner::FarRightTop) << ",\n" + << " NLB: " << orientedBox.GetCorner(BoxCorner::NearLeftBottom) << ",\n" + << " NLT: " << orientedBox.GetCorner(BoxCorner::NearLeftTop) << ",\n" + << " NRB: " << orientedBox.GetCorner(BoxCorner::NearRightBottom) << ",\n" + << " NRT: " << orientedBox.GetCorner(BoxCorner::NearRightTop) << ")\n"; } } diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp b/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp index dc0fcae84..b87b68149 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -256,10 +257,10 @@ namespace Nz::GL struct TextureUnit { GLuint sampler = 0; - std::array textureTargets = { 0 }; + EnumMap textureTargets = { 0 }; }; - std::array bufferTargets = { 0 }; + EnumMap bufferTargets = { 0 }; std::vector storageUnits; std::vector uboUnits; std::vector imageUnits; @@ -274,7 +275,7 @@ namespace Nz::GL RenderStates renderStates; }; - std::array m_extensionStatus; + EnumMap m_extensionStatus; std::array m_originalFunctionPointer; mutable std::unique_ptr m_blitFramebuffers; std::unordered_set m_supportedExtensions; diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Context.inl b/include/Nazara/OpenGLRenderer/Wrapper/Context.inl index 5f4bdba1b..5c9cd8a89 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Context.inl +++ b/include/Nazara/OpenGLRenderer/Wrapper/Context.inl @@ -37,7 +37,7 @@ namespace Nz::GL inline ExtensionStatus Context::GetExtensionStatus(Extension extension) const { - return m_extensionStatus[UnderlyingCast(extension)]; + return m_extensionStatus[extension]; } inline float Context::GetFloat(GLenum name) const diff --git a/include/Nazara/Platform/Cursor.hpp b/include/Nazara/Platform/Cursor.hpp index ae7d8b8a8..2d16c4d6b 100644 --- a/include/Nazara/Platform/Cursor.hpp +++ b/include/Nazara/Platform/Cursor.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace Nz @@ -53,7 +54,7 @@ namespace Nz SystemCursor m_systemCursor; std::unique_ptr m_impl; - static std::array, SystemCursorCount> s_systemCursors; + static EnumMap> s_systemCursors; }; } diff --git a/include/Nazara/Platform/Cursor.inl b/include/Nazara/Platform/Cursor.inl index 4d90b0061..33e659ef2 100644 --- a/include/Nazara/Platform/Cursor.inl +++ b/include/Nazara/Platform/Cursor.inl @@ -20,7 +20,7 @@ namespace Nz inline std::shared_ptr& Cursor::Get(SystemCursor cursor) { - return s_systemCursors[UnderlyingCast(cursor)]; + return s_systemCursors[cursor]; } } diff --git a/include/Nazara/Renderer/DebugDrawer.inl b/include/Nazara/Renderer/DebugDrawer.inl index a4007aabe..3ef210905 100644 --- a/include/Nazara/Renderer/DebugDrawer.inl +++ b/include/Nazara/Renderer/DebugDrawer.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include namespace Nz @@ -27,22 +28,22 @@ namespace Nz inline void DebugDrawer::DrawFrustum(const Frustumf& frustum, const Color& color) { - std::array corners; - for (std::size_t i = 0; i < BoxCornerCount; ++i) - corners[i] = frustum.ComputeCorner(static_cast(i)); + EnumMap corners; + for (auto&& [corner, pos] : corners.iter_kv()) + pos = frustum.ComputeCorner(corner); - DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearRightBottom)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::NearLeftTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftBottom)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::FarRightTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::FarLeftBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::FarLeftBottom)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::NearLeftTop)], corners[UnderlyingCast(BoxCorner::FarLeftTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::NearRightTop)], color); - DrawLine(corners[UnderlyingCast(BoxCorner::NearRightBottom)], corners[UnderlyingCast(BoxCorner::FarRightBottom)], color); + DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearRightBottom], color); + DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::NearLeftTop], color); + DrawLine(corners[BoxCorner::NearLeftBottom], corners[BoxCorner::FarLeftBottom], color); + DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarLeftTop], color); + DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::FarRightBottom], color); + DrawLine(corners[BoxCorner::FarRightTop], corners[BoxCorner::NearRightTop], color); + DrawLine(corners[BoxCorner::FarLeftBottom], corners[BoxCorner::FarRightBottom], color); + DrawLine(corners[BoxCorner::FarLeftBottom], corners[BoxCorner::FarLeftTop], color); + DrawLine(corners[BoxCorner::NearLeftTop], corners[BoxCorner::NearRightTop], color); + DrawLine(corners[BoxCorner::NearLeftTop], corners[BoxCorner::FarLeftTop], color); + DrawLine(corners[BoxCorner::NearRightBottom], corners[BoxCorner::NearRightTop], color); + DrawLine(corners[BoxCorner::NearRightBottom], corners[BoxCorner::FarRightBottom], color); } inline void DebugDrawer::DrawLine(const Vector3f& start, const Vector3f& end, const Color& color) diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index f6c742d0a..b519be26e 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -88,9 +89,9 @@ namespace Nz static bool Initialize(); static void Uninitialize(); - static std::array, PixelFormatCount> s_convertFunctions; - static std::array, PixelFormatCount> s_flipFunctions; - static std::array s_pixelFormatInfos; + static EnumMap> s_convertFunctions; + static EnumMap> s_flipFunctions; + static EnumMap s_pixelFormatInfos; }; } diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index b933dd85a..b13b56d2f 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -197,16 +197,16 @@ namespace Nz return true; } - ConvertFunction func = s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)]; + ConvertFunction func = s_convertFunctions[srcFormat][dstFormat]; if (!func) { - NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " is not supported"); + NazaraError("Pixel format conversion from " + std::string(GetName(srcFormat)) + " to " + std::string(GetName(dstFormat)) + " is not supported"); return false; } if (!func(reinterpret_cast(start), reinterpret_cast(end), reinterpret_cast(dst))) { - NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " failed"); + NazaraError("Pixel format conversion from " + std::string(GetName(srcFormat)) + " to " + std::string(GetName(dstFormat)) + " failed"); return false; } @@ -215,7 +215,7 @@ namespace Nz inline UInt8 PixelFormatInfo::GetBitsPerPixel(PixelFormat format) { - return s_pixelFormatInfos[UnderlyingCast(format)].bitsPerPixel; + return s_pixelFormatInfos[format].bitsPerPixel; } inline UInt8 PixelFormatInfo::GetBytesPerPixel(PixelFormat format) @@ -225,27 +225,27 @@ namespace Nz inline PixelFormatContent PixelFormatInfo::GetContent(PixelFormat format) { - return s_pixelFormatInfos[UnderlyingCast(format)].content; + return s_pixelFormatInfos[format].content; } inline const PixelFormatDescription& PixelFormatInfo::GetInfo(PixelFormat format) { - return s_pixelFormatInfos[UnderlyingCast(format)]; + return s_pixelFormatInfos[format]; } inline const std::string& PixelFormatInfo::GetName(PixelFormat format) { - return s_pixelFormatInfos[UnderlyingCast(format)].name; + return s_pixelFormatInfos[format].name; } inline bool PixelFormatInfo::HasAlpha(PixelFormat format) { - return s_pixelFormatInfos[UnderlyingCast(format)].alphaMask.TestAny(); + return s_pixelFormatInfos[format].alphaMask.TestAny(); } inline bool PixelFormatInfo::IsCompressed(PixelFormat format) { - return s_pixelFormatInfos[UnderlyingCast(format)].IsCompressed(); + return s_pixelFormatInfos[format].IsCompressed(); } inline bool PixelFormatInfo::IsConversionSupported(PixelFormat srcFormat, PixelFormat dstFormat) @@ -253,7 +253,7 @@ namespace Nz if (srcFormat == dstFormat) return true; - return s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] != nullptr; + return s_convertFunctions[srcFormat][dstFormat] != nullptr; } inline bool PixelFormatInfo::IsValid(PixelFormat format) @@ -263,12 +263,12 @@ namespace Nz inline void PixelFormatInfo::SetConvertFunction(PixelFormat srcFormat, PixelFormat dstFormat, ConvertFunction func) { - s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] = func; + s_convertFunctions[srcFormat][dstFormat] = func; } inline void PixelFormatInfo::SetFlipFunction(PixelFlipping flipping, PixelFormat format, FlipFunction func) { - s_flipFunctions[UnderlyingCast(flipping)][UnderlyingCast(format)] = func; + s_flipFunctions[format][flipping] = func; } } diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 7ece6ffd9..fb32955e1 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -77,7 +78,7 @@ namespace Nz std::size_t m_stride; VertexInputRate m_inputRate; - static std::array, VertexLayoutCount> s_declarations; + static EnumMap> s_declarations; }; } diff --git a/include/Nazara/Utility/VertexDeclaration.inl b/include/Nazara/Utility/VertexDeclaration.inl index 8d36d555b..54a78fd41 100644 --- a/include/Nazara/Utility/VertexDeclaration.inl +++ b/include/Nazara/Utility/VertexDeclaration.inl @@ -74,8 +74,7 @@ namespace Nz inline const std::shared_ptr& VertexDeclaration::Get(VertexLayout layout) { NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum"); - - return s_declarations[UnderlyingCast(layout)]; + return s_declarations[layout]; } } diff --git a/include/Nazara/VulkanRenderer/Wrapper/Device.hpp b/include/Nazara/VulkanRenderer/Wrapper/Device.hpp index 599675057..2049827a3 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Device.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Device.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -105,16 +106,14 @@ namespace Nz struct InternalData; - static constexpr std::size_t QueueCount = static_cast(QueueType::Max) + 1; - std::unique_ptr m_internalData; - std::array m_defaultQueues; std::unordered_set m_loadedExtensions; std::unordered_set m_loadedLayers; std::vector m_enabledQueuesInfos; std::vector m_queuesByFamily; Instance& m_instance; const Vk::PhysicalDevice* m_physicalDevice; + EnumMap m_defaultQueues; VkAllocationCallbacks m_allocator; VkDevice m_device; VkResult m_lastErrorCode; diff --git a/include/Nazara/VulkanRenderer/Wrapper/Device.inl b/include/Nazara/VulkanRenderer/Wrapper/Device.inl index fa337e5d5..d4c139001 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Device.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Device.inl @@ -13,7 +13,7 @@ namespace Nz::Vk { inline UInt32 Device::GetDefaultFamilyIndex(QueueType queueType) const { - return m_defaultQueues[UnderlyingCast(queueType)]; + return m_defaultQueues[queueType]; } inline const std::vector& Device::GetEnabledQueues() const diff --git a/src/Nazara/Audio/OpenALDevice.cpp b/src/Nazara/Audio/OpenALDevice.cpp index e1bd67b88..421c91c2b 100644 --- a/src/Nazara/Audio/OpenALDevice.cpp +++ b/src/Nazara/Audio/OpenALDevice.cpp @@ -33,23 +33,23 @@ namespace Nz // We complete the formats table m_audioFormatValues.fill(0); - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Mono)] = AL_FORMAT_MONO16; - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Stereo)] = AL_FORMAT_STEREO16; + m_audioFormatValues[AudioFormat::I16_Mono] = AL_FORMAT_MONO16; + m_audioFormatValues[AudioFormat::I16_Stereo] = AL_FORMAT_STEREO16; // "The presence of an enum value does not guarantee the applicability of an extension to the current context." if (library.alIsExtensionPresent("AL_EXT_MCFORMATS")) { - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Quad)] = m_library.alGetEnumValue("AL_FORMAT_QUAD16"); - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_5_1)] = m_library.alGetEnumValue("AL_FORMAT_51CHN16"); - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_6_1)] = m_library.alGetEnumValue("AL_FORMAT_61CHN16"); - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_7_1)] = m_library.alGetEnumValue("AL_FORMAT_71CHN16"); + m_audioFormatValues[AudioFormat::I16_Quad] = m_library.alGetEnumValue("AL_FORMAT_QUAD16"); + m_audioFormatValues[AudioFormat::I16_5_1] = m_library.alGetEnumValue("AL_FORMAT_51CHN16"); + m_audioFormatValues[AudioFormat::I16_6_1] = m_library.alGetEnumValue("AL_FORMAT_61CHN16"); + m_audioFormatValues[AudioFormat::I16_7_1] = m_library.alGetEnumValue("AL_FORMAT_71CHN16"); } else if (library.alIsExtensionPresent("AL_LOKI_quadriphonic")) - m_audioFormatValues[UnderlyingCast(AudioFormat::I16_Quad)] = m_library.alGetEnumValue("AL_FORMAT_QUAD16_LOKI"); + m_audioFormatValues[AudioFormat::I16_Quad] = m_library.alGetEnumValue("AL_FORMAT_QUAD16_LOKI"); m_extensionStatus.fill(false); if (library.alIsExtensionPresent("AL_SOFT_source_latency")) - m_extensionStatus[UnderlyingCast(OpenALExtension::SourceLatency)] = true; + m_extensionStatus[OpenALExtension::SourceLatency] = true; SetListenerDirection(Vector3f::Forward()); } @@ -226,7 +226,7 @@ namespace Nz if (format == AudioFormat::Unknown) return false; - return m_audioFormatValues[UnderlyingCast(format)] != 0; + return m_audioFormatValues[format] != 0; } /*! diff --git a/src/Nazara/Core/AbstractLogger.cpp b/src/Nazara/Core/AbstractLogger.cpp index 6561277e7..a41603a31 100644 --- a/src/Nazara/Core/AbstractLogger.cpp +++ b/src/Nazara/Core/AbstractLogger.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -11,14 +12,12 @@ namespace Nz { namespace NAZARA_ANONYMOUS_NAMESPACE { - const char* errorType[] = { + constexpr EnumMap s_errorTypes = { "Assert failed: ", // ErrorType::AssertFailed "Internal error: ", // ErrorType::Internal "Error: ", // ErrorType::Normal "Warning: " // ErrorType::Warning }; - - static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete"); } /*! @@ -44,7 +43,7 @@ namespace Nz NAZARA_USE_ANONYMOUS_NAMESPACE std::ostringstream ss; - ss << errorType[UnderlyingCast(type)] << error; + ss << s_errorTypes[type] << error; if (line != 0 && file && function) ss << " (" << file << ':' << line << ": " << function << ')'; diff --git a/src/Nazara/Core/HardwareInfo.cpp b/src/Nazara/Core/HardwareInfo.cpp index cdfd3e29b..ae5fe824b 100644 --- a/src/Nazara/Core/HardwareInfo.cpp +++ b/src/Nazara/Core/HardwareInfo.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -23,34 +24,34 @@ namespace Nz { namespace NAZARA_ANONYMOUS_NAMESPACE { - constexpr std::array s_vendorNames = { - std::string_view("ACRN"), // ProcessorVendor::ACRN - std::string_view("Advanced Micro Devices"), // ProcessorVendor::AMD - std::string_view("ao486"), // ProcessorVendor::Ao486 - std::string_view("Apple Rosetta 2"), // ProcessorVendor::AppleRosetta2 - std::string_view("bhyve"), // ProcessorVendor::Bhyve - std::string_view("Centaur Technology"), // ProcessorVendor::Centaur - std::string_view("Cyrix Corporation"), // ProcessorVendor::Cyrix - std::string_view("MCST Elbrus"), // ProcessorVendor::Elbrus - std::string_view("Hygon"), // ProcessorVendor::Hygon - std::string_view("Microsoft Hyper-V"), // ProcessorVendor::HyperV - std::string_view("Intel Corporation"), // ProcessorVendor::Intel - std::string_view("Kernel-based Virtual Machine"), // ProcessorVendor::KVM - std::string_view("Microsoft x86-to-ARM"), // ProcessorVendor::MicrosoftXTA - std::string_view("National Semiconductor"), // ProcessorVendor::NSC - std::string_view("NexGen"), // ProcessorVendor::NexGen - std::string_view("Parallels"), // ProcessorVendor::Parallels - std::string_view("QEMU"), // ProcessorVendor::QEMU - std::string_view("QNX Hypervisor"), // ProcessorVendor::QNX - std::string_view("Rise Technology"), // ProcessorVendor::Rise - std::string_view("Silicon Integrated Systems"), // ProcessorVendor::SiS - std::string_view("Transmeta Corporation"), // ProcessorVendor::Transmeta - std::string_view("United Microelectronics Corporation"), // ProcessorVendor::UMC - std::string_view("VIA Technologies"), // ProcessorVendor::VIA - std::string_view("VMware"), // ProcessorVendor::VMware - std::string_view("Vortex86"), // ProcessorVendor::Vortex - std::string_view("Xen"), // ProcessorVendor::XenHVM - std::string_view("Zhaoxin)") // ProcessorVendor::Zhaoxin + constexpr EnumMap s_vendorNames { + "ACRN", // ProcessorVendor::ACRN + "Advanced Micro Devices", // ProcessorVendor::AMD + "ao486", // ProcessorVendor::Ao486 + "Apple Rosetta 2", // ProcessorVendor::AppleRosetta2 + "bhyve", // ProcessorVendor::Bhyve + "Centaur Technology", // ProcessorVendor::Centaur + "Cyrix Corporation", // ProcessorVendor::Cyrix + "MCST Elbrus", // ProcessorVendor::Elbrus + "Hygon", // ProcessorVendor::Hygon + "Microsoft Hyper-V", // ProcessorVendor::HyperV + "Intel Corporation", // ProcessorVendor::Intel + "Kernel-based Virtual Machine", // ProcessorVendor::KVM + "Microsoft x86-to-ARM", // ProcessorVendor::MicrosoftXTA + "National Semiconductor", // ProcessorVendor::NSC + "NexGen", // ProcessorVendor::NexGen + "Parallels", // ProcessorVendor::Parallels + "QEMU", // ProcessorVendor::QEMU + "QNX Hypervisor", // ProcessorVendor::QNX + "Rise Technology", // ProcessorVendor::Rise + "Silicon Integrated Systems", // ProcessorVendor::SiS + "Transmeta Corporation", // ProcessorVendor::Transmeta + "United Microelectronics Corporation", // ProcessorVendor::UMC + "VIA Technologies", // ProcessorVendor::VIA + "VMware", // ProcessorVendor::VMware + "Vortex86", // ProcessorVendor::Vortex + "Xen", // ProcessorVendor::XenHVM + "Zhaoxin" // ProcessorVendor::Zhaoxin }; static_assert(s_vendorNames.size() == ProcessorVendorCount, "Processor vendor name array is incomplete"); @@ -111,7 +112,7 @@ namespace Nz { NAZARA_USE_ANONYMOUS_NAMESPACE - return s_vendorNames[UnderlyingCast(m_cpuVendor)]; + return s_vendorNames[m_cpuVendor]; } void HardwareInfo::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]) @@ -160,18 +161,18 @@ namespace Nz // Retrieval of certain capacities of the processor (ECX and EDX, function 1) HardwareInfoImpl::Cpuid(1, 0, registers.data()); - m_cpuCapabilities[UnderlyingCast(ProcessorCap::AES)] = (ecx & (1U << 25)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::AVX)] = (ecx & (1U << 28)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::FMA3)] = (ecx & (1U << 12)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::MMX)] = (edx & (1U << 23)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::Popcnt)] = (ecx & (1U << 23)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::RDRAND)] = (ecx & (1U << 30)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE)] = (edx & (1U << 25)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE2)] = (edx & (1U << 26)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE3)] = (ecx & (1U << 0)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSSE3)] = (ecx & (1U << 9)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE41)] = (ecx & (1U << 19)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE42)] = (ecx & (1U << 20)) != 0; + m_cpuCapabilities[ProcessorCap::AES] = (ecx & (1U << 25)) != 0; + m_cpuCapabilities[ProcessorCap::AVX] = (ecx & (1U << 28)) != 0; + m_cpuCapabilities[ProcessorCap::FMA3] = (ecx & (1U << 12)) != 0; + m_cpuCapabilities[ProcessorCap::MMX] = (edx & (1U << 23)) != 0; + m_cpuCapabilities[ProcessorCap::Popcnt] = (ecx & (1U << 23)) != 0; + m_cpuCapabilities[ProcessorCap::RDRAND] = (ecx & (1U << 30)) != 0; + m_cpuCapabilities[ProcessorCap::SSE] = (edx & (1U << 25)) != 0; + m_cpuCapabilities[ProcessorCap::SSE2] = (edx & (1U << 26)) != 0; + m_cpuCapabilities[ProcessorCap::SSE3] = (ecx & (1U << 0)) != 0; + m_cpuCapabilities[ProcessorCap::SSSE3] = (ecx & (1U << 9)) != 0; + m_cpuCapabilities[ProcessorCap::SSE41] = (ecx & (1U << 19)) != 0; + m_cpuCapabilities[ProcessorCap::SSE42] = (ecx & (1U << 20)) != 0; } // Retrieval of biggest extended function handled (EAX, function 0x80000000) @@ -183,10 +184,10 @@ namespace Nz // Retrieval of extended capabilities of the processor (ECX and EDX, function 0x80000001) HardwareInfoImpl::Cpuid(0x80000001, 0, registers.data()); - m_cpuCapabilities[UnderlyingCast(ProcessorCap::x64)] = (edx & (1U << 29)) != 0; // Support of 64bits, doesn't mean executable is 64bits - m_cpuCapabilities[UnderlyingCast(ProcessorCap::FMA4)] = (ecx & (1U << 16)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::SSE4a)] = (ecx & (1U << 6)) != 0; - m_cpuCapabilities[UnderlyingCast(ProcessorCap::XOP)] = (ecx & (1U << 11)) != 0; + m_cpuCapabilities[ProcessorCap::x64] = (edx & (1U << 29)) != 0; // Support of 64bits, doesn't mean executable is 64bits + m_cpuCapabilities[ProcessorCap::FMA4] = (ecx & (1U << 16)) != 0; + m_cpuCapabilities[ProcessorCap::SSE4a] = (ecx & (1U << 6)) != 0; + m_cpuCapabilities[ProcessorCap::XOP] = (ecx & (1U << 11)) != 0; if (maxSupportedExtendedFunction >= 0x80000004) { diff --git a/src/Nazara/Core/StdLogger.cpp b/src/Nazara/Core/StdLogger.cpp index 5d965f9dd..a103824b5 100644 --- a/src/Nazara/Core/StdLogger.cpp +++ b/src/Nazara/Core/StdLogger.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -11,14 +12,12 @@ namespace Nz { namespace NAZARA_ANONYMOUS_NAMESPACE { - const char* errorType[] = { - "Assert failed", // ErrorType::AssertFailed - "Internal error", // ErrorType::Internal - "Error", // ErrorType::Normal - "Warning" // ErrorType::Warning + constexpr EnumMap s_errorTypes = { + "Assert failed: ", // ErrorType::AssertFailed + "Internal error: ", // ErrorType::Internal + "Error: ", // ErrorType::Normal + "Warning: " // ErrorType::Warning }; - - static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete"); } /*! @@ -83,7 +82,7 @@ namespace Nz { NAZARA_USE_ANONYMOUS_NAMESPACE - fprintf(stderr, "%s: ", errorType[UnderlyingCast(type)]); + fprintf(stderr, "%s: ", s_errorTypes[type]); fwrite(error.data(), sizeof(char), error.size(), stdout); if (line != 0 && file && function) diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 344b2685b..3d71b1ec7 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -353,15 +353,15 @@ namespace Nz std::array whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - for (std::size_t i = 0; i < ImageTypeCount; ++i) + for (auto&& [imageType, texture] : m_defaultTextures.depthTextures.iter_kv()) { - texInfo.type = static_cast(i); - if (texInfo.type == ImageType::E3D) + if (imageType == ImageType::E3D) continue; - texInfo.layerCount = (texInfo.type == ImageType::Cubemap) ? 6 : 1; + texInfo.type = imageType; + texInfo.layerCount = (imageType == ImageType::Cubemap) ? 6 : 1; - m_defaultTextures.depthTextures[i] = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false); + texture = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false); } } @@ -373,12 +373,12 @@ namespace Nz std::array whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - for (std::size_t i = 0; i < ImageTypeCount; ++i) + for (auto&& [imageType, texture] : m_defaultTextures.whiteTextures.iter_kv()) { - texInfo.type = static_cast(i); - texInfo.layerCount = (texInfo.type == ImageType::Cubemap) ? 6 : 1; + texInfo.type = imageType; + texInfo.layerCount = (imageType == ImageType::Cubemap) ? 6 : 1; - m_defaultTextures.whiteTextures[i] = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false); + texture = m_renderDevice->InstantiateTexture(texInfo, whitePixels.data(), false); } } } diff --git a/src/Nazara/Graphics/LinearSlicedSprite.cpp b/src/Nazara/Graphics/LinearSlicedSprite.cpp index a2bbfaa78..e55df90c6 100644 --- a/src/Nazara/Graphics/LinearSlicedSprite.cpp +++ b/src/Nazara/Graphics/LinearSlicedSprite.cpp @@ -42,7 +42,7 @@ namespace Nz }; const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1); - const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; + const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D]; elements.emplace_back(registry.AllocateElement(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox)); } diff --git a/src/Nazara/Graphics/Material.cpp b/src/Nazara/Graphics/Material.cpp index 888a6be61..fec5e6478 100644 --- a/src/Nazara/Graphics/Material.cpp +++ b/src/Nazara/Graphics/Material.cpp @@ -86,25 +86,25 @@ namespace Nz // TODO: Ensure structs layout is what's expected if (auto it = block->uniformBlocks.find("InstanceData"); it != block->uniformBlocks.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::InstanceDataUbo)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::InstanceDataUbo] = it->second.bindingIndex; if (auto it = block->uniformBlocks.find("LightData"); it != block->uniformBlocks.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::LightDataUbo)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::LightDataUbo] = it->second.bindingIndex; if (auto it = block->uniformBlocks.find("ViewerData"); it != block->uniformBlocks.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::ViewerDataUbo)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::ViewerDataUbo] = it->second.bindingIndex; if (auto it = block->samplers.find("ShadowMaps2D"); it != block->samplers.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::Shadowmap2D)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::Shadowmap2D] = it->second.bindingIndex; if (auto it = block->samplers.find("ShadowMapsCube"); it != block->samplers.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::ShadowmapCube)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::ShadowmapCube] = it->second.bindingIndex; if (auto it = block->uniformBlocks.find("SkeletalData"); it != block->uniformBlocks.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::SkeletalDataUbo)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::SkeletalDataUbo] = it->second.bindingIndex; if (auto it = block->samplers.find("TextureOverlay"); it != block->samplers.end()) - m_engineShaderBindings[UnderlyingCast(EngineShaderBinding::OverlayTexture)] = it->second.bindingIndex; + m_engineShaderBindings[EngineShaderBinding::OverlayTexture] = it->second.bindingIndex; } for (const auto& handlerPtr : m_settings.GetPropertyHandlers()) diff --git a/src/Nazara/Graphics/MaterialInstance.cpp b/src/Nazara/Graphics/MaterialInstance.cpp index 20d449231..61a86d9ce 100644 --- a/src/Nazara/Graphics/MaterialInstance.cpp +++ b/src/Nazara/Graphics/MaterialInstance.cpp @@ -145,7 +145,7 @@ namespace Nz const auto& textureSlot = m_parent->GetTextureData(i); const auto& textureBinding = m_textureBinding[i]; - const std::shared_ptr& texture = (textureBinding.texture) ? textureBinding.texture : defaultTextures.whiteTextures[UnderlyingCast(textureSlot.imageType)]; + const std::shared_ptr& texture = (textureBinding.texture) ? textureBinding.texture : defaultTextures.whiteTextures[textureSlot.imageType]; const std::shared_ptr& sampler = (textureBinding.sampler) ? textureBinding.sampler : Graphics::Instance()->GetSamplerCache().Get({}); bindings.push_back({ diff --git a/src/Nazara/Graphics/SlicedSprite.cpp b/src/Nazara/Graphics/SlicedSprite.cpp index 90cc54691..9d5329055 100644 --- a/src/Nazara/Graphics/SlicedSprite.cpp +++ b/src/Nazara/Graphics/SlicedSprite.cpp @@ -37,7 +37,7 @@ namespace Nz }; const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1); - const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; + const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D]; elements.emplace_back(registry.AllocateElement(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), *elementData.scissorBox)); } diff --git a/src/Nazara/Graphics/Sprite.cpp b/src/Nazara/Graphics/Sprite.cpp index ecf5c2de2..866ce5ba9 100644 --- a/src/Nazara/Graphics/Sprite.cpp +++ b/src/Nazara/Graphics/Sprite.cpp @@ -40,7 +40,7 @@ namespace Nz }; const auto& renderPipeline = materialPipeline->GetRenderPipeline(&vertexBufferData, 1); - const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; + const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D]; elements.emplace_back(registry.AllocateElement(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data(), *elementData.scissorBox)); } diff --git a/src/Nazara/Graphics/SubmeshRenderer.cpp b/src/Nazara/Graphics/SubmeshRenderer.cpp index a5352566a..1710325f0 100644 --- a/src/Nazara/Graphics/SubmeshRenderer.cpp +++ b/src/Nazara/Graphics/SubmeshRenderer.cpp @@ -54,9 +54,9 @@ namespace Nz currentShaderBinding = nullptr; }; - const auto& depthTexture2D = Graphics::Instance()->GetDefaultTextures().depthTextures[UnderlyingCast(ImageType::E2D)]; - const auto& depthTextureCube = Graphics::Instance()->GetDefaultTextures().depthTextures[UnderlyingCast(ImageType::Cubemap)]; - const auto& whiteTexture2D = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; + const auto& depthTexture2D = Graphics::Instance()->GetDefaultTextures().depthTextures[ImageType::E2D]; + const auto& depthTextureCube = Graphics::Instance()->GetDefaultTextures().depthTextures[ImageType::Cubemap]; + const auto& whiteTexture2D = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D]; const auto& defaultSampler = graphics->GetSamplerCache().Get({}); TextureSamplerInfo samplerInfo; diff --git a/src/Nazara/Graphics/Tilemap.cpp b/src/Nazara/Graphics/Tilemap.cpp index c280927e1..96b59c98b 100644 --- a/src/Nazara/Graphics/Tilemap.cpp +++ b/src/Nazara/Graphics/Tilemap.cpp @@ -54,7 +54,7 @@ namespace Nz vertexDeclaration }; - const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; + const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[ImageType::E2D]; const VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(m_vertices.data()); for (std::size_t layerIndex = 0; layerIndex < m_layers.size(); ++layerIndex) @@ -116,11 +116,11 @@ namespace Nz void Tilemap::UpdateVertices() const { - std::array cornerExtent; - cornerExtent[UnderlyingCast(RectCorner::LeftBottom)] = Vector2f(0.f, 0.f); - cornerExtent[UnderlyingCast(RectCorner::RightBottom)] = Vector2f(1.f, 0.f); - cornerExtent[UnderlyingCast(RectCorner::LeftTop)] = Vector2f(0.f, 1.f); - cornerExtent[UnderlyingCast(RectCorner::RightTop)] = Vector2f(1.f, 1.f); + EnumMap cornerExtent; + cornerExtent[RectCorner::LeftBottom] = Vector2f(0.f, 0.f); + cornerExtent[RectCorner::RightBottom] = Vector2f(1.f, 0.f); + cornerExtent[RectCorner::LeftTop] = Vector2f(0.f, 1.f); + cornerExtent[RectCorner::RightTop] = Vector2f(1.f, 1.f); std::size_t spriteCount = 0; for (const Layer& layer : m_layers) @@ -150,7 +150,7 @@ namespace Nz for (RectCorner corner : { RectCorner::LeftBottom, RectCorner::RightBottom, RectCorner::LeftTop, RectCorner::RightTop }) { vertexPtr->color = tile.color; - vertexPtr->position = tileLeftBottom + Vector3f(m_tileSize * cornerExtent[UnderlyingCast(corner)] - originShift, 0.f); + vertexPtr->position = tileLeftBottom + Vector3f(m_tileSize * cornerExtent[corner] - originShift, 0.f); vertexPtr->uv = tile.textureCoords.GetCorner(corner); ++vertexPtr; diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 95af9ff5d..2ec025585 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1016,31 +1017,29 @@ namespace Nz int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol) { NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum"); - - static int addressFamily[] = { + + constexpr EnumMap addressFamily { AF_UNSPEC, //< NetProtocol::Any AF_INET, //< NetProtocol::IPv4 AF_INET6, //< NetProtocol::IPv6 -1 //< NetProtocol::Unknown }; - static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete"); - return addressFamily[UnderlyingCast(protocol)]; + return addressFamily[protocol]; } int SocketImpl::TranslateSocketTypeToSock(SocketType type) { NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum"); - - static int socketType[] = { + + constexpr EnumMap socketType { SOCK_RAW, //< SocketType::Raw SOCK_STREAM, //< SocketType::TCP SOCK_DGRAM, //< SocketType::UDP -1 //< SocketType::Unknown }; - static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete"); - return socketType[UnderlyingCast(type)]; + return socketType[type]; } void SocketImpl::Uninitialize() diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index ca5418d9f..229bd6b8f 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include // Some compilers (older versions of MinGW) lack Mstcpip.h which defines some structs/defines @@ -999,30 +1000,28 @@ namespace Nz { NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum"); - static int addressFamily[] = { + constexpr EnumMap addressFamily { AF_UNSPEC, //< NetProtocol::Any AF_INET, //< NetProtocol::IPv4 AF_INET6, //< NetProtocol::IPv6 -1 //< NetProtocol::Unknown }; - static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete"); - return addressFamily[UnderlyingCast(protocol)]; + return addressFamily[protocol]; } int SocketImpl::TranslateSocketTypeToSock(SocketType type) { NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum"); - - static int socketType[] = { + + constexpr EnumMap socketType { SOCK_RAW, //< SocketType::Raw SOCK_STREAM, //< SocketType::TCP SOCK_DGRAM, //< SocketType::UDP -1 //< SocketType::Unknown }; - static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete"); - return socketType[UnderlyingCast(type)]; + return socketType[type]; } void SocketImpl::Uninitialize() diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp index b77349ed0..82064b6fb 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp @@ -134,14 +134,14 @@ namespace Nz::GL force = true; #endif - if (m_state.bufferTargets[UnderlyingCast(target)] != buffer || force) + if (m_state.bufferTargets[target] != buffer || force) { if (!SetCurrentContext(this)) throw std::runtime_error("failed to activate context"); glBindBuffer(ToOpenGL(target), buffer); - m_state.bufferTargets[UnderlyingCast(target)] = buffer; + m_state.bufferTargets[target] = buffer; } } @@ -248,7 +248,7 @@ namespace Nz::GL unit.size = size; // glBindBufferRange does replace the currently bound buffer - m_state.bufferTargets[UnderlyingCast(BufferTarget::Storage)] = buffer; + m_state.bufferTargets[BufferTarget::Storage] = buffer; } } @@ -263,7 +263,7 @@ namespace Nz::GL throw std::runtime_error("unsupported texture unit #" + std::to_string(textureUnit)); auto& unit = m_state.textureUnits[textureUnit]; - if (unit.textureTargets[UnderlyingCast(target)] != texture) + if (unit.textureTargets[target] != texture) { if (!SetCurrentContext(this)) throw std::runtime_error("failed to activate context"); @@ -272,7 +272,7 @@ namespace Nz::GL glBindTexture(ToOpenGL(target), texture); - unit.textureTargets[UnderlyingCast(target)] = texture; + unit.textureTargets[target] = texture; } } @@ -294,7 +294,7 @@ namespace Nz::GL unit.size = size; // glBindBufferRange does replace the currently bound buffer - m_state.bufferTargets[UnderlyingCast(BufferTarget::Uniform)] = buffer; + m_state.bufferTargets[BufferTarget::Uniform] = buffer; } } @@ -457,87 +457,87 @@ namespace Nz::GL // Clip control if (m_params.type == ContextType::OpenGL && glVersion >= 450) - m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::Core; + m_extensionStatus[Extension::ClipControl] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_clip_control")) - m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::ClipControl] = ExtensionStatus::ARB; else if (m_supportedExtensions.count("GL_EXT_clip_control")) - m_extensionStatus[UnderlyingCast(Extension::ClipControl)] = ExtensionStatus::EXT; + m_extensionStatus[Extension::ClipControl] = ExtensionStatus::EXT; // Compute shaders if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310)) - m_extensionStatus[UnderlyingCast(Extension::ComputeShader)] = ExtensionStatus::Core; + m_extensionStatus[Extension::ComputeShader] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_compute_shader")) - m_extensionStatus[UnderlyingCast(Extension::ComputeShader)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::ComputeShader] = ExtensionStatus::ARB; // Debug output if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 320)) - m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::Core; + m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_KHR_debug")) - m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::KHR; + m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::KHR; else if (m_supportedExtensions.count("GL_ARB_debug_output")) - m_extensionStatus[UnderlyingCast(Extension::DebugOutput)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::DebugOutput] = ExtensionStatus::ARB; // Depth clamp if (m_params.type == ContextType::OpenGL && glVersion >= 320) - m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Core; + m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_depth_clamp")) - m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::ARB; else if (m_supportedExtensions.count("GL_EXT_depth_clamp")) - m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::EXT; + m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::EXT; else if (m_supportedExtensions.count("GL_NV_depth_clamp")) - m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor; + m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Vendor; // Polygon mode if (m_params.type == ContextType::OpenGL) - m_extensionStatus[UnderlyingCast(Extension::PolygonMode)] = ExtensionStatus::Core; + m_extensionStatus[Extension::PolygonMode] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_NV_polygon_mode")) - m_extensionStatus[UnderlyingCast(Extension::DepthClamp)] = ExtensionStatus::Vendor; + m_extensionStatus[Extension::DepthClamp] = ExtensionStatus::Vendor; // Shader image load formatted if (m_supportedExtensions.count("GL_EXT_shader_image_load_formatted")) - m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadFormatted)] = ExtensionStatus::EXT; + m_extensionStatus[Extension::ShaderImageLoadFormatted] = ExtensionStatus::EXT; // Shader image load/store if ((m_params.type == ContextType::OpenGL && glVersion >= 420) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310)) - m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::Core; + m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_shader_image_load_store")) - m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::ARB; else if (m_supportedExtensions.count("GL_EXT_shader_image_load_store")) - m_extensionStatus[UnderlyingCast(Extension::ShaderImageLoadStore)] = ExtensionStatus::EXT; + m_extensionStatus[Extension::ShaderImageLoadStore] = ExtensionStatus::EXT; // SPIR-V support if (m_params.type == ContextType::OpenGL && glVersion >= 460) - m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::Core; + m_extensionStatus[Extension::SpirV] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_gl_spirv")) - m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::SpirV] = ExtensionStatus::ARB; // Storage buffers (SSBO) if ((m_params.type == ContextType::OpenGL && glVersion >= 430) || (m_params.type == ContextType::OpenGL_ES && glVersion >= 310)) - m_extensionStatus[UnderlyingCast(Extension::StorageBuffers)] = ExtensionStatus::Core; + m_extensionStatus[Extension::StorageBuffers] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_shader_storage_buffer_object")) - m_extensionStatus[UnderlyingCast(Extension::StorageBuffers)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::StorageBuffers] = ExtensionStatus::ARB; // Texture compression (S3tc) if (m_supportedExtensions.count("GL_EXT_texture_compression_s3tc")) - m_extensionStatus[UnderlyingCast(Extension::TextureCompressionS3tc)] = ExtensionStatus::EXT; + m_extensionStatus[Extension::TextureCompressionS3tc] = ExtensionStatus::EXT; // Texture anisotropic filter if (m_params.type == ContextType::OpenGL && glVersion >= 460) - m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::Core; + m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_texture_filter_anisotropic")) - m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::ARB; else if (m_supportedExtensions.count("GL_EXT_texture_filter_anisotropic")) - m_extensionStatus[UnderlyingCast(Extension::TextureFilterAnisotropic)] = ExtensionStatus::EXT; + m_extensionStatus[Extension::TextureFilterAnisotropic] = ExtensionStatus::EXT; // Texture view if (m_params.type == ContextType::OpenGL && glVersion >= 430) - m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::Core; + m_extensionStatus[Extension::TextureView] = ExtensionStatus::Core; else if (m_supportedExtensions.count("GL_ARB_texture_view")) - m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::ARB; + m_extensionStatus[Extension::TextureView] = ExtensionStatus::ARB; else if (m_supportedExtensions.count("GL_OES_texture_view")) - m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::KHR; //< not sure about the OES => KHR mapping + m_extensionStatus[Extension::TextureView] = ExtensionStatus::KHR; //< not sure about the OES => KHR mapping else if (m_supportedExtensions.count("GL_EXT_texture_view")) - m_extensionStatus[UnderlyingCast(Extension::TextureView)] = ExtensionStatus::EXT; //< not sure about the OES => KHR mapping + m_extensionStatus[Extension::TextureView] = ExtensionStatus::EXT; //< not sure about the OES => KHR mapping #define NAZARA_OPENGLRENDERER_FUNC(name, sig) #define NAZARA_OPENGLRENDERER_EXT_FUNC(name, sig) loader.Load(name, #name, false); diff --git a/src/Nazara/Platform/Cursor.cpp b/src/Nazara/Platform/Cursor.cpp index 77a7da78c..10b10c65e 100644 --- a/src/Nazara/Platform/Cursor.cpp +++ b/src/Nazara/Platform/Cursor.cpp @@ -73,10 +73,10 @@ namespace Nz bool Cursor::Initialize() { - for (std::size_t i = 0; i < SystemCursorCount; ++i) + for (auto&& [cursor, cursorPtr] : s_systemCursors.iter_kv()) { - s_systemCursors[i] = std::make_shared(); - s_systemCursors[i]->Create(static_cast(i)); + cursorPtr = std::make_shared(); + cursorPtr->Create(cursor); } return true; @@ -88,5 +88,5 @@ namespace Nz cursor.reset(); } - std::array, SystemCursorCount> Cursor::s_systemCursors; + EnumMap> Cursor::s_systemCursors; } diff --git a/src/Nazara/Platform/SDL2/CursorImpl.cpp b/src/Nazara/Platform/SDL2/CursorImpl.cpp index a7ce7e4f9..9918aaec2 100644 --- a/src/Nazara/Platform/SDL2/CursorImpl.cpp +++ b/src/Nazara/Platform/SDL2/CursorImpl.cpp @@ -10,9 +10,9 @@ namespace Nz { - namespace + namespace NAZARA_ANONYMOUS_NAMESPACE { - std::array s_systemCursorIds = + constexpr EnumMap s_systemCursorIds = { SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor::Crosshair SDL_SYSTEM_CURSOR_ARROW, // SystemCursor::Default @@ -69,11 +69,13 @@ namespace Nz CursorImpl::CursorImpl(SystemCursor cursor) { + NAZARA_USE_ANONYMOUS_NAMESPACE + ErrorFlags errFlags(ErrorMode::ThrowException); if (cursor != SystemCursor::None) { - m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[UnderlyingCast(cursor)]); + m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]); if (!m_cursor) NazaraError("failed to create SDL cursor: " + std::string(SDL_GetError())); } diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 866ca7827..513cf31a5 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -116,7 +117,7 @@ namespace Nz #endif #else - constexpr std::array rendererPaths = { + constexpr EnumMap rendererPaths = { NazaraRendererPrefix "NazaraDirect3DRenderer" NazaraRendererDebugSuffix, // Direct3D NazaraRendererPrefix "NazaraMantleRenderer" NazaraRendererDebugSuffix, // Mantle NazaraRendererPrefix "NazaraMetalRenderer" NazaraRendererDebugSuffix, // Metal @@ -129,7 +130,7 @@ namespace Nz auto RegisterImpl = [&](RenderAPI api, auto ComputeScore) { - const char* rendererName = rendererPaths[UnderlyingCast(api)]; + const char* rendererName = rendererPaths[api]; assert(rendererName); std::filesystem::path fileName(rendererName); diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index 44f7d1cd6..26c01df4c 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -1411,7 +1411,7 @@ namespace Nz { NazaraAssert(IsValid(format), "invalid pixel format"); - auto& flipFunction = s_flipFunctions[UnderlyingCast(format)][UnderlyingCast(flipping)]; + auto& flipFunction = s_flipFunctions[format][flipping]; if (flipFunction) flipFunction(width, height, depth, reinterpret_cast(src), reinterpret_cast(dst)); else @@ -1499,13 +1499,12 @@ namespace Nz PixelFormat PixelFormatInfo::IdentifyFormat(const PixelFormatDescription& info) { - for (unsigned int i = 0; i < PixelFormatCount; ++i) + for (auto&& [format, formatDesc] : s_pixelFormatInfos.iter_kv()) { - PixelFormatDescription& info2 = s_pixelFormatInfos[i]; - if (info.bitsPerPixel == info2.bitsPerPixel && info.content == info2.content && - info.redMask == info2.redMask && info.greenMask == info2.greenMask && info.blueMask == info2.blueMask && info.alphaMask == info2.alphaMask && - info.redType == info2.redType && info.greenType == info2.greenType && info.blueType == info2.blueType && info.alphaType == info2.alphaType) - return static_cast(i); + if (info.bitsPerPixel == formatDesc.bitsPerPixel && info.content == formatDesc.content && + info.redMask == formatDesc.redMask && info.greenMask == formatDesc.greenMask && info.blueMask == formatDesc.blueMask && info.alphaMask == formatDesc.alphaMask && + info.redType == formatDesc.redType && info.greenType == formatDesc.greenType && info.blueType == formatDesc.blueType && info.alphaType == formatDesc.alphaType) + return format; } return PixelFormat::Undefined; @@ -1517,7 +1516,7 @@ namespace Nz auto SetupPixelFormat = [](PixelFormat format, PixelFormatDescription&& desc) { - s_pixelFormatInfos[UnderlyingCast(format)] = std::move(desc); + s_pixelFormatInfos[format] = std::move(desc); }; Bitset<> b8(0xFF); @@ -1586,10 +1585,10 @@ namespace Nz SetupPixelFormat(PixelFormat::Stencil8, PixelFormatDescription("Stencil8", PixelFormatContent::Stencil, 0xFF, 0, 0, 0, PixelFormatSubType::Unsigned)); SetupPixelFormat(PixelFormat::Stencil16, PixelFormatDescription("Stencil16", PixelFormatContent::Stencil, 0xFFFF, 0, 0, 0, PixelFormatSubType::Unsigned)); - for (unsigned int i = 0; i < PixelFormatCount; ++i) + for (auto&& [pixelFormat, pixelFormatInfo] : s_pixelFormatInfos.iter_kv()) { - if (!s_pixelFormatInfos[i].Validate()) - NazaraWarning("Pixel format 0x" + NumberToString(i, 16) + " (" + GetName(static_cast(i)) + ") failed validation tests"); + if (!pixelFormatInfo.Validate()) + NazaraWarning("Pixel format 0x" + NumberToString(UnderlyingCast(pixelFormat), 16) + " (" + std::string(GetName(pixelFormat)) + ") failed validation tests"); } /***********************************A8************************************/ @@ -1824,18 +1823,19 @@ namespace Nz void PixelFormatInfo::Uninitialize() { - for (std::size_t i = 0; i < PixelFormatCount; ++i) + for (auto&& [pixelFormat, formatInfo] : s_pixelFormatInfos.iter_kv()) { - s_pixelFormatInfos[i].Clear(); - for (std::size_t j = 0; j < PixelFormatCount; ++j) - s_convertFunctions[i][j] = nullptr; + formatInfo.Clear(); - for (std::size_t j = 0; j < PixelFlippingCount; ++j) - s_flipFunctions[i][j] = nullptr; + for (auto& convertFuncs : s_convertFunctions) + convertFuncs.fill(nullptr); + + for (auto& flipFuncs : s_flipFunctions) + flipFuncs.fill(nullptr); } } - std::array, PixelFormatCount> PixelFormatInfo::s_convertFunctions; - std::array, PixelFormatCount> PixelFormatInfo::s_flipFunctions; - std::array PixelFormatInfo::s_pixelFormatInfos; + EnumMap> PixelFormatInfo::s_convertFunctions; + EnumMap> PixelFormatInfo::s_flipFunctions; + EnumMap PixelFormatInfo::s_pixelFormatInfos; } diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index ad29f9728..372efe32f 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -16,8 +16,7 @@ namespace Nz { namespace NAZARA_ANONYMOUS_NAMESPACE { - std::size_t s_componentStride[ComponentTypeCount] = - { + constexpr EnumMap s_componentStride = { 4 * sizeof(float), // ComponentType::Color 1 * sizeof(double), // ComponentType::Double1 2 * sizeof(double), // ComponentType::Double2 @@ -33,6 +32,7 @@ namespace Nz 4 * sizeof(UInt32), // ComponentType::Int4 }; } + VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list components) : m_inputRate(inputRate) { @@ -63,7 +63,7 @@ namespace Nz component.offset = offset; component.type = entry.type; - offset += s_componentStride[UnderlyingCast(component.type)]; + offset += s_componentStride[component.type]; } m_stride = offset; @@ -105,7 +105,7 @@ namespace Nz }; // VertexLayout::XY : VertexStruct_XY - s_declarations[UnderlyingCast(VertexLayout::XY)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XY] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float2, @@ -113,9 +113,9 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY)]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout::XY"); + NazaraAssert(s_declarations[VertexLayout::XY]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout::XY"); - s_declarations[UnderlyingCast(VertexLayout::XY_Color)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XY_Color] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float2, @@ -128,10 +128,10 @@ namespace Nz }, }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY_Color)]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout::XY_Color"); + NazaraAssert(s_declarations[VertexLayout::XY_Color]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout::XY_Color"); // VertexLayout::XY_UV : VertexStruct_XY_UV - s_declarations[UnderlyingCast(VertexLayout::XY_UV)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XY_UV] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float2, @@ -144,10 +144,10 @@ namespace Nz }, }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY_UV)]->GetStride() == sizeof(VertexStruct_XY_UV), "Invalid stride for declaration VertexLayout::XY_UV"); + NazaraAssert(s_declarations[VertexLayout::XY_UV]->GetStride() == sizeof(VertexStruct_XY_UV), "Invalid stride for declaration VertexLayout::XY_UV"); // VertexLayout::XYZ : VertexStruct_XYZ - s_declarations[UnderlyingCast(VertexLayout::XYZ)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -155,10 +155,10 @@ namespace Nz }, }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ)]->GetStride() == sizeof(VertexStruct_XYZ), "Invalid stride for declaration VertexLayout::XYZ"); + NazaraAssert(s_declarations[VertexLayout::XYZ]->GetStride() == sizeof(VertexStruct_XYZ), "Invalid stride for declaration VertexLayout::XYZ"); // VertexLayout::XYZ_Color : VertexStruct_XYZ_Color - s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_Color] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -171,10 +171,10 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)]->GetStride() == sizeof(VertexStruct_XYZ_Color), "Invalid stride for declaration VertexLayout::XYZ_Color"); + NazaraAssert(s_declarations[VertexLayout::XYZ_Color]->GetStride() == sizeof(VertexStruct_XYZ_Color), "Invalid stride for declaration VertexLayout::XYZ_Color"); // VertexLayout::XYZ_Color_UV : VertexStruct_XYZ_Color_UV - s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_Color_UV] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -192,10 +192,10 @@ namespace Nz }, }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)]->GetStride() == sizeof(VertexStruct_XYZ_Color_UV), "Invalid stride for declaration VertexLayout::XYZ_Color_UV"); + NazaraAssert(s_declarations[VertexLayout::XYZ_Color_UV]->GetStride() == sizeof(VertexStruct_XYZ_Color_UV), "Invalid stride for declaration VertexLayout::XYZ_Color_UV"); // VertexLayout::XYZ_Normal : VertexStruct_XYZ_Normal - s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_Normal] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -208,10 +208,10 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)]->GetStride() == sizeof(VertexStruct_XYZ_Normal), "Invalid stride for declaration VertexLayout::XYZ_Normal"); + NazaraAssert(s_declarations[VertexLayout::XYZ_Normal]->GetStride() == sizeof(VertexStruct_XYZ_Normal), "Invalid stride for declaration VertexLayout::XYZ_Normal"); // VertexLayout::XYZ_Normal_UV : VertexStruct_XYZ_Normal_UV - s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_Normal_UV] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -229,10 +229,10 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV"); + NazaraAssert(s_declarations[VertexLayout::XYZ_Normal_UV]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV"); // VertexLayout::XYZ_Normal_UV_Tangent : VertexStruct_XYZ_Normal_UV_Tangent - s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_Normal_UV_Tangent] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -255,10 +255,10 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent"); + NazaraAssert(s_declarations[VertexLayout::XYZ_Normal_UV_Tangent]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent"); // VertexLayout::XYZ_Normal_UV_Tangent_Skinning : VertexStruct_XYZ_Normal_UV_Tangent_Skinning - s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent_Skinning)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_Normal_UV_Tangent_Skinning] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -291,10 +291,10 @@ namespace Nz }, }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent_Skinning)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent_Skinning"); + NazaraAssert(s_declarations[VertexLayout::XYZ_Normal_UV_Tangent_Skinning]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent_Skinning"); // VertexLayout::XYZ_UV : VertexStruct_XYZ_UV - s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::XYZ_UV] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Position, ComponentType::Float3, @@ -307,10 +307,10 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)]->GetStride() == sizeof(VertexStruct_XYZ_UV), "Invalid stride for declaration VertexLayout::XYZ_UV"); + NazaraAssert(s_declarations[VertexLayout::XYZ_UV]->GetStride() == sizeof(VertexStruct_XYZ_UV), "Invalid stride for declaration VertexLayout::XYZ_UV"); // VertexLayout::Matrix4 : Matrix4f - s_declarations[UnderlyingCast(VertexLayout::Matrix4)] = NewDeclaration(VertexInputRate::Vertex, { + s_declarations[VertexLayout::Matrix4] = NewDeclaration(VertexInputRate::Vertex, { { VertexComponent::Userdata, ComponentType::Float4, @@ -333,7 +333,7 @@ namespace Nz } }); - NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::Matrix4)]->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout::Matrix4"); + NazaraAssert(s_declarations[VertexLayout::Matrix4]->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout::Matrix4"); } catch (const std::exception& e) { @@ -349,5 +349,5 @@ namespace Nz s_declarations.fill(nullptr); } - std::array, VertexLayoutCount> VertexDeclaration::s_declarations; + EnumMap> VertexDeclaration::s_declarations; } diff --git a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp index d5a4427c7..3d52fd585 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp @@ -28,7 +28,7 @@ namespace Nz { } - std::array commandPools; + EnumMap commandPools; VulkanDescriptorSetLayoutCache setLayoutCache; }; @@ -49,7 +49,7 @@ namespace Nz AutoCommandBuffer Device::AllocateCommandBuffer(QueueType queueType) { - return m_internalData->commandPools[UnderlyingCast(queueType)].AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY); + return m_internalData->commandPools[queueType].AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY); } bool Device::Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator) @@ -155,24 +155,23 @@ namespace Nz return 0U; }; - std::size_t queueIndex = static_cast(queueType); for (const QueueFamilyInfo& familyInfo : m_enabledQueuesInfos) { if ((familyInfo.flags & QueueTypeToFlags(queueType)) == 0) continue; - m_defaultQueues[queueIndex] = familyInfo.familyIndex; + m_defaultQueues[queueType] = familyInfo.familyIndex; // Break only if queue has not been selected before auto queueBegin = m_defaultQueues.begin(); - auto queueEnd = queueBegin + queueIndex; + auto queueEnd = queueBegin + static_cast(queueType); if (std::find(queueBegin, queueEnd, familyInfo.familyIndex) == queueEnd) break; } - Vk::CommandPool& commandPool = m_internalData->commandPools[queueIndex]; - if (!commandPool.Create(*this, m_defaultQueues[queueIndex], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT)) + Vk::CommandPool& commandPool = m_internalData->commandPools[queueType]; + if (!commandPool.Create(*this, m_defaultQueues[queueType], VK_COMMAND_POOL_CREATE_TRANSIENT_BIT)) { NazaraError("Failed to create command pool: " + TranslateVulkanError(commandPool.GetLastErrorCode())); return false;