feat: add Configuration class with user-tunable defaults
This commit is contained in:
21
Core/Configuration.cs
Normal file
21
Core/Configuration.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
namespace VoxelEngine.Core;
|
||||||
|
|
||||||
|
public sealed class Configuration
|
||||||
|
{
|
||||||
|
public int RenderDistanceHorizontal { get; set; } = 8;
|
||||||
|
public int RenderDistanceVertical { get; set; } = 4;
|
||||||
|
public int SpawnReadyRadiusHorizontal { get; set; } = 1;
|
||||||
|
|
||||||
|
public int MaxGenerateJobsInFlight { get; set; } = 8;
|
||||||
|
public int MaxMeshUploadsPerFrame { get; set; } = 4;
|
||||||
|
public int WorkerThreadCount { get; set; } = Math.Max(1, Environment.ProcessorCount - 1);
|
||||||
|
|
||||||
|
public float MoveSpeed { get; set; } = 8f;
|
||||||
|
public float MouseSensitivity { get; set; } = 0.15f;
|
||||||
|
public float Fov { get; set; } = 60f;
|
||||||
|
|
||||||
|
public int WindowWidth { get; set; } = 1280;
|
||||||
|
public int WindowHeight { get; set; } = 720;
|
||||||
|
|
||||||
|
public int? Seed { get; set; } = null;
|
||||||
|
}
|
||||||
57
VoxelEngine.Tests/ConfigurationTests.cs
Normal file
57
VoxelEngine.Tests/ConfigurationTests.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using VoxelEngine.Core;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VoxelEngine.Tests;
|
||||||
|
|
||||||
|
public class ConfigurationTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Defaults_AreSane()
|
||||||
|
{
|
||||||
|
var c = new Configuration();
|
||||||
|
Assert.True(c.RenderDistanceHorizontal >= 1);
|
||||||
|
Assert.True(c.RenderDistanceVertical >= 1);
|
||||||
|
Assert.True(c.SpawnReadyRadiusHorizontal >= 0);
|
||||||
|
Assert.True(c.MaxGenerateJobsInFlight >= 1);
|
||||||
|
Assert.True(c.MaxMeshUploadsPerFrame >= 1);
|
||||||
|
Assert.True(c.WorkerThreadCount >= 1);
|
||||||
|
Assert.True(c.MoveSpeed > 0f);
|
||||||
|
Assert.True(c.MouseSensitivity > 0f);
|
||||||
|
Assert.InRange(c.Fov, 1f, 179f);
|
||||||
|
Assert.True(c.WindowWidth > 0);
|
||||||
|
Assert.True(c.WindowHeight > 0);
|
||||||
|
Assert.Null(c.Seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Properties_AreMutable()
|
||||||
|
{
|
||||||
|
var c = new Configuration { RenderDistanceHorizontal = 4, Seed = 1337 };
|
||||||
|
Assert.Equal(4, c.RenderDistanceHorizontal);
|
||||||
|
Assert.Equal(1337, c.Seed);
|
||||||
|
|
||||||
|
var c2 = new Configuration
|
||||||
|
{
|
||||||
|
RenderDistanceVertical = 2,
|
||||||
|
SpawnReadyRadiusHorizontal = 0,
|
||||||
|
MaxGenerateJobsInFlight = 2,
|
||||||
|
MaxMeshUploadsPerFrame = 1,
|
||||||
|
WorkerThreadCount = 2,
|
||||||
|
MoveSpeed = 4f,
|
||||||
|
MouseSensitivity = 0.5f,
|
||||||
|
Fov = 90f,
|
||||||
|
WindowWidth = 800,
|
||||||
|
WindowHeight = 600,
|
||||||
|
};
|
||||||
|
Assert.Equal(2, c2.RenderDistanceVertical);
|
||||||
|
Assert.Equal(0, c2.SpawnReadyRadiusHorizontal);
|
||||||
|
Assert.Equal(2, c2.MaxGenerateJobsInFlight);
|
||||||
|
Assert.Equal(1, c2.MaxMeshUploadsPerFrame);
|
||||||
|
Assert.Equal(2, c2.WorkerThreadCount);
|
||||||
|
Assert.Equal(4f, c2.MoveSpeed);
|
||||||
|
Assert.Equal(0.5f, c2.MouseSensitivity);
|
||||||
|
Assert.Equal(90f, c2.Fov);
|
||||||
|
Assert.Equal(800, c2.WindowWidth);
|
||||||
|
Assert.Equal(600, c2.WindowHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user