Development Guide
This document explains how to continue development on jrpm. All patterns are based on actual code implemented in this project (cross-reference with commits in git log).
Code Organization Quick Reference
| Directory | Responsibility |
|---|---|
src/ | All C++ source code (top-level named by system: rail_cmd.cpp, group_gui.cpp...) |
src/network/ | Networking (server/client/UDP/HTTP/content download) |
src/script/ | Script framework (Squirrel); api/ for AI/GS API classes |
src/table/settings/*.ini | Setting definition sources (settingsgen generates code) |
src/lang/english.txt | String definitions (strgen generates) |
src/sl/saveload_common.h | Save version (SLV) enum |
bin/ai/ | AI scripts (GlobalAI is an example) |
Common Development Patterns
- Adding a Game Command: Command enum +
DEF_CMD_TUPLE_NT+ handler + GUI/console entry point - Adding a Script API:
script_*.hpp/.cpp(auto-registers Squirrel bindings) - Adding a Setting:
.ini+settings_type.hfield + string
Building
bash
cmake -B build ..
cmake --build build -jDevelopment Notes
- Encoding: When modifying source code/documentation containing Chinese characters, ensure UTF-8 (the Write/Edit tool on this machine may produce GBK encoding; use
jgrpp-features/_fix_utf8.pyto fix); - Commit messages: Recommended to use English (to avoid terminal encoding issues);
- Inserting into command enum mid-sequence shifts subsequent command IDs — old binary versions will be inconsistent with new versions in multiplayer; this is normal within a fork, upgrade must be synchronized;
- Save version: When modifying save structure, add a new
SLV_*entry insrc/sl/saveload_common.hand updateSAVEGAME_VERSION; - New files:
.cppmust be added to the correspondingCMakeLists.txtsource list (src/CMakeLists.txtor subdirectory/script/api/CMakeLists.txt);script_*.hppis auto-discovered byfile(GLOB), no registration needed; - New strings: Add to
src/lang/english.txt(other languages fall back to English); - NewGRF/save compatibility: Changing
_openttd_content_version/ NewGRF version number needs caution (affects multiplayer and content compatibility).
Regression Testing Suggestions (Important)
The current branch has not been compiled on a real machine. After the first build, it is recommended to test in this order:
- Basic:
openttd-jrpm -vshowsjrpm-0.1.0; - Save: single-player run for 1-2 game years;
- Multiplayer: jrpm clients connect to each other; jgrpp/pxp clients join;
- New features: train decoupling (decouple/couple/reverse), modular airports (modify layout), parallel download, auto-grouping, build tooltip, GlobalAI;
- Legacy feature regression: signals, tracerestrict, scheduled dispatch, template replacement.