style: apply code-style cleanup (explicit types, this-qualification, switch expressions)

This commit is contained in:
2026-05-28 13:29:13 +02:00
parent 8e3195ca37
commit 70c986529b
9 changed files with 110 additions and 102 deletions

View File

@@ -30,28 +30,31 @@ public sealed class Game : GameWindow
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.CullFace);
_shader = new Shader("Assets/shaders/chunk.vert", "Assets/shaders/chunk.frag");
_texture = new Texture("Assets/textures/atlas.png");
this._shader = new Shader("Assets/shaders/chunk.vert", "Assets/shaders/chunk.frag");
this._texture = new Texture("Assets/textures/atlas.png");
Chunk chunk = BuildChunk();
float[] mesh = new ChunkMesher().Build(chunk, _registry);
_renderer = new ChunkRenderer(mesh);
Chunk chunk = this.BuildChunk();
float[] mesh = new ChunkMesher().Build(chunk, this._registry);
this._renderer = new ChunkRenderer(mesh);
_camera = new Camera(new Vector3(8f, 20f, 40f), ClientSize.X / (float)ClientSize.Y);
this._camera = new Camera(new Vector3(8f, 20f, 40f), this.ClientSize.X / (float)this.ClientSize.Y);
CursorState = CursorState.Grabbed;
this.CursorState = CursorState.Grabbed;
}
private Chunk BuildChunk()
{
var chunk = new Chunk();
Chunk chunk = new();
for (int x = 0; x < Chunk.Size; x++)
for (int z = 0; z < Chunk.Size; z++)
for (int y = 0; y < Chunk.Size; y++)
{
if (y == Chunk.Size - 1) chunk[x, y, z] = _registry.Grass.Id;
else if (y >= Chunk.Size - 4) chunk[x, y, z] = _registry.Dirt.Id;
else chunk[x, y, z] = _registry.Stone.Id;
chunk[x, y, z] = y switch
{
Chunk.Size - 1 => this._registry.Grass.Id,
>= Chunk.Size - 4 => this._registry.Dirt.Id,
_ => this._registry.Stone.Id
};
}
return chunk;
}
@@ -59,21 +62,21 @@ public sealed class Game : GameWindow
protected override void OnUpdateFrame(FrameEventArgs args)
{
base.OnUpdateFrame(args);
if (!IsFocused) return;
if (!this.IsFocused) return;
KeyboardState keyboard = KeyboardState;
if (keyboard.IsKeyDown(Keys.Escape)) { Close(); return; }
if (this.KeyboardState.IsKeyDown(Keys.Escape)) {
this.Close(); return; }
float distance = MoveSpeed * (float)args.Time;
if (keyboard.IsKeyDown(Keys.W)) _camera.Move(_camera.Front * distance);
if (keyboard.IsKeyDown(Keys.S)) _camera.Move(-_camera.Front * distance);
if (keyboard.IsKeyDown(Keys.A)) _camera.Move(-_camera.Right * distance);
if (keyboard.IsKeyDown(Keys.D)) _camera.Move(_camera.Right * distance);
if (keyboard.IsKeyDown(Keys.Space)) _camera.Move(Vector3.UnitY * distance);
if (keyboard.IsKeyDown(Keys.LeftShift)) _camera.Move(-Vector3.UnitY * distance);
float distance = Game.MoveSpeed * (float)args.Time;
if (this.KeyboardState.IsKeyDown(Keys.W)) this._camera.Move(this._camera.Front * distance);
if (this.KeyboardState.IsKeyDown(Keys.S)) this._camera.Move(-this._camera.Front * distance);
if (this.KeyboardState.IsKeyDown(Keys.A)) this._camera.Move(-this._camera.Right * distance);
if (this.KeyboardState.IsKeyDown(Keys.D)) this._camera.Move(this._camera.Right * distance);
if (this.KeyboardState.IsKeyDown(Keys.Space)) this._camera.Move(Vector3.UnitY * distance);
if (this.KeyboardState.IsKeyDown(Keys.LeftShift)) this._camera.Move(-Vector3.UnitY * distance);
Vector2 delta = MouseState.Delta;
_camera.AddRotation(delta.X * Sensitivity, -delta.Y * Sensitivity);
Vector2 delta = this.MouseState.Delta;
this._camera.AddRotation(delta.X * Game.Sensitivity, -delta.Y * Game.Sensitivity);
}
protected override void OnRenderFrame(FrameEventArgs args)
@@ -82,29 +85,30 @@ public sealed class Game : GameWindow
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
_shader.Use();
_shader.SetMatrix4("model", Matrix4.Identity);
_shader.SetMatrix4("view", _camera.GetViewMatrix());
_shader.SetMatrix4("projection", _camera.GetProjectionMatrix());
_shader.SetInt("atlas", 0);
_texture.Use(TextureUnit.Texture0);
_renderer.Draw();
this._shader.Use();
this._shader.SetMatrix4("model", Matrix4.Identity);
this._shader.SetMatrix4("view", this._camera.GetViewMatrix());
this._shader.SetMatrix4("projection", this._camera.GetProjectionMatrix());
this._shader.SetInt("atlas", 0);
this._texture.Use(TextureUnit.Texture0);
this._renderer.Draw();
SwapBuffers();
this.SwapBuffers();
}
protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);
GL.Viewport(0, 0, e.Width, e.Height);
if (_camera is not null) _camera.AspectRatio = e.Width / (float)e.Height;
// OnResize can fire before OnLoad (where _camera is created), so guard against it.
if (this._camera is not null) this._camera.AspectRatio = e.Width / (float)e.Height;
}
protected override void OnUnload()
{
_renderer.Dispose();
_texture.Dispose();
_shader.Dispose();
this._renderer.Dispose();
this._texture.Dispose();
this._shader.Dispose();
base.OnUnload();
}
}