[kit] Make a bunch of data structures public

This commit is contained in:
Eryn Wells 2017-08-08 12:36:33 -07:00
parent c84681559e
commit aa7b1ffe9d
2 changed files with 32 additions and 18 deletions

View file

@ -17,9 +17,25 @@ extension UnsafeMutableRawPointer {
} }
/// Metal's float4 type. 4 bytes per float, 16 bytes total, 16 byte aligned. /// Metal's float4 type. 4 bytes per float, 16 bytes total, 16 byte aligned.
struct Float4 { public struct Float4 {
var x: Float = 0 public var x: Float = 0
var y: Float = 0 public var y: Float = 0
var z: Float = 0 public var z: Float = 0
var w: Float = 0 public var w: Float = 0
public init() { }
public init(_ x: Float, _ y: Float, _ z: Float, _ w: Float) {
self.x = x
self.y = y
self.z = z
self.w = w
}
public init(r: Float, g: Float, b: Float, a: Float) {
x = r
y = g
z = b
w = a
}
} }

View file

@ -41,20 +41,18 @@ public struct Parameters {
let unused3: UInt16 = 0xBA let unused3: UInt16 = 0xBA
// Color parameters // Color parameters
var colorStyle = ColorStyle.gradient2Horizontal public var colorStyle = ColorStyle.gradient2Horizontal
var color0 = Float4() public var color0 = Float4()
var color1 = Float4() public var color1 = Float4()
var color2 = Float4() public var color2 = Float4()
var color3 = Float4() public var color3 = Float4()
public init() { }
public mutating func write(to buffer: MTLBuffer, offset: Int = 0) { public mutating func write(to buffer: MTLBuffer, offset: Int = 0) {
let head = buffer.contents() let start = buffer.contents().advanced(by: offset)
let start = head.advanced(by: offset)
let stride = MemoryLayout.stride(ofValue: self) let stride = MemoryLayout.stride(ofValue: self)
start.copyBytes(from: &self, count: stride) start.copyBytes(from: &self, count: stride)
NSLog("Populated parameters: size:\(size), n:\(numberOfBalls)") NSLog("Populated parameters: size:\(size), n:\(numberOfBalls)")
} }
} }
@ -110,14 +108,14 @@ public class Field {
private(set) var balls = [Ball]() private(set) var balls = [Ball]()
private var parameters = Parameters() private var parameters: Parameters
internal var bounds: CGRect { internal var bounds: CGRect {
return CGRect(origin: CGPoint(), size: CGSize(size: size)) return CGRect(origin: CGPoint(), size: CGSize(size: size))
} }
public init(size s: Size) { public init(parameters p: Parameters) {
size = s parameters = p
} }
public func update() { public func update() {