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