From ea6c1a9e40afb2414c9d692b91e4047d8dc634cf Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sat, 16 Apr 2022 17:33:36 -0400 Subject: [PATCH] Optimized UpdateTimeOfDay. --- src/overworld.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/overworld.c b/src/overworld.c index 332fa6d8c7..9d929a2448 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1474,44 +1474,45 @@ const struct BlendSettings gTimeOfDayBlend[] = }; u8 UpdateTimeOfDay(void) { - s8 hours, minutes; + s32 hours, minutes; RtcCalcLocalTime(); hours = gLocalTime.hours; minutes = gLocalTime.minutes; - if (hours >= 22 || hours < 4) { // night + if (hours < 4) { // night currentTimeBlend.weight = 256; currentTimeBlend.altWeight = 0; return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; - } else if (hours >= 4 && hours < 7) { // night->twilight + } else if (hours < 7) { // night->twilight currentTimeBlend.time0 = TIME_OF_DAY_NIGHT; currentTimeBlend.time1 = TIME_OF_DAY_TWILIGHT; currentTimeBlend.weight = 256 - 256 * ((hours - 4) * 60 + minutes) / ((7-4)*60); currentTimeBlend.altWeight = (256 - currentTimeBlend.weight) / 2; return gTimeOfDay = TIME_OF_DAY_DAY; - } else if (hours >= 7 && hours < 10) { // twilight->day + } else if (hours < 10) { // twilight->day currentTimeBlend.time0 = TIME_OF_DAY_TWILIGHT; currentTimeBlend.time1 = TIME_OF_DAY_DAY; currentTimeBlend.weight = 256 - 256 * ((hours - 7) * 60 + minutes) / ((10-7)*60); currentTimeBlend.altWeight = (256 - currentTimeBlend.weight) / 2 + 128; return gTimeOfDay = TIME_OF_DAY_DAY; - } else if (hours >= 10 && hours < 18) { // day + } else if (hours < 18) { // day currentTimeBlend.weight = currentTimeBlend.altWeight = 256; return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_DAY; - } else if (hours >= 18 && hours < 20) { // day->twilight + } else if (hours < 20) { // day->twilight currentTimeBlend.time0 = TIME_OF_DAY_DAY; currentTimeBlend.time1 = TIME_OF_DAY_TWILIGHT; currentTimeBlend.weight = 256 - 256 * ((hours - 18) * 60 + minutes) / ((20-18)*60); currentTimeBlend.altWeight = currentTimeBlend.weight / 2 + 128; return gTimeOfDay = TIME_OF_DAY_TWILIGHT; - } else if (hours >= 20 && hours < 22) { // twilight->night + } else if (hours < 22) { // twilight->night currentTimeBlend.time0 = TIME_OF_DAY_TWILIGHT; currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; currentTimeBlend.weight = 256 - 256 * ((hours - 20) * 60 + minutes) / ((22-20)*60); currentTimeBlend.altWeight = currentTimeBlend.weight / 2; return gTimeOfDay = TIME_OF_DAY_NIGHT; - } else { // This should never occur + } else { // 22-24, night currentTimeBlend.weight = 256; - return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_DAY; + currentTimeBlend.altWeight = 0; + return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; } }