Major refactor and organization, optimizations to chunk, world and renderer
This commit is contained in:
47
Graphics/ChunkMesh.cs
Normal file
47
Graphics/ChunkMesh.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Voxel.Graphics
|
||||
{
|
||||
public class ChunkMesh
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
private byte[] _packedData;
|
||||
public int Size = 0;
|
||||
|
||||
public ChunkMesh(int x, int y)
|
||||
{
|
||||
_packedData = Array.Empty<byte>();
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public void SetFaces(List<FaceData> faces)
|
||||
{
|
||||
Size = faces.Count;
|
||||
_packedData = PackFaces(faces);
|
||||
}
|
||||
|
||||
private static byte[] PackFaces(List<FaceData> faces)
|
||||
{
|
||||
const int BYTES_PER_FACE = 4;
|
||||
int totalFaces = faces.Count;
|
||||
var result = new byte[faces.Count * BYTES_PER_FACE];
|
||||
|
||||
for (int i = 0; i < totalFaces; i++)
|
||||
{
|
||||
var face = faces[i];
|
||||
uint packed = face._data;
|
||||
int offset = i * 4;
|
||||
|
||||
// Write little-endian (important!)
|
||||
result[offset] = (byte)(packed);
|
||||
result[offset + 1] = (byte)(packed >> 8);
|
||||
result[offset + 2] = (byte)(packed >> 16);
|
||||
result[offset + 3] = (byte)(packed >> 24);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] GetPackedData() => _packedData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user