SlideShare a Scribd company logo
Real-time Online Multiplayer
with
by fales
February, 2017
1 Introduction
Goals
Problems
Guidelines
Common techniques
TCP vs UDP
2 Godot Low Level Networking
Server
Client
Problems
Solutions
3 Godot High Level Networking
Server
Client
Optimizations
4 Benet module
5 End
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Goals
Having multiple persons playing the same game together, on different
machines, through a network.
No apparent input delay: Players must feel like they are playing the
game on their computer
No apparent lag or video delay: Players should experience a good
simulation
No cheaters: Players should not be allowed to do or see anything besides
what allowed by the game
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
The Internet is not a pipe
This is wrong
This is more like it
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Problems
Networks are unreliable (packets can take different route and
arrive out of order or get lost)
Networks have limited data rate and can be slow or become
clogged
Networks add delay (even the light takes time, imagine a
decades old copper twisted pair)
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Guidelines
There is no one fit all solution.
It really depends on you game. (genre, mechanics, interactions).
There are a few general guidelines
Everything should happen on the server, clients are mere
dummy displays.
Clients should only send their inputs or commands (server
must discard disallowed commands)
Send as little data as possible as often as possible to keep
latency at a minimum for RT games.
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Common techniques
UDP Networking
State synchronization
Interpolation
Compression/Size optimizations
Lag compensation
Common techniques
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
TCP vs UDP
TCP
Connection based
Reliable delivery
Ordered delivery
High latency
UDP
Connectionless
Unreliable delivery
Unordered delivery
Low latency
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Godot low level UDP
Echo Server
var _clients = []
var _udp = PacketPeerUDP .new()
func _ready ():
_udp.listen (4321)
set_process (true)
func _process(delta ):
var msgs = []
while _udp. get_available_packet_count () > 0:
var pkt = _udp.get_var () # or get_packet ()
var ip = _udp. get_packet_ip ()
var port = _udp. get_packet_port ()
if _clients.find(ip + ":" + str(port )) == -1:
# New client
_clients.append(ip + ":" + str(port ))
# Prepare message to be broadcasted
msgs.append(ip + ":" + str(port) + "-" + str(pkt ))
# Broadcast messages
for c in _clients:
var splitted = c.split(":")
_udp. set_send_address (splitted [0], int(splitted [1]))
for msg in msgs:
_udp.put_var(msg)
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Godot low level UDP
Client
var _udp = PacketPeerUDP .new()
func _ready ():
_udp. set_send_address ("localhost" ,4321)
set_process (true)
func _process(delta ):
var msgs = []
while _udp. get_available_packet_count () > 0:
var pkt = _udp.get_var () # or get_packet ()
msgs.append("Server␣says:␣" + str(pkt ))
# Show messages
for msg in msgs:
print(msg)
func send_data(data ):
_udp.put_var(data) # or put_packet
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Problems with UDP
Detect client disconnection (ping/timeout)
Detect out of order packets (time sync)
Detect/resend packet lost if we want it to be reliable
(sequence/acks)
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Some solutions
Have the client sends some ping packet, if a ping is not
received by the server for more than X seconds, the client
is considered disconnected
Send and additional time value with packets you want to be
ordered. Keep the last received time, if you receive a lower
time, drop it. (see wrap)
Have the two parties add sequence numbers to pacekets and
send acknowledgment of received data. Keep a queue of
last sent/received packets. Stop sending until you receive an
ack for the lowest missing packet if the new packet has a
sequence number higher than the lowsest plus the ack window
size. Reorder received packets... mess!
Note: have a look at var2bytes and bytes2var
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Godot High Level Networking
Based on ENet library (might change in the future or on
specific platform)
Allow both reliable and unreliable communication over UDP
Based on RPC calls
See http://docs.godotengine.org/en/latest/tutorials/high level multiplayer.html
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Godot High Level Networking II
Node network modes:
Master: This node is considered master (this instance owns it)
Slave: This node is considered slave (someone else owns it)
RPC/RSET modes:
sync: called both locally and over network
remote: called only remotely (no matter the owner)
slave: the function will be called only on slave nodes
master: the function will be called only on the master node
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Server
func create_server ():
set_network_mode ( NETWORK_MODE_MASTER )
var host = NetworkedMultiplayerENet .new()
host. create_server (4321 , 4)
get_tree (). set_network_peer (host)
var time = 0
func update_remote_state (tick ): # Tick is ideally 20/30 FPS (ie. 0.05/0.03)
var state = []
# Parse the game state
# ... eg.
state.append(get_pos ())
state.append( get_linear_velocity ())
# Send RPC , called on the node with the SAME PATH in the client
time += 1
rpc_unreliable (" update_state ", time , tick , state)
slave func update_state (time , tick , state ):
# ... (see next slide)
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Client
func create_client ():
set_network_mode ( NETWORK_MODE_SLAVE )
var client = NetworkedMultiplayerENet .new()
client. create_client ("127.0.0.1", 4321)
get_tree (). set_network_peer (client)
var last_time = 0
slave func update_state (time , tick , state ):
# Handle wrap -around , see rfc1185 as reference
if last_time >= time: # Out of order packet ... drop
return
last_time = time
# Handle state update here eg. tween this object
get_node("Tween"). stop_all ()
get_node("Tween"). interpolate_method (self , "set_pos",
get_pos (), state [0], tick ,
Tween.TRANS_LINEAR , Tween.EASE_IN)
get_node("Tween"). interpolate_method (self , " set_linear_velocity ",
get_linear_velocity (), state [1], tick ,
Tween.TRANS_LINEAR , Tween.EASE_IN)
get_node("Tween"). start ()
Note: the node that makes the RPC MUST have the same node path for in
both server and client for this to work
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Optimizations?
Try to bundle homogeneous data in the same state update
(but make sure the maximum packet size will be less than
400-450 bytes, or it might get dropped).
Optimize your state update! (see note, eg. boolean can be 1
byte instead of 4)
Use prediction!
Instead of interpolating recv pos and recv vel, interpolate to recv pos
+ recv vel * tick , and keep predicting till next frame
Note: http://docs.godotengine.org/en/stable/reference/binary serialization api.html
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Benet module
Developed to use ENet at full power
Does not use RPC (unless you want to)
Allow for broadcast send (to specific client)
Uses signals to notify of recv packets, clients
connect/disconnect
Allow for unreliable but ordered channels (you don’t have to
manage time)
Allows multiple channels
Github: https://github.com/Faless/godot-enet-better
Note: will likely not be included in Godot, I’m looking to port it to the C API
by karroffel and bojidar-bg when it’s ready
Real-time Online Multiplayer with Godot Engine fales
Introduction Godot Low Level Networking Godot High Level Networking Benet module End
Thanks for your time!
Questions?
Useful link:
http://gafferongames.com/networking-for-game-programmers/
Gaffer on Games - Game Networking
https://developer.valvesoftware.com/wiki/Lag compensation
Valve Wiki - Lag compensation
Full working demos in this presentation: https://github.com/Faless/godotcon-multiplayer
Real-time Online Multiplayer with Godot Engine fales

