Fix clock spinning violently from undefined behavior with bad casting (#849)

This commit is contained in:
Archez
2024-11-13 14:18:47 -05:00
committed by GitHub
parent 31685557d2
commit 1afe496fed
@@ -38,9 +38,12 @@
#define GET_CURRENT_CLOCK_HOUR(this) ((s32)TIME_TO_HOURS_F((this)->clockTime))
#define GET_CURRENT_CLOCK_MINUTE(this) ((s32)((this)->clockTime * (360 * 2.0f / 0x10000)) % 30)
#define GET_CLOCK_FACE_ROTATION(currentClockHour) ((s16)(currentClockHour * (0x10000 / 24.0f)))
// #region 2S2H [Port] Additional pre-cast to s32 prevents undefined behavior with casting float values larger than s16
// This undefined behavior lead to the clock rings and face spinning violently on some compilers
#define GET_CLOCK_FACE_ROTATION(currentClockHour) ((s16)(s32)(currentClockHour * (0x10000 / 24.0f)))
#define GET_MINUTE_RING_OR_EXTERIOR_GEAR_ROTATION(currentClockMinute) \
((s16)(currentClockMinute * (0x10000 * 12.0f / 360)))
((s16)(s32)(currentClockMinute * (0x10000 * 12.0f / 360)))
// #endregion
void ObjTokeidai_Init(Actor* thisx, PlayState* play);
void ObjTokeidai_Destroy(Actor* thisx, PlayState* play);