Game Engines 2021W Lecture 16

From Soma-notes
Revision as of 19:31, 11 March 2021 by Soma (talk | contribs) (Created page with "<pre> MMO's ----- MMOs are probably the hardest distributed applications to build What is hard when you do a distributed application? - managing consistent state - managing...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
MMO's
-----
MMOs are probably the hardest distributed applications to build

What is hard when you do a distributed application?
 - managing consistent state
 - managing latency

Latency is always an issue in games
 - time from input to modifying output
   - e.g., how long for a keypress to be echoed in a
     terminal
 - we want them responsive

But add in wide-area networking and it gets much harder
 - we're always fighting the speed of light
 - and networking infrastructure adds additional slowdowns
 - add in packet loss & delay and it gets much worse
   - really bad for TCP streams

TCP congestion control?

Internet is based on TCP/IP
 - IP: packets, sent best effort
   - just a fixed-sized record of data with source and
     destination, i.e., a message
   - IP makes no guarantees whether packets will arrive or
     not, or what order
 - TCP layers atop IP to build connections
   - i.e., a pipe
   - continuous byte stream with guaranteed order,
     integrity
   - but, at the cost of arbitrary delays (i.e.,
     data has to be re-sent)
 - if you don't need these guarantees, you use UDP
   on top of IP

So, if we care about latency, TCP is a problem
 - no guarantees about data delivery
 - in fact, when packets are lost, TCP interprets
   this as congestion (i.e., too much data) and expotentially slows things down (throttles)

Why is video streaming easier than gaming, from a distributed perspective?
 - you don't care about latency with video so much
 - so you can buffer
   - this is why pause can take a while to work on some
     platforms
   - (what should happen is pause happens instantly
      even if the data keeps coming for a while longer)
   - you really see this when seeking

You have to develop ways to hide latency in an MMO
 - but you can't just cache
 - one major strategy
   - predict what the players will do (simulations)
     - originally just dead reckoning
   - build in undo (rollback) when simulation is wrong
   

You also try to reduce latency
 - localized servers
 - minimize communication
   - send as little data as possible back and forth
   - but this means the clients have to do more
   - and this enables cheating
   - because the world is resident on the client
     - so the client knows things the player shouldn't
     - cheats can make this info available to the player
     - example: seeing through walls
   - this is why many online games are so strict about
     DRM or are restricted to consoles

The other hard thing with MMOs is managing shared state
 - because it is so easy to get inconsistency

This is really just the parallel programming problem
 - it is even hard on the client (i.e., multi-core
   programming)

Parallel programming is hard because it isn't easy
for two cores (connected in ANY way) to have consistent view of any shared state
 - really, the only data they manipulate are in their
   registers
 - data in registers is loaded from and stored to caches and then main memory (RAM), and from there sent over the network
   - at any place where data is stored, concurrent access
     is problematic
   - because all concurrent access is actually networking
     of some kind

Cores A and B, data x
A set x=5
B checks if x=5, then sets it to 0
What's the value of x?
 - could be 5, could be 0, depending on the order
 - this is a race condition

To avoid non-deterministic behavior, we have locks
 - but locks are just a protocol for deciding
   who went first
 - they ALWAYS slow things down, sometimes
   exponentially

So in the end, it is all messages
 - order of messages matter

data is never consistent unless we make sure it is

Player A shoots enemy, kill it
Player B sees enemy
 - is it dead?

This is why development in teams is harder than
development on your own
 - coordination is hard, because communication
   is expensive


Think about Fortnight
 - note the limit of 100 players, not too many,
   can be centralized in one server
 - matchmaking may use geographic location (ping times) to
   choose who should play whom
   - that's latency tolerant
 - lots of opportunities for predicting player behavior
 - but if your connection is bad, you're going to die
   and not even realize it

Whether your MMO works or not really depends on
your game design
 - has to take into account limitations of medium