From 8562c5d1f2b490bfd8ff01ec88d7878e16a2a16e Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 24 Mar 2026 05:28:01 +0300 Subject: [PATCH] added more unreachable checks --- source/engines/cry_engine/formulas.cpp | 5 ++++- source/engines/frostbite_engine/formulas.cpp | 6 +++++- source/engines/iw_engine/formulas.cpp | 15 ++++++++------- source/engines/source_engine/formulas.cpp | 15 ++++++++------- source/engines/unity_engine/formulas.cpp | 7 +++++-- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/source/engines/cry_engine/formulas.cpp b/source/engines/cry_engine/formulas.cpp index 4d5bc94..301016b 100644 --- a/source/engines/cry_engine/formulas.cpp +++ b/source/engines/cry_engine/formulas.cpp @@ -41,6 +41,9 @@ namespace omath::cry_engine return mat_perspective_left_handed( field_of_view, aspect_ratio, near, far); - return mat_perspective_left_handed(field_of_view, aspect_ratio, near, far); + if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) + return mat_perspective_left_handed( + field_of_view, aspect_ratio, near, far); + std::unreachable(); } } // namespace omath::unity_engine diff --git a/source/engines/frostbite_engine/formulas.cpp b/source/engines/frostbite_engine/formulas.cpp index 2c0d6cc..c3193cb 100644 --- a/source/engines/frostbite_engine/formulas.cpp +++ b/source/engines/frostbite_engine/formulas.cpp @@ -41,6 +41,10 @@ namespace omath::frostbite_engine return mat_perspective_left_handed( field_of_view, aspect_ratio, near, far); - return mat_perspective_left_handed(field_of_view, aspect_ratio, near, far); + if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) + return mat_perspective_left_handed( + field_of_view, aspect_ratio, near, far); + + std::unreachable(); } } // namespace omath::unity_engine diff --git a/source/engines/iw_engine/formulas.cpp b/source/engines/iw_engine/formulas.cpp index ca59ecd..e7ab4b8 100644 --- a/source/engines/iw_engine/formulas.cpp +++ b/source/engines/iw_engine/formulas.cpp @@ -50,12 +50,13 @@ namespace omath::iw_engine {0, 0, far / (far - near), -(near * far) / (far - near)}, {0, 0, 1, 0}, }; - - return { - {1.f / (aspect_ratio * fov_half_tan), 0, 0, 0}, - {0, 1.f / (fov_half_tan), 0, 0}, - {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, - {0, 0, 1, 0}, - }; + if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) + return { + {1.f / (aspect_ratio * fov_half_tan), 0, 0, 0}, + {0, 1.f / (fov_half_tan), 0, 0}, + {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, + {0, 0, 1, 0}, + }; + std::unreachable(); }; } // namespace omath::iw_engine diff --git a/source/engines/source_engine/formulas.cpp b/source/engines/source_engine/formulas.cpp index 0cf8084..85f7055 100644 --- a/source/engines/source_engine/formulas.cpp +++ b/source/engines/source_engine/formulas.cpp @@ -50,12 +50,13 @@ namespace omath::source_engine {0, 0, far / (far - near), -(near * far) / (far - near)}, {0, 0, 1, 0}, }; - - return { - {1.f / (aspect_ratio * fov_half_tan), 0, 0, 0}, - {0, 1.f / (fov_half_tan), 0, 0}, - {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, - {0, 0, 1, 0}, - }; + if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) + return { + {1.f / (aspect_ratio * fov_half_tan), 0, 0, 0}, + {0, 1.f / (fov_half_tan), 0, 0}, + {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, + {0, 0, 1, 0}, + }; + std::unreachable(); } } // namespace omath::source_engine diff --git a/source/engines/unity_engine/formulas.cpp b/source/engines/unity_engine/formulas.cpp index 7e95525..51e4c4c 100644 --- a/source/engines/unity_engine/formulas.cpp +++ b/source/engines/unity_engine/formulas.cpp @@ -40,7 +40,10 @@ namespace omath::unity_engine if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE) return omath::mat_perspective_right_handed( field_of_view, aspect_ratio, near, far); - - return omath::mat_perspective_right_handed(field_of_view, aspect_ratio, near, far); + if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE) + return omath::mat_perspective_right_handed(field_of_view, aspect_ratio, + near, far); + std::unreachable(); } } // namespace omath::unity_engine