Learn how to create a simple multiplayer game using Hadean Simulate and Hadean Connect.
Open the Hello Universe completed code from your starter pack, and over the following pages we'll discuss the components of a Simulate simulation in detail and demonstrate how to build the project, finishing with running the simulation in the cloud.
When creating a project using Simulate and Connect, there are three components that need to be created:
Simulate projects are all about creating a simulation. This is where the code for any game logic, scientific models or user interactions will be. The logic you write here will allow you to update the state of entities that exist in your simulation. Entities can have any state you like - maybe they have health and ammunition, or maybe they have an infection status. The two things that entities must have are a unique ID, and a position.
Simulate will use the position to understand which cell the entity belongs to, and from that which workers need to know about the entity. Simulate achieves scale by only letting workers that are simulating cells near an entity know about that entity - no individual worker will have a view of all entities in the simulation. This can sound scary, so Simulate provides a set of APIs to help you out, we'll show you some over the next few pages.
Having Simulate simulating all the entities in the world space is great, but normally we want to be able to see and interact with them. Imagine a game with no players - not much fun! But sending millions of entities to every player over the internet is not practical. To allow players to interact with simulations that have millions of entities and thousands of players, Simulate uses Connect. Connect is all about figuring out which entities a player needs to know about. The process of figuring out which entities a player should know about each tick is handled by the netcode.
The netcode is often the secret sauce in making a game run smoothly, and so Connect allows you complete control over what you need. Creating a really smooth, efficient netcode can be a difficult problem, so to help out Connect provides a generic implementation, which you can drop in to start using Connect quickly.
Simulate and Connect together allow you to scale your game to handle millions of entities and thousands of players. But taken on their own your players won't have a great experience - we need a client that can render all the entities and allow users to control their characters. The choice of client is left largely to you - using established game engines such as Unreal Engine or Unity are good choices, or you can use a custom engine.
Whichever engine you decide to use for your client, it must be able to interact with Connect. To help with this, Connect provides a Connect Client library that you can include in your project. This library will allow you to connect to a Connect node, receive entity data and send back messages for player input or state.
The starter pack includes shell scripts to build and run the simulation, either on your local machine or on a cluster. You can also modify these scripts as necessary as you progress with your project.
HelloUniversedirectory/folder in your IDE of choice to examine and modify the source code.
To build your project, simply run the following from your WSL or Linux terminal:
$ cd /path/to/your/simulate/project
$ ./scripts/build.sh all
This will build all of the components of your simulate project including the simulation itself, the clients, and netcode. It may take a few minutes depending on the specification of your VM. You can run
build.shwithout any parameters to see the various options for building individual components.
Once your project has built, use the following script to run it locally:
The run script pipes the output via a log filter/parser so you may only see a subset of the log output on your terminal. Press
CTRL-Cto end the simulation.
Congratulations - you have now run your first Hadean Simulate project!