Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Fraser Graham Killer Robots

2 278 vues

Publié le

  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Fraser Graham Killer Robots

  1. 1. Killer Robots are a Concurrency Problem Stephen McQuay @smcquay Fraser Graham @twisted_weasel
  2. 2. I am learning Go, it's awesome. I always wanted to write a game. Cool Cool
  3. 3. We should write a game, in Go… LOL
  4. 4. “REAL” GAMES C C++ NOT GAMES ! Java Python Ruby Go etc. “simple” GAMES Javascript Objective-C Flash😩 C#
  5. 5. “Go is like Java, right? Best suited for server stuff? Nobody ever made a successful game in Java!”
  6. 6. MINECRAFT
  7. 7. MATHPHYSICS OPEN GL GUINPUTCONCURRENCY
  8. 8. Let’s Make a Game! o/
  9. 9. Robots Are Cool
  10. 10. START:! MV 100, 200! FIR 300, 312! SCN 3000! JMPIF s0, FOUND! GOTO START:! FOUND:! FIR s0 Screenshots are Pre-Rendered
  11. 11. WEB WebGL Websockets Game Server
  12. 12. Game Architecture Bandwidth Management
  13. 13. Game Architecture
  14. 14. Robot Protocol Game Server Robot
  15. 15. Game Server SIMULATION LOGIC PLAYER MANAGEMENT SERIALIZATION SERIALIZATION SERIALIZATION SERIALIZATION
  16. 16. Game(s) Server SIMULATION LOGIC PLAYER MANAGEMENT SERIALIZATION SERIALIZATION SERIALIZATION SIMULATION LOGIC PLAYER MANAGEMENT SERIALIZATION SERIALIZATION SERIALIZATION SIMULATION LOGIC PLAYER MANAGEMENT SERIALIZATION SERIALIZATION SERIALIZATION
  17. 17. SIMULATION LOGIC PLAYER MANAGEMENT SERIALIZATION SERIALIZATION SERIALIZATION 60Hz Not 60Hz
  18. 18. SIMULATION LOGIC ! GOROUTINE PLAYER MANAGEMENT ! GOROUTINE PLAYER SERIALIZATION ! GOROUTINE(S) CHANNEL CHANNEL
  19. 19. Control, Control, You must learn Control Game Server Robot
  20. 20. Control, Control, You must learn Control Game Server Robot Game Broker
  21. 21. SIMULATION LOGIC ! GOROUTINE PLAYER MANAGEMENT ! GOROUTINE PLAYER SERIALIZATION ! GOROUTINE(S) CHANNEL CHANNEL HTTP CONTROL ! GOROUTINE SIMULATION LOGIC ! GOROUTINE PLAYER MANAGEMENT ! GOROUTINE PLAYER SERIALIZATION ! GOROUTINE(S) CHANNEL CHANNEL SIMULATION LOGIC ! GOROUTINE PLAYER MANAGEMENT ! GOROUTINE PLAYER SERIALIZATION ! GOROUTINE(S) CHANNEL CHANNEL
  22. 22. Bandwidth Management OR “How I Learned to Stop Worrying and Love Interfaces”
  23. 23. Robot Protocol Game Server Spectator Player
  24. 24. Robot Protocol Game Server Spectator Player
  25. 25. Robot Protocol Game Server Spectator Player
  26. 26. http://hyperboleandahalf.blogspot.com/2010/06/this-is-why-ill- never-be-adult.html
  27. 27. type Point struct { X, Y float64 } ! ... ! p := Point{x, y} b, err := json.Marshal(p) ! ... ! json: '{"X":23.827610293658736,"Y": 42.273774761991874}' bytes: 47 (worst)
  28. 28. func (fp *Point) AsArray() []float64 { return []float64{fp.X, fp.Y} } ! ... ! p := Point{x, y} b, err := json.Marshal(p.AsArray()) ! ... ! json: '[23.827610293658736,42.273774761991874]' bytes: 39 (47 worst)
  29. 29. type Point struct { X, Y float32 } ! func (p *Point) AsArray() []float32 { return []float32{p.X, p.Y} } ! ... ! jsoned: '[23.82761,42.273773]' bytes: 20 (47 worst) !
  30. 30. "(ಠ益ಠლ) but at what cost?!
  31. 31. game.go:123: invalid operation: d + f (mismatched types float64 and float32)
  32. 32. ʕノ◔ϖ◔ʔノ ︵ ┻━┻
  33. 33. type Gopher interface { Squeak() }
  34. 34. type Point struct { X, Y float64 } ! func (ip Point) Squeak() { // ... } ! ... ! var p Point = Point{2, 3} var g Gopher = Point{2, 3}
  35. 35. func foo(g Gopher) {} ! var p Point = Point{2, 3} foo(p)
  36. 36. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON
  37. 37. type Point struct { X, Y float64 } ! func (p *Point) MarshalJSON() ([]byte, error) { coords := []float32{ float32(fp.X), float32(fp.Y), } return json.Marshal(coords) } ! ... ! jsoned: '[23.82761,42.273773]' bytes: 20 (47 worst)
  38. 38. ! ┬─┬ ʕ◔ϖ◔ʔ
  39. 39. package encoding ! type BinaryMarshaler interface { MarshalBinary() (data []byte, err error) } ! type TextMarshaler interface { MarshalText() (text []byte, err error) }
  40. 40. type encoder interface { Encode(v interface{}) error } ! if encoding == "json" { player.enc = json.NewEncoder(ws) } else { player.enc = gob.NewEncoder(ws) } ! ... player.enc.Encode(boardState)
  41. 41. Demo
  42. 42. Future Work

×