-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BRAYNS 582 - Return 50% load progress for circuits (#1204)
- Loading branch information
1 parent
4657e8a
commit f551760
Showing
9 changed files
with
57 additions
and
38 deletions.
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
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 |
---|---|---|
@@ -1,30 +1,44 @@ | ||
#include "ProgressUpdater.h" | ||
|
||
ProgressUpdater::ProgressUpdater(const brayns::LoaderProgress &callback, const size_t numStages): | ||
#include <cassert> | ||
|
||
ProgressUpdater::ProgressUpdater(const brayns::LoaderProgress &callback, std::size_t numStages, float maxProgress): | ||
_callback(callback), | ||
_numStages(numStages), | ||
_stageSize(1.f / static_cast<float>(_numStages)), | ||
_stageSize(maxProgress / static_cast<float>(_numStages)), | ||
_currentStage(0), | ||
_currentStageChunkSize(1.f), | ||
_currentStageProgress(0.f) | ||
{ | ||
} | ||
|
||
void ProgressUpdater::beginStage(const size_t numSubElements) | ||
void ProgressUpdater::beginStage(std::string_view message, std::size_t numSubElements) | ||
{ | ||
assert(_currentStageProgress == 0.f); | ||
|
||
_currentMessage = std::string(message); | ||
_currentStageChunkSize = 1.f / static_cast<float>(numSubElements); | ||
} | ||
|
||
void ProgressUpdater::update(const std::string &message) noexcept | ||
void ProgressUpdater::update(std::size_t numSubElementsCompleted) noexcept | ||
{ | ||
const auto globalProgress = (static_cast<float>(_currentStage) + _currentStageProgress) * _stageSize; | ||
_currentStageProgress += _currentStageChunkSize; | ||
_currentStageProgress = _currentStageProgress > 1.f ? 1.f : _currentStageProgress; | ||
_callback.updateProgress(message, globalProgress); | ||
_currentStageProgress += _currentStageChunkSize * static_cast<float>(numSubElementsCompleted); | ||
_currentStageProgress = std::clamp(_currentStageProgress, 0.f, 1.f); | ||
_callback.updateProgress(_currentMessage, globalProgress); | ||
} | ||
|
||
void ProgressUpdater::endStage() | ||
{ | ||
++_currentStage; | ||
_currentStageProgress = 0.f; | ||
// Send a final update after each stage to show complete progress | ||
update(0); | ||
} | ||
|
||
void ProgressUpdater::end(std::string_view message) | ||
{ | ||
assert(_currentStage == _numStages); | ||
|
||
_callback.updateProgress(std::string(message), static_cast<float>(_numStages) * _stageSize); | ||
}; |
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