diff --git a/include/config/config_game.h b/include/config/config_game.h index c9933518d..62bc30a57 100644 --- a/include/config/config_game.h +++ b/include/config/config_game.h @@ -9,7 +9,8 @@ // Disables AA (Improves console performance but causes visible seams between unconnected geometry). //#define DISABLE_AA -// Use a folded polynomial instead of a lookup table. This has a speed boots and makes the calculation more precise. +// Use a folded polynomial instead of a lookup table. This has a speed boost and makes the calculation more precise. +// causes minor physics and camera inconsistancies #define DISABLE_SIN_COS_LOOKUP_TABLE // Fix annoying glitches (crashes and softlocks) diff --git a/src/code/sys_math.c b/src/code/sys_math.c index f19719bb9..a3f329d13 100644 --- a/src/code/sys_math.c +++ b/src/code/sys_math.c @@ -1,5 +1,7 @@ #include "global.h" +#include "config.h" + f32 sFactorialTbl[] = { 1.0f, 1.0f, 2.0f, 6.0f, 24.0f, 120.0f, 720.0f, 5040.0f, 40320.0f, 362880.0f, 3628800.0f, 39916800.0f, 479001600.0f }; @@ -43,7 +45,11 @@ f32 Math_PowF(f32 base, s32 exp) { * @return sin(angle) */ f32 Math_SinF(f32 angle) { +#ifdef DISABLE_SIN_COS_LOOKUP_TABLE + return (f32)(Math_SinS(RAD_TO_BINANG(angle))); +#else return sins((s16)(angle * (0x7FFF / M_PI))) * SHT_MINV; +#endif } /** @@ -51,5 +57,9 @@ f32 Math_SinF(f32 angle) { * @return cos(angle) */ f32 Math_CosF(f32 angle) { +#ifdef DISABLE_SIN_COS_LOOKUP_TABLE + return (f32)(Math_CosS(RAD_TO_BINANG(angle))); +#else return coss((s16)(angle * (0x7FFF / M_PI))) * SHT_MINV; +#endif } diff --git a/src/libultra/gu/cosf.c b/src/libultra/gu/cosf.c index 639084093..bed240e38 100644 --- a/src/libultra/gu/cosf.c +++ b/src/libultra/gu/cosf.c @@ -1,6 +1,10 @@ #include "ultra64.h" #include "global.h" +#include "functions.h" +#include "config.h" + +#ifndef DISABLE_SIN_COS_LOOKUP_TABLE static const du P[] = { { 0x3FF00000, 0x00000000 }, { 0xBFC55554, 0xBC83656D }, { 0x3F8110ED, 0x3804C2A0 }, { 0xBF29F6FF, 0xEEA56814 }, { 0x3EC5DBDF, 0x0E314BFE }, @@ -13,12 +17,15 @@ static const du pihi = { 0x400921FB, 0x50000000 }; static const du pilo = { 0x3E6110B4, 0x611A6263 }; static const fu zero = { 0x00000000 }; - +#endif /** * @param angle radians * @return cos(angle) */ f32 cosf(f32 angle) { +#ifdef DISABLE_SIN_COS_LOOKUP_TABLE +return Math_CosF(angle); +#else f32 absx; f64 dx; f64 xSq; @@ -60,4 +67,5 @@ f32 cosf(f32 angle) { } return zero.f; +#endif } diff --git a/src/libultra/gu/coss.c b/src/libultra/gu/coss.c index b92704593..004a8e132 100644 --- a/src/libultra/gu/coss.c +++ b/src/libultra/gu/coss.c @@ -1,4 +1,5 @@ #include "global.h" +#include "functions.h" #include "config.h" /** @@ -7,7 +8,7 @@ */ s16 coss(u16 angle) { #ifdef DISABLE_SIN_COS_LOOKUP_TABLE - return Math_CosS(angle) * 0x7FFF; + return Math_CosS(TRUNCF_BINANG((s16)angle))*0x7FFF; #else return sins(angle + 0x4000); #endif diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c index 49929e843..78721fc98 100644 --- a/src/libultra/gu/sinf.c +++ b/src/libultra/gu/sinf.c @@ -1,6 +1,9 @@ #include "global.h" #include "ultra64.h" +#include "functions.h" +#include "config.h" +#ifndef DISABLE_SIN_COS_LOOKUP_TABLE static const du P[] = { { 0x3FF00000, 0x00000000 }, { 0xBFC55554, 0xBC83656D }, { 0x3F8110ED, 0x3804C2A0 }, { 0xBF29F6FF, 0xEEA56814 }, { 0x3EC5DBDF, 0x0E314BFE }, @@ -13,12 +16,15 @@ static const du pihi = { 0x400921FB, 0x50000000 }; static const du pilo = { 0x3E6110B4, 0x611A6263 }; static const fu zero = { 0x00000000 }; - +#endif /** * @param angle radians * @return sin(angle) */ f32 sinf(f32 angle) { +#ifdef DISABLE_SIN_COS_LOOKUP_TABLE + return Math_SinF(angle); +#else f64 dx; f64 xSq; f64 polyApprox; @@ -65,4 +71,5 @@ f32 sinf(f32 angle) { return __libm_qnan_f; } return zero.f; +#endif } diff --git a/src/libultra/gu/sins.c b/src/libultra/gu/sins.c index 0310ca584..99c47b4c9 100644 --- a/src/libultra/gu/sins.c +++ b/src/libultra/gu/sins.c @@ -1,4 +1,5 @@ #include "ultra64.h" +#include "functions.h" #include "config.h" #ifndef DISABLE_SIN_COS_LOOKUP_TABLE @@ -10,7 +11,7 @@ */ s16 sins(u16 angle) { #ifdef DISABLE_SIN_COS_LOOKUP_TABLE -return Math_SinS(angle) * 0x7FFF; + return Math_SinS(TRUNCF_BINANG((s16)angle))*0x7FFF; #else s16 value;