Skip to content

Commit 70b6106

Browse files
committed
add in naughty dog bug...
1 parent ad008f9 commit 70b6106

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

include/ctr/macros.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ typedef int8_t s8;
4646
#define OFFSETOF(TYPE, ELEMENT) ((unsigned int)&(((TYPE *)0)->ELEMENT))
4747

4848
#define nullptr ((void *) 0)
49-
#define force_inline static inline __attribute__((always_inline))
49+
#define force_inline static inline __attribute__((always_inline))
50+
51+
//#define FIX_CTR_BUGS

include/ctr/profiler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
22

33
//#define REWRITE_PROFILER
4-
void LoadProfilerPatches();
4+
5+
void LoadProfilerPatches();

rewrite/src/exe/coll.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,28 @@ static s32 _COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const Coll
8585
if (deltaTri[0].x != 0)
8686
{
8787
s32 dem = ((deltaTri[1].y * deltaTri[0].x) - (deltaTri[0].y * deltaTri[1].x)) >> 6;
88-
if (dem == 0) { return BARYCENTRIC_TEST_INVALID; }
89-
beta = (((deltaT.y * deltaTri[0].x) - (deltaT.x * deltaTri[1].x)) << 6) / dem;
90-
gamma = ((deltaT.x * FP_ONE) - (beta * deltaTri[0].y)) / deltaTri[0].x;
88+
if (dem != 0)
89+
{
90+
beta = (((deltaT.y * deltaTri[0].x) - (deltaT.x * deltaTri[1].x)) << 6) / dem;
91+
gamma = ((deltaT.x * FP_ONE) - (beta * deltaTri[0].y)) / deltaTri[0].x;
92+
}
9193
}
9294
else
9395
{
94-
if (deltaTri[0].y == 0) { return BARYCENTRIC_TEST_INVALID; }
95-
beta = FP_DIV(deltaT.y, deltaTri[0].y);
96-
if (deltaTri[1].x == 0) { return BARYCENTRIC_TEST_INVALID; }
97-
gamma = ((deltaT.y * FP_ONE) - (beta * deltaTri[1].y)) / deltaTri[1].x;
96+
if ((deltaTri[0].y != 0) && (deltaTri[1].x != 0))
97+
{
98+
beta = FP_DIV(deltaT.y, deltaTri[0].y);
99+
gamma = ((deltaT.y * FP_ONE) - (beta * deltaTri[1].y)) / deltaTri[1].x;
100+
}
98101
}
99-
if (beta == FP(-1) || gamma == FP(-1)) { return BARYCENTRIC_TEST_INVALID; }
102+
103+
/* Naughty Dog bug: their hand written assembly code
104+
forgets to check beta == -1, creating false collisions */
105+
#ifdef FIX_CTR_BUGS
106+
if ((beta == FP(-1)) || (gamma == FP(-1))) { return BARYCENTRIC_TEST_INVALID; }
107+
#else
108+
if (gamma == FP(-1)) { return BARYCENTRIC_TEST_INVALID; }
109+
#endif
100110

101111
s32 alpha = beta + gamma + FP(-1);
102112
if (gamma < 0)

0 commit comments

Comments
 (0)