diff --git a/src/server/terrain/CaveBiomeMap.zig b/src/server/terrain/CaveBiomeMap.zig index deff0c214..eb50bf45e 100644 --- a/src/server/terrain/CaveBiomeMap.zig +++ b/src/server/terrain/CaveBiomeMap.zig @@ -568,7 +568,7 @@ pub const CaveBiomeMapView = struct { // MARK: CaveBiomeMapView // MARK: cache const cacheSize = 1 << 8; // Must be a power of 2! const cacheMask = cacheSize - 1; -const associativity = 8; +const associativity = 8; // 128 MiB var cache: Cache(CaveBiomeMapFragment, cacheSize, associativity, CaveBiomeMapFragment.decreaseRefCount) = .{}; var profile: TerrainGenerationProfile = undefined; diff --git a/src/server/terrain/ClimateMap.zig b/src/server/terrain/ClimateMap.zig index 3614c343c..183bf7d6d 100644 --- a/src/server/terrain/ClimateMap.zig +++ b/src/server/terrain/ClimateMap.zig @@ -101,9 +101,9 @@ pub const ClimateMapGenerator = struct { }; -const cacheSize = 1 << 8; // Must be a power of 2! +const cacheSize = 1 << 5; // Must be a power of 2! const cacheMask = cacheSize - 1; -const associativity = 4; +const associativity = 8; // ~400 MiB var cache: Cache(ClimateMapFragment, cacheSize, associativity, ClimateMapFragment.decreaseRefCount) = .{}; var profile: TerrainGenerationProfile = undefined; diff --git a/src/server/terrain/mapgen/MapGenV1.zig b/src/server/terrain/mapgen/MapGenV1.zig index 49f6c4b25..d5b454b17 100644 --- a/src/server/terrain/mapgen/MapGenV1.zig +++ b/src/server/terrain/mapgen/MapGenV1.zig @@ -72,8 +72,8 @@ pub fn generateMapFragment(map: *MapFragment, worldSeed: u64) void { RandomlyWeightedFractalNoise.generateSparseFractalTerrain(map.pos.wx, map.pos.wy, 256, worldSeed ^ 6758947592930535, mountainMap, map.pos.voxelSize); // A smooth map for smaller hills. - const hillMap = PerlinNoise.generateSmoothNoise(main.globalAllocator, map.pos.wx, map.pos.wy, mapSize, mapSize, 128, 32, worldSeed ^ 157839765839495820, map.pos.voxelSize, 0.5); - defer hillMap.deinit(main.globalAllocator); + const hillMap = PerlinNoise.generateSmoothNoise(main.stackAllocator, map.pos.wx, map.pos.wy, mapSize, mapSize, 128, 32, worldSeed ^ 157839765839495820, map.pos.voxelSize, 0.5); + defer hillMap.deinit(main.stackAllocator); // A fractal map to generate high-detail roughness. const roughMap = Array2D(f32).init(main.stackAllocator, scaledSize, scaledSize); diff --git a/src/server/terrain/noise/PerlinNoise.zig b/src/server/terrain/noise/PerlinNoise.zig index 197d84956..d4d6debba 100644 --- a/src/server/terrain/noise/PerlinNoise.zig +++ b/src/server/terrain/noise/PerlinNoise.zig @@ -129,6 +129,7 @@ const Context = struct { /// Returns a ridgid map of floats with values between 0 and 1. pub fn generateRidgidNoise(allocator: NeverFailingAllocator, x: i32, y: i32, width: u31, height: u31, maxScale: u31, minScale: u31, worldSeed: u64, voxelSize: u31, reductionFactor: f32) Array2D(f32) { const map = Array2D(f32).init(allocator, width/voxelSize, height/voxelSize); + @memset(map.mem, 0); var seed = worldSeed; random.scrambleSeed(&seed); var context = Context { @@ -161,6 +162,7 @@ pub fn generateRidgidNoise(allocator: NeverFailingAllocator, x: i32, y: i32, wid /// Returns a smooth map of floats with values between 0 and 1. pub fn generateSmoothNoise(allocator: NeverFailingAllocator, x: i32, y: i32, width: u31, height: u31, maxScale: u31, minScale: u31, worldSeed: u64, voxelSize: u31, reductionFactor: f32) Array2D(f32) { const map = Array2D(f32).init(allocator, width/voxelSize, height/voxelSize); + @memset(map.mem, 0); var seed = worldSeed; random.scrambleSeed(&seed); var context = Context {