Update project to use Godot.NET.Sdk 4.3.0 and improve terrain generation performance

This commit is contained in:
ImBenji
2025-10-18 18:26:55 +01:00
parent ca3f88cf17
commit f7de1c67af
7 changed files with 93 additions and 55 deletions

View File

@@ -6,6 +6,7 @@ using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Godot.Collections;
using Environment = Godot.Environment;
public enum DebugType
{
@@ -148,6 +149,30 @@ public partial class World : Node2D
}
}
private float _TemperatureNoiseAmplitude = 0.1f;
[Export]
public float TemperatureNoiseAmplitude
{
get => _TemperatureNoiseAmplitude;
set
{
_TemperatureNoiseAmplitude = value;
LoadTiles();
}
}
private float _MoistureNoiseAmplitude = 0.1f;
[Export]
public float MoistureNoiseAmplitude
{
get => _MoistureNoiseAmplitude;
set
{
_MoistureNoiseAmplitude = value;
LoadTiles();
}
}
private DebugType _debugType = DebugType.None;
[Export]
public DebugType DebugType
@@ -162,8 +187,10 @@ public partial class World : Node2D
ConcurrentDictionary<Vector2I, Tile> _tiles = new ConcurrentDictionary<Vector2I, Tile>();
private CancellationTokenSource _cancellationTokenSource;
private static readonly int MaxDegreeOfParallelism = Math.Max(1, (int)(System.Environment.ProcessorCount * 0.5));
public World()
{
@@ -233,7 +260,7 @@ public partial class World : Node2D
{
if (cancellationToken.IsCancellationRequested) return;
Parallel.For(0, chunksY, new ParallelOptions { CancellationToken = cancellationToken }, y =>
for (int y = 0; y < chunksY; y++)
{
if (cancellationToken.IsCancellationRequested) return;
@@ -248,14 +275,14 @@ public partial class World : Node2D
{
CallDeferred("add_child", tile);
_tiles[chunkId] = tile;
GD.Print("Loaded tile at chunk " + chunkId);
// GD.Print("Loaded tile at chunk " + chunkId);
}
});
}
}
}
catch (OperationCanceledException)
{
GD.Print("Tile generation cancelled");
// GD.Print("Tile generation cancelled");
}
}, cancellationToken);