New SkCurve type with multiple curve segments
- Converted all linear force stuff into a single affector,
used at either spawn or update time appropriately.
The new affector can either set or adjust velocity.
- Converted lifetime to a curve.
- Removed SkRangedFloat, initial velocity params, etc.
Looks like a large addition, but that's mostly down to the
JSON getting bigger. There's a net reduction in LoC.
Bug: skia:
Change-Id: Iac7417f15f96d0313efd08c4b26dc3250b80fa77
Reviewed-on: https://skia-review.googlesource.com/c/192102
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/modules/particles/include/SkCurve.h b/modules/particles/include/SkCurve.h
index 3b9bfc4..cca41a1 100644
--- a/modules/particles/include/SkCurve.h
+++ b/modules/particles/include/SkCurve.h
@@ -9,36 +9,39 @@
#define SkCurve_DEFINED
#include "SkScalar.h"
+#include "SkTArray.h"
class SkFieldVisitor;
class SkRandom;
-// TODO: Generalize this to a keyframed list of cubics
+struct SkCurveSegment {
+ SkScalar eval(SkScalar x, SkRandom& random) const;
+ void visitFields(SkFieldVisitor* v);
+
+ void setConstant(SkScalar c) {
+ fConstant = true;
+ fRanged = false;
+ fMin[0] = c;
+ }
+
+ SkScalar fMin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+ SkScalar fMax[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+
+ bool fConstant = true;
+ bool fRanged = false;
+ bool fBidirectional = false;
+};
struct SkCurve {
SkCurve(SkScalar c = 0.0f) {
- fRanged = false;
- fMin[0] = fMin[1] = fMin[2] = fMin[3] = c;
- fMax[0] = fMax[1] = fMax[2] = fMax[3] = c;
+ fSegments.push_back().setConstant(c);
}
- SkScalar eval(float x, SkRandom& random) const;
+ SkScalar eval(SkScalar x, SkRandom& random) const;
void visitFields(SkFieldVisitor* v);
- bool fRanged;
- SkScalar fMin[4];
- SkScalar fMax[4]; // used if ranged
-};
-
-// Ranged constant. Keeping this here temporarily. Phase this out in favor of SkCurve everywhere.
-struct SkRangedFloat {
- float eval(SkRandom& random) const;
- float* vec() { return &fMin; }
-
- float fMin = 0.0f;
- float fMax = 0.0f;
-
- void visitFields(SkFieldVisitor* v);
+ SkTArray<SkScalar, true> fXValues;
+ SkTArray<SkCurveSegment, true> fSegments;
};
#endif // SkCurve_DEFINED