Slide 1

Slide 1 text

SwiftͰͭ͘Δ ϑΝϛίϯΤϛϡϨʔλͷ εεϝ 2019-09-05 iOSDC Japan 2019 thara @zetta1985

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

໨ඪ

Slide 5

Slide 5 text

$16 116 13(30. $)"30. 3".

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

ϑΝϛίϯΤϛϡϨʔλΛ SwiftͰॻ͘͜ͱͷϝϦοτ

Slide 10

Slide 10 text

ϝϦοτ 1 ݻఆ௕੔਺ܕ

Slide 11

Slide 11 text

ݻఆ௕੔਺ܕ • UInt8 / Int8 • UInt16 / Int16 • UInt32 / Int32 • ͜ΕΒ͕ͳ͚Ε͹ɺANDԋࢉͩΒ͚ʹͳΔ • Javaܥͱ͔LLͱ͔͸͜Ε͕͠ΜͲ͍͔΋

Slide 12

Slide 12 text

ࢀߟɿJava࣮૷ͷ৔߹ https://github.com/andrew-hoffman/halfnes

Slide 13

Slide 13 text

ࢀߟɿTypeScript࣮૷ͷ৔߹ https://github.com/r7kamura/nes8

Slide 14

Slide 14 text

ϝϦοτ 2 Overflow Operator

Slide 15

Slide 15 text

Overflow Operator // 65535 let value = UInt16.max // 0 let result = value &+ 1

Slide 16

Slide 16 text

ϝϦοτ 3 OptionSet

Slide 17

Slide 17 text

ϏοτϚεΫఆٛ struct Status: OptionSet { let rawValue: UInt8 /// Negative static let N = Status(rawValue: 1 << 7) /// Overflow static let V = Status(rawValue: 1 << 6) /// Decimal mode static let D = Status(rawValue: 1 << 3) /// IRQ prevention static let I = Status(rawValue: 1 << 2) /// Zero static let Z = Status(rawValue: 1 << 1) /// Carry static let C = Status(rawValue: 1 << 0) /// The B flag static let B = Status(rawValue: 0b00110000) }

Slide 18

Slide 18 text

ҙਤ͕Θ͔Γ΍͍͢Ϗοτԋࢉ // 0b1001100 var cpuStatus: Status = [.V, .D, .I] // 0b1001100 & ~0b00001101 = 0b1000000 cpuStatus.remove([.C, .D, .I]) // 0b1000000 | 0b0000001 = 0b1000001 cpuStatus.formUnion(.C)

Slide 19

Slide 19 text

ϝϦοτ 4 ύϑΥʔϚϯε

Slide 20

Slide 20 text

swift run -c debug 3 FPS

Slide 21

Slide 21 text

swift run -c release 100 FPS

Slide 22

Slide 22 text

ؾΛ͚͍ͭͯͨ͜ͱ • ΦϒδΣΫτΛແବʹ࡞Βͳ͍ • ΫϩʔδϟΛಈతʹ࡞Βͳ͍ • ແବͳܭࢉ͸͠ͳ͍ • ܧঝ͠ͳ͍Ϋϥεʹ͸finalΛ͚ͭΔ • ͳΔ΂͘privateʹ͢Δ

Slide 23

Slide 23 text

͜ͷఔ౓ͷҙࣝͰ΋ 100FPSग़Δ ↓ Θ͔Γ΍͢͞ΛॏࢹͰ͖Δ

Slide 24

Slide 24 text

ϋϚͬͨ͜ͱ

Slide 25

Slide 25 text

Release BuildͷΈ ϨϯμϦϯά͞Εͳ͍

Slide 26

Slide 26 text

PureSwift/SDL public func copy(_ texture: SDLTexture, source: SDL_Rect? = nil, destination: SDL_Rect? = nil) throws { let srcPtr: UnsafePointer? if let rect = source { srcPtr = withUnsafePointer(to: rect) { $0 } } else { srcPtr = nil } ... try SDL_RenderCopy(ptr, texture.ptr, sourcePointer, destPtr).sdlThrow(... } https://github.com/PureSwift/SDL

Slide 27

Slide 27 text

thara/SDL public func copy(_ texture: SDLTexture, _ s: inout SDL_Rect, _ d: inout SDL_Rect) throws { try SDL_RenderCopy(ptr, texture.ptr, &s, &d).sdlThrow(type: type(of: self)) } public func copy(_ texture: SDLTexture, _ s: inout SDL_Rect) throws { try SDL_RenderCopy(ptr, texture.ptr, &s, nil).sdlThrow(type: type(of: self)) } public func copy(_ texture: SDLTexture, _ d: inout SDL_Rect) throws { try SDL_RenderCopy(ptr, texture.ptr, nil, &d).sdlThrow(type: type(of: self)) }

Slide 28

Slide 28 text

·ͱΊ • SwiftͰ͸ίʔυͷΘ͔Γ΍͢͞Λॏࢹͯ͠ΤϛϡϨʔλ։ൃͰ͖Δ • ݻఆ௕੔਺ܕͰϊΠζͱͳΔϚεΫ͕ෆཁ • Overflow OperatorͰϥοϓΞϥ΢ϯυ͢Δԋࢉ͕ࣗ໌ • OptionSetʹΑΔϏοτϚεΫͷߴ͍දݱྗ • ίϯύΠϥͷ࠷దԽ͕͍͢͝ • ͗ͯ͢͢͝όάͷݪҼ͕Θ͔Βͳ͍

Slide 29

Slide 29 text

ΤϛϡϨʔλ։ൃλΠϜϥΠϯ

Slide 30

Slide 30 text

No content