Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
Coding style changes
Browse files Browse the repository at this point in the history
- Constants are PascalCase, not UPPER_CASE
- Abbreviations like Gfx, Gl, Id instead of GFX, GL, ID
  • Loading branch information
copygirl committed May 4, 2022
1 parent 29abbda commit e96dbdd
Show file tree
Hide file tree
Showing 33 changed files with 287 additions and 289 deletions.
12 changes: 6 additions & 6 deletions src/Immersion/PictureInPictureFollow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PictureInPictureFollow
{
public Game Game { get; } = null!;

public Universe.Entity PIPCamera { get; private set; }
public Universe.Entity PipCamera { get; private set; }

public void OnLoad()
{
Expand All @@ -21,8 +21,8 @@ public void OnLoad()
// var (_, mesh) = Game.GetAll<Mesh>().First();
// Game.Set(Game.MainCamera, mesh);

PIPCamera = Game.Entities.New()
.Set(Camera.Create3D(
PipCamera = Game.Entities.New()
.Set(Camera.Create3d(
fieldOfView: 90.0F,
clearColor: Color.Black,
viewport: new(8, 8, 320, 180)
Expand All @@ -31,16 +31,16 @@ public void OnLoad()

public void OnUnload()
{
PIPCamera.Delete();
PIPCamera = default;
PipCamera.Delete();
PipCamera = default;
}

public void OnUpdate(double delta)
{
var cameraPos = Game.MainCamera.Get<Transform>().Translation;
var lookAt = Matrix4x4.CreateLookAt(new(8, 28, 8), cameraPos, Vector3.UnitY);
Matrix4x4.Invert(lookAt, out lookAt);
PIPCamera.Set((Transform)lookAt);
PipCamera.Set((Transform)lookAt);
}
}
}
8 changes: 4 additions & 4 deletions src/Immersion/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Program : Game
static void Main() => new Program().Run();


public Random RND { get; } = new();
public Random Rnd { get; } = new();

public Program()
{
Expand All @@ -45,10 +45,10 @@ protected override void OnLoad()
for (var x = -12; x <= 12; x++)
for (var z = -12; z <= 12; z++) {
var position = Matrix4x4.CreateTranslation(x * 2, 25, z * 2);
var rotation = Matrix4x4.CreateRotationY(RND.NextFloat(MathF.PI * 2));
var rotation = Matrix4x4.CreateRotationY(Rnd.NextFloat(MathF.PI * 2));
Entities.New()
.Set((Transform)(rotation * position))
.Set(RND.Pick(heartMesh, swordMesh));
.Set(Rnd.Pick(heartMesh, swordMesh));
}

MainCamera.Set((Transform)Matrix4x4.CreateTranslation(0, 26, 0));
Expand All @@ -68,7 +68,7 @@ void CreateChunk(ChunkPos pos)
for (var y = 0; y < 16; y++)
for (var z = 0; z < 16; z++) {
var yy = (pos.Y << 4) | y;
if (RND.NextBool(0.5 - yy / 48.0))
if (Rnd.NextBool(0.5 - yy / 48.0))
storage[x, y, z] = new((yy > 16) ? grass
: (yy > -16) ? dirt
: stone);
Expand Down
8 changes: 4 additions & 4 deletions src/gaemstone.Bloxel/BlockFacing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public enum BlockFacing

public static class BlockFacings
{
public static readonly ImmutableHashSet<BlockFacing> HORIZONTALS
public static readonly ImmutableHashSet<BlockFacing> Horizontals
= ImmutableHashSet.Create(BlockFacing.East , BlockFacing.West ,
BlockFacing.South, BlockFacing.North);

public static readonly ImmutableHashSet<BlockFacing> VERTICALS
public static readonly ImmutableHashSet<BlockFacing> Verticals
= ImmutableHashSet.Create(BlockFacing.Up, BlockFacing.Down);

public static readonly ImmutableHashSet<BlockFacing> ALL
= HORIZONTALS.Union(VERTICALS);
public static readonly ImmutableHashSet<BlockFacing> All
= Horizontals.Union(Verticals);
}

public static class BlockFacingExtensions
Expand Down
2 changes: 1 addition & 1 deletion src/gaemstone.Bloxel/BlockPos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gaemstone.Bloxel
public readonly struct BlockPos
: IEquatable<BlockPos>
{
public static readonly BlockPos ORIGIN = new(0, 0, 0);
public static readonly BlockPos Origin = new(0, 0, 0);

public int X { get; }
public int Y { get; }
Expand Down
10 changes: 5 additions & 5 deletions src/gaemstone.Bloxel/Chunks/ChunkPaletteStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace gaemstone.Bloxel.Chunks
// https://www.reddit.com/r/VoxelGameDev/comments/9yu8qy/palettebased_compression_for_chunked_discrete/
public class ChunkPaletteStorage<T>
{
const int SIZE = 16 * 16 * 16;
const int Size = 16 * 16 * 16;
static readonly EqualityComparer<T> COMPARER
= EqualityComparer<T>.Default;

Expand Down Expand Up @@ -90,19 +90,19 @@ int NewPaletteEntry()

void GrowPalette() {
if (_palette == null) {
_data = new(SIZE);
_data = new(Size);
_palette = new PaletteEntry[2];
_usedPalettes = 1;
_indicesLength = 1;
_palette[0] = new PaletteEntry { Value = Default, RefCount = SIZE };
_palette[0] = new PaletteEntry { Value = Default, RefCount = Size };
return;
}

_indicesLength <<= 1;

var oldIndicesLength = _indicesLength >> 1;
var newData = new BitArray(SIZE * _indicesLength);
for (var i = 0; i < SIZE; i++)
var newData = new BitArray(Size * _indicesLength);
for (var i = 0; i < Size; i++)
for (var j = 0; j < oldIndicesLength; j++)
newData.Set(i * _indicesLength + j, _data!.Get(i * oldIndicesLength + j));
_data = newData;
Expand Down
22 changes: 11 additions & 11 deletions src/gaemstone.Bloxel/Client/ChunkMeshGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace gaemstone.Bloxel.Client
public class ChunkMeshGenerator
: IProcessor
{
const int STARTING_CAPACITY = 1024;
const int StartingCapacity = 1024;

static readonly Vector3[][] OFFSET_PER_FACING = {
static readonly Vector3[][] OffsetPerFacing = {
new Vector3[]{ new(1,1,1), new(1,0,1), new(1,0,0), new(1,1,0) }, // East (+X)
new Vector3[]{ new(0,1,0), new(0,0,0), new(0,0,1), new(0,1,1) }, // West (-X)
new Vector3[]{ new(1,1,0), new(0,1,0), new(0,1,1), new(1,1,1) }, // Up (+Y)
Expand All @@ -22,7 +22,7 @@ public class ChunkMeshGenerator
new Vector3[]{ new(1,1,0), new(1,0,0), new(0,0,0), new(0,1,0) } // North (-Z)
};

static readonly int[] TRIANGLE_INDICES
static readonly int[] TriangleIndices
= { 0, 1, 3, 1, 2, 3 };


Expand All @@ -31,10 +31,10 @@ static readonly int[] TRIANGLE_INDICES
// TODO: Automatically populate other processors.
MeshManager _meshManager = null!;

ushort[] _indices = new ushort[STARTING_CAPACITY];
Vector3[] _vertices = new Vector3[STARTING_CAPACITY];
Vector3[] _normals = new Vector3[STARTING_CAPACITY];
Vector2[] _uvs = new Vector2[STARTING_CAPACITY];
ushort[] _indices = new ushort[StartingCapacity];
Vector3[] _vertices = new Vector3[StartingCapacity];
Vector3[] _normals = new Vector3[StartingCapacity];
Vector2[] _uvs = new Vector2[StartingCapacity];


public void OnLoad()
Expand Down Expand Up @@ -80,7 +80,7 @@ public void OnUpdate(double delta)
var blockVertex = new Vector3(x, y, z);
var textureCell = Game.Get<TextureCoords4>(block);

foreach (var facing in BlockFacings.ALL) {
foreach (var facing in BlockFacings.All) {
if (!IsNeighborEmpty(storages, x, y, z, facing)) continue;

if (_indices.Length <= indexCount + 6)
Expand All @@ -91,12 +91,12 @@ public void OnUpdate(double delta)
Array.Resize(ref _uvs , _vertices.Length << 1);
}

for (var i = 0; i < TRIANGLE_INDICES.Length; i++)
_indices[indexCount++] = (ushort)(vertexCount + TRIANGLE_INDICES[i]);
for (var i = 0; i < TriangleIndices.Length; i++)
_indices[indexCount++] = (ushort)(vertexCount + TriangleIndices[i]);

var normal = facing.ToVector3();
for (var i = 0; i < 4; i++) {
var offset = OFFSET_PER_FACING[(int)facing][i];
var offset = OffsetPerFacing[(int)facing][i];
_vertices[vertexCount] = blockVertex + offset;
_normals[vertexCount] = normal;
_uvs[vertexCount] = i switch {
Expand Down
42 changes: 21 additions & 21 deletions src/gaemstone.Bloxel/Neighbor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,32 @@ public enum Neighbor : byte

public static class Neighbors
{
public static readonly ImmutableHashSet<Neighbor> HORIZONTALS
public static readonly ImmutableHashSet<Neighbor> Horizontals
= ImmutableHashSet.Create(Neighbor.East , Neighbor.West ,
Neighbor.South, Neighbor.North);

public static readonly ImmutableHashSet<Neighbor> VERTICALS
public static readonly ImmutableHashSet<Neighbor> Verticals
= ImmutableHashSet.Create(Neighbor.Up, Neighbor.Down);

public static readonly ImmutableHashSet<Neighbor> FACINGS
= HORIZONTALS.Union(VERTICALS);
public static readonly ImmutableHashSet<Neighbor> Facings
= Horizontals.Union(Verticals);

public static readonly ImmutableHashSet<Neighbor> CARDINALS
= HORIZONTALS.Union(new []{
public static readonly ImmutableHashSet<Neighbor> Cardinals
= Horizontals.Union(new []{
Neighbor.SouthEast, Neighbor.SouthWest,
Neighbor.NorthEast, Neighbor.NorthWest });

public static readonly ImmutableHashSet<Neighbor> ALL_AXIS_PLANES
= FACINGS.Union(new []{
public static readonly ImmutableHashSet<Neighbor> AllAxisPlanes
= Facings.Union(new []{
Neighbor.SouthEast, Neighbor.SouthWest,
Neighbor.NorthEast, Neighbor.NorthWest,
Neighbor.UpEast , Neighbor.UpWest ,
Neighbor.UpSouth , Neighbor.UpNorth ,
Neighbor.DownEast , Neighbor.DownWest ,
Neighbor.DownSouth, Neighbor.DownNorth });

public static readonly ImmutableHashSet<Neighbor> ALL
= ALL_AXIS_PLANES.Union(new []{
public static readonly ImmutableHashSet<Neighbor> All
= AllAxisPlanes.Union(new []{
Neighbor.UpSouthEast, Neighbor.UpSouthWest,
Neighbor.UpNorthEast, Neighbor.UpNorthWest,
Neighbor.DownSouthEast, Neighbor.DownSouthWest,
Expand All @@ -83,14 +83,14 @@ public static readonly ImmutableHashSet<Neighbor> ALL

public static class NeighborExtensions
{
const int X_SET_BIT = 0b000010, X_VALUE_BIT = 0b000001;
const int Y_SET_BIT = 0b001000, Y_VALUE_BIT = 0b000100;
const int Z_SET_BIT = 0b100000, Z_VALUE_BIT = 0b010000;
const int SetBitX = 0b000010, ValueBitX = 0b000001;
const int SetBitY = 0b001000, ValueBitY = 0b000100;
const int SetBitZ = 0b100000, ValueBitZ = 0b010000;
public static void Deconstruct(this Neighbor self, out int x, out int y, out int z)
{
x = (((int)self & X_SET_BIT) != 0) ? ((((int)self & X_VALUE_BIT) != 0) ? 1 : -1) : 0;
y = (((int)self & Y_SET_BIT) != 0) ? ((((int)self & Y_VALUE_BIT) != 0) ? 1 : -1) : 0;
z = (((int)self & Z_SET_BIT) != 0) ? ((((int)self & Z_VALUE_BIT) != 0) ? 1 : -1) : 0;
x = (((int)self & SetBitX) != 0) ? ((((int)self & ValueBitX) != 0) ? 1 : -1) : 0;
y = (((int)self & SetBitY) != 0) ? ((((int)self & ValueBitY) != 0) ? 1 : -1) : 0;
z = (((int)self & SetBitZ) != 0) ? ((((int)self & ValueBitZ) != 0) ? 1 : -1) : 0;
}


Expand Down Expand Up @@ -182,15 +182,15 @@ public static bool IsNone(this Neighbor self)
=> (self == Neighbor.None);

public static bool IsHorizontal(this Neighbor self)
=> Neighbors.HORIZONTALS.Contains(self);
=> Neighbors.Horizontals.Contains(self);
public static bool IsVertical(this Neighbor self)
=> Neighbors.VERTICALS.Contains(self);
=> Neighbors.Verticals.Contains(self);
public static bool IsCardinal(this Neighbor self)
=> Neighbors.CARDINALS.Contains(self);
=> Neighbors.Cardinals.Contains(self);
public static bool IsFacing(this Neighbor self)
=> Neighbors.FACINGS.Contains(self);
=> Neighbors.Facings.Contains(self);
public static bool IsValid(this Neighbor self)
=> Neighbors.ALL.Contains(self);
=> Neighbors.All.Contains(self);


public static string ToShortString(this Neighbor self)
Expand Down
10 changes: 5 additions & 5 deletions src/gaemstone.Client/Components/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ namespace gaemstone.Client
{
public class Camera
{
public static readonly Camera Default2D = Create2D();
public static readonly Camera Default3D = Create3D(80.0F);
public static readonly Camera Default2d = Create2d();
public static readonly Camera Default3d = Create3d(80.0F);

public static Camera Create2D(
public static Camera Create2d(
float nearPlane = -100.0F, float farPlane = 100.0F,
Color? clearColor = null, Rectangle? viewport = null
) => new(){
NearPlane = nearPlane, FarPlane = farPlane,
ClearColor = clearColor, Viewport = viewport,
};

public static Camera Create3D(
public static Camera Create3d(
float fieldOfView, float nearPlane = 0.1F, float farPlane = 200.0F,
Color? clearColor = null, Rectangle? viewport = null
) => new(){
Expand All @@ -31,7 +31,7 @@ public static Camera Create3D(

public bool IsOrthographic {
get => (FieldOfView == 0.0F);
set => FieldOfView = (value ? 0.0F : Default3D.FieldOfView);
set => FieldOfView = (value ? 0.0F : Default3d.FieldOfView);
}

public override string ToString()
Expand Down
6 changes: 3 additions & 3 deletions src/gaemstone.Client/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ protected virtual void OnLoad()
{
_input = Window.CreateInput();

GFX.Initialize(Window);
GFX.OnDebugOutput += (source, type, id, severity, message) =>
Gfx.Initialize(Window);
Gfx.OnDebugOutput += (source, type, id, severity, message) =>
Console.WriteLine($"[GLDebug] [{severity}] {type}/{id}: {message}");

// TODO: Automatically create components that have a specific attribute?
Expand All @@ -78,7 +78,7 @@ protected virtual void OnLoad()

MainCamera = Entities.New()
.Set((Transform)Matrix4x4.Identity)
.Set(Camera.Default3D);
.Set(Camera.Default3d);
}

protected virtual void OnClosing()
Expand Down
10 changes: 5 additions & 5 deletions src/gaemstone.Client/Graphics/Components/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ namespace gaemstone.Client.Graphics
{
public readonly struct Mesh
{
public VertexArray VAO { get; }
public VertexArray Vao { get; }
public int Triangles { get; }
public bool IsIndexed { get; }

internal Mesh(VertexArray vao, int triangles, bool isIndexed = true)
=> (VAO, Triangles, IsIndexed) = (vao, triangles, isIndexed);
=> (Vao, Triangles, IsIndexed) = (vao, triangles, isIndexed);

public void Draw()
=> Draw(0, Triangles * 3);
public void Draw(int start, int count)
{ unsafe {
VAO.Bind();
if (IsIndexed) GFX.GL.DrawElements(
Vao.Bind();
if (IsIndexed) Gfx.Gl.DrawElements(
PrimitiveType.Triangles, (uint)count,
DrawElementsType.UnsignedShort, (void*)start);
else GFX.GL.DrawArrays(
else Gfx.Gl.DrawArrays(
PrimitiveType.Triangles,
start, (uint)count);
} }
Expand Down
Loading

0 comments on commit e96dbdd

Please sign in to comment.