style: apply code-style cleanup (explicit types, this-qualification, switch expressions)
This commit is contained in:
@@ -14,13 +14,13 @@ public sealed class BlockRegistry
|
||||
public BlockRegistry()
|
||||
{
|
||||
// Index by id. Order does not matter; slot = block.Id.
|
||||
var blocks = new IBlock[] { Air, Stone, Dirt, Grass };
|
||||
_byId = new IBlock[blocks.Length];
|
||||
IBlock[] blocks = new IBlock[] { this.Air, this.Stone, this.Dirt, this.Grass };
|
||||
this._byId = new IBlock[blocks.Length];
|
||||
foreach (IBlock block in blocks)
|
||||
{
|
||||
_byId[block.Id] = block;
|
||||
this._byId[block.Id] = block;
|
||||
}
|
||||
}
|
||||
|
||||
public IBlock Get(ushort id) => _byId[id];
|
||||
public IBlock Get(ushort id) => this._byId[id];
|
||||
}
|
||||
|
||||
@@ -4,16 +4,16 @@ public sealed class Chunk
|
||||
{
|
||||
public const int Size = 16;
|
||||
|
||||
private readonly ushort[] _ids = new ushort[Size * Size * Size];
|
||||
private readonly ushort[] _ids = new ushort[Chunk.Size * Chunk.Size * Chunk.Size];
|
||||
|
||||
public ushort this[int x, int y, int z]
|
||||
{
|
||||
get => _ids[Index(x, y, z)];
|
||||
set => _ids[Index(x, y, z)] = value;
|
||||
get => this._ids[Chunk.Index(x, y, z)];
|
||||
set => this._ids[Chunk.Index(x, y, z)] = value;
|
||||
}
|
||||
|
||||
public static bool InBounds(int x, int y, int z) =>
|
||||
x >= 0 && x < Size && y >= 0 && y < Size && z >= 0 && z < Size;
|
||||
x is >= 0 and < Chunk.Size && y is >= 0 and < Chunk.Size && z is >= 0 and < Chunk.Size;
|
||||
|
||||
private static int Index(int x, int y, int z) => (x * Size + y) * Size + z;
|
||||
private static int Index(int x, int y, int z) => (x * Chunk.Size + y) * Chunk.Size + z;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,12 @@ public sealed class ChunkMesher : IChunkMesher
|
||||
(float, float, float) @base, (float, float, float) u,
|
||||
(float, float, float) v, float shade)
|
||||
{
|
||||
Kind = kind; Normal = normal; Base = @base; U = u; V = v; Shade = shade;
|
||||
this.Kind = kind;
|
||||
this.Normal = normal;
|
||||
this.Base = @base;
|
||||
this.U = u;
|
||||
this.V = v;
|
||||
this.Shade = shade;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +47,7 @@ public sealed class ChunkMesher : IChunkMesher
|
||||
|
||||
public float[] Build(Chunk chunk, BlockRegistry registry)
|
||||
{
|
||||
var verts = new List<float>();
|
||||
List<float> verts = new();
|
||||
|
||||
for (int x = 0; x < Chunk.Size; x++)
|
||||
for (int y = 0; y < Chunk.Size; y++)
|
||||
@@ -51,7 +56,7 @@ public sealed class ChunkMesher : IChunkMesher
|
||||
IBlock block = registry.Get(chunk[x, y, z]);
|
||||
if (!block.IsOpaque) continue;
|
||||
|
||||
foreach (Face face in Faces)
|
||||
foreach (Face face in ChunkMesher.Faces)
|
||||
{
|
||||
int nx = x + face.Normal.x;
|
||||
int ny = y + face.Normal.y;
|
||||
@@ -62,7 +67,7 @@ public sealed class ChunkMesher : IChunkMesher
|
||||
Chunk.InBounds(nx, ny, nz) && registry.Get(chunk[nx, ny, nz]).IsOpaque;
|
||||
if (neighborOpaque) continue;
|
||||
|
||||
AddFace(verts, x, y, z, face, block.GetTextureIndex(face.Kind));
|
||||
ChunkMesher.AddFace(verts, x, y, z, face, block.GetTextureIndex(face.Kind));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,22 +76,21 @@ public sealed class ChunkMesher : IChunkMesher
|
||||
|
||||
private static void AddFace(List<float> verts, int x, int y, int z, Face face, int texIndex)
|
||||
{
|
||||
float tileWidth = 1f / AtlasTiles;
|
||||
float tileWidth = 1f / ChunkMesher.AtlasTiles;
|
||||
float uBase = texIndex * tileWidth;
|
||||
|
||||
foreach (int corner in Triangle)
|
||||
foreach (int corner in ChunkMesher.Triangle)
|
||||
{
|
||||
(float cu, float cv) = Corners[corner];
|
||||
(float cu, float cv) = ChunkMesher.Corners[corner];
|
||||
|
||||
float px = x + face.Base.x + face.U.x * cu + face.V.x * cv;
|
||||
float py = y + face.Base.y + face.U.y * cu + face.V.y * cv;
|
||||
float pz = z + face.Base.z + face.U.z * cu + face.V.z * cv;
|
||||
|
||||
float u = uBase + cu * tileWidth;
|
||||
float v = cv;
|
||||
|
||||
verts.Add(px); verts.Add(py); verts.Add(pz);
|
||||
verts.Add(u); verts.Add(v);
|
||||
verts.Add(u); verts.Add(cv);
|
||||
verts.Add(face.Shade);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user