SlideShare a Scribd company logo
1 of 117
Networking for Physics
    Programmers
        Glenn Fiedler
      www.gafferongames.com



         @gafferongames
DEMO
“How do I network my
 physics simulation?”
Network Models
1.   Pure client/server
2.   Client side prediction
3.   Deterministic lockstep
4.   Authority scheme
1. Pure client/server
How does it work?
•   Client does not run any game logic
•   Client sends input to server
•   Server sends render state back to client
Examples
•   SSH
•   VNC
•   OnLive
Applied to physics
•   Client send inputs to server
•   Server runs sim and sends position and
    orientation of rigid bodies back to client
•   Client buffers and interpolates between
    nearest two samples to render
Advantages
•   Simple
•   Secure
•   Late join is easy
Disadvantages
•   Round trip delay between player input and
    physics response
2. Client side prediction
How does it work?
•   Special treatment of local player object
•   Client simulates local player object ahead
    without waiting for server round trip
•   Server sends correction to client if it
    disagrees with client state
server




         n



client
server


input and state (n)



            n



 client
server


input and state (n)



            n



 client
server


input and state (n)



            n



 client
server


input and state (n)



            n



 client
server


input and state (n)



            n



 client
server


input and state (n)
                               state (n)


            n



 client
server


input and state (n)
                               state (n)


            n



 client
server


input and state (n)
                               state (n)


            n



 client
server


input and state (n)
                               state (n)


            n



 client
server


input and state (n)
                               state (n)


            n                   n+t



 client
server


input and state (n)
                               state (n)


            n                   n+t



 client
server


input and state (n)



            n                        n+t



 client
                      Lag time ‘t’
server


             rewind
                               state (n)


         n                      n+t



client
server


                 rewind
                                   state (n)


             n                      n+t



client     apply
         correction
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
server


             rewind
                                      state (n)


         n                             n+t



client
                      replay using
                      stored inputs
Examples
•   Halo (competitive)
•   Quake
•   Unreal
•   Counterstrike, TF2, Left4Dead, Portal 2?
Applied to physics
•   Determine player state (rigid body)
•   Advanced: May include objects player is
    interacting with
•   Rewind and replay all or part of simulation
    to apply correction from server
Advantages
•   No round trip delay for player actions
•   Almost as secure as pure client/server
•   Late join still relatively easy to implement
Disadvantages
•   Expensive to rewind and replay physics
•   Collision between player objects are poorly
    defined
3. Deterministic Lockstep
How does it work?
•   Each machine runs same game code
•   Wait for input from all players before
    advancing to next frame
•   Rely on determinism to stay in sync
Input Server




Peer to Peer
Input Server




         delay own input




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Input Server




Peer to Peer
Inputs(n)




            n
Inputs(n)




            n   n+1
n   n+1
Inputs(n+1)




        n     n+1
Inputs(n+1)




        n     n+1 n+2
n   n+1 n+2
Inputs(n+2)




  n   n+1 n+2
Inputs(n+2)




  n   n+1 n+2 n+3
n   n+1 n+2 n+3
n   n+1 n+2 n+3   ...
n   n+1 n+2 n+3   ...   ...
Examples
•   Every RTS ever made
•   Halo COOP story mode
•   Little Big Planet (soft body physics + fluids)
•   PixelJunk Shooter 2 (fluid sim)
•   Most fighting games (SF4, GGPO)
GGPO
•   Good Game Peace Out
•   Play Street Fighter 2 emulated ROM online
    without feeling latency
•   How does it do it?
Lag time ‘t’
...   n
Lag time ‘t’
      ...     n


Fork state!

              n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Lag time ‘t’
...   n




      n   n+1    n+2   n+3   ...   n+t
Inputs(n)

                        Lag time ‘t’
        ...   n




              n   n+1    n+2   n+3   ...   n+t
Inputs(n)

                              Lag time ‘t’
        ...   n   n+1




              n   n+1   n+2   n+3   ...   n+t
Lag time ‘t’
...   n   n+1




      n   n+1    n+2   n+3   ...   n+t


                discarded
Lag time ‘t’
 ...   n     n+1




       n     n+1   n+2   n+3   ...   n+t


Fork state

             n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1
