docs: update developer guide with new generation pass instructions and examples

Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
方而静 2025-08-03 15:35:29 +08:00
parent 5ea6d46a9f
commit a241b9b9bf
Signed by: szTom
GPG Key ID: 072D999D60C6473C

View File

@ -160,22 +160,41 @@ Each biome defines terrain generation ratios:
To add a new generation pass: To add a new generation pass:
1. **Create Pass Implementation**: Add new file in `src/pass/` 1. **Create Pass Declaration**: Add a header file in `include/tilemap/pass/`, declaring a Pass class (e.g., `MyCustomPass`) that overloads `void operator()(TileMap &tilemap)`. See existing passes for structure and required members.
2. **Add to Pipeline**: Update `TerrainGenerator::operator()` 2. **Create Pass Implementation**: Add the corresponding implementation file in `src/tilemap/pass/`, implementing the declared class and its methods.
3. **RNG Management**: Use jump functions for independent RNG streams 3. **Add to Pipeline**: Update `TerrainGenerator::operator()` to invoke your new pass in the desired order.
4. **Configuration**: Add parameters to `GenerationConfig` if needed 4. **RNG Management**: Use jump functions to create an independent RNG stream for your pass, ensuring deterministic results. Pass the RNG to your class constructor as needed.
5. **Configuration**: If your pass requires configuration parameters, add them to `GenerationConfig` and pass them to your class.
Example pass structure: **Example header (include/tilemap/pass/my_custom_pass.h):**
```cpp ```cpp
void TerrainGenerator::my_custom_pass(TileMap &tilemap) { class MyCustomPass {
auto rng = master_rng_.jump_96(); // Independent RNG stream public:
MyCustomPass(const GenerationConfig &config, Xoroshiro128PP rng);
// Process tilemap... void operator()(TileMap &tilemap);
for (auto chunk_y = 0; chunk_y < tilemap.get_size(); ++chunk_y) { // ...other methods as needed...
for (auto chunk_x = 0; chunk_x < tilemap.get_size(); ++chunk_x) { };
auto& chunk = tilemap.get_chunk(chunk_x, chunk_y); ```
// Process chunk...
} **Example implementation (src/tilemap/pass/my_custom_pass.cpp):**
} ```cpp
MyCustomPass::MyCustomPass(const GenerationConfig &config, Xoroshiro128PP rng)
: config_(config), rng_(rng) {}
void MyCustomPass::operator()(TileMap &tilemap) {
// Process tilemap using config_ and rng_
// ...implementation...
} }
``` ```
**Pipeline integration:**
```cpp
void TerrainGenerator::operator()(TileMap &tilemap) {
// ...existing passes...
MyCustomPass custom_pass(config_, master_rng_.jump_96());
custom_pass(tilemap);
// ...other passes...
}
```
Refer to existing passes in `include/tilemap/pass/` and `src/tilemap/pass/` for detailed structure, member variables, and best practices.