remove layer usage to reduce vram consumption
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
#include <cmath>
|
||||
#include <qnamespace.h>
|
||||
|
||||
namespace {
|
||||
constexpr float k_retireMs = 120.0f;
|
||||
}
|
||||
|
||||
BlobRect::BlobRect(QQuickItem* parent) : BlobShape(parent) {}
|
||||
|
||||
BlobRect::~BlobRect() {
|
||||
@@ -12,41 +16,75 @@ BlobRect::~BlobRect() {
|
||||
}
|
||||
|
||||
void BlobRect::updatePolish() {
|
||||
if (m_physicsActive) {
|
||||
float totalDelta = std::abs(m_dm00 - 1.0f) + std::abs(m_dm01) +
|
||||
std::abs(m_dm11 - 1.0f);
|
||||
float totalVel =
|
||||
std::abs(m_dmVel00) + std::abs(m_dmVel01) + std::abs(m_dmVel11);
|
||||
BlobShape::updatePolish();
|
||||
|
||||
if (totalDelta < 0.004f && totalVel < 0.05f) {
|
||||
if (!m_physicsActive) return;
|
||||
|
||||
if (m_retiring) {
|
||||
const float t = std::clamp(
|
||||
static_cast<float>(m_retireElapsed.elapsed()) / k_retireMs,
|
||||
0.0f,
|
||||
1.0f);
|
||||
const float s = t * t * (3.0f - 2.0f * t);
|
||||
|
||||
if (t >= 1.0f) {
|
||||
m_dm00 = 1.0f;
|
||||
m_dm01 = 0.0f;
|
||||
m_dm11 = 1.0f;
|
||||
m_dmVel00 = m_dmVel01 = m_dmVel11 = 0.0f;
|
||||
m_deformMatrix = QMatrix4x4();
|
||||
emit rawDeformMatrixChanged();
|
||||
updateCenteredDeformMatrix();
|
||||
m_retiring = false;
|
||||
m_physicsActive = false;
|
||||
|
||||
if (m_group) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() {
|
||||
if (m_group) m_group->markDirty();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
} else {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() {
|
||||
if (m_physicsActive && m_group) m_group->markDirty();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
m_dm00 = m_retire00 + (1.0f - m_retire00) * s;
|
||||
m_dm01 = m_retire01 - m_retire01 * s;
|
||||
m_dm11 = m_retire11 + (1.0f - m_retire11) * s;
|
||||
m_deformMatrix = QMatrix4x4(
|
||||
m_dm00,
|
||||
m_dm01,
|
||||
0,
|
||||
0,
|
||||
m_dm01,
|
||||
m_dm11,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1);
|
||||
}
|
||||
|
||||
emit rawDeformMatrixChanged();
|
||||
updateCenteredDeformMatrix();
|
||||
|
||||
if (!m_physicsActive) return;
|
||||
} else {
|
||||
const float totalDelta = std::abs(m_dm00 - 1.0f) + std::abs(m_dm01) +
|
||||
std::abs(m_dm11 - 1.0f);
|
||||
const float totalVel =
|
||||
std::abs(m_dmVel00) + std::abs(m_dmVel01) + std::abs(m_dmVel11);
|
||||
|
||||
if (totalDelta < 0.004f && totalVel < 0.05f) beginRetire();
|
||||
}
|
||||
|
||||
BlobShape::updatePolish();
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() {
|
||||
if (m_physicsActive && m_group) m_group->markDirty();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void BlobRect::beginRetire() {
|
||||
m_retire00 = m_dm00;
|
||||
m_retire01 = m_dm01;
|
||||
m_retire11 = m_dm11;
|
||||
m_dmVel00 = m_dmVel01 = m_dmVel11 = 0.0f;
|
||||
m_retireElapsed.start();
|
||||
m_retiring = true;
|
||||
}
|
||||
|
||||
void BlobRect::updatePhysics() {
|
||||
@@ -74,6 +112,13 @@ void BlobRect::updatePhysics() {
|
||||
|
||||
const float speed = std::sqrt(velX * velX + velY * velY);
|
||||
|
||||
if (m_retiring) {
|
||||
if (speed > 5.0f)
|
||||
m_retiring = false;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_physicsActive) {
|
||||
if (speed < 5.0f) return;
|
||||
m_physicsActive = true;
|
||||
@@ -297,6 +342,8 @@ void BlobRect::excludeCornersRemoveLast(QQmlListProperty<BlobRect>* prop) {
|
||||
}
|
||||
|
||||
void BlobRect::checkAtRest(float speed) {
|
||||
if (m_retiring) return;
|
||||
|
||||
constexpr float kEpsilon = 0.002f;
|
||||
const bool atRest =
|
||||
std::abs(m_dm00 - 1.0f) < kEpsilon && std::abs(m_dm01) < kEpsilon &&
|
||||
@@ -304,25 +351,5 @@ void BlobRect::checkAtRest(float speed) {
|
||||
std::abs(m_dmVel01) < kEpsilon && std::abs(m_dmVel11) < kEpsilon &&
|
||||
speed < 5.0f;
|
||||
|
||||
if (atRest) {
|
||||
m_dm00 = 1.0f;
|
||||
m_dm01 = 0.0f;
|
||||
m_dm11 = 1.0f;
|
||||
m_dmVel00 = 0.0f;
|
||||
m_dmVel01 = 0.0f;
|
||||
m_dmVel11 = 0.0f;
|
||||
m_deformMatrix = QMatrix4x4();
|
||||
emit rawDeformMatrixChanged();
|
||||
updateCenteredDeformMatrix();
|
||||
m_physicsActive = false;
|
||||
|
||||
if (m_group) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() {
|
||||
if (m_group) m_group->markDirty();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
if (atRest) beginRetire();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user