More Related Content

What's hot

Kafka’s New Control Plane: The Quorum Controller | Colin McCabe, Confluent
Kafka’s New Control Plane: The Quorum Controller | Colin McCabe, ConfluentKafka’s New Control Plane: The Quorum Controller | Colin McCabe, Confluent
Kafka’s New Control Plane: The Quorum Controller | Colin McCabe, Confluent
HostedbyConfluent
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
Chandresh Pancholi
 
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
David Salz
 
BitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven rendererBitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven renderer
tobias_persson
 
Designing software for a million users
Designing software for a million usersDesigning software for a million users
Designing software for a million users
Ian Sommerville
 
Cross platform app development with flutter
Cross platform app development with flutterCross platform app development with flutter
Cross platform app development with flutter
Hwan Jo
 
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Unity Technologies
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
Apigee | Google Cloud
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
José Paumard
 
Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab System
Unity Technologies
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
Slawomir Dorzak
 
Go, meet Lua
Go, meet LuaGo, meet Lua
Go, meet Lua
Andre Burgaud
 
GStreamer 101
GStreamer 101GStreamer 101
GStreamer 101
yuvipanda
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
ICS
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part III
Linux Internals - Part IIILinux Internals - Part III
Linux Internals - Part III
Emertxe Information Technologies Pvt Ltd
 
gRPC
gRPCgRPC
Async/Await
Async/AwaitAsync/Await
Async/Await
Jeff Hart
 
Parallel Futures of a Game Engine
Parallel Futures of a Game EngineParallel Futures of a Game Engine
Parallel Futures of a Game Engine
Johan Andersson
 
Mobile games
Mobile gamesMobile games
Mobile games
Thomas Grill
 

What's hot (20)

Kafka’s New Control Plane: The Quorum Controller | Colin McCabe, Confluent
Kafka’s New Control Plane: The Quorum Controller | Colin McCabe, ConfluentKafka’s New Control Plane: The Quorum Controller | Colin McCabe, Confluent
Kafka’s New Control Plane: The Quorum Controller | Colin McCabe, Confluent
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
 
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
 
BitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven rendererBitSquid Tech: Benefits of a data-driven renderer
BitSquid Tech: Benefits of a data-driven renderer
 
Designing software for a million users
Designing software for a million usersDesigning software for a million users
Designing software for a million users
 
Cross platform app development with flutter
Cross platform app development with flutterCross platform app development with flutter
Cross platform app development with flutter
 
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab System
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
 
Go, meet Lua
Go, meet LuaGo, meet Lua
Go, meet Lua
 
GStreamer 101
GStreamer 101GStreamer 101
GStreamer 101
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Linux Internals - Part III
Linux Internals - Part IIILinux Internals - Part III
Linux Internals - Part III
 
gRPC
gRPCgRPC
gRPC
 
Async/Await
Async/AwaitAsync/Await
Async/Await
 
Parallel Futures of a Game Engine
Parallel Futures of a Game EngineParallel Futures of a Game Engine
Parallel Futures of a Game Engine
 
Mobile games
Mobile gamesMobile games
Mobile games
 

Similar to Real-time Online Multiplayer with Godot Engine

FreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 serverFreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 server
Tomaz Muraus
 
"Taming the Dragon": Get Started with Zenoh
"Taming the Dragon": Get Started with Zenoh"Taming the Dragon": Get Started with Zenoh
"Taming the Dragon": Get Started with Zenoh
ZettaScaleTechnology
 
netty_qcon_v4
netty_qcon_v4netty_qcon_v4
netty_qcon_v4
Norman Maurer
 
class12_Networking2
class12_Networking2class12_Networking2
class12_Networking2
T. J. Saotome
 
Xilinx track g
Xilinx   track gXilinx   track g
Xilinx track g
Alona Gradman
 
Putting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internetPutting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internet
Andrew Roughan
 
13048671.ppt
13048671.ppt13048671.ppt
13048671.ppt
LyVu51
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Ericom Software
 
NAT and firewall presentation - how setup a nice firewall
NAT and firewall presentation - how setup a nice firewallNAT and firewall presentation - how setup a nice firewall
NAT and firewall presentation - how setup a nice firewall
Cassiano Campes
 
Computer network (12)
Computer network (12)Computer network (12)
Computer network (12)
NYversity
 
7 hands on
7 hands on7 hands on
7 hands on
videos
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
VoiceBootcamp Ccnp collaboration lab guide v1.0 sample
VoiceBootcamp Ccnp collaboration lab guide v1.0 sampleVoiceBootcamp Ccnp collaboration lab guide v1.0 sample
VoiceBootcamp Ccnp collaboration lab guide v1.0 sample
Faisal Khan
 
Building a Network IP Camera using Erlang
Building a Network IP Camera using ErlangBuilding a Network IP Camera using Erlang
Building a Network IP Camera using Erlang
Frank Hunleth
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
Hisaki Ohara
 
Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015
Hiroshi Ota
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
Xie ChengChao
 
Tensorflow in Docker
Tensorflow in DockerTensorflow in Docker
Tensorflow in Docker
Eric Ahn
 
Client server
Client serverClient server
Client server
maryam1231
 
An Empirical Evaluation of TCP Performance in Online Games
An Empirical Evaluation of TCP Performance in Online GamesAn Empirical Evaluation of TCP Performance in Online Games
An Empirical Evaluation of TCP Performance in Online Games
Academia Sinica
 

Similar to Real-time Online Multiplayer with Godot Engine (20)

FreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 serverFreeBSD, ipfw and OpenVPN 2.1 server
FreeBSD, ipfw and OpenVPN 2.1 server
 
"Taming the Dragon": Get Started with Zenoh
"Taming the Dragon": Get Started with Zenoh"Taming the Dragon": Get Started with Zenoh
"Taming the Dragon": Get Started with Zenoh
 
netty_qcon_v4
netty_qcon_v4netty_qcon_v4
netty_qcon_v4
 
class12_Networking2
class12_Networking2class12_Networking2
class12_Networking2
 
Xilinx track g
Xilinx   track gXilinx   track g
Xilinx track g
 
Putting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internetPutting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internet
 
13048671.ppt
13048671.ppt13048671.ppt
13048671.ppt
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
NAT and firewall presentation - how setup a nice firewall
NAT and firewall presentation - how setup a nice firewallNAT and firewall presentation - how setup a nice firewall
NAT and firewall presentation - how setup a nice firewall
 
