forked from DizzyEggg/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
cawtds
wants to merge
5
commits into
rh-hideout:upcoming
Choose a base branch
from
cawtds:fake-rtc-datetime
base: upcoming
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+336
−69
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e718f0c
add datetime conversion for fakeRTC
cawtds 41e26ef
add different day increments to reset_rtc_screen
cawtds 65d2f8b
rtc info in saveblock
cawtds 5cac63f
Merge remote-tracking branch 'rhh/upcoming' into fake-rtc-datetime
cawtds 7daeb73
added datetime and functionality to extract datetime from local time
cawtds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,17 @@ | |
#include "fake_rtc.h" | ||
#include "event_data.h" | ||
|
||
struct Time *FakeRtc_GetCurrentTime(void) | ||
void FakeRtc_Reset(void) | ||
{ | ||
#if OW_USE_FAKE_RTC | ||
memset(&gSaveBlock3Ptr->fakeRTC, 0, sizeof(gSaveBlock3Ptr->fakeRTC)); | ||
gSaveBlock3Ptr->fakeRTC.month = MONTH_JAN; | ||
gSaveBlock3Ptr->fakeRTC.day = 1; | ||
gSaveBlock3Ptr->fakeRTC.dayOfWeek = WEEKDAY_SAT; | ||
#endif | ||
} | ||
|
||
struct SiiRtcInfo *FakeRtc_GetCurrentTime(void) | ||
{ | ||
#if OW_USE_FAKE_RTC | ||
return &gSaveBlock3Ptr->fakeRTC; | ||
|
@@ -17,11 +27,9 @@ struct Time *FakeRtc_GetCurrentTime(void) | |
|
||
void FakeRtc_GetRawInfo(struct SiiRtcInfo *rtc) | ||
{ | ||
struct Time* time = FakeRtc_GetCurrentTime(); | ||
rtc->second = time->seconds; | ||
rtc->minute = time->minutes; | ||
rtc->hour = time->hours; | ||
rtc->day = time->days; | ||
struct SiiRtcInfo *fakeRtc = FakeRtc_GetCurrentTime(); | ||
if (fakeRtc != NULL) | ||
memcpy(rtc, fakeRtc, sizeof(struct SiiRtcInfo)); | ||
} | ||
|
||
void FakeRtc_TickTimeForward(void) | ||
|
@@ -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()); | ||
} | ||
|
||
void FakeRtc_AdvanceTimeBy(u32 hours, u32 minutes, u32 seconds) | ||
void FakeRtc_AdvanceTimeBy(u32 days, u32 hours, u32 minutes, u32 seconds) | ||
{ | ||
struct Time* time = FakeRtc_GetCurrentTime(); | ||
seconds += time->seconds; | ||
minutes += time->minutes; | ||
hours += time->hours; | ||
struct SiiRtcInfo *rtc = FakeRtc_GetCurrentTime(); | ||
|
||
seconds += rtc->second; | ||
minutes += rtc->minute; | ||
hours += rtc->hour; | ||
|
||
while(seconds >= SECONDS_PER_MINUTE) | ||
{ | ||
|
@@ -56,27 +65,49 @@ void FakeRtc_AdvanceTimeBy(u32 hours, u32 minutes, u32 seconds) | |
|
||
while(hours >= HOURS_PER_DAY) | ||
{ | ||
time->days++; | ||
days++; | ||
hours -= HOURS_PER_DAY; | ||
} | ||
|
||
time->seconds = seconds; | ||
time->minutes = minutes; | ||
time->hours = hours; | ||
rtc->second = seconds; | ||
rtc->minute = minutes; | ||
rtc->hour = hours; | ||
|
||
while (days > 0) | ||
{ | ||
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); | ||
rtc->dayOfWeek = (rtc->dayOfWeek + remainingDaysInMonth + 1) % WEEKDAY_COUNT; | ||
} | ||
else | ||
{ | ||
rtc->day += days; | ||
rtc->dayOfWeek = (rtc->dayOfWeek + days) % WEEKDAY_COUNT; | ||
days = 0; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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);
} |
||
|
||
void FakeRtc_ManuallySetTime(u32 hour, u32 minute, u32 second) | ||
{ | ||
struct Time diff, target; | ||
RtcCalcLocalTime(); | ||
|
||
target.hours = hour; | ||
target.minutes = minute; | ||
target.seconds = second; | ||
target.days = gLocalTime.days; | ||
void FakeRtc_ManuallySetTime(u32 day, u32 hour, u32 minute, u32 second) | ||
{ | ||
FakeRtc_Reset(); | ||
FakeRtc_AdvanceTimeBy(day, hour, minute, second); | ||
} | ||
|
||
CalcTimeDifference(&diff, &gLocalTime, &target); | ||
FakeRtc_AdvanceTimeBy(diff.hours, diff.minutes, diff.seconds); | ||
void AdvanceScript(void) | ||
{ | ||
FakeRtc_AdvanceTimeBy(300, 0, 0, 0); | ||
} | ||
|
||
u32 FakeRtc_GetSecondsRatio(void) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.