From 30de90303f185960aa9070bd63733d04fa148a26 Mon Sep 17 00:00:00 2001 From: Admiral-Fish Date: Mon, 8 Mar 2021 10:23:56 -0700 Subject: [PATCH] Fix error in day addition #142 --- Source/Core/Gen3/Searchers/RTCSearcher.cpp | 34 +++++++++++++--------- Source/Core/Gen3/Searchers/RTCSearcher.hpp | 2 +- Source/Core/Util/DateTime.cpp | 2 +- Source/Forms/Gen3/Tools/GameCubeRTC.cpp | 2 +- Source/Forms/Gen3/Tools/GameCubeRTC.ui | 22 +++++++------- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Source/Core/Gen3/Searchers/RTCSearcher.cpp b/Source/Core/Gen3/Searchers/RTCSearcher.cpp index 8fa1e19fe..a64a40a70 100644 --- a/Source/Core/Gen3/Searchers/RTCSearcher.cpp +++ b/Source/Core/Gen3/Searchers/RTCSearcher.cpp @@ -24,7 +24,7 @@ RTCSearcher::RTCSearcher() : searching(false) { } -void RTCSearcher::startSearch(u32 initialSeed, u32 targetSeed, u32 initialAdvances, u32 maxAdvances, const DateTime &end) +void RTCSearcher::startSearch(u32 initialSeed, u32 targetSeed, u32 initialAdvances, u32 maxAdvances, const Date &end) { searching = true; @@ -33,22 +33,30 @@ void RTCSearcher::startSearch(u32 initialSeed, u32 targetSeed, u32 initialAdvanc targetSeed = back.getSeed(); - DateTime time; - for (; time < end; time.addSeconds(1), initialSeed += 40500000) + for (Date date; date < end; date.addDays(1)) { - XDRNG rng(initialSeed); - - for (u32 x = 0; x < maxAdvances; x++) + for (u8 hour = 0; hour < 24; hour++) { - if (!searching) + for (u8 minute = 0; minute < 60; minute++) { - return; - } + for (u8 second = 0; second < 60; second++, initialSeed += 40500000) + { + XDRNG rng(initialSeed); - if (rng.next() == targetSeed) - { - std::lock_guard guard(mutex); - results.emplace_back(time, initialSeed, x + 1 + initialAdvances); + for (u32 x = 0; x < maxAdvances; x++) + { + if (!searching) + { + return; + } + + if (rng.next() == targetSeed) + { + std::lock_guard guard(mutex); + results.emplace_back(DateTime(date, Time(hour, minute, second)), initialSeed, x + 1 + initialAdvances); + } + } + } } } } diff --git a/Source/Core/Gen3/Searchers/RTCSearcher.hpp b/Source/Core/Gen3/Searchers/RTCSearcher.hpp index 77d75bb04..b64c265cc 100644 --- a/Source/Core/Gen3/Searchers/RTCSearcher.hpp +++ b/Source/Core/Gen3/Searchers/RTCSearcher.hpp @@ -29,7 +29,7 @@ class RTCSearcher { public: RTCSearcher(); - void startSearch(u32 initialSeed, u32 targetSeed, u32 initialAdvances, u32 maxAdvances, const DateTime &end); + void startSearch(u32 initialSeed, u32 targetSeed, u32 initialAdvances, u32 maxAdvances, const Date &end); void cancelSearch(); std::vector getResults(); diff --git a/Source/Core/Util/DateTime.cpp b/Source/Core/Util/DateTime.cpp index 3513eb704..2a63de16e 100644 --- a/Source/Core/Util/DateTime.cpp +++ b/Source/Core/Util/DateTime.cpp @@ -159,7 +159,7 @@ void DateTime::addSeconds(int seconds) { if (time.addSeconds(seconds)) { - date.addDays(1); + date = date.addDays(1); } } diff --git a/Source/Forms/Gen3/Tools/GameCubeRTC.cpp b/Source/Forms/Gen3/Tools/GameCubeRTC.cpp index d1b0060d2..69ea4f811 100644 --- a/Source/Forms/Gen3/Tools/GameCubeRTC.cpp +++ b/Source/Forms/Gen3/Tools/GameCubeRTC.cpp @@ -91,7 +91,7 @@ void GameCubeRTC::search() u32 targetSeed = ui->textBoxTargetSeed->getUInt(); u32 initialAdvances = ui->textBoxMinAdvance->getUInt(); u32 maxAdvances = ui->textBoxMaxAdvance->getUInt(); - DateTime end = ui->dateTimeEdit->getDateTime(); + Date end = ui->dateEdit->getDate(); auto *searcher = new RTCSearcher(); diff --git a/Source/Forms/Gen3/Tools/GameCubeRTC.ui b/Source/Forms/Gen3/Tools/GameCubeRTC.ui index 7c1653aaf..7e06301a6 100644 --- a/Source/Forms/Gen3/Tools/GameCubeRTC.ui +++ b/Source/Forms/Gen3/Tools/GameCubeRTC.ui @@ -71,13 +71,6 @@ - - - - true - - - @@ -95,6 +88,13 @@ + + + + true + + + @@ -139,17 +139,17 @@
Forms/Controls/TableView.hpp
- DateTimeEdit - QDateTimeEdit -
Forms/Controls/DateTimeEdit.hpp
+ DateEdit + QDateEdit +
Forms/Controls/DateEdit.hpp
textBoxStartSeed textBoxTargetSeed - dateTimeEdit textBoxMinAdvance textBoxMaxAdvance + dateEdit pushButtonSearch pushButtonCancel tableView