Fixed blobs paint with high update rate.
This commit is contained in:
parent
120a52c143
commit
9ebd51c8f8
4 changed files with 37 additions and 12 deletions
|
|
@ -52,11 +52,12 @@ void Blob::generateSingleValues(int i) {
|
||||||
+ kSegmentSpeedDiff * std::abs(RandomAdditional());
|
+ 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++) {
|
for (auto i = 0; i < _segmentsCount; i++) {
|
||||||
auto &segment = segmentAt(i);
|
auto &segment = segmentAt(i);
|
||||||
segment.progress += (segment.speed * _minSpeed)
|
segment.progress += (_minSpeed + level * _maxSpeed * speedScale)
|
||||||
+ level * segment.speed * _maxSpeed * speedScale;
|
* segment.speed
|
||||||
|
* rate;
|
||||||
if (segment.progress >= 1) {
|
if (segment.progress >= 1) {
|
||||||
generateSingleValues(i);
|
generateSingleValues(i);
|
||||||
generateTwoValues(i);
|
generateTwoValues(i);
|
||||||
|
|
@ -152,9 +153,9 @@ void RadialBlob::generateTwoValues(int i) {
|
||||||
radius.setNext(_radiuses.min + std::abs(RandomAdditional()) * radDiff);
|
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;
|
_scale = level;
|
||||||
Blob::update(level, speedScale);
|
Blob::update(level, speedScale, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
Blob::Segment &RadialBlob::segmentAt(int i) {
|
Blob::Segment &RadialBlob::segmentAt(int i) {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public:
|
||||||
Blob(int n, float minSpeed = 0, float maxSpeed = 0);
|
Blob(int n, float minSpeed = 0, float maxSpeed = 0);
|
||||||
virtual ~Blob() = default;
|
virtual ~Blob() = default;
|
||||||
|
|
||||||
void update(float level, float speedScale);
|
void update(float level, float speedScale, float64 rate);
|
||||||
void generateBlob();
|
void generateBlob();
|
||||||
|
|
||||||
void setRadiuses(Radiuses values);
|
void setRadiuses(Radiuses values);
|
||||||
|
|
@ -59,7 +59,7 @@ public:
|
||||||
RadialBlob(int n, float minScale, float minSpeed = 0, float maxSpeed = 0);
|
RadialBlob(int n, float minScale, float minSpeed = 0, float maxSpeed = 0);
|
||||||
|
|
||||||
void paint(Painter &p, const QBrush &brush, float outerScale = 1.);
|
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:
|
private:
|
||||||
struct Segment : Blob::Segment {
|
struct Segment : Blob::Segment {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,13 @@
|
||||||
|
|
||||||
namespace Ui::Paint {
|
namespace Ui::Paint {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kRateLimitF = 1000. / 60.;
|
||||||
|
constexpr auto kRateLimit = int(kRateLimitF + 0.5); // Round.
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
Blobs::Blobs(
|
Blobs::Blobs(
|
||||||
std::vector<BlobData> blobDatas,
|
std::vector<BlobData> blobDatas,
|
||||||
float levelDuration,
|
float levelDuration,
|
||||||
|
|
@ -76,7 +83,6 @@ void Blobs::resetLevel() {
|
||||||
void Blobs::paint(Painter &p, const QBrush &brush, float outerScale) {
|
void Blobs::paint(Painter &p, const QBrush &brush, float outerScale) {
|
||||||
const auto opacity = p.opacity();
|
const auto opacity = p.opacity();
|
||||||
for (auto i = 0; i < _blobs.size(); i++) {
|
for (auto i = 0; i < _blobs.size(); i++) {
|
||||||
_blobs[i].update(_levelValue.current(), _blobDatas[i].speedScale);
|
|
||||||
const auto alpha = _blobDatas[i].alpha;
|
const auto alpha = _blobDatas[i].alpha;
|
||||||
if (alpha != 1.) {
|
if (alpha != 1.) {
|
||||||
p.setOpacity(opacity * alpha);
|
p.setOpacity(opacity * alpha);
|
||||||
|
|
@ -89,7 +95,15 @@ void Blobs::paint(Painter &p, const QBrush &brush, float outerScale) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blobs::updateLevel(crl::time dt) {
|
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 {
|
float64 Blobs::currentLevel() const {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,13 @@
|
||||||
|
|
||||||
namespace Ui::Paint {
|
namespace Ui::Paint {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kRateLimitF = 1000. / 60.;
|
||||||
|
constexpr auto kRateLimit = int(kRateLimitF + 0.5); // Round.
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
LinearBlobs::LinearBlobs(
|
LinearBlobs::LinearBlobs(
|
||||||
std::vector<BlobData> blobDatas,
|
std::vector<BlobData> blobDatas,
|
||||||
float levelDuration,
|
float levelDuration,
|
||||||
|
|
@ -75,7 +82,6 @@ void LinearBlobs::paint(Painter &p, const QBrush &brush, int width) {
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
const auto opacity = p.opacity();
|
const auto opacity = p.opacity();
|
||||||
for (auto i = 0; i < _blobs.size(); i++) {
|
for (auto i = 0; i < _blobs.size(); i++) {
|
||||||
_blobs[i].update(_levelValue.current(), _blobDatas[i].speedScale);
|
|
||||||
const auto alpha = _blobDatas[i].alpha;
|
const auto alpha = _blobDatas[i].alpha;
|
||||||
if (alpha != 1.) {
|
if (alpha != 1.) {
|
||||||
p.setOpacity(opacity * alpha);
|
p.setOpacity(opacity * alpha);
|
||||||
|
|
@ -88,8 +94,8 @@ void LinearBlobs::paint(Painter &p, const QBrush &brush, int width) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinearBlobs::updateLevel(crl::time dt) {
|
void LinearBlobs::updateLevel(crl::time dt) {
|
||||||
const auto d = (dt > 20) ? 17 : dt;
|
const auto limitedDt = (dt > 20) ? kRateLimit : dt;
|
||||||
_levelValue.update(d);
|
_levelValue.update(limitedDt);
|
||||||
|
|
||||||
const auto level = (float)currentLevel();
|
const auto level = (float)currentLevel();
|
||||||
for (auto i = 0; i < _blobs.size(); i++) {
|
for (auto i = 0; i < _blobs.size(); i++) {
|
||||||
|
|
@ -97,6 +103,10 @@ void LinearBlobs::updateLevel(crl::time dt) {
|
||||||
_blobs[i].setRadiuses({
|
_blobs[i].setRadiuses({
|
||||||
data.minRadius,
|
data.minRadius,
|
||||||
data.idleRadius + (data.maxRadius - data.idleRadius) * level });
|
data.idleRadius + (data.maxRadius - data.idleRadius) * level });
|
||||||
|
_blobs[i].update(
|
||||||
|
_levelValue.current(),
|
||||||
|
data.speedScale,
|
||||||
|
limitedDt / kRateLimitF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue