mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:20:06 +00:00
Update timeline manager step function to handle volume times between indexed values
This commit is contained in:
parent
2a9dc72721
commit
845d5b5707
1 changed files with 51 additions and 67 deletions
|
|
@ -336,10 +336,10 @@ void TimelineManager::ReceiveMapWidgetPainted(std::size_t mapIndex)
|
||||||
std::unique_lock lock {p->radarSweepMonitorMutex_};
|
std::unique_lock lock {p->radarSweepMonitorMutex_};
|
||||||
|
|
||||||
// If the radar sweep has been updated
|
// If the radar sweep has been updated
|
||||||
if (p->radarSweepsUpdated_.contains(mapIndex))
|
if (p->radarSweepsUpdated_.contains(mapIndex) &&
|
||||||
|
!p->radarSweepsComplete_.contains(mapIndex))
|
||||||
{
|
{
|
||||||
// Mark the radar sweep complete
|
// Mark the radar sweep complete
|
||||||
p->radarSweepsUpdated_.erase(mapIndex);
|
|
||||||
p->radarSweepsComplete_.insert(mapIndex);
|
p->radarSweepsComplete_.insert(mapIndex);
|
||||||
|
|
||||||
// If all sweeps have completed rendering
|
// If all sweeps have completed rendering
|
||||||
|
|
@ -631,79 +631,63 @@ void TimelineManager::Impl::Step(Direction direction)
|
||||||
// Take a lock for time selection
|
// Take a lock for time selection
|
||||||
std::unique_lock lock {selectTimeMutex_};
|
std::unique_lock lock {selectTimeMutex_};
|
||||||
|
|
||||||
// Determine time to get active volume times
|
std::chrono::system_clock::time_point newTime = selectedTime_;
|
||||||
std::chrono::system_clock::time_point queryTime = adjustedTime_;
|
|
||||||
if (queryTime == std::chrono::system_clock::time_point {})
|
if (newTime == std::chrono::system_clock::time_point {})
|
||||||
{
|
{
|
||||||
queryTime = std::chrono::system_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request active volume times
|
|
||||||
auto radarProductManager =
|
|
||||||
manager::RadarProductManager::Instance(radarSite_);
|
|
||||||
auto volumeTimes = radarProductManager->GetActiveVolumeTimes(queryTime);
|
|
||||||
|
|
||||||
if (volumeTimes.empty())
|
|
||||||
{
|
|
||||||
logger_->debug("No products to step through");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamically update maximum cached volume scans
|
|
||||||
UpdateCacheLimit(radarProductManager, volumeTimes);
|
|
||||||
|
|
||||||
std::set<std::chrono::system_clock::time_point>::const_iterator it;
|
|
||||||
|
|
||||||
if (adjustedTime_ == std::chrono::system_clock::time_point {})
|
|
||||||
{
|
|
||||||
// If the adjusted time is live, get the last element in the set
|
|
||||||
it = std::prev(volumeTimes.cend());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Get the current element in the set
|
|
||||||
it = scwx::util::GetBoundedElementIterator(volumeTimes, adjustedTime_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it == volumeTimes.cend())
|
|
||||||
{
|
|
||||||
// Should not get here, but protect against an error
|
|
||||||
logger_->error("No suitable volume time found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == Direction::Back)
|
if (direction == Direction::Back)
|
||||||
{
|
{
|
||||||
// Only if we aren't at the beginning of the volume times set
|
newTime = std::chrono::floor<std::chrono::minutes>(
|
||||||
if (it != volumeTimes.cbegin())
|
std::chrono::system_clock::now());
|
||||||
{
|
|
||||||
// Select the previous time
|
|
||||||
adjustedTime_ = *(--it);
|
|
||||||
selectedTime_ = adjustedTime_;
|
|
||||||
|
|
||||||
logger_->debug("Volume time updated: {}",
|
|
||||||
scwx::util::TimeString(adjustedTime_));
|
|
||||||
|
|
||||||
Q_EMIT self_->LiveStateUpdated(false);
|
|
||||||
Q_EMIT self_->VolumeTimeUpdated(adjustedTime_);
|
|
||||||
Q_EMIT self_->SelectedTimeUpdated(adjustedTime_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Only if we aren't at the end of the volume times set
|
// Cannot step forward any further
|
||||||
if (it != std::prev(volumeTimes.cend()))
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock prior to selecting time
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
// Lock radar sweep monitor
|
||||||
|
std::unique_lock radarSweepMonitorLock {radarSweepMonitorMutex_};
|
||||||
|
|
||||||
|
// Attempt to step forward or backward up to 30 minutes until an update is
|
||||||
|
// received on at least one map
|
||||||
|
for (std::size_t i = 0; i < 30; ++i)
|
||||||
{
|
{
|
||||||
// Select the next time
|
using namespace std::chrono_literals;
|
||||||
adjustedTime_ = *(++it);
|
|
||||||
selectedTime_ = adjustedTime_;
|
|
||||||
|
|
||||||
logger_->debug("Volume time updated: {}",
|
// Increment/decrement selected time by one minute
|
||||||
scwx::util::TimeString(adjustedTime_));
|
if (direction == Direction::Back)
|
||||||
|
{
|
||||||
|
newTime -= 1min;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newTime += 1min;
|
||||||
|
|
||||||
Q_EMIT self_->LiveStateUpdated(false);
|
// If the new time is more than 2 minutes in the future, stop stepping
|
||||||
Q_EMIT self_->VolumeTimeUpdated(adjustedTime_);
|
if (newTime > std::chrono::system_clock::now() + 2min)
|
||||||
Q_EMIT self_->SelectedTimeUpdated(adjustedTime_);
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset radar sweep monitor in preparation for update
|
||||||
|
RadarSweepMonitorReset();
|
||||||
|
|
||||||
|
// Select the time
|
||||||
|
SelectTime(newTime);
|
||||||
|
|
||||||
|
// Wait for radar sweeps to update
|
||||||
|
RadarSweepMonitorWait(radarSweepMonitorLock);
|
||||||
|
|
||||||
|
// Check for updates
|
||||||
|
if (!radarSweepsUpdated_.empty())
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue