remove layer usage to reduce vram consumption
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
#pragma once
|
||||
|
||||
#include "blobshape2.hpp"
|
||||
|
||||
#include <qelapsedtimer.h>
|
||||
#include <qpointer.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <qqmllist.h>
|
||||
|
||||
class BlobRect2 : public BlobShape2 {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
Q_PROPERTY(
|
||||
qreal stiffness READ stiffness WRITE setStiffness NOTIFY
|
||||
stiffnessChanged)
|
||||
Q_PROPERTY(qreal damping READ damping WRITE setDamping NOTIFY dampingChanged)
|
||||
Q_PROPERTY(
|
||||
qreal deformScale READ deformScale WRITE setDeformScale NOTIFY
|
||||
deformScaleChanged)
|
||||
Q_PROPERTY(
|
||||
QQmlListProperty<BlobRect2> exclude READ exclude NOTIFY excludeChanged)
|
||||
Q_PROPERTY(
|
||||
QQmlListProperty<BlobRect2> excludeCorners READ excludeCorners NOTIFY
|
||||
excludeCornersChanged)
|
||||
Q_PROPERTY(
|
||||
qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius NOTIFY
|
||||
topLeftRadiusChanged)
|
||||
Q_PROPERTY(
|
||||
qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY
|
||||
topRightRadiusChanged)
|
||||
Q_PROPERTY(
|
||||
qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius
|
||||
NOTIFY bottomLeftRadiusChanged)
|
||||
Q_PROPERTY(
|
||||
qreal bottomRightRadius READ bottomRightRadius WRITE
|
||||
setBottomRightRadius NOTIFY bottomRightRadiusChanged)
|
||||
|
||||
public:
|
||||
explicit BlobRect2(QQuickItem* parent = nullptr);
|
||||
~BlobRect2() override;
|
||||
|
||||
[[nodiscard]] qreal stiffness() const { return m_stiffness; }
|
||||
|
||||
void setStiffness(qreal s) {
|
||||
if (!qFuzzyCompare(m_stiffness, s)) {
|
||||
m_stiffness = s;
|
||||
emit stiffnessChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] qreal damping() const { return m_damping; }
|
||||
|
||||
void setDamping(qreal value) {
|
||||
if (!qFuzzyCompare(m_damping, value)) {
|
||||
m_damping = value;
|
||||
emit dampingChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] qreal deformScale() const { return m_deformScale; }
|
||||
|
||||
void setDeformScale(qreal s) {
|
||||
if (!qFuzzyCompare(m_deformScale, s)) {
|
||||
m_deformScale = s;
|
||||
emit deformScaleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QQmlListProperty<BlobRect2> exclude();
|
||||
QQmlListProperty<BlobRect2> excludeCorners();
|
||||
|
||||
bool isExcluded(const BlobShape2* other) const override;
|
||||
bool isCornerExcluded(const BlobShape2* other) const override;
|
||||
void cornerRadii(float out[4]) const override;
|
||||
|
||||
[[nodiscard]] qreal topLeftRadius() const { return m_topLeftRadius; }
|
||||
|
||||
void setTopLeftRadius(qreal r);
|
||||
|
||||
[[nodiscard]] qreal topRightRadius() const { return m_topRightRadius; }
|
||||
|
||||
void setTopRightRadius(qreal r);
|
||||
|
||||
[[nodiscard]] qreal bottomLeftRadius() const { return m_bottomLeftRadius; }
|
||||
|
||||
void setBottomLeftRadius(qreal r);
|
||||
|
||||
[[nodiscard]] qreal bottomRightRadius() const {
|
||||
return m_bottomRightRadius;
|
||||
}
|
||||
|
||||
void setBottomRightRadius(qreal r);
|
||||
|
||||
signals:
|
||||
void stiffnessChanged();
|
||||
void dampingChanged();
|
||||
void deformScaleChanged();
|
||||
void excludeChanged();
|
||||
void excludeCornersChanged();
|
||||
void topLeftRadiusChanged();
|
||||
void topRightRadiusChanged();
|
||||
void bottomLeftRadiusChanged();
|
||||
void bottomRightRadiusChanged();
|
||||
|
||||
protected:
|
||||
void updatePhysics() override;
|
||||
|
||||
private:
|
||||
void checkAtRest(float speed);
|
||||
void beginRetire();
|
||||
void finishAtIdentity();
|
||||
|
||||
// Physics state
|
||||
QPointF m_prevScenePos;
|
||||
QElapsedTimer m_elapsed;
|
||||
bool m_physicsActive = false;
|
||||
bool m_hasPrevPos = false;
|
||||
|
||||
bool m_retiring = false;
|
||||
QElapsedTimer m_retireElapsed;
|
||||
float m_retire00 = 1.0f;
|
||||
float m_retire01 = 0.0f;
|
||||
float m_retire11 = 1.0f;
|
||||
|
||||
// Symmetric 2x2 deformation matrix components (3 independent: m00, m01,
|
||||
// m11) Rest state is identity: m00=1, m01=0, m11=1
|
||||
float m_dm00 = 1.0f;
|
||||
float m_dm01 = 0.0f;
|
||||
float m_dm11 = 1.0f;
|
||||
|
||||
// Spring velocities for each component
|
||||
float m_dmVel00 = 0.0f;
|
||||
float m_dmVel01 = 0.0f;
|
||||
float m_dmVel11 = 0.0f;
|
||||
|
||||
qreal m_stiffness = 200.0;
|
||||
qreal m_damping = 16.0;
|
||||
qreal m_deformScale = 0.0005;
|
||||
|
||||
qreal m_topLeftRadius = -1;
|
||||
qreal m_topRightRadius = -1;
|
||||
qreal m_bottomLeftRadius = -1;
|
||||
qreal m_bottomRightRadius = -1;
|
||||
|
||||
QList<QPointer<BlobRect2>> m_exclude;
|
||||
QList<QPointer<BlobRect2>> m_excludeCorners;
|
||||
|
||||
static void excludeAppend(
|
||||
QQmlListProperty<BlobRect2>* prop, BlobRect2* rect);
|
||||
static qsizetype excludeCount(QQmlListProperty<BlobRect2>* prop);
|
||||
static BlobRect2* excludeAt(
|
||||
QQmlListProperty<BlobRect2>* prop, qsizetype index);
|
||||
static void excludeClear(QQmlListProperty<BlobRect2>* prop);
|
||||
static void excludeReplace(
|
||||
QQmlListProperty<BlobRect2>* prop, qsizetype index, BlobRect2* rect);
|
||||
static void excludeRemoveLast(QQmlListProperty<BlobRect2>* prop);
|
||||
|
||||
static void excludeCornersAppend(
|
||||
QQmlListProperty<BlobRect2>* prop, BlobRect2* rect);
|
||||
static qsizetype excludeCornersCount(QQmlListProperty<BlobRect2>* prop);
|
||||
static BlobRect2* excludeCornersAt(
|
||||
QQmlListProperty<BlobRect2>* prop, qsizetype index);
|
||||
static void excludeCornersClear(QQmlListProperty<BlobRect2>* prop);
|
||||
static void excludeCornersReplace(
|
||||
QQmlListProperty<BlobRect2>* prop, qsizetype index, BlobRect2* rect);
|
||||
static void excludeCornersRemoveLast(QQmlListProperty<BlobRect2>* prop);
|
||||
};
|
||||
Reference in New Issue
Block a user