TRX/docs/CONTRIBUTING.md

309 lines
9.6 KiB
Markdown
Raw Permalink Normal View History

2021-10-23 00:00:39 +02:00
# Development guidelines
2021-02-12 13:47:17 +01:00
2023-08-24 01:10:49 +02:00
## Build workflow
2021-02-12 13:47:17 +01:00
2024-10-03 10:34:01 +02:00
Initial build:
2021-10-23 00:00:39 +02:00
- Compile the project (described in the next section)
2024-10-03 10:34:01 +02:00
- Copy all executable files from `build/` to your game directory
2024-10-14 11:30:59 +02:00
- Copy the contents of `data/*/ship/` to your game directory
2024-10-03 10:34:01 +02:00
Subsequent builds:
- Compile the project
- Copy all executable files from `build/` to your game directory
(we recommend making a script file to do this)
2021-10-23 00:00:39 +02:00
2024-04-09 15:08:46 +02:00
2023-08-24 01:10:49 +02:00
## Compiling
### Compiling on Ubuntu
2021-10-23 00:00:39 +02:00
- **With Docker**:
2024-10-02 10:23:23 +02:00
Make sure to install Docker and [just](https://github.com/casey/just).
To see the list of all possible build targets, run `just -l`. To build the
images, use the `just *-build-*` commands relevant to the game and platform
you want to build for. The binaries should appear in the `build/`
directory.
2021-10-23 00:00:39 +02:00
- **Without Docker**:
2021-10-23 00:00:39 +02:00
2021-11-17 12:08:20 +01:00
This scenario is not officially supported, but you can see how it's done by
2024-10-02 10:23:23 +02:00
examining the files in the `tools/*/docker/` directory for the external
dependencies and `meson.build` for the local files, then tailoring your
system to match the process.
2021-10-23 00:00:39 +02:00
2024-04-09 15:08:46 +02:00
2023-08-24 01:10:49 +02:00
### Compiling on Windows
2021-10-23 00:00:39 +02:00
- **Using WSL**:
Install WSL (video guide: https://www.youtube.com/watch?v=5RTSlby-l9w)
- Run Powershell as Administrator
- Copy and paste the following command: `Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux`
- Restart the computer
- Go to Windows App Store
- Install Ubuntu
Run WSL and continue with the instructions from the `Compiling on Ubuntu` section.
2025-01-02 00:04:22 -05:00
### Compiling on MacOS
MacPorts:
https://github.com/macports/macports-base/releases
- **With Docker**:
Make sure to install Docker and [just](https://github.com/casey/just).
To see the list of all possible build targets, run `just -l`. To build the
images, use the `just *-build-*` commands relevant to the game and platform
you want to build for. The binaries should appear in the `build/`
directory.
- **Without Docker**:
This scenario is not officially supported, but you can see how it's done by
examining the files in the `tools/*/docker/` directory for the external
dependencies and `meson.build` for the local files, then tailoring your
system to match the process.
2024-04-09 15:08:46 +02:00
2023-08-24 01:10:49 +02:00
### Supported compilers
Please be advised that any build systems that are not the one we use for
automating releases (= mingw-w64) come at user's own risk. They might crash or
2024-10-02 10:23:23 +02:00
even refuse to compile.
2023-08-24 01:10:49 +02:00
2024-04-09 15:08:46 +02:00
## Working with the project
### Top values
- Compatibility with the original game's look and feel
2024-10-03 10:34:01 +02:00
- Player choice whether to enable any impactful changes
2024-04-09 15:08:46 +02:00
- Maintainability
- Automation where possible
- Documentation (git history and GitHub issues are great for this purpose)
### Automatic code formatting
This project uses [pre-commit](https://pre-commit.com/) to make sure the code
is formatted the right way. This tool has additional external dependencies:
2024-09-17 23:27:12 +02:00
`clang-format` for automatic code formatting. To install pre-commit:
2024-04-09 15:08:46 +02:00
```
python3 -m pip install --user pre-commit
pre-commit install
```
To install required external dependencies on Ubuntu:
```
2024-09-17 23:27:12 +02:00
apt-get install -y clang-format-18
2024-04-09 15:08:46 +02:00
```
2024-10-03 10:34:01 +02:00
After this, each commit should trigger a hook to automatically format changes.
To manually initiate this process, run `just lint-format`. This excludes the
slower checks that could affect productivity for the full process, run `just
lint`. If installing the above software isn't possible, the CI pipeline will
indicate necessary changes in case of mistakes.
2024-04-09 15:08:46 +02:00
### Coding convention
2021-11-04 22:39:11 +01:00
- Variables are `lower_snake_case`
2021-11-24 18:00:06 +01:00
- Global variables are `g_PascalCase`
2024-10-03 10:34:01 +02:00
- Module variables are `m_PascalCase` and static
- Global function names are `Module_PascalCase`
- Module functions are `M_PascalCase` and static
2021-11-04 22:39:11 +01:00
- Macros are `UPPER_SNAKE_CASE`
- Struct names are `UPPER_SNAKE_CASE`
- Struct members are `lower_snake_case`
- Enum names are `UPPER_SNAKE_CASE`
2021-11-24 18:00:06 +01:00
- Enum members are `UPPER_SNAKE_CASE`
2021-11-04 22:39:11 +01:00
2024-10-03 10:34:01 +02:00
It's recommended to minimize the use of global variables. Instead, consider
declaring them as `static` within the module they're used.
2021-11-04 22:39:11 +01:00
2021-12-13 11:12:22 +01:00
Other things:
2024-10-03 10:34:01 +02:00
- We use clang-format to automatically format the code.
- We do not omit `{` and `}`.
- We use K&R brace style.
- We condense consecutive `if` expressions into one.
Recommended:
```c
2021-12-13 11:12:22 +01:00
if (a && b) {
}
```
2024-10-03 10:34:01 +02:00
Not recommended:
2021-12-13 11:12:22 +01:00
2024-10-03 10:34:01 +02:00
```c
2021-12-13 11:12:22 +01:00
if (a) {
if (b) {
}
}
```
2024-10-03 10:34:01 +02:00
When expressions become extraordinarily complex, consider refactoring them
into smaller conditions or functions.
2021-12-13 11:12:22 +01:00
2021-10-23 00:00:39 +02:00
2024-04-09 15:08:46 +02:00
### Submitting changes
2021-10-23 00:00:39 +02:00
2024-10-03 10:34:01 +02:00
We commit via pull requests rather than directly to the protected `develop`
branch. Each pull request undergoes a peer review and requires at least one
approval from the development team before merging. We ensure that all
discussions are resolved and aim to test changes prior to merging. When a code
review comment is minor and the author has addressed it, they should mark it as
resolved. Otherwise, we leave discussions open to allow reviewers to respond.
After addressing all change requests, it's considerate to re-request a review
from the relevant parties.
2023-08-24 01:10:49 +02:00
2024-04-09 15:08:46 +02:00
### Changelog
2021-10-23 00:00:39 +02:00
2024-10-03 10:34:01 +02:00
We maintain a changelog for each project in the `CHANGELOG.md` files, recording
any changes except internal modifications or refactors. New features and
original bug fixes should also be documented in the `README.md`. If a change
2025-02-04 19:45:28 +01:00
affects game flow behavior, be sure to update the `GAME_FLOW.md` accordingly.
2024-10-03 10:34:01 +02:00
Likewise, changes to the console commands should update `COMMANDS.md`.
2021-10-23 00:00:39 +02:00
2024-04-09 15:08:46 +02:00
### Commit scope
2021-10-23 00:00:39 +02:00
2024-10-03 10:34:01 +02:00
When merging, we use rebasing for a clean commit history. For that reason,
each significant change should have an isolated commit. It's okay to force-push
pull requests.
2021-10-23 00:00:39 +02:00
2024-04-09 15:08:46 +02:00
### Commit messages
2023-08-24 01:10:49 +02:00
2024-10-03 10:34:01 +02:00
**Bug fixes and feature implementations should include the phrase `Resolves
#123`.** For player-facing changes without an existing ticket, a ticket needs
to be created first.
2023-08-24 01:10:49 +02:00
Anything else is just for consistency and general neatness. Our commit messages
aim to respect the 50/72 rule and have the following form:
module-prefix: description in an imperative mood (max 50 characters)
Longer description of what happens that can span multiple lines. Each
2023-08-24 16:41:20 +02:00
line should be maximally 72 characters long, with the exceptions of
2023-08-24 01:10:49 +02:00
code/log dumps.
The prefix should describe the module that the pull request touches the most.
In general this is the name of the `.c` or `.h` file with the most changes.
Note that this includes the folder names which are separated with `/`. Avoid
underscores (`_`) in favor of dashes (`-`).
The description should be as concise as possible; any details should be given
in the commit message body. Use simple, to the point words like `add`, `fix`,
`remove`, `improve`.
Good:
```
ui: improve resolution changing
Added the ability for the player to switch resolutions directly from
the game ui.
Resolves #123.
```
Great:
```
log: fix varargs for Log_Message()
On Linux, the engine crashes when printing the log messages. This
happens because the current code re-uses the same va_list variable on
two calls to vprintf() and vfprintf(). Actually, this is not allowed.
For using the same information on multiple formatting functions, it is
needed to create a copy of the primary va_list to a second one, by using
va_copy(). After rewriting properly the Log_Message() function, the
segmentation fault is gone. Tested on both Linux and Windows builds.
```
2024-10-03 10:34:01 +02:00
> [!NOTE]
> This has no ticket number, but it was an internal change improving support
> for a platform unsupported at that time, which made it acceptable.
2023-08-24 01:10:49 +02:00
Bad:
2024-10-03 10:34:01 +02:00
2023-08-24 01:10:49 +02:00
```
ui: implemented the ability to switch resolutions from the ui
```
2024-10-03 10:34:01 +02:00
2023-08-24 01:10:49 +02:00
- the subject doesn't use imperative mood
- the subject is too long
2024-10-03 10:34:01 +02:00
- it's missing a ticket number
2023-08-24 01:10:49 +02:00
Bad:
2024-10-03 10:34:01 +02:00
2023-08-24 01:10:49 +02:00
```
dart: added dart emitters to the savegame (#779)
dart: added dart emitters to the savegame
Add function for checking legacy savegame save flags
Resolves #774.
```
- it duplicates the subject in the message body
- the subject doesn't use imperative mood
2024-10-03 10:34:01 +02:00
When using squash to merge, it is acceptable for GitHub to append the pull
request number, but it's important to carefully review the body field, as it
often includes unwanted content.
2023-08-24 01:10:49 +02:00
2024-04-09 15:08:46 +02:00
### Branching model
2023-08-24 01:10:49 +02:00
We have two branches: `develop` and `stable`. `develop` is where all changes
about to be published in the next release land. `stable` is the latest release.
We avoid creating merge commits between these two they should always point to
the same HEAD when applicable. This means that any hotfixes that need to be
released ahead of unpublished work in `develop` are merged directly to
`stable`, and `develop` needs to be then rebased on top of the now-patched
`stable`.
2024-04-09 15:08:46 +02:00
### Tooling
2024-10-03 10:34:01 +02:00
Internal tools are typically coded in a reasonably recent version of Python,
while avoiding the use of bash, shell, and similar languages.
2024-04-09 15:08:46 +02:00
### Releasing a new version
2023-08-24 01:10:49 +02:00
New version releases happen automatically whenever a new tag is pushed to the
`stable` branch with the help of GitHub actions. In general this is accompanied
2024-10-03 10:34:01 +02:00
with a special commit `docs: release X.Y.Z` that also adjusts the changelog.
See git history for details.
2023-08-24 01:10:49 +02:00
2024-04-09 15:08:46 +02:00
2023-08-24 01:10:49 +02:00
## Glossary
2024-10-03 10:34:01 +02:00
- OG: original game (for TR1 this is most often TombATI)
- PS: the PlayStation version of the game
- UK Box: a variant of Tomb Raider II released on physical discs in the UK
- Multipatch: a variant of Tomb Raider II released on Steam
2023-08-24 01:10:49 +02:00
- Vole: a rat that swims
- Pod: a mutant egg (including the big egg)
- Cabin: the room with the pistols from Natla's Mines
- Statue: centaur statues from the entrance of Tihocan's Tomb
- Bacon Lara: the doppelgänger Lara in the Atlantis level
- Torso/Adam: the big boss mutant from The Great Pyramid level
2024-10-03 10:34:01 +02:00
- Tomb1Main: the previous name of this TR1X project
- T1M: short hand of Tomb1Main