Computer network (12)
Computer network (12)Computer network (12)
Computer network (12)
 
7 hands on
7 hands on7 hands on
7 hands on
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
VoiceBootcamp Ccnp collaboration lab guide v1.0 sample
VoiceBootcamp Ccnp collaboration lab guide v1.0 sampleVoiceBootcamp Ccnp collaboration lab guide v1.0 sample
VoiceBootcamp Ccnp collaboration lab guide v1.0 sample
 
Building a Network IP Camera using Erlang
Building a Network IP Camera using ErlangBuilding a Network IP Camera using Erlang
Building a Network IP Camera using Erlang
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015Network Test Automation - Net Ops Coding 2015
Network Test Automation - Net Ops Coding 2015
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
 
Tensorflow in Docker
Tensorflow in DockerTensorflow in Docker
Tensorflow in Docker
 
Client server
Client serverClient server
Client server
 
An Empirical Evaluation of TCP Performance in Online Games
An Empirical Evaluation of TCP Performance in Online GamesAn Empirical Evaluation of TCP Performance in Online Games
An Empirical Evaluation of TCP Performance in Online Games
 

Recently uploaded

Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
aisafed42
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 

Recently uploaded (20)

Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 

Real-time Online Multiplayer with Godot Engine

  • 2. 1 Introduction Goals Problems Guidelines Common techniques TCP vs UDP 2 Godot Low Level Networking Server Client Problems Solutions 3 Godot High Level Networking Server Client Optimizations 4 Benet module 5 End Real-time Online Multiplayer with Godot Engine fales
  • 3. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Goals Having multiple persons playing the same game together, on different machines, through a network. No apparent input delay: Players must feel like they are playing the game on their computer No apparent lag or video delay: Players should experience a good simulation No cheaters: Players should not be allowed to do or see anything besides what allowed by the game Real-time Online Multiplayer with Godot Engine fales
  • 4. Introduction Godot Low Level Networking Godot High Level Networking Benet module End The Internet is not a pipe This is wrong This is more like it Real-time Online Multiplayer with Godot Engine fales
  • 5. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Problems Networks are unreliable (packets can take different route and arrive out of order or get lost) Networks have limited data rate and can be slow or become clogged Networks add delay (even the light takes time, imagine a decades old copper twisted pair) Real-time Online Multiplayer with Godot Engine fales
  • 6. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Guidelines There is no one fit all solution. It really depends on you game. (genre, mechanics, interactions). There are a few general guidelines Everything should happen on the server, clients are mere dummy displays. Clients should only send their inputs or commands (server must discard disallowed commands) Send as little data as possible as often as possible to keep latency at a minimum for RT games. Real-time Online Multiplayer with Godot Engine fales
  • 7. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Common techniques UDP Networking State synchronization Interpolation Compression/Size optimizations Lag compensation Common techniques Real-time Online Multiplayer with Godot Engine fales
  • 8. Introduction Godot Low Level Networking Godot High Level Networking Benet module End TCP vs UDP TCP Connection based Reliable delivery Ordered delivery High latency UDP Connectionless Unreliable delivery Unordered delivery Low latency Real-time Online Multiplayer with Godot Engine fales
  • 9. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Godot low level UDP Echo Server var _clients = [] var _udp = PacketPeerUDP .new() func _ready (): _udp.listen (4321) set_process (true) func _process(delta ): var msgs = [] while _udp. get_available_packet_count () > 0: var pkt = _udp.get_var () # or get_packet () var ip = _udp. get_packet_ip () var port = _udp. get_packet_port () if _clients.find(ip + ":" + str(port )) == -1: # New client _clients.append(ip + ":" + str(port )) # Prepare message to be broadcasted msgs.append(ip + ":" + str(port) + "-" + str(pkt )) # Broadcast messages for c in _clients: var splitted = c.split(":") _udp. set_send_address (splitted [0], int(splitted [1])) for msg in msgs: _udp.put_var(msg) Real-time Online Multiplayer with Godot Engine fales
  • 10. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Godot low level UDP Client var _udp = PacketPeerUDP .new() func _ready (): _udp. set_send_address ("localhost" ,4321) set_process (true) func _process(delta ): var msgs = [] while _udp. get_available_packet_count () > 0: var pkt = _udp.get_var () # or get_packet () msgs.append("Server␣says:␣" + str(pkt )) # Show messages for msg in msgs: print(msg) func send_data(data ): _udp.put_var(data) # or put_packet Real-time Online Multiplayer with Godot Engine fales
  • 11. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Problems with UDP Detect client disconnection (ping/timeout) Detect out of order packets (time sync) Detect/resend packet lost if we want it to be reliable (sequence/acks) Real-time Online Multiplayer with Godot Engine fales
  • 12. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Some solutions Have the client sends some ping packet, if a ping is not received by the server for more than X seconds, the client is considered disconnected Send and additional time value with packets you want to be ordered. Keep the last received time, if you receive a lower time, drop it. (see wrap) Have the two parties add sequence numbers to pacekets and send acknowledgment of received data. Keep a queue of last sent/received packets. Stop sending until you receive an ack for the lowest missing packet if the new packet has a sequence number higher than the lowsest plus the ack window size. Reorder received packets... mess! Note: have a look at var2bytes and bytes2var Real-time Online Multiplayer with Godot Engine fales
  • 13. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Godot High Level Networking Based on ENet library (might change in the future or on specific platform) Allow both reliable and unreliable communication over UDP Based on RPC calls See http://docs.godotengine.org/en/latest/tutorials/high level multiplayer.html Real-time Online Multiplayer with Godot Engine fales
  • 14. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Godot High Level Networking II Node network modes: Master: This node is considered master (this instance owns it) Slave: This node is considered slave (someone else owns it) RPC/RSET modes: sync: called both locally and over network remote: called only remotely (no matter the owner) slave: the function will be called only on slave nodes master: the function will be called only on the master node Real-time Online Multiplayer with Godot Engine fales
  • 15. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Server func create_server (): set_network_mode ( NETWORK_MODE_MASTER ) var host = NetworkedMultiplayerENet .new() host. create_server (4321 , 4) get_tree (). set_network_peer (host) var time = 0 func update_remote_state (tick ): # Tick is ideally 20/30 FPS (ie. 0.05/0.03) var state = [] # Parse the game state # ... eg. state.append(get_pos ()) state.append( get_linear_velocity ()) # Send RPC , called on the node with the SAME PATH in the client time += 1 rpc_unreliable (" update_state ", time , tick , state) slave func update_state (time , tick , state ): # ... (see next slide) Real-time Online Multiplayer with Godot Engine fales
  • 16. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Client func create_client (): set_network_mode ( NETWORK_MODE_SLAVE ) var client = NetworkedMultiplayerENet .new() client. create_client ("127.0.0.1", 4321) get_tree (). set_network_peer (client) var last_time = 0 slave func update_state (time , tick , state ): # Handle wrap -around , see rfc1185 as reference if last_time >= time: # Out of order packet ... drop return last_time = time # Handle state update here eg. tween this object get_node("Tween"). stop_all () get_node("Tween"). interpolate_method (self , "set_pos", get_pos (), state [0], tick , Tween.TRANS_LINEAR , Tween.EASE_IN) get_node("Tween"). interpolate_method (self , " set_linear_velocity ", get_linear_velocity (), state [1], tick , Tween.TRANS_LINEAR , Tween.EASE_IN) get_node("Tween"). start () Note: the node that makes the RPC MUST have the same node path for in both server and client for this to work Real-time Online Multiplayer with Godot Engine fales
  • 17. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Optimizations? Try to bundle homogeneous data in the same state update (but make sure the maximum packet size will be less than 400-450 bytes, or it might get dropped). Optimize your state update! (see note, eg. boolean can be 1 byte instead of 4) Use prediction! Instead of interpolating recv pos and recv vel, interpolate to recv pos + recv vel * tick , and keep predicting till next frame Note: http://docs.godotengine.org/en/stable/reference/binary serialization api.html Real-time Online Multiplayer with Godot Engine fales
  • 18. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Benet module Developed to use ENet at full power Does not use RPC (unless you want to) Allow for broadcast send (to specific client) Uses signals to notify of recv packets, clients connect/disconnect Allow for unreliable but ordered channels (you don’t have to manage time) Allows multiple channels Github: https://github.com/Faless/godot-enet-better Note: will likely not be included in Godot, I’m looking to port it to the C API by karroffel and bojidar-bg when it’s ready Real-time Online Multiplayer with Godot Engine fales
  • 19. Introduction Godot Low Level Networking Godot High Level Networking Benet module End Thanks for your time! Questions? Useful link: http://gafferongames.com/networking-for-game-programmers/ Gaffer on Games - Game Networking https://developer.valvesoftware.com/wiki/Lag compensation Valve Wiki - Lag compensation Full working demos in this presentation: https://github.com/Faless/godotcon-multiplayer Real-time Online Multiplayer with Godot Engine fales