top of page

Netgame

Overview

  • Role: Programmer

  • Genre: 3D Multi-Player First-Person Space Combat

  • Engine: Personal Engine in C++

  • Team Size: Myself

  • Development Time: 3 months

High Concept

Netgame is an online first-person space combat sim where players control their own spaceships to fight against other players on a lost planet.

Core Mechanics

The Network System

    Netgame is a multi-player game, which means the most important part in the development stage is to build a strong and stable server that provides minimum network fluctuations. Hence, I built a network system that can create an authoritative server and a remote server. The authoritative server is the main server that holds the game instance, updates game information, and creates clients. Every major update needs to be handled in this server and then sends back to all the remote servers. The remote server is the player's server that runs the game, sends updated information to the authoritative server, and updates the game after receiving messages from the main server.

 

    Both two servers contain a key component called endpoint. It contains two threads, the server and the receiver. The server waits for the server to send messages. the receiver receives messages, reads information, and passes the information to its server. The code below shows how each thread does its job using thread-safe queues. 

WeChat Screenshot_20220221002409.png

    Since the game needs to handle hundreds or thousands of packages every second, it uses UDP protocol to send and receive messages, which causes package drops sometimes but much faster package reading speed. Also, since the main goal of this project is to practice online game development, it doesn't not very complicated security techniques to avoid hacking and cheating.

Phong Lighting and Normal Mapping

    In my previous project Simple Miner, I used a really simple lighting technique to handle point lighting. In this project, I implemented phone lighting instead to give a better view of the graphics. The method I used is Phong lighting, which gives more glossy surfaces. To do that, I created a lighting shader that can calculate the lighting color on any pixels based on their normal values. The image below illustrates how directional lighting is applied in the game where hills have a bright side and a shadow side. 

WeChat Screenshot_20220221004213.png

    Since players are controlling spaceships in the game, I wanted the ships to look great, to add more details. While keeping the same vertexes of the ships, I used normal mapping to enhance the appearance and details of the ships. The code below is the final shader used for rendering the models. The game first reads each model's normal, binormal, and tangent information. Then it passes the information to the shader when rendering the model. Finally, the shader extracts the actual normal from the normal texture and uses it to calculate lighting. 

WeChat Screenshot_20220221004945.png

FBX Model Loading

    FBX model is one of the most common model types used in the game industry. In my previous projects, all I did was just create a shape and attach textures to it. In Netgame, I implemented an FBX loader that can load any FBX models including their vertexes, lighting, and camera information. The image below shows the Corvette's information read by the FBX loader. The loader can read its camera information and create cameras attached to the object class, which allows players to switch between different cameras during the game.

WeChat Screenshot_20220221010313.png

    The example below demonstrates what an arrow cube looks like in the 3D viewer and in the game. The lighting applies perfectly on the cube, and also the normal mapping shows its bumps and dents.

WeChat Screenshot_20220221010809.png
ezgif.com-gif-maker (15).gif

The Particle System

    In Netgame, I implemented a particle system that can generate particles based on the input settings and render the particles using the particle shader I wrote. The idea is to rewrite the geometry shader that can expand one vertex into a billboard facing the player's camera. The new shader now can render particles just like any other professional engines do, which allows me to generate an explosion particle. The image below shows an example of particles in the game. The particles spawn at the end of the missile and then gray out after existing time. 

   

WeChat Screenshot_20220221011905.png

    The code below shows the particle system generating particles based on the input settings. It first determines how many particles it needs to emit in this frame and then generates the particles. Each particle will know its existing time, start color, end color, start scale, and end scale. The advantage of this system is that I can modify it easily. If I want to add speed variances, I can simply add a speed variable, which now the system can apply a randomized speed to each new particle. 

   

WeChat Screenshot_20220221012610.png

Post Mortem

What Went Well

  • The game supports a maximum of 4 players playing at the same time.

  • Learned some rendering techniques that are commonly used in the game industry.

  • Learned how multi-player games work behind the scenes. 

  • Designed a particle system in my engine that can be used in the future.

What Went Wrong

  • Performance is a problem in which the game will be laggy after 10 minutes of playing.

  • The game could crash if multiple people try to connect as the authoritative server.

What Needs Work

  • The game should be able to handle package drops.

  • Much game-related information was stored in the engine which should be moved to the game part later.

  • Performance improvement.

Netgame
Overview
Core Mechanics
The Network System
Phong Lighting and Normal Mapping
FBX Model Loading
The Particle System
Post Mortem
bottom of page