Skip to content

Fix trace tests with x87 floating point #1153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/common/cm/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <gtest/gtest.h>
#include <gmock/gmock.h>

#include "cm_public.h"
#include "common/FileSystem.h"

namespace {

using ::testing::FloatNear;
using ::testing::Pointwise;

constexpr int contentmask = ~0;
constexpr int skipmask = 0;

Expand Down Expand Up @@ -139,6 +143,11 @@ TEST_F(TraceTest, AllInPatch)
EXPECT_EQ(1.0f, tr.fraction);
}

// The patch planes (produced from a cGrid_t) come out fairly differently if 80-bit x87 math is used
constexpr float PATCH_PLANE_NORMAL_ATOL = 5.0e-6;
constexpr float PATCH_PLANE_DIST_ATOL = 8.0e-3;
constexpr float PATCH_TRACE_FRACTION_ATOL = 3.0e-6;

TEST_F(TraceTest, PointHitPatch)
{
trace_t tr;
Expand All @@ -149,8 +158,11 @@ TEST_F(TraceTest, PointHitPatch)
EXPECT_EQ(CM_CheckTraceConsistency(start, end, contentmask, skipmask, tr), "");

EXPECT_FALSE(tr.startsolid);
EXPECT_FLOAT_EQ(tr.fraction, 0.4261826);
EXPECT_NEAR(tr.fraction, 0.426183, PATCH_TRACE_FRACTION_ATOL);
EXPECT_EQ(tr.contents, CONTENTS_SOLID);
const vec3_t expectedPlaneNormal = {0, .2425355, -0.970142};
EXPECT_THAT(tr.plane.normal, Pointwise(FloatNear(PATCH_PLANE_NORMAL_ATOL), expectedPlaneNormal));
EXPECT_NEAR(tr.plane.dist, 325.9677, PATCH_PLANE_DIST_ATOL);
}

TEST_F(TraceTest, BoxHitPatch)
Expand All @@ -165,8 +177,11 @@ TEST_F(TraceTest, BoxHitPatch)
EXPECT_EQ(CM_CheckTraceConsistency(start, end, contentmask, skipmask, tr), "");

EXPECT_FALSE(tr.startsolid);
EXPECT_FLOAT_EQ(tr.fraction, 0.1921389);
EXPECT_NEAR(tr.fraction, 0.192139, PATCH_TRACE_FRACTION_ATOL);
EXPECT_EQ(tr.contents, CONTENTS_SOLID);
const vec3_t expectedPlaneNormal = {0, .2425355, -0.970142};
EXPECT_THAT(tr.plane.normal, Pointwise(FloatNear(PATCH_PLANE_NORMAL_ATOL), expectedPlaneNormal));
EXPECT_NEAR(tr.plane.dist, 362.105, PATCH_PLANE_DIST_ATOL);
}

} // namespace
12 changes: 8 additions & 4 deletions src/engine/framework/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,14 @@ static void Init(int argc, char** argv)
cmdlineArgs_t cmdlineArgs;

#ifdef _WIN32
// If we were launched from a console, make our output visible on it
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
(void)freopen("CONOUT$", "w", stdout);
(void)freopen("CONOUT$", "w", stderr);
// Detect MSYS2 terminal. The AttachConsole code makes output not appear
const char* msystem = getenv("MSYSTEM");
if (!msystem || !Str::IsPrefix("MINGW", msystem)) {
// If we were launched from a console, make our output visible on it
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
(void)freopen("CONOUT$", "w", stdout);
(void)freopen("CONOUT$", "w", stderr);
}
}
#endif

Expand Down