Table of Contents

Building Socially Distant from source

Although Socially Distant is fairly straight-forward to build, it is slightly more complex than most .NET projects and therefore requires some prior one-time setup before you can successfully compile the game. Furthermore, this setup depends on what platform you're on. This article explains exactly how to build Socially Distant from source.

Pre-requisites

You will need:

  • A 64-bit PC running Windows or Linux
  • Steam
  • .NET SDK 8
  • For Linux users, Wine or Docker. You will need a Wine environment to compile shaders with.
  • Basic familiarity with the .NET CLI
  • Git

If you plan on contributing to the game, an acidic light community account is also required. You can create an account on the community GitLab server if you do not have any. Signing in with Discord, GitHub, and Patreon is also possible.

Clone the game

Clone the open-source version of the game to get started.

git clone https://gitlab.acidiclight.dev/sociallydistant/sociallydistant.git

If you plan to contribute to the game, you will need a fork on our GitLab server. Use the GitLab UI to create the fork, then add it as a remote to your cloned version of the repository.

git remote add fork https://gitlab.acidiclight.dev/YOUR_USERNAME/sociallydistant.git

For more info on contributing to the game, see Contribution guidelines.

Add the NuGet feed for Socially Distant

Socially Distant is made using Ritchie's Toolbox, a de facto custom game engine built on top of a fork of MonoGame. In order for .NET to acquire the required build tools and libraries for the game, you will need to add a new NuGet feed to your system's NuGet configuration. This only needs to be done once per user account per computer.

dotnet nuget add source -n gitlab-acidiclight https://gitlab.acidiclight.dev/api/v4/projects/13/packages/nuget/index.json

If, at any time, you want to remove this NuGet feed, run:

dotnet nuget remove source gitlab-acidiclight

IMPORTANT: Shader compilation

Shader compilation is a mandatory part of game compilation, and rather unfortunately, is flaky due to MonoGame limitations. If you want it to smoothly, and don't feel like troubleshooting, then follow this section to the letter.

If you're on Windows

Most likely, you will be fine. However, it is highly advised that you install Visual Studio with the ".NET Desktop Development" and "Desktop Development with C++" workloads. Even if you don't use Visual Studio as an IDE, this will ensure your system has the necessary native Windows libraries needed for asset compilation (including shader compilation) to succeed.

If you're on Linux

A Windows-compatible build environment is required for shader compilation to succeed. This is because MonoGame shaders are written in HLSL and compiled using MojoShader, which uses the proprietary Direct3D shader compiler under the hood.

Using Wine directly

If you plan on actually developing the game, the recommended way to set up shader compilation is by using Wine directly.

You will need a 64-bit Wine installation, i.e wine64. Some distributions do not properly package Wine, resulting in a 32-bit environment being set up even when you specifically asked for a 64-bit one. If you run into this, your distro has done you a dis-service and the game will not build.

The esaiest way to check if your distribution is sane is to set up a 64-bit Wine prefix and check the %PROCESSOR_ARCHITECTURE% environment variable within the Windows environment.

export WINEARCH=win64
export WINEPREFIX="$HOME/.winetest"
wine64 wineboot
wine64 cmd
C:\> echo %PROCESSOR_ARCHITECTURE%

If it outputs x86_64, then great. Otherwise, you're on your own.

When you've installed Wine64 and verified that it actually works, navigate to the root of your repository and run the MGFXC Wine setup script.

chmod +x mgfxc-wine-setuo.sh
./mgfxc-wine-setup.sh

You will need to log out of and log back into your computer for the changes to take effect.

You can verify that the setup finished successfully, after re-logging, by checking the MGFXC_WINE_PATH environment variable has been set.

echo $MGFXC_WINE_PATH
# should look like
/home/ritchie/.winemonogame

If the environment variable isn't set, you may need to configure your login shell to set it to the value of $HOME/.winemonogame.

Docker

If you have Docker on your system, and want to build the game that way, a pre-configured Docker image with the necessary build tools for Socially Distant is available. However, this is built primarily around being used for CI/CD rather than as a development environment. Nonetheless, you can get a container and run a shell on it with this command.

docker run --rm -it cr.acidiclight.dev/docker-images/monogame-linux-build/dotnet-mgcb:latest /bin/bash

Note that you will need to add the custom NuGet feed within the container itself.

Compile the game

If you've gotten this far, then everything from here on out is a breeze.

Quickly run the game

Run the game by running the SociallyDistant project with dotnet run. This compiles the game and launches it.

cd src/SociallyDistant
dotnet run

Build the game for release/installation

If you want to create a release version of the game, use dotnet publish to generate a self-contained build of the game for your platform. We do not create framework-dependent builds of the game for release, and we do not support the use of them, since self-contained builds are guaranteed to have the correct version of the .NET runtime bundled with them.

cd src/SociallyDistant

# Build for Linux
dotnet publish --self-contained -r linux-x64 -c release -o /path/to/build/output

# Build for Windows (Note: Must be done *on* Windows.)
dotnet publish --self-contained -r win-x64 -c release -o "C:\Path\To\Build\Output"

Building the Socially Distant Core

The third officially-supported way to build Socially Distant is to build its core framework (SociallyDistant.Framework). This builds only the parts of the game that are necessary to write mods with. In the future, the development workflow for mod developers will be streamlined.

Note: Do not do a self-contained build for SociallyDistant.Framework.

cd src/SociallyDistant.Framework
dotnet publish -c debug -o /path/to/modding/build/output

Then, reference the resulting assemblies in your mod's C# project.