Skip to content

Commit f3b5a3a

Browse files
jstzwjsunnycase
authored andcommitted
Overworld gen (#42)
* Correct the terrain * Ready to fix a bug * Fix storage bug * Fix storage's bug
1 parent 0cf0ef9 commit f3b5a3a

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

src/MineCase.Server.Grains/World/Generation/ChunkGeneratorOverworldGrain.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task GenerateChunk(ChunkColumnStorage chunk, int x, int z, Generato
9494
await GenerateBasicTerrain(chunk, x, z, settings);
9595

9696
// Todo add biomes blocks
97-
ReplaceBiomeBlocks(settings, x, z, chunk, _biomesForGeneration);
97+
await ReplaceBiomeBlocks(settings, x, z, chunk, _biomesForGeneration);
9898

9999
// Todo genrate structure
100100
await GenerateSkylightMap(chunk);
@@ -254,7 +254,7 @@ private Task GenerateDensityMap(float[,,] densityMap, int xOffset, int yOffset,
254254
groundYOffset = (groundYOffset * 4.0F - 1.0F) / 8.0F;
255255

256256
// 取一个-0.36~0.125的随机数,这个随机数决定了起伏的地表
257-
float random = (_depthMap[x1, 0, z1] - 0.5F) * 128 / 8000.0F;
257+
float random = (_depthMap[x1, 0, z1] - 0.5F) * 160000 / 8000.0F;
258258
if (random < 0.0F)
259259
{
260260
random = -random * 0.3F;
@@ -306,9 +306,9 @@ private Task GenerateDensityMap(float[,,] densityMap, int xOffset, int yOffset,
306306
}
307307

308308
// 并不保证lowerLimit < upperLimit,不过没有影响
309-
float lowerLimit = (_minLimitMap[x1, y, z1] - 0.5F) * 128 / settings.LowerLimitScale; // lowerLimitScale=512
310-
float upperLimit = (_maxLimitMap[x1, y, z1] - 0.5F) * 128 / settings.UpperLimitScale; // upperLimitScale=512
311-
float t = ((_mainNoiseMap[x1, y, z1] - 0.5F) * 128 / 10.0F + 1.0F) / 2.0F;
309+
float lowerLimit = (_minLimitMap[x1, y, z1] - 0.5F) * 160000 / settings.LowerLimitScale; // lowerLimitScale=512
310+
float upperLimit = (_maxLimitMap[x1, y, z1] - 0.5F) * 160000 / settings.UpperLimitScale; // upperLimitScale=512
311+
float t = ((_mainNoiseMap[x1, y, z1] - 0.5F) * 160000 / 10.0F + 1.0F) / 2.0F;
312312

313313
// 这个函数t < 0则取lowerLimit,t > 1则取upperLimit,否则以t为参数在上下限间线性插值
314314
float result = MathHelper.DenormalizeClamp(lowerLimit, upperLimit, t) - offset;
@@ -330,7 +330,7 @@ private Task GenerateDensityMap(float[,,] densityMap, int xOffset, int yOffset,
330330
return Task.CompletedTask;
331331
}
332332

333-
public void ReplaceBiomeBlocks(GeneratorSettings settings, int x, int z, ChunkColumnStorage chunk, Biome[,] biomesIn)
333+
private Task ReplaceBiomeBlocks(GeneratorSettings settings, int x, int z, ChunkColumnStorage chunk, Biome[,] biomesIn)
334334
{
335335
_surfaceNoise.Noise(
336336
_surfaceMap,
@@ -342,9 +342,11 @@ public void ReplaceBiomeBlocks(GeneratorSettings settings, int x, int z, ChunkCo
342342
for (int z1 = 0; z1 < 16; ++z1)
343343
{
344344
Biome biome = biomesIn[x1, z1];
345-
biome.GenerateBiomeTerrain(settings.SeaLevel, _random, chunk, x * 16 + x1, z * 16 + z1, _surfaceMap[x1, 0, z1]);
345+
biome.GenerateBiomeTerrain(settings.SeaLevel, _random, chunk, x, z, x1, z1, _surfaceMap[x1, 0, z1]);
346346
}
347347
}
348+
349+
return Task.CompletedTask;
348350
}
349351

350352
private Task GenerateSkylightMap(ChunkColumnStorage chunk)

src/MineCase.Server.Interfaces/World/Biomes/Biome.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,24 @@ public static Biome GetBiome(int id)
7878
switch (biomeId)
7979
{
8080
case BiomeId.Ocean:
81-
// return new BiomeOcean();
81+
// return new BiomeOcean();
8282
case BiomeId.Plains:
83-
// return new BiomePlains();
83+
// return new BiomePlains();
8484
case BiomeId.Desert:
85-
// return new BiomeDesert();
85+
// return new BiomeDesert();
8686
case BiomeId.ExtremeHills:
87-
// return new BiomeExtremeHills();
87+
// return new BiomeExtremeHills();
8888
default:
8989
return null;
9090
}
9191
}
9292

93-
public void GenerateBiomeTerrain(int seaLevel, Random rand, ChunkColumnStorage chunk, int x, int z, double noiseVal)
93+
public void GenerateBiomeTerrain(int seaLevel, Random rand, ChunkColumnStorage chunk, int chunk_x, int chunk_z, int x_in_chunk, int z_in_chunk, double noiseVal)
9494
{
9595
BlockState topBlockstate = _topBlock;
9696
BlockState fillerBlockstate = _fillerBlock;
9797
int surfaceFlag = -1;
9898
int surfaceDepth = (int)(noiseVal / 3.0D + 3.0D + rand.NextDouble() * 0.25D);
99-
int x_in_chunk = x & 0xF;
100-
int z_in_chunk = z & 0xF;
10199

102100
for (int y = 255; y >= 0; --y)
103101
{

src/MineCase.Server.Interfaces/World/ChunkColumnStorage.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public sealed class ChunkSectionStorage
4848
private const byte _bitsId = 9;
4949
private const byte _bitsMeta = 4;
5050
private const byte _bitsPerBlock = _bitsId + _bitsMeta;
51+
private const uint _idMask = (1u << _bitsId) - 1;
5152
private const uint _metaMask = (1u << _bitsMeta) - 1;
5253
private const ulong _blockMask = (1u << _bitsPerBlock) - 1;
5354

@@ -78,8 +79,8 @@ public sealed class DataArray
7879
var value = Storage[offset.indexOffset] >> offset.bitOffset;
7980
var rest = _bitsPerBlock - toRead;
8081
if (rest > 0)
81-
value = (value << rest) | (Storage[offset.bitOffset + 1] & ((1u << rest) - 1));
82-
return new BlockState { Id = (uint)(value >> _bitsMeta), MetaValue = (uint)(value & _metaMask) };
82+
value |= (Storage[offset.indexOffset + 1] & ((1u << rest) - 1)) << toRead;
83+
return new BlockState { Id = (uint)((value >> _bitsMeta) & _idMask), MetaValue = (uint)(value & _metaMask) };
8384
}
8485

8586
set

src/MineCase.Server.Interfaces/World/Generation/GeneratorSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class GeneratorSettings
3030

3131
public float DepthNoiseScaleZ { get; set; } = 200.0F;
3232

33-
public float CoordinateScale { get; set; } = 684.412F; // mc = 684.412F;
33+
public float CoordinateScale { get; set; } = 0.05F; // mc = 684.412F;
3434

35-
public float HeightScale { get; set; } = 684.412F; // mc = 684.412F;
35+
public float HeightScale { get; set; } = 0.05F; // mc = 684.412F;
3636

3737
public float MainNoiseScaleX { get; set; } = 80.0F;
3838

0 commit comments

Comments
 (0)