Fix high CPU use caused by ItemParticle

This commit is contained in:
Nicolas Werner 2023-10-09 03:48:58 +02:00
parent 2a687a202a
commit 25f19c11b1
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -9,6 +9,7 @@ Item {
id: effectRoot id: effectRoot
readonly property int maxLifespan: Math.max(confettiEmitter.lifeSpan, rainfallEmitter.lifeSpan) readonly property int maxLifespan: Math.max(confettiEmitter.lifeSpan, rainfallEmitter.lifeSpan)
required property bool shouldEffectsRun required property bool shouldEffectsRun
visible: effectRoot.shouldEffectsRun
function pulseConfetti() function pulseConfetti()
{ {
@ -25,11 +26,13 @@ Item {
Component.onCompleted: pause(); Component.onCompleted: pause();
paused: !effectRoot.shouldEffectsRun paused: !effectRoot.shouldEffectsRun
running: effectRoot.shouldEffectsRun
} }
Emitter { Emitter {
id: confettiEmitter id: confettiEmitter
Component.onCompleted: stop();
group: "confetti" group: "confetti"
width: effectRoot.width * 3/4 width: effectRoot.width * 3/4
enabled: false enabled: false
@ -89,25 +92,46 @@ Item {
enabled: false enabled: false
anchors.horizontalCenter: effectRoot.horizontalCenter anchors.horizontalCenter: effectRoot.horizontalCenter
y: -60 y: -60
emitRate: effectRoot.width / 50 emitRate: effectRoot.width / 30
lifeSpan: 10000 lifeSpan: 10000
system: particleSystem system: particleSystem
velocity: PointDirection { velocity: PointDirection {
x: 0 x: 0
y: 300 y: 400
xVariation: 0 xVariation: 0
yVariation: 75 yVariation: 75
} }
ItemParticle { // causes high CPU load, see: https://bugreports.qt.io/browse/QTBUG-117923
//ItemParticle {
// system: particleSystem
// groups: ["rain"]
// fade: false
// visible: effectRoot.shouldEffectsRun
// delegate: Rectangle {
// width: 2
// height: 30 + 30 * Math.random()
// radius: 2
// color: "#0099ff"
// }
//}
ImageParticle {
system: particleSystem system: particleSystem
groups: ["rain"] groups: ["rain"]
fade: false source: "qrc:/confettiparticle.svg"
delegate: Rectangle { rotationVelocity: 0
width: 2 rotationVelocityVariation: 0
height: 30 + 30 * Math.random() colorVariation: 0
radius: 2
color: "#0099ff" color: "#0099ff"
entryEffect: ImageParticle.None
xVector: PointDirection {
x: 0.01
y: 0
}
yVector: PointDirection {
x: 0
y: 5
} }
} }
} }