lambdaclass / mirra_backend

Multiplayer 2D physics engine, matchmaking, market and leaderboard for 2D and 3D Games
Apache License 2.0
26 stars 5 forks source link

Mirra Backend

Mirra Backend is an umbrella project that contains several apps within it.

The objective is to split the project into multiple applications (modules) based on their responsibilities. This will allow us to add decoupled modules that can be used together without having a dependency between them.

Requirements

The installer will ask you for the sudo password, and then print the details about what steps it will perform to install Nix. You have to accept this to proceed with the installation.

Make sure there weren't any errors during the installation and, if there are none, close the shell and start a new one.

To test if Nix generally works, just run GNU hello or any other package:

nix run nixpkgs#hello
> Hello, world!

For a more detailed explanation, visit the Nixcademy installation guide.

After installing Nix, run the following command to install devenv:

nix-env -if https://install.devenv.sh/latest

For devenv to manage caches for you, add yourself to trusted-users in nix conf:

# Log in as super user first
sudo su -
vim /etc/nix/nix.conf
# Add the users you want to use nix store to nix.conf file
trusted-users = root your-user
# Restart nix-daemon
sudo launchctl kickstart -k system/org.nixos.nix-daemon

Clone the repo:

git clone https://github.com/lambdaclass/mirra_backend.git

Install the last elixir package manager inside devenv:

devenv shell
mix archive.install github hexpm/hex branch latest

Start applications

To build and run all the applications, run the following command:

devenv up

Then navigate to the following link to start a game: http://localhost:3000/

If you want to have access to the Elixir console, instead do:

devenv shell postgres
# Then in another terminal:
devenv shell
make start

Note you need to have ran devenv up earlier.

Applications

Arena

This app is responsible for handling the game logic and is composed of 2 parts:

To run this app individually, you can use the following commands:

cd apps/arena/
make deps
make start

For more information, you can read its documentation

Game Client

This app is a representation of the arena using simple 2D shapes and polygons that interact with each other. This provides a developer-friendly way to understand what is happening.

For now, this client is only connected to the Arena app, but it could be integrated with any other application.

To run this app individually, you can use the following commands:

cd apps/game_client/
make deps
make start

For more information, you can read its documentation

Gateway

Receives messages via websocket and routes them to the corresponding game's application.

ChampionsOfMirra

Application for Champions Of Mirra game. Has modules for:

GameBackend

Persistance layer and shared logic:

What's important to note is that each game's application decides how to use the functionalities these applications have. For example, take a look at how Champions of Mirra implements Champions.Units.select_unit/3 and unselect_unit/2. For the first one, we have some rules on how and when a unit can be selected, so we check they are met before calling the GameBackend app. For the second one, we don't care for the context it is called in, so we just call GameBackend.Units.unselect_unit/2 instantly. Another game might have different requirements for unit selection/unselection, and it would be handled in its own NewGame.Units module.

Configurator

This app is in charge of the configurations. Think either full game config or feature flags for A/B testing

In it you will be able to create new configurations and decide the default version to be used. Configurations are inmutable to allow rollbacks and easier A/B testing, you can always create a new one based on the default one or one in particular

Read more

Future iterations

In future iterations, we will add the following apps:

And some more.