fixed code formatter.
minor bug fixes to a few systems as well.
This commit is contained in:
parent
657e19f48f
commit
01d2cbf4b3
@ -27,19 +27,19 @@ namespace AdvChkSys
|
||||
/// <summary>
|
||||
/// Creates a new WorldConstraints object.
|
||||
/// </summary>
|
||||
public static WorldConstraints CreateDefaultConstraints() => new WorldConstraints();
|
||||
public static WorldConstraints CreateDefaultConstraints() => new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new 2D chunk manager with optional constraints.
|
||||
/// </summary>
|
||||
public static ChunkManager2D<byte> Create2DManager(WorldConstraints? constraints = null) =>
|
||||
new ChunkManager2D<byte>(constraints);
|
||||
new(constraints);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new 3D chunk manager with optional constraints.
|
||||
/// </summary>
|
||||
public static ChunkManager3D<byte> Create3DManager(WorldConstraints? constraints = null) =>
|
||||
new ChunkManager3D<byte>(constraints);
|
||||
new(constraints);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a detailed report of the current memory usage by the chunk system.
|
||||
@ -73,13 +73,13 @@ namespace AdvChkSys
|
||||
/// Creates a spatial index for 2D chunks.
|
||||
/// </summary>
|
||||
public static SpatialChunkIndex<Chunk2D<T>> CreateSpatialIndex2D<T>() =>
|
||||
new SpatialChunkIndex<Chunk2D<T>>();
|
||||
new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a spatial index for 3D chunks.
|
||||
/// </summary>
|
||||
public static SpatialChunkIndex<Chunk3D<T>> CreateSpatialIndex3D<T>() =>
|
||||
new SpatialChunkIndex<Chunk3D<T>>();
|
||||
new();
|
||||
|
||||
/// <summary>
|
||||
/// Configures the threading system for high throughput.
|
||||
|
||||
@ -91,13 +91,13 @@ namespace AdvChkSys.Chunk
|
||||
get
|
||||
{
|
||||
if (localX < 0 || localX >= Width || localY < 0 || localY >= Height)
|
||||
throw new ArgumentOutOfRangeException($"Coordinates ({localX}, {localY}) out of bounds [0-{Width-1}, 0-{Height-1}]");
|
||||
throw new ArgumentOutOfRangeException($"Coordinates ({localX}, {localY}) out of bounds [0-{Width - 1}, 0-{Height - 1}]");
|
||||
return _isAllAir ? default! : _data![localX, localY];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (localX < 0 || localX >= Width || localY < 0 || localY >= Height)
|
||||
throw new ArgumentOutOfRangeException($"Coordinates ({localX}, {localY}) out of bounds [0-{Width-1}, 0-{Height-1}]");
|
||||
throw new ArgumentOutOfRangeException($"Coordinates ({localX}, {localY}) out of bounds [0-{Width - 1}, 0-{Height - 1}]");
|
||||
if (_isAllAir)
|
||||
throw new InvalidOperationException("Cannot set cell in all-air chunk.");
|
||||
_data![localX, localY] = value;
|
||||
|
||||
@ -2,12 +2,12 @@ using System;
|
||||
|
||||
namespace AdvChkSys.Constraints
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents constraints and limits for the chunk world.
|
||||
/// Can be used to restrict world size, chunk counts, and other resource limits.
|
||||
/// </summary>
|
||||
public class WorldConstraints
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents constraints and limits for the chunk world.
|
||||
/// Can be used to restrict world size, chunk counts, and other resource limits.
|
||||
/// </summary>
|
||||
public class WorldConstraints
|
||||
{
|
||||
/// <summary>
|
||||
/// If set, the minimum allowed chunk X coordinate (inclusive).
|
||||
/// </summary>
|
||||
@ -63,5 +63,5 @@ public class WorldConstraints
|
||||
if (MaxLoadedChunks.HasValue && loadedChunkCount > MaxLoadedChunks.Value) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,8 +51,10 @@ namespace AdvChkSys.Diagnostics
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var memStatus = new MemoryHelper.MEMORYSTATUSEX();
|
||||
memStatus.dwLength = (uint)Marshal.SizeOf(typeof(MemoryHelper.MEMORYSTATUSEX));
|
||||
var memStatus = new MemoryHelper.MEMORYSTATUSEX
|
||||
{
|
||||
dwLength = (uint)Marshal.SizeOf(typeof(MemoryHelper.MEMORYSTATUSEX))
|
||||
};
|
||||
if (MemoryHelper.GlobalMemoryStatusEx(ref memStatus))
|
||||
{
|
||||
return memStatus.ullTotalPhys;
|
||||
|
||||
@ -4,12 +4,12 @@ using System.Threading;
|
||||
|
||||
namespace AdvChkSys.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides events for chunk lifecycle operations such as loading, unloading, saving, and more.
|
||||
/// Thread-safe event subscription and invocation.
|
||||
/// </summary>
|
||||
public static class ChunkEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides events for chunk lifecycle operations such as loading, unloading, saving, and more.
|
||||
/// Thread-safe event subscription and invocation.
|
||||
/// </summary>
|
||||
public static class ChunkEvents
|
||||
{
|
||||
// Backing fields for thread-safe event handling
|
||||
private static Action<Interfaces.IChunk>? _chunkLoaded;
|
||||
private static Action<Interfaces.IChunk>? _chunkUnloaded;
|
||||
@ -122,5 +122,5 @@ public static class ChunkEvents
|
||||
newHandler = (Action<Interfaces.IChunk>?)Delegate.Remove(prevHandler, handler);
|
||||
} while (Interlocked.CompareExchange(ref field, newHandler, prevHandler) != prevHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,12 +3,12 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AdvChkSys.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for managing chunks in memory.
|
||||
/// Provides methods for loading, unloading, and accessing chunks.
|
||||
/// </summary>
|
||||
public interface IChunkManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for managing chunks in memory.
|
||||
/// Provides methods for loading, unloading, and accessing chunks.
|
||||
/// </summary>
|
||||
public interface IChunkManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns true if the chunk at (x, y) is loaded.
|
||||
/// </summary>
|
||||
@ -34,5 +34,5 @@ public interface IChunkManager
|
||||
/// Enumerates all loaded chunks.
|
||||
/// </summary>
|
||||
IEnumerable<IChunk> GetAllChunks();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ namespace AdvChkSys.Manager
|
||||
private readonly WorldConstraints? _constraints;
|
||||
private readonly int _capacity;
|
||||
private readonly Dictionary<(int, int), Task<Chunk2D<T>>> _loadingChunks = new();
|
||||
private readonly object _lock = new object();
|
||||
private readonly object _lock = new();
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for custom air check logic
|
||||
|
||||
@ -6,16 +6,16 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AdvChkSys.Resources
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages allocation and release of chunk resources in memory.
|
||||
/// Can be extended to track resource usage, pooling, or implement custom memory strategies.
|
||||
/// </summary>
|
||||
public static class ChunkResourceManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages allocation and release of chunk resources in memory.
|
||||
/// Can be extended to track resource usage, pooling, or implement custom memory strategies.
|
||||
/// </summary>
|
||||
public static class ChunkResourceManager
|
||||
{
|
||||
// Example: Track allocated chunks (for diagnostics, pooling, or resource limits)
|
||||
private static readonly ConcurrentDictionary<IChunk, DateTime> _allocatedChunks = new ConcurrentDictionary<IChunk, DateTime>();
|
||||
private static readonly ConcurrentDictionary<IChunk, DateTime> _allocatedChunks = new();
|
||||
private static int _allocatedChunkCount;
|
||||
private static readonly object _lock = new object();
|
||||
private static readonly object _lock = new();
|
||||
private static readonly HashSet<IChunk> _activeChunks = new();
|
||||
|
||||
/// <summary>
|
||||
@ -68,5 +68,5 @@ public static class ChunkResourceManager
|
||||
return _activeChunks.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,8 +221,8 @@ namespace AdvChkSys.Threading
|
||||
// Cancel all pending operations
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var operation = queue.Dequeue();
|
||||
operation.Completion.TrySetCanceled();
|
||||
var (Operation, Completion) = queue.Dequeue();
|
||||
Completion.TrySetCanceled();
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
@ -16,7 +16,7 @@ namespace AdvChkSys.Threading
|
||||
private static bool _currentThreadIsProcessingItems;
|
||||
|
||||
// The list of tasks to be executed
|
||||
private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
|
||||
private readonly LinkedList<Task> _tasks = new();
|
||||
|
||||
// The maximum concurrency level allowed by this scheduler.
|
||||
private int _maximumConcurrencyLevel;
|
||||
|
||||
@ -115,8 +115,8 @@ namespace AdvChkSys.Util
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (var node in _lruList)
|
||||
yield return node.value;
|
||||
foreach (var (key, value) in _lruList)
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user