[Add] Thread fix

This commit is contained in:
2026-04-08 09:34:45 +07:00
parent 12430cdf4f
commit 50831947b9
8 changed files with 181 additions and 189 deletions
@@ -53,7 +53,7 @@ namespace InfiniteWorld.VoxelWorld
internal readonly struct VoxelWorldResolvedSettings
{
private static readonly IReadOnlyList<VoxelBiomeProfile> EmptyBiomes = System.Array.Empty<VoxelBiomeProfile>();
private static readonly IReadOnlyList<WorldPrefabCollection> EmptyPlacementCollections = System.Array.Empty<WorldPrefabCollection>();
private static readonly IReadOnlyList<WorldPrefabCollectionRuntime> EmptyPlacementCollections = System.Array.Empty<WorldPrefabCollectionRuntime>();
public static readonly VoxelWorldResolvedSettings Default = Resolve(null);
@@ -79,7 +79,7 @@ namespace InfiniteWorld.VoxelWorld
IReadOnlyList<VoxelBiomeProfile> biomeProfiles,
float biomeNoiseScale,
float biomeSize,
IReadOnlyList<WorldPrefabCollection> placementCollections,
IReadOnlyList<WorldPrefabCollectionRuntime> placementCollections,
int maxAsyncChunkJobs,
int maxChunkBuildsPerFrame,
int maxChunkMeshBuildsPerFrame,
@@ -140,7 +140,7 @@ namespace InfiniteWorld.VoxelWorld
public IReadOnlyList<VoxelBiomeProfile> BiomeProfiles { get; }
public float BiomeNoiseScale { get; }
public float BiomeSize { get; }
public IReadOnlyList<WorldPrefabCollection> PlacementCollections { get; }
public IReadOnlyList<WorldPrefabCollectionRuntime> PlacementCollections { get; }
public int MaxAsyncChunkJobs { get; }
public int MaxChunkBuildsPerFrame { get; }
public int MaxChunkMeshBuildsPerFrame { get; }
@@ -154,9 +154,7 @@ namespace InfiniteWorld.VoxelWorld
IReadOnlyList<VoxelBiomeProfile> biomes = config != null && config.biomeProfiles != null
? config.biomeProfiles
: EmptyBiomes;
IReadOnlyList<WorldPrefabCollection> placements = config != null && config.placementCollections != null
? config.placementCollections
: EmptyPlacementCollections;
IReadOnlyList<WorldPrefabCollectionRuntime> placements = ResolvePlacementCollections(config);
return new VoxelWorldResolvedSettings(
Mathf.Max(8, config != null ? config.chunkSize : 16),
@@ -189,5 +187,58 @@ namespace InfiniteWorld.VoxelWorld
Mathf.Max(1, config != null ? config.renderRegionSizeInChunks : 4),
Mathf.Max(1, config != null ? config.maxRegionBuildsPerFrame : 1));
}
private static IReadOnlyList<WorldPrefabCollectionRuntime> ResolvePlacementCollections(VoxelWorldConfig config)
{
if (config == null || config.placementCollections == null || config.placementCollections.Count == 0)
{
return EmptyPlacementCollections;
}
List<WorldPrefabCollectionRuntime> result = new List<WorldPrefabCollectionRuntime>(config.placementCollections.Count);
for (int collectionIndex = 0; collectionIndex < config.placementCollections.Count; collectionIndex++)
{
WorldPrefabCollection collection = config.placementCollections[collectionIndex];
if (collection == null)
{
continue;
}
List<WorldPrefabEntryRuntime> entries = new List<WorldPrefabEntryRuntime>();
if (collection.entries != null)
{
for (int entryIndex = 0; entryIndex < collection.entries.Count; entryIndex++)
{
WorldPrefabEntry entry = collection.entries[entryIndex];
if (entry == null)
{
continue;
}
entries.Add(new WorldPrefabEntryRuntime(
entryIndex,
entry.id,
entry.weight,
entry.spawnChancePercent,
entry.placementMode,
entry.footprint,
entry.clearance,
entry.flattenPadding,
entry.flattenSearchRadius,
entry.allowRotations,
entry.prefab != null));
}
}
result.Add(new WorldPrefabCollectionRuntime(
collectionIndex,
Mathf.Max(0, collection.maxPlacementsPerChunk),
Mathf.Max(1, collection.attemptsPerPlacement),
Mathf.Max(0, collection.chunkEdgePadding),
entries));
}
return result.Count > 0 ? result : EmptyPlacementCollections;
}
}
}