diff options
| author | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
| commit | fe2baedc760c2f29e2c720f6b1132a2de33c5430 (patch) | |
| tree | dfbe1c72a17805a3cab6e0d47433e9021890c9ca /src/World/Generation/Generator.cpp | |
| parent | 41fbca10f6c6cdd9c1623f1347e7ecb40f5e7f59 (diff) | |
| download | meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.tar.zst meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.zip | |
Use own size types
Diffstat (limited to 'src/World/Generation/Generator.cpp')
| -rw-r--r-- | src/World/Generation/Generator.cpp | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/src/World/Generation/Generator.cpp b/src/World/Generation/Generator.cpp index 19a3dc8..88e69a7 100644 --- a/src/World/Generation/Generator.cpp +++ b/src/World/Generation/Generator.cpp @@ -4,7 +4,7 @@ namespace MC::World::Generation { -Chunk Generator::generate(int64_t chunk_x, int64_t chunk_y) { +Chunk Generator::generate(I64 chunk_x, I64 chunk_y) { Chunk chunk(chunk_x, chunk_y); auto landmass_map = generate_landmass_map(chunk_x, chunk_y); @@ -24,10 +24,10 @@ Chunk Generator::generate(int64_t chunk_x, int64_t chunk_y) { } #define SIMPLE_MAP_GENERATOR(name, getter) \ -Generator::Map2D<float> Generator::name(int64_t chunk_x, int64_t chunk_y) { \ +Generator::Map2D<Real> Generator::name(I64 chunk_x, I64 chunk_y) { \ Matrix<Chunk::Width, Chunk::Width> map{}; \ - for (uint x = 0; x < Chunk::Width; x++) { \ - for (uint y = 0; y < Chunk::Width; y++) { \ + for (UInt x = 0; x < Chunk::Width; x++) { \ + for (UInt y = 0; y < Chunk::Width; y++) { \ auto pos = chunk_position_to_world_vector(chunk_x, chunk_y, x, y); \ map(x, y) = getter(pos); \ } \ @@ -38,11 +38,11 @@ Generator::Map2D<float> Generator::name(int64_t chunk_x, int64_t chunk_y) { SIMPLE_MAP_GENERATOR(generate_landmass_map, get_landmass) SIMPLE_MAP_GENERATOR(generate_hill_map, get_hill) -Generator::Map2D<float> Generator::generate_height_map(Map2D<float>& landmass_map, Map2D<float>& hill_map) { - Map2D<float> height_map{}; +Generator::Map2D<Real> Generator::generate_height_map(Map2D<Real>& landmass_map, Map2D<Real>& hill_map) { + Map2D<Real> height_map{}; - for (uint x = 0; x < Chunk::Width; x++) { - for (uint y = 0; y < Chunk::Width; y++) { + for (UInt x = 0; x < Chunk::Width; x++) { + for (UInt y = 0; y < Chunk::Width; y++) { auto landmass_effect = landmass_map(x, y); auto hill_effect = hill_map(x, y); @@ -62,18 +62,18 @@ SIMPLE_MAP_GENERATOR(generate_temperature_map, get_temperature) SIMPLE_MAP_GENERATOR(generate_humidity_map, get_humidity) Generator::Map2D<BiomeType> Generator::generate_biome_map( - Map2D<float>& landmass_map, Map2D<float>& hill_map, - Map2D<float>& temperature_map, Map2D<float>& humidity_map + Map2D<Real>& landmass_map, Map2D<Real>& hill_map, + Map2D<Real>& temperature_map, Map2D<Real>& humidity_map ) { Map2D<BiomeType> biome_map{}; - for (uint x = 0; x < Chunk::Width; x++) { - for (uint y = 0; y < Chunk::Width; y++) { - float landmass = landmass_map(x, y); - float hill = hill_map(x, y); + for (UInt x = 0; x < Chunk::Width; x++) { + for (UInt y = 0; y < Chunk::Width; y++) { + Real landmass = landmass_map(x, y); + Real hill = hill_map(x, y); - float temperature = temperature_map(x, y); - float humidity = humidity_map(x, y); + Real temperature = temperature_map(x, y); + Real humidity = humidity_map(x, y); HillSlice hill_slice; if (hill > 0.55) { hill_slice = HillSlice::Mountain; } @@ -103,17 +103,17 @@ Generator::Map2D<BiomeType> Generator::generate_biome_map( return biome_map; } -Generator::Map3D<bool> Generator::generate_terrain(Map2D<float>& height_map, int64_t chunk_x, int64_t chunk_y) { - float jaggedness = 0.10f; +Generator::Map3D<Bool> Generator::generate_terrain(Map2D<Real>& height_map, I64 chunk_x, I64 chunk_y) { + Real jaggedness = 0.10f; - Map3D<bool> terrain_map{}; - for (uint x = 0; x < Chunk::Width; x++) { - for (uint z = 0; z < Chunk::Width; z++) { + Map3D<Bool> terrain_map{}; + for (UInt x = 0; x < Chunk::Width; x++) { + for (UInt z = 0; z < Chunk::Width; z++) { auto height = height_map(x, z); - for (uint y = 0; y < Chunk::Height; y++) { - float density = get_density({Chunk::Width * chunk_x + (float)x, (float)y, Chunk::Width * chunk_y + (float)z}); - float threshold = Math::sigmoid(((float)y / (Chunk::Height * height * 2) - 0.5f) / jaggedness); + for (UInt y = 0; y < Chunk::Height; y++) { + Real density = get_density({Chunk::Width * chunk_x + (Real)x, (Real)y, Chunk::Width * chunk_y + (Real)z}); + Real threshold = Math::sigmoid(((Real)y / (Chunk::Height * height * 2) - 0.5f) / jaggedness); if (density > threshold) { terrain_map(x, y, z) = true; @@ -125,12 +125,12 @@ Generator::Map3D<bool> Generator::generate_terrain(Map2D<float>& height_map, int return terrain_map; } -void Generator::decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<bool>& terrain_map) { - constexpr uint dirt_depth = 4; - constexpr uint water_height = 40; +void Generator::decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<Bool>& terrain_map) { + constexpr UInt dirt_depth = 4; + constexpr UInt water_height = 40; - for (uint x = 0; x < Chunk::Width; x++) { - for (uint z = 0; z < Chunk::Width; z++) { + for (UInt x = 0; x < Chunk::Width; x++) { + for (UInt z = 0; z < Chunk::Width; z++) { auto biome = biome_map(x, z); BlockType top_block{}; @@ -160,7 +160,7 @@ void Generator::decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<b } auto column_depth = 0; - for (uint y = Chunk::Height - 1; y > 0; y--) { + for (UInt y = Chunk::Height - 1; y > 0; y--) { auto block = terrain_map(x, y, z); if (block) { if (column_depth == 0 && y >= water_height - 1) { @@ -186,11 +186,11 @@ void Generator::decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<b } } -#define CURVE_START(y) constexpr auto lerp = Math::linear_interpolation; float _py = (y); float _px = 0.0f; +#define CURVE_START(y) constexpr auto lerp = Math::linear_interpolation; Real _py = (y); Real _px = 0.0f; #define CURVE_POINT(x, y) if (v < (x)) return lerp({_py, (y)}, _px, (x), v); _py = y; _px = (x) #define CURVE_END(y) return lerp({_py, (y)}, _px, 1.0f, v); -float Generator::get_landmass(Vector<2> pos) const { +Real Generator::get_landmass(Vector<2> pos) const { auto v = m_landmass_noise.at(pos); CURVE_START(1.0f); @@ -205,7 +205,7 @@ float Generator::get_landmass(Vector<2> pos) const { CURVE_END(1.0f); } -float Generator::get_hill(Vector<2> pos) const { +Real Generator::get_hill(Vector<2> pos) const { auto v = m_hill_noise.at(pos); CURVE_START(0.33f); @@ -219,30 +219,30 @@ float Generator::get_hill(Vector<2> pos) const { CURVE_END(0.33f); } -float Generator::get_humidity(Vector<2> pos) const { +Real Generator::get_humidity(Vector<2> pos) const { auto v = m_humidity_noise.at(pos); return v; } -float Generator::get_temperature(Vector<2> pos) const { +Real Generator::get_temperature(Vector<2> pos) const { auto v = m_temperature_noise.at(pos); return v; } -float Generator::get_density(Vector<3> pos) const { +Real Generator::get_density(Vector<3> pos) const { auto v = m_density_noise.at(pos); return v; } -Vector<2> Generator::chunk_position_to_world_vector(int64_t chunk_x, int64_t chunk_y, uint x, uint y) { - return {(float)x + chunk_x * Chunk::Width, (float)y + chunk_y * Chunk::Width}; +Vector<2> Generator::chunk_position_to_world_vector(I64 chunk_x, I64 chunk_y, UInt x, UInt y) { + return {(Real)x + chunk_x * Chunk::Width, (Real)y + chunk_y * Chunk::Width}; } std::array<BiomeType, Generator::biome_lookup_table_size> Generator::create_biome_lookup_table() { std::array<BiomeType, biome_lookup_table_size> table{}; - auto inc = [](auto& x) { x = (std::remove_reference_t<decltype(x)>)((uint)x + 1); }; - auto cmp = [](auto x, auto s) { return (uint)x < (uint)s; }; + auto inc = [](auto& x) { x = (std::remove_reference_t<decltype(x)>)((UInt)x + 1); }; + auto cmp = [](auto x, auto s) { return (UInt)x < (UInt)s; }; for (HillSlice hill_slice{}; cmp(hill_slice, HillSliceSize); inc(hill_slice)) { for (LandmassSlice landmass_slice{}; cmp(landmass_slice, LandmassSliceSize); inc(landmass_slice)) { @@ -317,9 +317,9 @@ std::array<BiomeType, Generator::biome_lookup_table_size> Generator::create_biom return table; } -size_t Generator::biome_lookup_table_index(HillSlice hill_slice, LandmassSlice landmass_slice, TemperatureZone temperature_zone, HumidityZone humidity_zone) { - auto hs = (uint8_t)hill_slice; auto ls = (uint8_t)landmass_slice; auto tz = (uint8_t)temperature_zone; auto hz = (uint8_t)humidity_zone; - auto LS_S = (uint8_t)LandmassSliceSize; auto TZ_S = (uint8_t)TemperatureZoneSize; auto HZ_S = (uint8_t)HumidityZoneSize; +USize Generator::biome_lookup_table_index(HillSlice hill_slice, LandmassSlice landmass_slice, TemperatureZone temperature_zone, HumidityZone humidity_zone) { + auto hs = (U8)hill_slice; auto ls = (U8)landmass_slice; auto tz = (U8)temperature_zone; auto hz = (U8)humidity_zone; + auto LS_S = (U8)LandmassSliceSize; auto TZ_S = (U8)TemperatureZoneSize; auto HZ_S = (U8)HumidityZoneSize; return (hs * LS_S * TZ_S * HZ_S) + (ls * TZ_S * HZ_S) + (tz * HZ_S) + hz; } |
