diff --git a/MetalParticles.xcodeproj/project.pbxproj b/MetalParticles.xcodeproj/project.pbxproj
index 21c5694..45a94ac 100644
--- a/MetalParticles.xcodeproj/project.pbxproj
+++ b/MetalParticles.xcodeproj/project.pbxproj
@@ -206,10 +206,12 @@
TargetAttributes = {
BE75EE8B1A6A2CC000B20D49 = {
CreatedOnToolsVersion = 6.1.1;
- DevelopmentTeam = ZBFYF9JG5V;
+ DevelopmentTeam = GCXLS66975;
+ LastSwiftMigration = 0830;
};
BE75EEA01A6A2CC000B20D49 = {
CreatedOnToolsVersion = 6.1.1;
+ LastSwiftMigration = 0830;
TestTargetID = BE75EE8B1A6A2CC000B20D49;
};
};
@@ -397,6 +399,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ DEVELOPMENT_TEAM = GCXLS66975;
INFOPLIST_FILE = MetalParticles/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -406,6 +409,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "uk.co.flexmonkey.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -415,6 +419,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ DEVELOPMENT_TEAM = GCXLS66975;
INFOPLIST_FILE = MetalParticles/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -424,6 +429,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "uk.co.flexmonkey.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -443,6 +449,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "uk.co.flexmonkey.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MetalParticles.app/MetalParticles";
};
name = Debug;
@@ -459,6 +466,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "uk.co.flexmonkey.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MetalParticles.app/MetalParticles";
};
name = Release;
diff --git a/MetalParticles.xcodeproj/project.xcworkspace/xcuserdata/FumiyaYamanaka.xcuserdatad/UserInterfaceState.xcuserstate b/MetalParticles.xcodeproj/project.xcworkspace/xcuserdata/FumiyaYamanaka.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..47b63be
Binary files /dev/null and b/MetalParticles.xcodeproj/project.xcworkspace/xcuserdata/FumiyaYamanaka.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/MetalParticles.xcodeproj/xcuserdata/FumiyaYamanaka.xcuserdatad/xcschemes/MetalParticles.xcscheme b/MetalParticles.xcodeproj/xcuserdata/FumiyaYamanaka.xcuserdatad/xcschemes/MetalParticles.xcscheme
new file mode 100644
index 0000000..1a10228
--- /dev/null
+++ b/MetalParticles.xcodeproj/xcuserdata/FumiyaYamanaka.xcuserdatad/xcschemes/MetalParticles.xcscheme
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MetalParticles.xcodeproj/xcuserdata/FumiyaYamanaka.xcuserdatad/xcschemes/xcschememanagement.plist b/MetalParticles.xcodeproj/xcuserdata/FumiyaYamanaka.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..da92f67
--- /dev/null
+++ b/MetalParticles.xcodeproj/xcuserdata/FumiyaYamanaka.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,27 @@
+
+
+
+
+ SchemeUserState
+
+ MetalParticles.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ BE75EE8B1A6A2CC000B20D49
+
+ primary
+
+
+ BE75EEA01A6A2CC000B20D49
+
+ primary
+
+
+
+
+
diff --git a/MetalParticles/AppDelegate.swift b/MetalParticles/AppDelegate.swift
index b3751fc..37391a9 100644
--- a/MetalParticles/AppDelegate.swift
+++ b/MetalParticles/AppDelegate.swift
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
- func applicationWillResignActive(application: UIApplication) {
+ func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- func applicationDidEnterBackground(application: UIApplication) {
+ func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- func applicationWillEnterForeground(application: UIApplication) {
+ func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- func applicationDidBecomeActive(application: UIApplication) {
+ func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- func applicationWillTerminate(application: UIApplication) {
+ func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
diff --git a/MetalParticles/MarkerWidget.swift b/MetalParticles/MarkerWidget.swift
index d511f66..909666a 100644
--- a/MetalParticles/MarkerWidget.swift
+++ b/MetalParticles/MarkerWidget.swift
@@ -24,11 +24,11 @@ class Circle: CAShapeLayer
{
func draw()
{
- fillColor = UIColor.lightGrayColor().CGColor
+ fillColor = UIColor.lightGray.cgColor
let ballRect = CGRect(x: -10, y: -10, width: 20, height: 20)
- let ballPath = UIBezierPath(ovalInRect: ballRect)
+ let ballPath = UIBezierPath(ovalIn: ballRect)
- path = ballPath.CGPath
+ path = ballPath.cgPath
}
-}
\ No newline at end of file
+}
diff --git a/MetalParticles/ParticleLab.swift b/MetalParticles/ParticleLab.swift
index c775ace..8fc422a 100644
--- a/MetalParticles/ParticleLab.swift
+++ b/MetalParticles/ParticleLab.swift
@@ -28,38 +28,38 @@ class ParticleLab: MTKView
let imageWidth: UInt
let imageHeight: UInt
- private var imageWidthFloatBuffer: MTLBuffer!
- private var imageHeightFloatBuffer: MTLBuffer!
+ fileprivate var imageWidthFloatBuffer: MTLBuffer!
+ fileprivate var imageHeightFloatBuffer: MTLBuffer!
let bytesPerRow: UInt
let region: MTLRegion
let blankBitmapRawData : [UInt8]
- private var kernelFunction: MTLFunction!
- private var pipelineState: MTLComputePipelineState!
- private var defaultLibrary: MTLLibrary! = nil
- private var commandQueue: MTLCommandQueue! = nil
+ fileprivate var kernelFunction: MTLFunction!
+ fileprivate var pipelineState: MTLComputePipelineState!
+ fileprivate var defaultLibrary: MTLLibrary! = nil
+ fileprivate var commandQueue: MTLCommandQueue! = nil
- private var threadsPerThreadgroup:MTLSize!
- private var threadgroupsPerGrid:MTLSize!
+ fileprivate var threadsPerThreadgroup:MTLSize!
+ fileprivate var threadgroupsPerGrid:MTLSize!
let particleCount: Int
let alignment:Int = 0x4000
let particlesMemoryByteSize:Int
- private var particlesMemory:UnsafeMutablePointer = nil
- private var particlesVoidPtr: COpaquePointer!
- private var particlesParticlePtr: UnsafeMutablePointer!
- private var particlesParticleBufferPtr: UnsafeMutableBufferPointer!
+ fileprivate var particlesMemory:UnsafeMutableRawPointer? = nil
+ fileprivate var particlesVoidPtr: OpaquePointer!
+ fileprivate var particlesParticlePtr: UnsafeMutablePointer!
+ fileprivate var particlesParticleBufferPtr: UnsafeMutableBufferPointer!
- private var gravityWellParticle = Particle(A: Vector4(x: 0, y: 0, z: 0, w: 0),
+ fileprivate var gravityWellParticle = Particle(A: Vector4(x: 0, y: 0, z: 0, w: 0),
B: Vector4(x: 0, y: 0, z: 0, w: 0),
C: Vector4(x: 0, y: 0, z: 0, w: 0),
D: Vector4(x: 0, y: 0, z: 0, w: 0))
- private var frameStartTime: CFAbsoluteTime!
- private var frameNumber = 0
- let particleSize = sizeof(Particle)
+ fileprivate var frameStartTime: CFAbsoluteTime!
+ fileprivate var frameNumber = 0
+ let particleSize = MemoryLayout.size
weak var particleLabDelegate: ParticleLabDelegate?
@@ -94,17 +94,17 @@ class ParticleLab: MTKView
bytesPerRow = 4 * imageWidth
region = MTLRegionMake2D(0, 0, Int(imageWidth), Int(imageHeight))
- blankBitmapRawData = [UInt8](count: Int(imageWidth * imageHeight * 4), repeatedValue: 0)
- particlesMemoryByteSize = particleCount * sizeof(Particle)
+ blankBitmapRawData = [UInt8](repeating: 0, count: Int(imageWidth * imageHeight * 4))
+ particlesMemoryByteSize = particleCount * MemoryLayout.size
- let formatter = NSNumberFormatter()
+ let formatter = NumberFormatter()
formatter.usesGroupingSeparator = true
- formatter.numberStyle = NSNumberFormatterStyle.DecimalStyle
+ formatter.numberStyle = NumberFormatter.Style.decimal
- statusPrefix = formatter.stringFromNumber(numParticles.rawValue * 4)! + " Particles"
+ statusPrefix = formatter.string(from: NSNumber(value: numParticles.rawValue * 4))! + " Particles"
- let frameWidth = hiDPI ? width / UInt(UIScreen.mainScreen().scale) : width
- let frameHeight = hiDPI ? height / UInt(UIScreen.mainScreen().scale) : height
+ let frameWidth = hiDPI ? width / UInt(UIScreen.main.scale) : width
+ let frameHeight = hiDPI ? height / UInt(UIScreen.main.scale) : height
super.init(frame: CGRect(x: 0, y: 0, width: Int(frameWidth), height: Int(frameHeight)), device: MTLCreateSystemDefaultDevice())
@@ -115,7 +115,7 @@ class ParticleLab: MTKView
setUpMetal()
- multipleTouchEnabled = true
+ isMultipleTouchEnabled = true
}
required init(coder: NSCoder)
@@ -129,11 +129,11 @@ class ParticleLab: MTKView
free(particlesMemory)
}
- private func setUpParticles()
+ fileprivate func setUpParticles()
{
posix_memalign(&particlesMemory, alignment, particlesMemoryByteSize)
- particlesVoidPtr = COpaquePointer(particlesMemory)
+ particlesVoidPtr = OpaquePointer(particlesMemory)
particlesParticlePtr = UnsafeMutablePointer(particlesVoidPtr)
particlesParticleBufferPtr = UnsafeMutableBufferPointer(start: particlesParticlePtr, count: particleCount)
@@ -142,13 +142,13 @@ class ParticleLab: MTKView
func resetGravityWells()
{
- setGravityWellProperties(gravityWell: .One, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
- setGravityWellProperties(gravityWell: .Two, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
- setGravityWellProperties(gravityWell: .Three, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
- setGravityWellProperties(gravityWell: .Four, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
+ setGravityWellProperties(gravityWell: .one, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
+ setGravityWellProperties(gravityWell: .two, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
+ setGravityWellProperties(gravityWell: .three, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
+ setGravityWellProperties(gravityWell: .four, normalisedPositionX: 0.5, normalisedPositionY: 0.5, mass: 0, spin: 0)
}
- func resetParticles(edgesOnly: Bool = false)
+ func resetParticles(_ edgesOnly: Bool = false)
{
func rand() -> Float32
{
@@ -215,7 +215,7 @@ class ParticleLab: MTKView
}
}
- private func setUpMetal()
+ fileprivate func setUpMetal()
{
device = MTLCreateSystemDefaultDevice()
@@ -227,13 +227,13 @@ class ParticleLab: MTKView
}
defaultLibrary = device.newDefaultLibrary()
- commandQueue = device.newCommandQueue()
+ commandQueue = device.makeCommandQueue()
- kernelFunction = defaultLibrary.newFunctionWithName("particleRendererShader")
+ kernelFunction = defaultLibrary.makeFunction(name: "particleRendererShader")
do
{
- try pipelineState = device.newComputePipelineStateWithFunction(kernelFunction!)
+ try pipelineState = device.makeComputePipelineState(function: kernelFunction!)
}
catch
{
@@ -250,12 +250,12 @@ class ParticleLab: MTKView
var imageWidthFloat = Float(imageWidth)
var imageHeightFloat = Float(imageHeight)
- imageWidthFloatBuffer = device.newBufferWithBytes(&imageWidthFloat, length: sizeof(Float), options: MTLResourceOptions.CPUCacheModeDefaultCache)
+ imageWidthFloatBuffer = device.makeBuffer(bytes: &imageWidthFloat, length: MemoryLayout.size, options: MTLResourceOptions())
- imageHeightFloatBuffer = device.newBufferWithBytes(&imageHeightFloat, length: sizeof(Float), options: MTLResourceOptions.CPUCacheModeDefaultCache)
+ imageHeightFloatBuffer = device.makeBuffer(bytes: &imageHeightFloat, length: MemoryLayout.size, options: MTLResourceOptions())
}
- override func drawRect(dirtyRect: CGRect)
+ override func draw(_ dirtyRect: CGRect)
{
guard let device = device else
{
@@ -277,31 +277,31 @@ class ParticleLab: MTKView
frameNumber = 0
}
- let commandBuffer = commandQueue.commandBuffer()
- let commandEncoder = commandBuffer.computeCommandEncoder()
+ let commandBuffer = commandQueue.makeCommandBuffer()
+ let commandEncoder = commandBuffer.makeComputeCommandEncoder()
commandEncoder.setComputePipelineState(pipelineState)
- let particlesBufferNoCopy = device.newBufferWithBytesNoCopy(particlesMemory, length: Int(particlesMemoryByteSize),
- options: MTLResourceOptions.CPUCacheModeDefaultCache, deallocator: nil)
+ let particlesBufferNoCopy = device.makeBuffer(bytesNoCopy: particlesMemory!, length: Int(particlesMemoryByteSize),
+ options: MTLResourceOptions(), deallocator: nil)
- commandEncoder.setBuffer(particlesBufferNoCopy, offset: 0, atIndex: 0)
- commandEncoder.setBuffer(particlesBufferNoCopy, offset: 0, atIndex: 1)
+ commandEncoder.setBuffer(particlesBufferNoCopy, offset: 0, at: 0)
+ commandEncoder.setBuffer(particlesBufferNoCopy, offset: 0, at: 1)
- let inGravityWell = device.newBufferWithBytes(&gravityWellParticle, length: particleSize, options: MTLResourceOptions.CPUCacheModeDefaultCache)
- commandEncoder.setBuffer(inGravityWell, offset: 0, atIndex: 2)
+ let inGravityWell = device.makeBuffer(bytes: &gravityWellParticle, length: particleSize, options: MTLResourceOptions())
+ commandEncoder.setBuffer(inGravityWell, offset: 0, at: 2)
- let colorBuffer = device.newBufferWithBytes(&particleColor, length: sizeof(ParticleColor), options: MTLResourceOptions.CPUCacheModeDefaultCache)
- commandEncoder.setBuffer(colorBuffer, offset: 0, atIndex: 3)
+ let colorBuffer = device.makeBuffer(bytes: &particleColor, length: MemoryLayout.size, options: MTLResourceOptions())
+ commandEncoder.setBuffer(colorBuffer, offset: 0, at: 3)
- commandEncoder.setBuffer(imageWidthFloatBuffer, offset: 0, atIndex: 4)
- commandEncoder.setBuffer(imageHeightFloatBuffer, offset: 0, atIndex: 5)
+ commandEncoder.setBuffer(imageWidthFloatBuffer, offset: 0, at: 4)
+ commandEncoder.setBuffer(imageHeightFloatBuffer, offset: 0, at: 5)
- let dragFactorBuffer = device.newBufferWithBytes(&dragFactor, length: sizeof(Float), options: MTLResourceOptions.CPUCacheModeDefaultCache)
- commandEncoder.setBuffer(dragFactorBuffer, offset: 0, atIndex: 6)
+ let dragFactorBuffer = device.makeBuffer(bytes: &dragFactor, length: MemoryLayout.size, options: MTLResourceOptions())
+ commandEncoder.setBuffer(dragFactorBuffer, offset: 0, at: 6)
- let respawnOutOfBoundsParticlesBuffer = device.newBufferWithBytes(&respawnOutOfBoundsParticles, length: sizeof(Bool), options: MTLResourceOptions.CPUCacheModeDefaultCache)
- commandEncoder.setBuffer(respawnOutOfBoundsParticlesBuffer, offset: 0, atIndex: 7)
+ let respawnOutOfBoundsParticlesBuffer = device.makeBuffer(bytes: &respawnOutOfBoundsParticles, length: MemoryLayout.size, options: MTLResourceOptions())
+ commandEncoder.setBuffer(respawnOutOfBoundsParticlesBuffer, offset: 0, at: 7)
guard let drawable = currentDrawable else
{
@@ -314,14 +314,14 @@ class ParticleLab: MTKView
if clearOnStep
{
- drawable.texture.replaceRegion(self.region,
+ drawable.texture.replace(region: self.region,
mipmapLevel: 0,
withBytes: blankBitmapRawData,
bytesPerRow: Int(bytesPerRow))
}
- commandEncoder.setTexture(drawable.texture, atIndex: 0)
+ commandEncoder.setTexture(drawable.texture, at: 0)
commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
@@ -329,14 +329,14 @@ class ParticleLab: MTKView
if !clearOnStep
{
- let inPlaceTexture = UnsafeMutablePointer.alloc(1)
- inPlaceTexture.initialize(drawable.texture)
+ let inPlaceTexture = UnsafeMutablePointer.allocate(capacity: 1)
+ inPlaceTexture.initialize(to: drawable.texture)
- blur.encodeToCommandBuffer(commandBuffer,
+ blur.encode(commandBuffer: commandBuffer,
inPlaceTexture: inPlaceTexture,
fallbackCopyAllocator: nil)
- erode.encodeToCommandBuffer(commandBuffer,
+ erode.encode(commandBuffer: commandBuffer,
inPlaceTexture: inPlaceTexture,
fallbackCopyAllocator: nil)
}
@@ -348,7 +348,7 @@ class ParticleLab: MTKView
particleLabDelegate?.particleLabDidUpdate(statusPrefix + statusPostix)
}
- final func getGravityWellNormalisedPosition(gravityWell gravityWell: GravityWell) -> (x: Float, y: Float)
+ final func getGravityWellNormalisedPosition(gravityWell: GravityWell) -> (x: Float, y: Float)
{
let returnPoint: (x: Float, y: Float)
@@ -357,66 +357,66 @@ class ParticleLab: MTKView
switch gravityWell
{
- case .One:
+ case .one:
returnPoint = (x: gravityWellParticle.A.x / imageWidthFloat, y: gravityWellParticle.A.y / imageHeightFloat)
- case .Two:
+ case .two:
returnPoint = (x: gravityWellParticle.B.x / imageWidthFloat, y: gravityWellParticle.B.y / imageHeightFloat)
- case .Three:
+ case .three:
returnPoint = (x: gravityWellParticle.C.x / imageWidthFloat, y: gravityWellParticle.C.y / imageHeightFloat)
- case .Four:
+ case .four:
returnPoint = (x: gravityWellParticle.D.x / imageWidthFloat, y: gravityWellParticle.D.y / imageHeightFloat)
}
return returnPoint
}
- final func setGravityWellProperties(gravityWellIndex gravityWellIndex: Int, normalisedPositionX: Float, normalisedPositionY: Float, mass: Float, spin: Float)
+ final func setGravityWellProperties(gravityWellIndex: Int, normalisedPositionX: Float, normalisedPositionY: Float, mass: Float, spin: Float)
{
switch gravityWellIndex
{
case 1:
- setGravityWellProperties(gravityWell: .Two, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
+ setGravityWellProperties(gravityWell: .two, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
case 2:
- setGravityWellProperties(gravityWell: .Three, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
+ setGravityWellProperties(gravityWell: .three, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
case 3:
- setGravityWellProperties(gravityWell: .Four, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
+ setGravityWellProperties(gravityWell: .four, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
default:
- setGravityWellProperties(gravityWell: .One, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
+ setGravityWellProperties(gravityWell: .one, normalisedPositionX: normalisedPositionX, normalisedPositionY: normalisedPositionY, mass: mass, spin: spin)
}
}
- final func setGravityWellProperties(gravityWell gravityWell: GravityWell, normalisedPositionX: Float, normalisedPositionY: Float, mass: Float, spin: Float)
+ final func setGravityWellProperties(gravityWell: GravityWell, normalisedPositionX: Float, normalisedPositionY: Float, mass: Float, spin: Float)
{
let imageWidthFloat = Float(imageWidth)
let imageHeightFloat = Float(imageHeight)
switch gravityWell
{
- case .One:
+ case .one:
gravityWellParticle.A.x = imageWidthFloat * normalisedPositionX
gravityWellParticle.A.y = imageHeightFloat * normalisedPositionY
gravityWellParticle.A.z = mass
gravityWellParticle.A.w = spin
- case .Two:
+ case .two:
gravityWellParticle.B.x = imageWidthFloat * normalisedPositionX
gravityWellParticle.B.y = imageHeightFloat * normalisedPositionY
gravityWellParticle.B.z = mass
gravityWellParticle.B.w = spin
- case .Three:
+ case .three:
gravityWellParticle.C.x = imageWidthFloat * normalisedPositionX
gravityWellParticle.C.y = imageHeightFloat * normalisedPositionY
gravityWellParticle.C.z = mass
gravityWellParticle.C.w = spin
- case .Four:
+ case .four:
gravityWellParticle.D.x = imageWidthFloat * normalisedPositionX
gravityWellParticle.D.y = imageHeightFloat * normalisedPositionY
gravityWellParticle.D.z = mass
@@ -427,29 +427,29 @@ class ParticleLab: MTKView
protocol ParticleLabDelegate: NSObjectProtocol
{
- func particleLabDidUpdate(status: String)
+ func particleLabDidUpdate(_ status: String)
func particleLabMetalUnavailable()
}
enum GravityWell
{
- case One
- case Two
- case Three
- case Four
+ case one
+ case two
+ case three
+ case four
}
// Since each Particle instance defines four particles, the visible particle count
// in the API is four times the number we need to create.
enum ParticleCount: Int
{
- case QtrMillion = 65_536
- case HalfMillion = 131_072
- case OneMillion = 262_144
- case TwoMillion = 524_288
- case FourMillion = 1_048_576
- case EightMillion = 2_097_152
- case SixteenMillion = 4_194_304
+ case qtrMillion = 65_536
+ case halfMillion = 131_072
+ case oneMillion = 262_144
+ case twoMillion = 524_288
+ case fourMillion = 1_048_576
+ case eightMillion = 2_097_152
+ case sixteenMillion = 4_194_304
}
// Paticles are split into three classes. The supplied particle color defines one
diff --git a/MetalParticles/ViewController.swift b/MetalParticles/ViewController.swift
index c078c8c..ebe0469 100644
--- a/MetalParticles/ViewController.swift
+++ b/MetalParticles/ViewController.swift
@@ -46,16 +46,16 @@ class ViewController: UIViewController, ParticleLabDelegate
{
super.viewDidLoad()
- view.backgroundColor = UIColor.blackColor()
+ view.backgroundColor = UIColor.black
- print(UIScreen.mainScreen().scale)
+ print(UIScreen.main.scale)
- let numParticles = ParticleCount.EightMillion
+ let numParticles = ParticleCount.eightMillion
if hiDPI
{
- particleLab = ParticleLab(width: UInt(view.frame.width * UIScreen.mainScreen().scale),
- height: UInt(view.frame.height * UIScreen.mainScreen().scale),
+ particleLab = ParticleLab(width: UInt(view.frame.width * UIScreen.main.scale),
+ height: UInt(view.frame.height * UIScreen.main.scale),
numParticles: numParticles,
hiDPI: true)
}
@@ -79,19 +79,19 @@ class ViewController: UIViewController, ParticleLabDelegate
view.addSubview(particleLab)
- menuButton.layer.borderColor = UIColor.lightGrayColor().CGColor
+ menuButton.layer.borderColor = UIColor.lightGray.cgColor
menuButton.layer.borderWidth = 1
menuButton.layer.cornerRadius = 5
- menuButton.layer.backgroundColor = UIColor.darkGrayColor().CGColor
+ menuButton.layer.backgroundColor = UIColor.darkGray.cgColor
menuButton.showsTouchWhenHighlighted = true
- menuButton.imageView?.contentMode = UIViewContentMode.ScaleAspectFit
- menuButton.setImage(UIImage(named: "hamburger.png"), forState: UIControlState.Normal)
- menuButton.addTarget(self, action: #selector(ViewController.displayCallout), forControlEvents: UIControlEvents.TouchDown)
+ menuButton.imageView?.contentMode = UIViewContentMode.scaleAspectFit
+ menuButton.setImage(UIImage(named: "hamburger.png"), for: UIControlState())
+ menuButton.addTarget(self, action: #selector(ViewController.displayCallout), for: UIControlEvents.touchDown)
view.addSubview(menuButton)
statusLabel.text = "http://flexmonkey.blogspot.co.uk"
- statusLabel.textColor = UIColor.darkGrayColor()
+ statusLabel.textColor = UIColor.darkGray
view.addSubview(statusLabel)
}
@@ -99,9 +99,9 @@ class ViewController: UIViewController, ParticleLabDelegate
override func viewDidLayoutSubviews()
{
statusLabel.frame = CGRect(x: 5,
- y: view.frame.height - statusLabel.intrinsicContentSize().height,
+ y: view.frame.height - statusLabel.intrinsicContentSize.height,
width: view.frame.width,
- height: statusLabel.intrinsicContentSize().height)
+ height: statusLabel.intrinsicContentSize.height)
menuButton.frame = CGRect(x: view.frame.width - 35,
y: view.frame.height - 35,
@@ -114,25 +114,25 @@ class ViewController: UIViewController, ParticleLabDelegate
// handle metal unavailable here
}
- override func touchesBegan(touches: Set, withEvent event: UIEvent?)
+ override func touchesBegan(_ touches: Set, with event: UIEvent?)
{
currentTouches = currentTouches.union(touches)
}
- override func touchesEnded(touches: Set, withEvent event: UIEvent?)
+ override func touchesEnded(_ touches: Set, with event: UIEvent?)
{
- currentTouches = currentTouches.subtract(touches)
+ currentTouches = currentTouches.subtracting(touches)
}
func displayCallout()
{
- let alertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
+ let alertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
- let cloudChamberAction = UIAlertAction(title: DemoModes.cloudChamber.rawValue, style: UIAlertActionStyle.Default, handler: calloutActionHandler)
- let orbitsAction = UIAlertAction(title: DemoModes.orbits.rawValue, style: UIAlertActionStyle.Default, handler: calloutActionHandler)
- let multiTouchAction = UIAlertAction(title: DemoModes.multiTouch.rawValue, style: UIAlertActionStyle.Default, handler: calloutActionHandler)
- let respawnAction = UIAlertAction(title: DemoModes.respawn.rawValue, style: UIAlertActionStyle.Default, handler: calloutActionHandler)
- let iPadProAction = UIAlertAction(title: DemoModes.iPadProDemo.rawValue, style: UIAlertActionStyle.Default, handler: calloutActionHandler)
+ let cloudChamberAction = UIAlertAction(title: DemoModes.cloudChamber.rawValue, style: UIAlertActionStyle.default, handler: calloutActionHandler)
+ let orbitsAction = UIAlertAction(title: DemoModes.orbits.rawValue, style: UIAlertActionStyle.default, handler: calloutActionHandler)
+ let multiTouchAction = UIAlertAction(title: DemoModes.multiTouch.rawValue, style: UIAlertActionStyle.default, handler: calloutActionHandler)
+ let respawnAction = UIAlertAction(title: DemoModes.respawn.rawValue, style: UIAlertActionStyle.default, handler: calloutActionHandler)
+ let iPadProAction = UIAlertAction(title: DemoModes.iPadProDemo.rawValue, style: UIAlertActionStyle.default, handler: calloutActionHandler)
alertController.addAction(cloudChamberAction)
alertController.addAction(orbitsAction)
@@ -149,12 +149,12 @@ class ViewController: UIViewController, ParticleLabDelegate
popoverPresentationController.sourceView = view
}
- particleLab.paused = true
+ particleLab.isPaused = true
- presentViewController(alertController, animated: true, completion: {self.particleLab.paused = false})
+ present(alertController, animated: true, completion: {self.particleLab.isPaused = false})
}
- func calloutActionHandler(value: UIAlertAction!) -> Void
+ func calloutActionHandler(_ value: UIAlertAction!) -> Void
{
demoMode = DemoModes(rawValue: value.title!) ?? DemoModes.iPadProDemo
@@ -192,7 +192,7 @@ class ViewController: UIViewController, ParticleLabDelegate
}
}
- func particleLabDidUpdate(status: String)
+ func particleLabDidUpdate(_ status: String)
{
statusLabel.text = "http://flexmonkey.blogspot.co.uk | " + status
@@ -221,13 +221,13 @@ class ViewController: UIViewController, ParticleLabDelegate
{
gravityWellAngle = gravityWellAngle + 0.02
- particleLab.setGravityWellProperties(gravityWell: .One,
+ particleLab.setGravityWellProperties(gravityWell: .one,
normalisedPositionX: 0.5 + 0.45 * sin(gravityWellAngle),
normalisedPositionY: 0.5 + 0.15 * cos(gravityWellAngle),
mass: 14,
spin: 16)
- particleLab.setGravityWellProperties(gravityWell: .Two,
+ particleLab.setGravityWellProperties(gravityWell: .two,
normalisedPositionX: 0.5 + 0.25 * cos(gravityWellAngle * 1.3),
normalisedPositionY: 0.5 + 0.6 * sin(gravityWellAngle * 1.3),
mass: 8,
@@ -239,15 +239,15 @@ class ViewController: UIViewController, ParticleLabDelegate
{
let currentTouchesArray = Array(currentTouches)
- for (i, currentTouch) in currentTouchesArray.enumerate() where i < 4
+ for (i, currentTouch) in currentTouchesArray.enumerated() where i < 4
{
let touchMultiplier = currentTouch.force == 0 && currentTouch.maximumPossibleForce == 0
? 1
: Float(currentTouch.force / currentTouch.maximumPossibleForce)
particleLab.setGravityWellProperties(gravityWellIndex: i,
- normalisedPositionX: Float(currentTouch.locationInView(view).x / view.frame.width) ,
- normalisedPositionY: Float(currentTouch.locationInView(view).y / view.frame.height),
+ normalisedPositionX: Float(currentTouch.location(in: view).x / view.frame.width) ,
+ normalisedPositionY: Float(currentTouch.location(in: view).y / view.frame.height),
mass: 40 * touchMultiplier,
spin: 20 * touchMultiplier)
}
@@ -267,28 +267,28 @@ class ViewController: UIViewController, ParticleLabDelegate
{
gravityWellAngle = gravityWellAngle + 0.004
- particleLab.setGravityWellProperties(gravityWell: .One,
+ particleLab.setGravityWellProperties(gravityWell: .one,
normalisedPositionX: 0.5 + 0.1 * sin(gravityWellAngle + floatPi * 0.5),
normalisedPositionY: 0.5 + 0.1 * cos(gravityWellAngle + floatPi * 0.5),
mass: 11 * sin(gravityWellAngle / 1.8),
spin: 23 * cos(gravityWellAngle / 2.1))
- particleLab.setGravityWellProperties(gravityWell: .Two,
+ particleLab.setGravityWellProperties(gravityWell: .two,
normalisedPositionX: 0.5 + 0.1 * sin(gravityWellAngle + floatPi * 1.5),
normalisedPositionY: 0.5 + 0.1 * cos(gravityWellAngle + floatPi * 1.5),
mass: 11 * sin(gravityWellAngle / 0.9),
spin: 23 * cos(gravityWellAngle / 1.05))
- particleLab.setGravityWellProperties(gravityWell: .Three,
+ particleLab.setGravityWellProperties(gravityWell: .three,
normalisedPositionX: 0.5 + (0.35 + sin(gravityWellAngle * 2.7)) * cos(gravityWellAngle / 1.3),
normalisedPositionY: 0.5 + (0.35 + sin(gravityWellAngle * 2.7)) * sin(gravityWellAngle / 1.3),
mass: 13, spin: 19 * sin(gravityWellAngle * 1.75))
- let particleOnePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .One)
- let particleTwoPosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .Two)
- let particleThreePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .Three)
+ let particleOnePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .one)
+ let particleTwoPosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .two)
+ let particleThreePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .three)
- particleLab.setGravityWellProperties(gravityWell: .Four,
+ particleLab.setGravityWellProperties(gravityWell: .four,
normalisedPositionX: (particleOnePosition.x + particleTwoPosition.x + particleThreePosition.x) / 3 + 0.03 * sin(gravityWellAngle),
normalisedPositionY: (particleOnePosition.y + particleTwoPosition.y + particleThreePosition.y) / 3 + 0.03 * cos(gravityWellAngle),
mass: 8 ,
@@ -299,31 +299,31 @@ class ViewController: UIViewController, ParticleLabDelegate
{
gravityWellAngle = gravityWellAngle + 0.0015
- particleLab.setGravityWellProperties(gravityWell: .One,
+ particleLab.setGravityWellProperties(gravityWell: .one,
normalisedPositionX: 0.5 + 0.006 * cos(gravityWellAngle * 43),
normalisedPositionY: 0.5 + 0.006 * sin(gravityWellAngle * 43),
mass: 10,
spin: 24)
- let particleOnePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .One)
+ let particleOnePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .one)
- particleLab.setGravityWellProperties(gravityWell: .Two,
+ particleLab.setGravityWellProperties(gravityWell: .two,
normalisedPositionX: particleOnePosition.x + 0.3 * sin(gravityWellAngle * 5),
normalisedPositionY: particleOnePosition.y + 0.3 * cos(gravityWellAngle * 5),
mass: 4,
spin: 18)
- let particleTwoPosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .Two)
+ let particleTwoPosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .two)
- particleLab.setGravityWellProperties(gravityWell: .Three,
+ particleLab.setGravityWellProperties(gravityWell: .three,
normalisedPositionX: particleTwoPosition.x + 0.1 * cos(gravityWellAngle * 23),
normalisedPositionY: particleTwoPosition.y + 0.1 * sin(gravityWellAngle * 23),
mass: 6,
spin: 17)
- let particleThreePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .Three)
+ let particleThreePosition = particleLab.getGravityWellNormalisedPosition(gravityWell: .three)
- particleLab.setGravityWellProperties(gravityWell: .Four,
+ particleLab.setGravityWellProperties(gravityWell: .four,
normalisedPositionX: particleThreePosition.x + 0.03 * sin(gravityWellAngle * 37),
normalisedPositionY: particleThreePosition.y + 0.03 * cos(gravityWellAngle * 37),
mass: 8,
@@ -334,39 +334,39 @@ class ViewController: UIViewController, ParticleLabDelegate
{
gravityWellAngle = gravityWellAngle + 0.02
- particleLab.setGravityWellProperties(gravityWell: .One,
+ particleLab.setGravityWellProperties(gravityWell: .one,
normalisedPositionX: 0.5 + 0.1 * sin(gravityWellAngle + floatPi * 0.5),
normalisedPositionY: 0.5 + 0.1 * cos(gravityWellAngle + floatPi * 0.5),
mass: 11 * sin(gravityWellAngle / 1.9),
spin: 23 * cos(gravityWellAngle / 2.1))
- particleLab.setGravityWellProperties(gravityWell: .Four,
+ particleLab.setGravityWellProperties(gravityWell: .four,
normalisedPositionX: 0.5 + 0.1 * sin(gravityWellAngle + floatPi * 1.5),
normalisedPositionY: 0.5 + 0.1 * cos(gravityWellAngle + floatPi * 1.5),
mass: 11 * sin(gravityWellAngle / 1.9),
spin: 23 * cos(gravityWellAngle / 2.1))
- particleLab.setGravityWellProperties(gravityWell: .Two,
+ particleLab.setGravityWellProperties(gravityWell: .two,
normalisedPositionX: 0.5 + (0.35 + sin(gravityWellAngle * 2.7)) * cos(gravityWellAngle / 1.3),
normalisedPositionY: 0.5 + (0.35 + sin(gravityWellAngle * 2.7)) * sin(gravityWellAngle / 1.3),
mass: 26, spin: -19 * sin(gravityWellAngle * 1.5))
- particleLab.setGravityWellProperties(gravityWell: .Three,
+ particleLab.setGravityWellProperties(gravityWell: .three,
normalisedPositionX: 0.5 + (0.35 + sin(gravityWellAngle * 2.7)) * cos(gravityWellAngle / 1.3 + floatPi),
normalisedPositionY: 0.5 + (0.35 + sin(gravityWellAngle * 2.7)) * sin(gravityWellAngle / 1.3 + floatPi),
mass: 26, spin: -19 * sin(gravityWellAngle * 1.5))
}
- override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
+ override var supportedInterfaceOrientations : UIInterfaceOrientationMask
{
- return UIInterfaceOrientationMask.Landscape
+ return UIInterfaceOrientationMask.landscape
}
- override func preferredStatusBarStyle() -> UIStatusBarStyle
+ override var preferredStatusBarStyle : UIStatusBarStyle
{
- return UIStatusBarStyle.LightContent
+ return UIStatusBarStyle.lightContent
}
override func didReceiveMemoryWarning()
@@ -375,7 +375,7 @@ class ViewController: UIViewController, ParticleLabDelegate
// Dispose of any resources that can be recreated.
}
- override func prefersStatusBarHidden() -> Bool
+ override var prefersStatusBarHidden : Bool
{
return true
}
diff --git a/MetalParticlesTests/MetalParticlesTests.swift b/MetalParticlesTests/MetalParticlesTests.swift
index 2c67dd4..c893803 100644
--- a/MetalParticlesTests/MetalParticlesTests.swift
+++ b/MetalParticlesTests/MetalParticlesTests.swift
@@ -28,7 +28,7 @@ class MetalParticlesTests: XCTestCase {
func testPerformanceExample() {
// This is an example of a performance test case.
- self.measureBlock() {
+ self.measure() {
// Put the code you want to measure the time of here.
}
}