[MetaballsKit] Fix up didSet responder for Field.size

This commit is contained in:
Eryn Wells 2017-08-04 21:10:52 -07:00
parent da5c664ee6
commit 22fbaed88c

View file

@ -36,9 +36,19 @@ public struct Ball {
public class Field { public class Field {
public var size: CGSize { public var size: CGSize {
didSet { didSet {
// Remove balls that fall outside the new bounds. if size != oldValue {
balls = balls.filter { bounds.contains($0.bounds) } let numberOfBallsBeforeFilter = balls.count
updateThreadgroupSizes(withFieldSize: size)
// Remove balls that fall outside the new bounds.
balls = balls.filter { bounds.contains($0.bounds) }
// Update Metal state as needed.
updateThreadgroupSizes(withFieldSize: size)
sampleTexture = nil
if numberOfBallsBeforeFilter != balls.count {
ballBuffer = nil
}
}
} }
} }