Lag time ‘t’
...   n   n+1




      n   n+1   n+2   n+3   ...   n+t




          n+1   n+2   n+3   ...   n+t   n+t+1   :(
Applied to physics
•   Physics engine must be deterministic
•   Used fixed timestep decoupled from render
    framerate (eg. “Fix your timestep!”)
•   Fork all or part of simulation to hide
    latency
Advantages
•   Only need to send player inputs
•   Handles interactions between players well
•   Everything ‘just works’
Disadvantages
•   Low player counts only (2-4)
•   Floating point determinism world of pain
•   Late join can be difficult or impossible
•   Forking simulation is very expensive
4. Authority scheme
How does it work?
•   Split up the simulation and run parts of
    the world on different machines
•   Design the split to support networking
    goals, eg. latency hiding, convenience
Examples
•   Mercenaries 2
•   Insomniac games “Sync host”
•   Many, many other console games
Applied to physics
•   Take authority over objects you interact
    with. Become the server for these objects.
•   Resolve conflicts when multiple players
    want authority over the same object
DEMO
Advantages
•   Does not require 100% determinism
•   Does not wait for most lagged player
•   No need to rewind & replay or fork
    simulation to hide latency
Disadvantages
•   Trusting the client (cheating)
•   Difficult to handle interactions between
    multiple players
•   Late join is difficult
Network Models
1.   Pure client/server
2.   Client side prediction
3.   Deterministic lockstep
4.   Authority scheme
How to choose?
•   If latency is no problem, pure client/server
•   This is the simplest option
How to choose?
•   If you have too much state to send use
    deterministic lockstep
•   Beware of floating point determinism
•   Keep player count low (2-4)
•   Optional: Fork simulation to hide lag
How to choose?
•   If you aren’t deterministic, or have high
    player counts use client side prediction or
    authority scheme
How to choose?
•   Client side prediction is basically an
    anti-cheat measure for FPS
•   If you cannot afford it, do a COOP game with
    authority scheme instead
•   Advanced: Validate authority physics on
    dedicated server?
Thank you
Glenn Fiedler
www.gafferongames.com



   @gafferongames

More Related Content

What's hot (12)

NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
 
No Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time JavaNo Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time Java
 
Simple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time JavaSimple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time Java
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
Enhancing the region model of RTSJ
Enhancing the region model of RTSJEnhancing the region model of RTSJ
Enhancing the region model of RTSJ
 
2011.jtr.pbasanta.
2011.jtr.pbasanta.2011.jtr.pbasanta.
2011.jtr.pbasanta.
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 
Iterative Multilevel Empirical Bayes (IMEB): An efficient flexible and robust...
Iterative Multilevel Empirical Bayes (IMEB): An efficient flexible and robust...Iterative Multilevel Empirical Bayes (IMEB): An efficient flexible and robust...
Iterative Multilevel Empirical Bayes (IMEB): An efficient flexible and robust...
 
Ns2
Ns2Ns2
Ns2
 
Paxos building-reliable-system
Paxos building-reliable-systemPaxos building-reliable-system
Paxos building-reliable-system
 

Viewers also liked

Sustentación del proyecto 1
Sustentación del proyecto 1Sustentación del proyecto 1
Sustentación del proyecto 1luchitoroa
 
Recomendaciones para powerpoint
Recomendaciones para powerpoint Recomendaciones para powerpoint
Recomendaciones para powerpoint Nyaa1
 
Social media fm april 2011 tweede versie
Social media fm april 2011 tweede versieSocial media fm april 2011 tweede versie
Social media fm april 2011 tweede versieQRCommunicatie
 
Escola secundaria fernando lopes graça 2
Escola secundaria fernando lopes graça            2Escola secundaria fernando lopes graça            2
Escola secundaria fernando lopes graça 2guest76159cb
 
Componentes fisicos
Componentes fisicosComponentes fisicos
Componentes fisicosevelin75
 
Clase1 au liderazgo sep 2011 nueva
Clase1 au liderazgo  sep 2011 nuevaClase1 au liderazgo  sep 2011 nueva
Clase1 au liderazgo sep 2011 nuevaJavier Juliac
 
Bahia Políticas Públicas Baixo Sul
Bahia Políticas Públicas Baixo SulBahia Políticas Públicas Baixo Sul
Bahia Políticas Públicas Baixo SulRomeu Temporal
 
Atenas y la historia de la democracia
Atenas y la historia de la democraciaAtenas y la historia de la democracia
Atenas y la historia de la democraciaJordan Pskat
 
P O W E R P O I N T2
P O W E R P O I N T2P O W E R P O I N T2
P O W E R P O I N T2Apple
 
Historia clero
Historia cleroHistoria clero
Historia cleroEscoladocs
 
Learn to Publish A Scientific Research Paper
Learn to Publish A Scientific Research PaperLearn to Publish A Scientific Research Paper
Learn to Publish A Scientific Research Paperayman diab
 

Viewers also liked (20)

Sustentación del proyecto 1
Sustentación del proyecto 1Sustentación del proyecto 1
Sustentación del proyecto 1
 
Recomendaciones para powerpoint
Recomendaciones para powerpoint Recomendaciones para powerpoint
Recomendaciones para powerpoint
 
Tadeo graficas(1)
Tadeo graficas(1)Tadeo graficas(1)
Tadeo graficas(1)
 
Social media fm april 2011 tweede versie
Social media fm april 2011 tweede versieSocial media fm april 2011 tweede versie
Social media fm april 2011 tweede versie
 
Bullying
BullyingBullying
Bullying
 
Maicol
MaicolMaicol
Maicol
 
Escola secundaria fernando lopes graça 2
Escola secundaria fernando lopes graça            2Escola secundaria fernando lopes graça            2
Escola secundaria fernando lopes graça 2
 
Colores en la cultura mapuche
Colores en la cultura mapucheColores en la cultura mapuche
Colores en la cultura mapuche
 
Ruhr2010
Ruhr2010Ruhr2010
Ruhr2010
 
Componentes fisicos
Componentes fisicosComponentes fisicos
Componentes fisicos
 
Clase1 au liderazgo sep 2011 nueva
Clase1 au liderazgo  sep 2011 nuevaClase1 au liderazgo  sep 2011 nueva
Clase1 au liderazgo sep 2011 nueva
 
Bahia Políticas Públicas Baixo Sul
Bahia Políticas Públicas Baixo SulBahia Políticas Públicas Baixo Sul
Bahia Políticas Públicas Baixo Sul
 
Excchange Cristina and Maddie
Excchange Cristina and MaddieExcchange Cristina and Maddie
Excchange Cristina and Maddie
 
Woices
WoicesWoices
Woices
 
Atenas y la historia de la democracia
Atenas y la historia de la democraciaAtenas y la historia de la democracia
Atenas y la historia de la democracia
 
P O W E R P O I N T2
P O W E R P O I N T2P O W E R P O I N T2
P O W E R P O I N T2
 
José alberto lleberia gómez
José alberto lleberia gómezJosé alberto lleberia gómez
José alberto lleberia gómez
 
Historia clero
Historia cleroHistoria clero
Historia clero
 
Escuelas Verdes
Escuelas VerdesEscuelas Verdes
Escuelas Verdes
 
Learn to Publish A Scientific Research Paper
Learn to Publish A Scientific Research PaperLearn to Publish A Scientific Research Paper
Learn to Publish A Scientific Research Paper
 

Recently uploaded

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Recently uploaded (20)

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

GDC Networked Physics 2011

Editor's Notes

  1. \n
  2. \n
  3. Martijn het Hoofd & Matthijs Blaas emailed me and asked me\n\n“How do I network my physics simulation”\n\nI talked with them for many weeks over email explaining all that I know.\n\nDuring this conversation I discovered that the networking model that I use for my demo was probably not the best networking model for their game. \n\nThere’s more than one way to do it.\n
  4. So this talk is about how to choose the right network model for your physics simulation.\n\nA network model is the strategy you use for synchronizing your simulation over the network.\n\nIt’s what you put in your packets and what you do with it on the other side.\n\nEach network model presented here has it’s own tradeoffs, advantages and disadvantages.\n\nThis is the most important thing to understand about networking. The rest is implementation detail.\n
  5. \n
  6. First up is pure client server. \n\nAKA “dumb terminal”, “dumb client”, “thin client”\n
  7. The most important thing to understand is that the client does not run any game logic.\n\nThe client is dumb.\n\nThe client just sends the inputs to the server.\n\nThe server sends to the client whatever the client needs to show what’s happening on the server.\n
  8. Some examples:\n\nSecure shell. Key presses are sent to the machine you are connected to. It sends back the terminal codes so you can see what happens.\n\nVNC. Mouse and keyboard input sent to server. Compressed bitmaps sent back to client.\n\nOnLive. Controller input sent to server. Video stream sent back to client.\n
  9. How can we apply this to a physics simulation?\n\nEach client sends their inputs controlling the simulation to the server. eg. arrow keys.\n\nEach frame the server takes the last input from each client and steps the simulation forward\n\nThe server sends positions and orientations for each rigid body back to the client.\n\nThe client buffers these positions and orientations and interpolates between them to render.\n
  10. It’s simple.\n\nIt’s secure.\n\nAnd it’s easy to support late join (joining a game already in progress).\n
  11. But there is a delay before you see the result of your input.\n\neg. You press “up” then 250ms later you move forward.\n
  12. \n
  13. Client side prediction is the technique first person shooters use to hide this latency.\n
  14. Here is how it works:\n\nThe local player object is treated differently from other objects.\n\nThe client player runs the same simulation code that runs on the server for his object to advance himself forward without waiting for the input round trip to the server and back.\n\nThis is done while still keeping the server authoritative over the client player position, orientation etc \n\nThis is important on the PC because otherwise players could cheat.\n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. apply correction (in the past!)\n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. Some examples: \n\nHalo competitive mode. \n\nQuake. Unreal. All Valve games. I assume Portal 2 does as well, although I’m not 100% sure.\n\n\n
  41. How to apply client side prediction to physics?\n\nSend both the inputs and the player state to the server\n\neg. position, orientation, linear velocity, angular velocity.\n\nAs an advanced technique, you can also attempt to perform client side prediction on other objects the player is interacting with, eg. the vehicle they are in, or the objects they are pushing around\n\nValve has been doing this since Left4Dead 2.\n
  42. Advantages:\n\nNo delay between player input and actions.\n\nAlmost as secure as client server. \n\nLate join is still relatively easy to implement.\n
  43. Disadvantages:\n\nRewinding and replaying the simulation can get expensive (CPU)\n\nAlso because each player is predicting ahead according to their own inputs without considering the inputs of other players, inconsistencies occur when player objects collide with each other.\n\nThis is why first person shooters are usually static worlds where players interact at a distance\n
  44. \n
  45. Next is deterministic lockstep.\n
  46. Each machine runs the same game code and waits for all player inputs before simulating the frame.\n\nThe idea is that if the same initial state + the same inputs gives the same result, then all machines stay in sync.\n\nIMPORTANT: In order for this to work you need exactly the same result down to the floating point bits. Not close. Not near. Exactly the same.\n\nThis can be quite difficult to achieve in practice. Google “Floating point determinism” for details.\n
  47. \n
  48. Age of Empires “1500 Archers” article on Gamasutra.\n
  49. \n
  50. \n
  51. \n
  52. \n
  53. Problems with lag switches. One player can delay packets making other players wait.\n
  54. Input server.\n\nStarcraft 2 does something like this.\n\nBetter protection against lag switches.\n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. Every RTS game ever made. Too many units to possibly send over the network.\n\nHalo COOP mode uses deterministic lockstep. They have different network models for competitive and COOP play.\n\nLittle big planet has soft body physics and fluid simulation. Too much state to send.\n\nPixelJunk shooter has a fluid simulation with hundreds of thousand particles. Too much state to send.\n\nFighting games. SF4. GPPO typically networked deterministic lockstep because players interact with each other as a rule.\n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. Low player counts because you must wait for the most lagged player.\n\nStatistically speaking as the number of players increase the chance that at any moment some player is experiencing network problems approaches 1.\n\nThis is why there are no MMOs using deterministic lockstep :)\n\nFloating point determinism is difficult to achieve. Possible but difficult.\n\nLate join. Hard to capture deterministic checkpoint and restore it on another machine. What if you had 100,000 particles in your world? Too much state to send in any reasonable amount of time.\n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. Explain why I went with authority scheme.\n\nI don’t want latency when moving around so I can’t use pure client/server.\n\nI want to roll around in a big katamari ball without lag so client side prediction is a bit difficult, the simulation is very expensive and I cannot afford to rewind and replay it.\n\nMy demo is a large streaming world and in a real world situation the loading of assets from disk when objects activate would not be deterministic: eg. streaming from disk. I cannot use deterministic lockstep.\n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n