Development
This article aims to introduce you into DDNet development, since it's an open-source game, it relies on random people kind enough to contribute to it on their free time.
Your development environment
It is extremely recommended to set up a Linux environment to begin programming in DDNet for the following reasons (as of now):
- Most DDNet contributors actually use Linux to contribute.
- Easier package management, you can easily install all the needed libraries and begin contributing.
- This article doesn't have yet a Windows version and is focused on Linux.
First an foremost, DDNet is coded using the C++ programming language, you will need to be fairly familiar with it, but you can also know the basics and learn more with it.
Some useful resources to learn C++:
- cplusplus tutorial
- cppreference.com
- Your search engine of preference
The source code of DDNet is managed using Git, a version control system, an essential tool to collaborate with multiple developers.
If you don't have git yet in your Linux distribution, make sure to install it, for example in most debian/ubuntu based distributions: sudo apt install git
.
Getting the source code
The source code is located on Github, you can get the source code by cloning without the need of an account, but if you want to ever put your changes to the official source code you will need one.
If you are not familiar with git/github you can learn the basics here: Hello World - Github
Installing the dependencies
If you are on Linux, you can install all the needed dependencies by reading the README on the DDNet github page: https://github.com/ddnet/ddnet#dependencies-on-linux--macos
For Arch Linux:
sudo pacman -S --needed base-devel cmake curl freetype2 git glew gmock libnotify opusfile python sdl2 sqlite wavpack
Compiling DDNet
We use CMake to control the compilation process, if you have all the dependencies installed, it's as easy as following these commands (make sure you are on the DDNet folder):
mkdir build
cd build
cmake ..
make -j$(nproc)
The source code layout
Now that you can build DDNet you can begin editing it.
The src/base directory
Since DDNet is a cross-platform game, an abstraction layer over that is needed to make development easier, this directory contains many useful functions to handle that.
The src/engine directory
Here lies the game engine, it handles most stuff that is not gameplay related, such as graphics, sound, network, etc...
The src/game directory
All gameplay related code is here, separated into client and server.
Server side
This game uses its own Entity Component System, the main class to which all other entities derive from is CEntity
located in src/game/server/entity.h
.
These entities are managed by the game world located here src/game/server/gameworld.h
Some important entities are:
- CCharacter: Represents a tee that is alive, it is instantiated when a tee spawns and deleted when it dies. For information about the player kept between deaths, see CPlayer.
Client side
The client side is made up of components, these are classes that inherit CComponent
: These components can implement the virtual methods such as OnInit
, OnMessage
, etc to provide their functionality.
Networking
The network protocol is mostly generated by python scripts that output C++ code, for example, datasrc/network.py
defines all network packets.
External resources
- An intro to the DDraceNetwork game source code by User:Ryozuki
- Code conventions in DDraceNetwork by User:Ryozuki
- Implementing a chat command in DDraceNetwork by User:Ryozuki
- Auto generated docs
- Technical documentation of Teeworlds file formats and network protocol
- The Anatomy of a One Tick Unfreeze
- Teeworlds programming YouTube tutorial by ChillerDragon