Top Banner
33

Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Apr 14, 2017

Download

Technology

Yoshifumi Kawai
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 2: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Work

Unity

Private

https://medium.com/@neuecc http://neue.cc/

@neuecc

https://github.com/neuecc/UniRx

Page 3: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Mobile JRPGhttps://kuro-kishi.jp

Unity

ASP.NET

Photon

Page 4: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Main feature on Game

Chat and Notification

Page 5: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Support C#!

Can be able to write logic in server

Have many cases in Unity

Page 6: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

PUN(Photon Unity Network)

We don’t use PUN,

use Client SDK(with Own Framework)

Page 7: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Getting Started

Photon Server

Page 8: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

It is class library

Execution flow

Page 9: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

public class Startup : ApplicationBase{

// create connection when connected on serverprotected override PeerBase CreatePeer(InitRequest initRequest){

if (/* from client request */){

return new MyClientPeer(initRequest);}else // from server request{

return new InboundS2SPeer(initRequest);}

}

protected override void Setup(){

// Launching process// Connect to master servervar outboundPeer = new OutboundS2SPeer();outboundPeer.ConnectTcp();

}

protected override void TearDown(){

// Quitting process}

}

public class MyClientPeer : ClientPeer{

public MyClientPeer(InitRequest initRequest): base(initRequest)

{

}

protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters{

// byte: operationRequest.OperationCode// Dictionary<byte, object>: operationRequest.Parameters

// Send response to clientthis.SendOperationResponse(new OperationResponse(), sendParameters);

}

protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail){}

}

Page 10: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

// 1. from Unity to Servervar peer = new ClientSidePeer(new MyListener());peer.OpCustom(opCode: 10, parameter: new Dictionary<byte, object>());

// 2. Receive on Serverprotected override void OnOperationRequest(OperationRequest operationRequest){

// switch by opCodeswitch (operationRequest.OperationCode){

case 10:// Parameter from dictionary(<byte, object>)var parameter = operationRequest.Parameters;

/* process request */

// 3. Send result to clientthis.SendOperationResponse(new OperationResponse(operationCode: 5));break;

default:break;

}}

Page 11: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

// Unity Clientpublic class MyListener : IPhotonPeerListener{

// 4. Received from Serverpublic void OnOperationResponse(OperationResponse operationResponse){

// Return responseswitch (operationResponse.OperationCode){

case 5:// process responsebreak;

}}

}

// 3. Server: Send result to clientthis.SendOperationResponse(new OperationResponse(operationCode: 5), sendParameters);

Page 12: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

// switch by opCodeswitch (operationRequest.OperationCode){

case 0:break;

case 1:break;

case 2:break;

case 3:break;

case 4:break;

case 5:break;

case 6:break;

case 7:break;

case 8:break;

case 9:break

case 10:break;

Page 13: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

// switch by opCodeswitch (operationRequest.OperationCode){

case 0:break;

case 1:break;

case 2:break;

case 3:break;

case 4:break;

case 5:break;

Page 14: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

// switch by opCodeswitch (operationRequest.OperationCode){

case 0:break;

case 1:break;

case 2:break;

case 3:break;

case 4:

Page 15: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 16: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Intro to PhotonWire

Page 17: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

send byte, Dictionary and switch and switch

Can not track send-receive message

Page 18: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 19: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 20: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Typed Asynchronous RPC Layerhttps://github.com/neuecc/PhotonWire

Page 21: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Windows Client

Page 22: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Server to Server

Page 23: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 24: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 25: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 26: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 27: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 28: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity
Page 29: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

Next PhotonWire

Page 30: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

DESERIALIZE SPEED

Replacing serializer

Page 31: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

(De)serialize is slow in Unity

ScriptableObject > JsonUtility > *** > MsgPack > XxxJSON

Page 32: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

New WireFormat which does not Deserialize

Fit to C# and Unity

Will be available soon

Page 33: Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity