#C1 Multiplayer Gaming: A Networking Case Study

#C1 Multiplayer Gaming: A Networking Case Study

·

6 min read

As a game programming student at Kingston University London, I'm currently engaged in the 'Connected Games Development' module [#C - Blogs of Connected Games Module], crafting a multiplayer game. Throughout this process, I'll be documenting my learning, development challenges, and every step of the journey here.


Introduction

This article serves as a comprehensive case study that covers networking models, protocols, common challenges, and optimization techniques. Let's take a look into the fundamental elements that shape the backbone of multiplayer gaming.


I. Network Models: A Deeper Look

A. Client-Server Model

  • In the client-server model, a centralized server bears the responsibility of managing game logic and state. Clients communicate with the server to send and receive data.

    Typical client-server architecture: server maintains canonical game... |  Download Scientific Diagram

  • Pros: The simplicity of implementation, centralized control.

  • Cons: Potential single point of failure, scalability challenges.

  • Types:

    • Dedicated Server: A standalone server solely focused on managing the game state.

    • Listen Server: A player's client acts as both the server and a client.

B. Peer-to-Peer Model

  • In a peer-to-peer model, all participating peers share the game state, creating a decentralized network. Each peer communicates directly with others.

    Building a realtime multiplayer browser game in less than a day - Part 2/4  - DEV Community

  • Pros: Enhanced scalability, no single point of failure.

  • Cons: Synchronization complexities arise, potential for cheating.

  • Types:

    • Unstructured P2P: Peers communicate directly with each other without a centralized control mechanism.

    • Structured P2P: Peers are organized into a structured network, enhancing efficiency.

C. Hybrid Models

  • Hybrid models blend aspects of both client-server and peer-to-peer architectures, striking a balance between control and scalability.

    PDF] A Hybrid Scheme for Massive Multiplayer Online Games using Mobile  Agent on Dynamic Quadtree Architecture | Semantic Scholar

  • Pros: Offers a compromise between control and scalability.

  • Cons: Implementation complexity increases, potential synchronization issues.

  • Example: Destiny 2 employs a hybrid model, combining the stability of dedicated servers with the scalability of peer-to-peer connections.

    A Look At GPU Performance In Destiny 2: 1080p, 1440p, Ultrawide & 4K –  Techgage


II. Navigating the Sea of Protocols: Choosing Wisely

A. TCP (Transmission Control Protocol) vs. UDP (User Datagram Protocol)

  • TCP: TCP ensures reliable and ordered data transfer, making it suitable for applications where data integrity is crucial.

    • Pros: Ensures data integrity.

    • Cons: Higher latency, unsuitable for real-time applications.

    • Use Cases: Player authentication, non-real-time game data.

  • UDP: UDP facilitates fast but unreliable data transfer, ideal for real-time applications like multiplayer gaming.

    • Pros: Low latency, ideal for real-time applications.

    • Cons: No guarantee of delivery or order.

    • Use Cases: Real-time player movements, fast-paced actions.

      Introductory Guide to Tuning Your TCP and UDP Performance

B. Additional Protocol Considerations

  • WebSocket: A protocol providing full-duplex communication channels over a single, long-lived connection.

  • HTTP/2: Enhances web performance and efficiency, suitable for certain game-related communication.

C. Choosing the Right Protocol

  • Game Requirements: Tailoring the choice of protocol based on the specific requirements of the game.

  • Hybrid Approaches: Leveraging TCP for critical data and UDP for real-time updates.

  • Example: Fortnite utilizes a combination of TCP and UDP for efficient data transfer.

    The metaverse is already here — it's called Fortnite | by Owen Williams |  Medium


III. Overcoming Network Challenges: Battling Latency, Lag, Jitter, and Packet Loss

A. Understanding Latency

  • Latency is the time delay between input and the corresponding output in a networked environment.

    High latency player peeks a Low latency player

  • Techniques: Employing client-side prediction to simulate future states based on past inputs, and implementing lag compensation.

B. Lag and Jitter

  • Lag: Lag is the delay in data transfer, affecting the responsiveness of the game.

  • Jitter: Jitter refers to the variation in latency over time.

  • Mitigation: Implementing buffering mechanisms and smoothing algorithms.

    How It Works: Lag compensation and Interp in CS:GO on Make a GIF

C. Packet Loss

  • Definition: Packet loss occurs when data packets are lost during transmission.

  • Combat Strategies: Employing error correction techniques and packet retransmission.

    What is Packet loss and how to fix it - YouTube

    Latency, the time delay in data transmission, directly contributes to lag in online gaming, creating a noticeable delay between actions and their outcomes. Packet loss exacerbates these issues by requiring retransmission of lost data, further increasing latency and amplifying lag. In the intricate dance of online gaming, minimizing latency and addressing packet loss are essential for a seamless and responsive player experience.

Jitter - NETWORK ENCYCLOPEDIA


IV. Strategies for Seamless Gameplay: Avoiding Common Pitfalls

A. Prediction Techniques

  • Client-Side Prediction: Simulating future states based on past inputs to maintain smooth gameplay.

  • Types:

    • Dead Reckoning: Predicting a player's future position based on their current velocity and direction. This method assumes that the player will continue moving in the same trajectory.

      Dead reckoning - Wikipedia

      • Extrapolation: Estimating future states based on historical data. For example, predicting a player's position by extrapolating from their recent movements.

      • Interpolation: Filling in the gaps between received data points to create a smoother representation of player movement.

        Example for one-dimensional interpolation and extrapolation. | Download  Scientific Diagram

  • Server-Side Prediction: The server handles prediction to ensure consistency among all players.

    • Deterministic Prediction: The server uses a deterministic simulation to predict the outcomes of players' actions based on received inputs. This ensures that all clients receive the same predictions, maintaining synchronization.

      Randomness and Game Design – KEITH BURGUN GAMES

B. Optimization Methods

  • 1. Bandwidth Optimization: Minimizing data transfer for efficiency.

    • 1.1 Delta Compression: Sending only the changes (delta) in game state rather than the entire state, reducing the amount of data transmitted.

      The illustration of normal compression and delta compression. | Download  Scientific Diagram

    • 1.2 Networked Entity Interpolation: Smoothly interpolating the position and movement of entities between received updates to reduce choppiness in movement.

      Entity Interpolation - Gabriel Gambetta

    • 1.3 State Synchronization: Sending only the relevant state information to each player, optimizing the use of bandwidth.

      Game server synchronization of large amounts of data in a battle | Welcome  to Monstarlab's Engineering Blog

  • 2. Spatial Partitioning: Efficiently updating and transmitting relevant game data to reduce unnecessary traffic.

    • 2.1 Bounding Volume Hierarchy (BVH): Dividing the game world into hierarchical bounding volumes, optimizing collision detection and reducing the number of updates needed.

      Bounding volume hierarchy - Wikipedia

    • 2.2 Octrees: Dividing 3D space into octants, useful for efficiently culling objects that are not visible to a player.

      Advanced Octrees 1: preliminaries, insertion strategies and maximum tree  depth | The Infinite Loop

  • Example: Minecraft uses a combination of delta compression and spatial partitioning to optimize network traffic. It sends only the changes in the game world and uses spatial partitioning to transmit data relevant to a player's location.

    Minecraft | Nintendo Switch games | Games | Nintendo


Conclusion

In summary, this exploration of game networking reveals the intricate tapestry that underlies a successful multiplayer experience. From the foundational choices of network models and protocols to the art of prediction and optimization, every facet contributes to the seamless dance of data in connected games.

Recognizing the interconnected challenges of latency, lag, and packet loss, I am poised to apply these insights in crafting a responsive and immersive 3v3 multiplayer game. I'll share my progress, insights, and the unfolding steps in the creation of this multiplayer game. I hope you find this case study [#C1] helpful, see you in #C2.

Until the next update, happy coding!