Photon & UnityBuilding Realtime Multiplayer Games
Part I: Introduction to Photon
Photon in a Nutshell    •   Photon is a Socket Server & Framework         –   Target: Realtime, Multiplayer, Cross Platfor...
U4ia (= euphoria)• Industry Veterans (Dusty Welch, Chris Archer & team)• Free-to-play, AAA, Hardcore, Browser Based Games•...
5
6
7
8
9
10
Photon Compared to „Social SDKs“•   Leaderboards                  •   Matchmaking•   Challenges                    •   Rea...
Unity Rules!But we do more …
Type of Games   •   Room based games (2-32 players)        –   FPS, Racer, Casual Game        –   Broadcast of Messages to...
What Does it give You: Build vs Buy
What Does it give You: Build vs Buy
Rules of Thumb: CCU is Usually Overestimated    •   CCU * 10 = DAU    •   DAU * 10 = MAU    •   MAU * x = Downloads (how m...
Load Test: The Setup    • Scenario       – 25 rooms x 16 players = 400 CCU       – 2 x 50 bytes reliable / s, 10 x 50 byte...
Load Test: Traffic is the Cost Driver    • Traffic (400CCU, per month)       – Traffic = 8MB/s * 60 * 60 * 24 * 30 * 50% =...
Load Test: Realworld, our own Cloud    •   Largest game has 13,000 CCUs    •   800,000 msg/s (req, resp, ev)    •   90 TB ...
API/SDK Options   • Plain APIs (full control)       – Operation: Request/Response       – Events: From the server   • Phot...
Photon Unity Networking (PUN)• Unity Networking (UN) is very convenient, simple and  powerful• It is the entry point for m...
PUN Feature CoverageSynchronization                            RPCs2 Position, Rotation, Scale                2 From clien...
Additional FeaturesPlatform as a Service (PaaS)             Dashboard+ No server installs with the Cloud      + See CCUs, ...
Counters to Track Down Issues              Overall:              A peers disconnects every 2h (average)              20k p...
Unite12 Announcement #1:   • Cloud “forever free” plan   • 20CCU   • Unlimited apps
Unite12 Announcement #2:   • Playmaker integration   • Easy Unity Networking
Unite12 Announcement #3:   For Indies   • 1 Server: $99   • 3 Server: $199   Per title, unlimited CCUs
Part II: Photon Unite Networking (PUN)                hands-on
Running a local Cloud    •   Register and get app ID (cloud.exitgames.com)    •   Download Photon Server    •   Unpack it ...
PUN Nuts & Bolts   •   Lobby       –   Matchmaking       –   Properties can be synced   •   Rooms       –   Exchange data ...
Quick Usage Intro    •   ConnectUsingSettings()         –   US, EU or Asia    •   Get from the Lobby into a Room quickly  ...
Properties & using them for Matchmaking    •   Properties are a key-value storage for custom data         –   Attached to ...
Tips & Tricks: Loading a Level    •   Two main Problems:         –   Long loading time causes a timeout (update thread is ...
Beyond PUN   •   Operations, Responses and Events   •   Calling operations   •   Handling Events   •   Event cache
Quality of Service (QoS)    •   How to reduce messages    •   How to read vital stats
Part III: References
39
40
41
42
Photon Session / Unite12 Conference
Photon Session / Unite12 Conference
Upcoming SlideShare
Loading in …5
×

Photon Session / Unite12 Conference

2,769 views

Published on

Session from the Unite12 Conference in Amsterdam.

Photon Session / Unite12 Conference

  1. 1. Photon & UnityBuilding Realtime Multiplayer Games
  2. 2. Part I: Introduction to Photon
  3. 3. Photon in a Nutshell • Photon is a Socket Server & Framework – Target: Realtime, Multiplayer, Cross Platform Games • 16k+ registered developers – 800 new devs every months and rising – AAA customers: u4ia, Codemasters, Nival, Glu, ... – Indies: CMUNE, Kogama, Bigbite, 3Sprockets, ... • Transparent pricing, empower Indies
  4. 4. U4ia (= euphoria)• Industry Veterans (Dusty Welch, Chris Archer & team)• Free-to-play, AAA, Hardcore, Browser Based Games• „The middleware that gave us the least headache ...“, Dan MacDonald, Lead Programmer 4
  5. 5. 5
  6. 6. 6
  7. 7. 7
  8. 8. 8
  9. 9. 9
  10. 10. 10
  11. 11. Photon Compared to „Social SDKs“• Leaderboards • Matchmaking• Challenges • Realtime gameplay•• Achievements Social Network Integr. != • • Reliable UDP, TCP, Websockets FPS & MMO• News, Push • Load Balancing• Gamestatesync• Payment vNEXT• Downloadable Content • Least Ping Routing• Virtualgoods/-currency • Private Clouds• Unlock • Custom Server Logic•• Cross platform Efficiency = • • iOS, Android, WP7, Unity, Flash, HTML5, ... „No fluff“
  12. 12. Unity Rules!But we do more …
  13. 13. Type of Games • Room based games (2-32 players) – FPS, Racer, Casual Game – Broadcast of Messages to all Players – Framework: Lite, LiteLobby, Load Balancing – U4ia: Offensive Combat, CMUNE: Überstrike, Codemasters: F1 Online, Kogama, ... • MMO games – Hundreds of People per Map/World/Region – Interest Management – Framework: MMO – Innogames: Kartuga, FOX: Family Guy Online, ...
  14. 14. What Does it give You: Build vs Buy
  15. 15. What Does it give You: Build vs Buy
  16. 16. Rules of Thumb: CCU is Usually Overestimated • CCU * 10 = DAU • DAU * 10 = MAU • MAU * x = Downloads (how many play connected?) • 100 CCU = 10,000 MAU • 1,000 CCU = 100,000 MAU • Real World Sample (Mobile): – 4,000,000 downloads >> 3,000 CCU
  17. 17. Load Test: The Setup • Scenario – 25 rooms x 16 players = 400 CCU – 2 x 50 bytes reliable / s, 10 x 50 bytes unreliable / s • Server: Quad-Core, 8GB RAM, Win7 x64 – In: 4,500 msg/s (1,2 MB/s) – Out: 65,000 msg/s (7.5 MB/s) – CPU: ~30% – NIC (100Mbit): 80% saturated – Client RTT: ~40ms
  18. 18. Load Test: Traffic is the Cost Driver • Traffic (400CCU, per month) – Traffic = 8MB/s * 60 * 60 * 24 * 30 * 50% = ~10 TB • Cost – Server Cost (HW, OS & traffic): $400 – Cost per CCU ~= $400/400CCU = $1 – 400 CCU ~= 4,000 DAU ~= 40,000 MAU – Cost per MAU ~= 1 Cent
  19. 19. Load Test: Realworld, our own Cloud • Largest game has 13,000 CCUs • 800,000 msg/s (req, resp, ev) • 90 TB per month traffic • 40 Servers – US, Europe & Asia • Our „perfect“ Box – Single CPU, 4 Cores, 4GB RAM, 5TB traffic • Eat your own dogfood (deploy, stability, ops)
  20. 20. API/SDK Options • Plain APIs (full control) – Operation: Request/Response – Events: From the server • Photon Unity Networking (PUN) – API compatible to Unity Networking – Using Plain APIs under the hood – Get it in the Unity Asset Store • Playmaker (via PUN) – Using the PUN APIs
  21. 21. Photon Unity Networking (PUN)• Unity Networking (UN) is very convenient, simple and powerful• It is the entry point for most Indies to start Networking experiments• BUT it has several major draw backs ! UN needs a Master Server to be hosted ! P2P leads to NAT/punch-through issues (especially in mobile networks) ! Dropped hosts kill the games and so frustrate players ! UN will (probably) never run on the new Unity exports Flash / Chrome NaCl
  22. 22. PUN Feature CoverageSynchronization RPCs2 Position, Rotation, Scale 2 From client to client2 Serialization by script 2 By method name2 Buffered Instantiation 2 Receiver selectable- Animation 2 BufferedGrouping and Scope- Not supported by server Callbacks- Events are ignored accordingly 2 Player joins, leaves 2 Connection statesServer Logic 2 Instantiation2 MasterClient replaces Host(Remark: Photon is just used as „relay“) Network Simulation 2 Lag, Jitter, Loss - Bandwidth throtteling
  23. 23. Additional FeaturesPlatform as a Service (PaaS) Dashboard+ No server installs with the Cloud + See CCUs, Disconnects etc.+ Transparent load balancing Host TransitionProperties (Rooms and Players) + Remaining players select new+ Key-Value collection for custom data MasterClient(name, etc.) Offline ModeRuntime Scene GameObjects + Same logic for offline gaming+ Can be instantiated with owner“scene“
  24. 24. Counters to Track Down Issues Overall: A peers disconnects every 2h (average) 20k peers, 80msg/s per room, 800k msg/s Specific Game: A peers disconnects every 6-12min (average) Dig further in ...
  25. 25. Unite12 Announcement #1: • Cloud “forever free” plan • 20CCU • Unlimited apps
  26. 26. Unite12 Announcement #2: • Playmaker integration • Easy Unity Networking
  27. 27. Unite12 Announcement #3: For Indies • 1 Server: $99 • 3 Server: $199 Per title, unlimited CCUs
  28. 28. Part II: Photon Unite Networking (PUN) hands-on
  29. 29. Running a local Cloud • Register and get app ID (cloud.exitgames.com) • Download Photon Server • Unpack it • Run “MyCloud”
  30. 30. PUN Nuts & Bolts • Lobby – Matchmaking – Properties can be synced • Rooms – Exchange data in realtime (text, positions ...) – Set and get properties of Players and Rooms
  31. 31. Quick Usage Intro • ConnectUsingSettings() – US, EU or Asia • Get from the Lobby into a Room quickly – CreateRoom(), JoinRoom() • Setup a Monster for network sync – Add prefab – Add PhotonView – Add script for update
  32. 32. Properties & using them for Matchmaking • Properties are a key-value storage for custom data – Attached to Players or Rooms – Sample: Attach the played map to a room (map=„Island“) • Properties can be synced to the Lobby – Synced properties are defined on creation – Sample: Sync the map key-value to the Lobby • JoinRandomRoom() can filter rooms by properties – Pass in Hashtable of key-value pairs – Sample: Match rooms with a certain map
  33. 33. Tips & Tricks: Loading a Level • Two main Problems: – Long loading time causes a timeout (update thread is not called) – Updates getting lost during load (scene updates ...), e.g. objects do not exist yet • Pause message queue and dispatch after load – Creates a thread to keep connection alive • Setting a prefix – Detect quickly if message is for another level
  34. 34. Beyond PUN • Operations, Responses and Events • Calling operations • Handling Events • Event cache
  35. 35. Quality of Service (QoS) • How to reduce messages • How to read vital stats
  36. 36. Part III: References
  37. 37. 39
  38. 38. 40
  39. 39. 41
  40. 40. 42

×