Update project to use Godot.NET.Sdk 4.3.0 and improve terrain generation performance
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user