szdytom 0b245e0483
feat: Add dual noise terrain generation demo
- Introduced a new example `dual_noise_demo.cpp` to showcase the base and surface generation system.
- Updated biome properties to include ice thresholds and surface feature parameters.
- Enhanced chunk structure to support biomes for sub-chunks.
- Refactored terrain generation logic to separate base terrain and surface feature generation.
- Improved biome determination logic to include new biomes and their properties.
- Updated tile representation to use enums for base and surface tile types.
- Added detailed analysis of generated terrain and sample tile outputs in the demo.

Signed-off-by: szdytom <szdytom@qq.com>
2025-08-01 15:32:36 +08:00

79 lines
2.0 KiB
C++

#ifndef TILEMAP_BIOME_H
#define TILEMAP_BIOME_H
#include <cstdint>
#include <string_view>
namespace istd {
// Biome types based on temperature and humidity
enum class BiomeType : std::uint8_t {
Desert = 0, // Hot & Dry
Savanna = 1, // Hot & Moderate
TropicalRainforest = 2, // Hot & Wet
Grassland = 3, // Temperate & Dry
DeciduousForest = 4, // Temperate & Moderate
TemperateRainforest = 5, // Temperate & Wet
Tundra = 6, // Cold & Dry
Taiga = 7, // Cold & Moderate
FrozenOcean = 8 // Cold & Wet
};
// Biome properties for terrain generation
struct BiomeProperties {
// Base terrain thresholds (0.0 - 1.0)
double water_threshold;
double mountain_threshold;
double sand_threshold;
double ice_threshold;
// Surface coverage thresholds (0.0 - 1.0)
double wood_threshold;
double snow_threshold;
// Noise parameters for base terrain
double base_scale;
int base_octaves;
double base_persistence;
// Noise parameters for surface features
double surface_scale;
int surface_octaves;
double surface_persistence;
// Biome name for debugging
std::string_view name;
};
// Get biome properties for terrain generation
const BiomeProperties &get_biome_properties(BiomeType biome);
// Determine biome type based on temperature and humidity
BiomeType determine_biome(double temperature, double humidity);
// Sub-chunk position within a chunk (4x4 grid of 16x16 sub-chunks)
struct SubChunkPos {
std::uint8_t sub_x; // 0-3
std::uint8_t sub_y; // 0-3
constexpr SubChunkPos(std::uint8_t x, std::uint8_t y): sub_x(x), sub_y(y) {}
};
// Convert local tile coordinates to sub-chunk position
constexpr SubChunkPos tile_to_subchunk(
std::uint8_t local_x, std::uint8_t local_y
) {
return SubChunkPos(local_x / 16, local_y / 16);
}
// Get the starting tile coordinates for a sub-chunk
constexpr std::pair<std::uint8_t, std::uint8_t> subchunk_to_tile_start(
const SubChunkPos &pos
) {
return {pos.sub_x * 16, pos.sub_y * 16};
}
} // namespace istd
#endif