git.iko.soy/metal-metaballs
on master help sign in
Fixed warnings.
ee36c25Vinicius Vendramini
PixelImage/MetalMetaballRenderer.swift+1−6
@@ -58,7 +58,7 @@ import ChameleonFramework
58
58
59 internal func updateTargetView() {
59 internal func updateTargetView() {
60 let timeout = DispatchTime.now() + Double(1000000000) / Double(NSEC_PER_SEC)
60 let timeout = DispatchTime.now() + Double(1000000000) / Double(NSEC_PER_SEC)
61− semaphore.wait(timeout: timeout)
61+ _ = semaphore.wait(timeout: timeout)
62
62
63 state = .ending
63 state = .ending
64
64
@@ -143,11 +143,6 @@ import ChameleonFramework
143 let bytesPerRow = width * 4
143 let bytesPerRow = width * 4
144 let region = MTLRegionMake2D(0, 0, width, height)
144 let region = MTLRegionMake2D(0, 0, width, height)
145
145
146− // Allocate the buffer if needed
147− if computeContext.imageBuffer == nil {
148− computeContext.imageBuffer = malloc(imageByteCount)
149− }
150−
151 // Transfer texture info into image buffer
146 // Transfer texture info into image buffer
152 texture.getBytes(computeContext.imageBuffer,
147 texture.getBytes(computeContext.imageBuffer,
153 bytesPerRow: bytesPerRow,
148 bytesPerRow: bytesPerRow,
PixelImage/SwiftSugar/PowerOperator.swift+7−1
@@ -1,6 +1,12 @@
1import Darwin
1import Darwin
2
2
3+precedencegroup PowerPrecedence {
4+ higherThan: MultiplicationPrecedence
3−infix operator ^ { associativity right precedence 131 }
5+ associativity: right
6+}
7+
8+//
9+infix operator ^: PowerPrecedence
4
10
5func ^ <T: DoubleValuable>(left: T, right: T) -> T {
11func ^ <T: DoubleValuable>(left: T, right: T) -> T {
6 return T.fromDouble(pow(left.toDouble, right.toDouble))
12 return T.fromDouble(pow(left.toDouble, right.toDouble))
PixelImage/ViewController.swift+11−10
@@ -20,8 +20,9 @@ class ViewController: UIViewController, MetaballDataSource {
20
20
21 view.backgroundColor = UIColor.white
21 view.backgroundColor = UIColor.white
22
22
23− let recognizer = UIPanGestureRecognizer(target: self,
23+ let recognizer = UIPanGestureRecognizer(
24+ target: self,
24− action: "handlePan:")
25+ action: #selector(ViewController.handlePan(_:)))
25 view.addGestureRecognizer(recognizer)
26 view.addGestureRecognizer(recognizer)
26
27
27 var positions = [CGPoint]()
28 var positions = [CGPoint]()
@@ -29,8 +30,8 @@ class ViewController: UIViewController, MetaballDataSource {
29 x: Double(screenWidth) / 2,
30 x: Double(screenWidth) / 2,
30 y: Double(screenHeight) / 2))
31 y: Double(screenHeight) / 2))
31 for i in 1...5 {
32 for i in 1...5 {
32− let sine = sin(Double(i) * 2 * M_PI / 5)
33+ let sine = sin(Double(i) * 2 * .pi / 5)
33− let cosine = cos(Double(i) * 2 * M_PI / 5)
34+ let cosine = cos(Double(i) * 2 * .pi / 5)
34 let radius: Double = 150
35 let radius: Double = 150
35 let x = Double(screenWidth) / 2 + sine * radius
36 let x = Double(screenWidth) / 2 + sine * radius
36 let y = Double(screenHeight) / 2 + cosine * radius
37 let y = Double(screenHeight) / 2 + cosine * radius
@@ -81,8 +82,8 @@ class ViewController: UIViewController, MetaballDataSource {
81 UIView.animate(withDuration: 1.0, delay: 0,
82 UIView.animate(withDuration: 1.0, delay: 0,
82 options: UIViewAnimationOptions(),
83 options: UIViewAnimationOptions(),
83 animations: { () -> Void in
84 animations: { () -> Void in
84− let sine = sin(Double(i) * 2 * M_PI / 5)
85+ let sine = sin(Double(i) * 2 * .pi / 5)
85− let cosine = cos(Double(i) * 2 * M_PI / 5)
86+ let cosine = cos(Double(i) * 2 * .pi / 5)
86 let radius: Double = 85
87 let radius: Double = 85
87 let x = Double(screenWidth) / 2 + sine * radius
88 let x = Double(screenWidth) / 2 + sine * radius
88 let y = Double(screenHeight) / 2 + cosine * radius
89 let y = Double(screenHeight) / 2 + cosine * radius
@@ -99,8 +100,8 @@ class ViewController: UIViewController, MetaballDataSource {
99 initialSpringVelocity: 0,
100 initialSpringVelocity: 0,
100 options: UIViewAnimationOptions(),
101 options: UIViewAnimationOptions(),
101 animations: { () -> Void in
102 animations: { () -> Void in
102− let sine = sin(Double(i) * 2 * M_PI / 5)
103+ let sine = sin(Double(i) * 2 * .pi / 5)
103− let cosine = cos(Double(i) * 2 * M_PI / 5)
104+ let cosine = cos(Double(i) * 2 * .pi / 5)
104 let radius: Double = 150
105 let radius: Double = 150
105 let x = Double(screenWidth) / 2 + sine * radius
106 let x = Double(screenWidth) / 2 + sine * radius
106 let y = Double(screenHeight) / 2 + cosine * radius
107 let y = Double(screenHeight) / 2 + cosine * radius
@@ -130,7 +131,7 @@ class ViewController: UIViewController, MetaballDataSource {
130 Timer.scheduledTimer(
131 Timer.scheduledTimer(
131 timeInterval: 1.0 / 60.0,
132 timeInterval: 1.0 / 60.0,
132 target: self,
133 target: self,
133− selector: "animateMetaballWithTimer:",
134+ selector: #selector(ViewController.animateMetaball(withTimer:)),
134 userInfo: parameters,
135 userInfo: parameters,
135 repeats: true)
136 repeats: true)
136 }
137 }
@@ -168,7 +169,7 @@ class ViewController: UIViewController, MetaballDataSource {
168 Timer.scheduledTimer(
169 Timer.scheduledTimer(
169 timeInterval: 1.0 / 60.0,
170 timeInterval: 1.0 / 60.0,
170 target: self,
171 target: self,
171− selector: "animateEdgeWithTimer:",
172+ selector: #selector(ViewController.animateEdge(withTimer:)),
172 userInfo: parameters,
173 userInfo: parameters,
173 repeats: true)
174 repeats: true)
174 }
175 }