Fixed blobs paint with high update rate.

This commit is contained in:
23rd 2021-01-02 14:35:02 +03:00 committed by John Preston
parent 120a52c143
commit 9ebd51c8f8
4 changed files with 37 additions and 12 deletions

View file

@ -52,11 +52,12 @@ void Blob::generateSingleValues(int i) {
+ kSegmentSpeedDiff * std::abs(RandomAdditional());
}
void Blob::update(float level, float speedScale) {
void Blob::update(float level, float speedScale, float64 rate) {
for (auto i = 0; i < _segmentsCount; i++) {
auto &segment = segmentAt(i);
segment.progress += (segment.speed * _minSpeed)
+ level * segment.speed * _maxSpeed * speedScale;
segment.progress += (_minSpeed + level * _maxSpeed * speedScale)
* segment.speed
* rate;
if (segment.progress >= 1) {
generateSingleValues(i);
generateTwoValues(i);
@ -152,9 +153,9 @@ void RadialBlob::generateTwoValues(int i) {
radius.setNext(_radiuses.min + std::abs(RandomAdditional()) * radDiff);
}
void RadialBlob::update(float level, float speedScale) {
void RadialBlob::update(float level, float speedScale, float64 rate) {
_scale = level;
Blob::update(level, speedScale);
Blob::update(level, speedScale, rate);
}
Blob::Segment &RadialBlob::segmentAt(int i) {

View file

@ -20,7 +20,7 @@ public:
Blob(int n, float minSpeed = 0, float maxSpeed = 0);
virtual ~Blob() = default;
void update(float level, float speedScale);
void update(float level, float speedScale, float64 rate);
void generateBlob();
void setRadiuses(Radiuses values);
@ -59,7 +59,7 @@ public:
RadialBlob(int n, float minScale, float minSpeed = 0, float maxSpeed = 0);
void paint(Painter &p, const QBrush &brush, float outerScale = 1.);
void update(float level, float speedScale);
void update(float level, float speedScale, float64 rate);
private:
struct Segment : Blob::Segment {

View file

@ -10,6 +10,13 @@
namespace Ui::Paint {
namespace {
constexpr auto kRateLimitF = 1000. / 60.;
constexpr auto kRateLimit = int(kRateLimitF + 0.5); // Round.
} // namespace
Blobs::Blobs(
std::vector<BlobData> blobDatas,
float levelDuration,
@ -76,7 +83,6 @@ void Blobs::resetLevel() {
void Blobs::paint(Painter &p, const QBrush &brush, float outerScale) {
const auto opacity = p.opacity();
for (auto i = 0; i < _blobs.size(); i++) {
_blobs[i].update(_levelValue.current(), _blobDatas[i].speedScale);
const auto alpha = _blobDatas[i].alpha;
if (alpha != 1.) {
p.setOpacity(opacity * alpha);
@ -89,7 +95,15 @@ void Blobs::paint(Painter &p, const QBrush &brush, float outerScale) {
}
void Blobs::updateLevel(crl::time dt) {
_levelValue.update((dt > 20) ? 17 : dt);
const auto limitedDt = (dt > 20) ? kRateLimit : dt;
_levelValue.update(limitedDt);
for (auto i = 0; i < _blobs.size(); i++) {
_blobs[i].update(
_levelValue.current(),
_blobDatas[i].speedScale,
limitedDt / kRateLimitF);
}
}
float64 Blobs::currentLevel() const {

View file

@ -10,6 +10,13 @@
namespace Ui::Paint {
namespace {
constexpr auto kRateLimitF = 1000. / 60.;
constexpr auto kRateLimit = int(kRateLimitF + 0.5); // Round.
} // namespace
LinearBlobs::LinearBlobs(
std::vector<BlobData> blobDatas,
float levelDuration,
@ -75,7 +82,6 @@ void LinearBlobs::paint(Painter &p, const QBrush &brush, int width) {
PainterHighQualityEnabler hq(p);
const auto opacity = p.opacity();
for (auto i = 0; i < _blobs.size(); i++) {
_blobs[i].update(_levelValue.current(), _blobDatas[i].speedScale);
const auto alpha = _blobDatas[i].alpha;
if (alpha != 1.) {
p.setOpacity(opacity * alpha);
@ -88,8 +94,8 @@ void LinearBlobs::paint(Painter &p, const QBrush &brush, int width) {
}
void LinearBlobs::updateLevel(crl::time dt) {
const auto d = (dt > 20) ? 17 : dt;
_levelValue.update(d);
const auto limitedDt = (dt > 20) ? kRateLimit : dt;
_levelValue.update(limitedDt);
const auto level = (float)currentLevel();
for (auto i = 0; i < _blobs.size(); i++) {
@ -97,6 +103,10 @@ void LinearBlobs::updateLevel(crl::time dt) {
_blobs[i].setRadiuses({
data.minRadius,
data.idleRadius + (data.maxRadius - data.idleRadius) * level });
_blobs[i].update(
_levelValue.current(),
data.speedScale,
limitedDt / kRateLimitF);
}
}