fix blobs dirty tracking #87
@@ -85,6 +85,8 @@ void BlobGroup::markShapeDirty(BlobShape* source) {
|
|||||||
const QRectF otherRect(static_cast<double>(shape->m_cachedPaddedX), static_cast<double>(shape->m_cachedPaddedY),
|
const QRectF otherRect(static_cast<double>(shape->m_cachedPaddedX), static_cast<double>(shape->m_cachedPaddedY),
|
||||||
static_cast<double>(shape->m_cachedPaddedW), static_cast<double>(shape->m_cachedPaddedH));
|
static_cast<double>(shape->m_cachedPaddedW), static_cast<double>(shape->m_cachedPaddedH));
|
||||||
if (srcRect.intersects(otherRect)) {
|
if (srcRect.intersects(otherRect)) {
|
||||||
|
shape->setExpandedRect(srcRect);
|
||||||
|
shape->m_hasExpandedRect = true;
|
||||||
shape->polish();
|
shape->polish();
|
||||||
shape->update();
|
shape->update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,26 +69,6 @@ void BlobShape::geometryChange(const QRectF& newGeometry, const QRectF& oldGeome
|
|||||||
QQuickItem::geometryChange(newGeometry, oldGeometry);
|
QQuickItem::geometryChange(newGeometry, oldGeometry);
|
||||||
updateCenteredDeformMatrix();
|
updateCenteredDeformMatrix();
|
||||||
if (m_group) {
|
if (m_group) {
|
||||||
// Update cached values so markShapeDirty uses current geometry
|
|
||||||
const QPointF scenePos = mapToScene(QPointF(0, 0));
|
|
||||||
if (isInvertedRect()) {
|
|
||||||
m_cachedPaddedX = static_cast<float>(scenePos.x());
|
|
||||||
m_cachedPaddedY = static_cast<float>(scenePos.y());
|
|
||||||
m_cachedPaddedW = static_cast<float>(width());
|
|
||||||
m_cachedPaddedH = static_cast<float>(height());
|
|
||||||
m_localPaddedRect = QRectF(0, 0, width(), height());
|
|
||||||
} else {
|
|
||||||
const float hw = static_cast<float>(width()) * 0.5f;
|
|
||||||
const float hh = static_cast<float>(height()) * 0.5f;
|
|
||||||
const float totalPad = static_cast<float>(m_group->smoothing()) + deformPadding(m_deformMatrix, hw, hh);
|
|
||||||
m_cachedPaddedX = static_cast<float>(scenePos.x()) - totalPad;
|
|
||||||
m_cachedPaddedY = static_cast<float>(scenePos.y()) - totalPad;
|
|
||||||
m_cachedPaddedW = static_cast<float>(width()) + 2.0f * totalPad;
|
|
||||||
m_cachedPaddedH = static_cast<float>(height()) + 2.0f * totalPad;
|
|
||||||
m_localPaddedRect = QRectF(static_cast<double>(-totalPad), static_cast<double>(-totalPad),
|
|
||||||
width() + 2.0 * static_cast<double>(totalPad), height() + 2.0 * static_cast<double>(totalPad));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accumulate sub-pixel drift so slow movements don't desync the shader
|
// Accumulate sub-pixel drift so slow movements don't desync the shader
|
||||||
m_pendingDx += static_cast<float>(newGeometry.x() - oldGeometry.x());
|
m_pendingDx += static_cast<float>(newGeometry.x() - oldGeometry.x());
|
||||||
m_pendingDy += static_cast<float>(newGeometry.y() - oldGeometry.y());
|
m_pendingDy += static_cast<float>(newGeometry.y() - oldGeometry.y());
|
||||||
@@ -138,6 +118,8 @@ void BlobShape::updatePolish() {
|
|||||||
if (!m_group)
|
if (!m_group)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_hasExpandedRect = false;
|
||||||
|
|
||||||
// Ensure all shapes have up-to-date physics (only once per frame)
|
// Ensure all shapes have up-to-date physics (only once per frame)
|
||||||
m_group->ensurePhysicsUpdated();
|
m_group->ensurePhysicsUpdated();
|
||||||
|
|
||||||
@@ -189,6 +171,8 @@ void BlobShape::updatePolish() {
|
|||||||
bool include = false;
|
bool include = false;
|
||||||
if (isInvertedRect()) {
|
if (isInvertedRect()) {
|
||||||
include = true;
|
include = true;
|
||||||
|
} else if (m_hasExpandedRect) {
|
||||||
|
include = m_expandedRect.intersects(otherPadded);
|
||||||
} else {
|
} else {
|
||||||
const float otherHW = static_cast<float>(other->width()) * 0.5f;
|
const float otherHW = static_cast<float>(other->width()) * 0.5f;
|
||||||
const float otherHH = static_cast<float>(other->height()) * 0.5f;
|
const float otherHH = static_cast<float>(other->height()) * 0.5f;
|
||||||
|
|||||||
@@ -70,6 +70,16 @@ virtual void registerWithGroup();
|
|||||||
virtual void unregisterFromGroup();
|
virtual void unregisterFromGroup();
|
||||||
void updateCenteredDeformMatrix();
|
void updateCenteredDeformMatrix();
|
||||||
|
|
||||||
|
void setExpandedRect(const QRectF& rect) {
|
||||||
|
m_expandedRect = rect;
|
||||||
|
}
|
||||||
|
const QRectF& expandedRect() const {
|
||||||
|
return m_expandedRect;
|
||||||
|
}
|
||||||
|
bool hasExpandedRect() const {
|
||||||
|
return m_hasExpandedRect;
|
||||||
|
}
|
||||||
|
|
||||||
BlobGroup* m_group = nullptr;
|
BlobGroup* m_group = nullptr;
|
||||||
qreal m_radius = 0;
|
qreal m_radius = 0;
|
||||||
QMatrix4x4 m_deformMatrix; // identity by default
|
QMatrix4x4 m_deformMatrix; // identity by default
|
||||||
@@ -89,4 +99,7 @@ bool m_cachedHasInverted = false;
|
|||||||
float m_cachedInvertedRadius = 0;
|
float m_cachedInvertedRadius = 0;
|
||||||
float m_cachedInvertedOuter[4] = {};
|
float m_cachedInvertedOuter[4] = {};
|
||||||
float m_cachedInvertedInner[4] = {};
|
float m_cachedInvertedInner[4] = {};
|
||||||
|
|
||||||
|
QRectF m_expandedRect;
|
||||||
|
bool m_hasExpandedRect = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user