Skip to content
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

FakeRtc datetime and ResetRtcScreen day increments #5695

Open
wants to merge 3 commits into
base: upcoming
Choose a base branch
from

Conversation

cawtds
Copy link

@cawtds cawtds commented Nov 20, 2024

Description

Adds date extraction to FakeRtc_GetRawInfo. FakeRtc currently discards any date information.
Also added different day increments to ResetRtcScreen.

Discord contact info

.cawt

@AlexOn1ine AlexOn1ine requested a review from pkmnsnfrn November 20, 2024 12:53
@cawtds cawtds marked this pull request as draft November 21, 2024 15:37
@cawtds cawtds marked this pull request as ready for review November 21, 2024 23:44
@AlexOn1ine
Copy link
Collaborator

@pkmnsnfrn do you think you could review this?

@pkmnsnfrn
Copy link
Collaborator

I intend to review this, but I sent this to cawt and my concern stands:

I skipped over date because nothing in vanilla Emerald uses date and I wanted to make sure my testing was accurate
I think its fine to include and I would like to include it, but I'm unsure as to how to test it since nothing uses date

@AlexOn1ine
Copy link
Collaborator

I intend to review this, but I sent this to cawt and my concern stands:

I skipped over date because nothing in vanilla Emerald uses date and I wanted to make sure my testing was accurate
I think its fine to include and I would like to include it, but I'm unsure as to how to test it since nothing uses date

2 Options:

  1. Trust cawt if the code makes sense
  2. Make a script for a trainer that can only be challenged on a specific date and use the mGBA Game Pak Sensor to manipulate the date

Copy link
Collaborator

@pkmnsnfrn pkmnsnfrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in testing revealed any issues
I would like to do a future PR that makes more of this data readily accessible via scripts like date and day of week but that's not needed right now!

@@ -32,15 +40,16 @@ void FakeRtc_TickTimeForward(void)
if (FlagGet(OW_FLAG_PAUSE_TIME))
return;

FakeRtc_AdvanceTimeBy(0, 0, FakeRtc_GetSecondsRatio());
FakeRtc_AdvanceTimeBy(0, 0, 0, FakeRtc_GetSecondsRatio());
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void FakeRtc_AdvanceSeconds(struct SiiRtcInfo *rtc, u32 *days, u32*hours, u32 *minutes, u32 *seconds)
{
*seconds += rtc->second;
*minutes += rtc->minute;
*hours += rtc->hour;
while (*seconds >= SECONDS_PER_MINUTE)
{
*minutes++;
*seconds -= SECONDS_PER_MINUTE;
}
while (*minutes >= MINUTES_PER_HOUR)
{
*hours++;
*minutes -= MINUTES_PER_HOUR;
}
while (*hours >= HOURS_PER_DAY)
{
*days++;
*hours -= HOURS_PER_DAY;
}
rtc->second = *seconds;
rtc->minute = *minutes;
rtc->hour = *hours;
}
static void FakeRtc_SetDayOfWeek(struct SiiRtcInfo *rtc, u32 daysToAdd)
{
rtc->dayOfWeek = (rtc->dayOfWeek + daysToAdd) % WEEKDAY_COUNT;
}
static void FakeRtc_AdvanceDays(struct SiiRtcInfo *rtc, u32 *days)
{
u32 remainingDaysInMonth = (sNumDaysInMonths[rtc->month - 1] + (rtc->month == MONTH_FEB && IsLeapYear(rtc->year)) - rtc->day);
if (*days > remainingDaysInMonth)
{
rtc->day = 1;
rtc->month++;
if (rtc->month > MONTH_DEC)
{
rtc->month = MONTH_JAN;
rtc->year++;
}
*days -= (remainingDaysInMonth + 1);
FakeRtc_SetDayOfWeek(rtc, remainingDaysInMonth + 1);
}
else
{
rtc->day += *days;
FakeRtc_SetDayOfWeek(rtc, *days);
*days = 0;
}
}

rtc->dayOfWeek = (rtc->dayOfWeek + days) % WEEKDAY_COUNT;
days = 0;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github is being stupid but I'm trying to leave a suggestion to replace this function with

void FakeRtc_AdvanceTimeBy(u32 days, u32 hours, u32 minutes, u32 seconds)
{
    struct SiiRtcInfo *rtc = FakeRtc_GetCurrentTime();
    FakeRtc_AdvanceSeconds(rtc, &days, &hours, &minutes, &seconds);

    while (days > 0)
        FakeRtc_AdvanceDays(rtc, &days);
}

@AlexOn1ine AlexOn1ine added the new-feature Adds a feature label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants