Skip to content

Commit 897f173

Browse files
authored
Merge pull request #58 from xezno/engine-refactor
Large-scale engine refactor
2 parents 520cd40 + de35d9d commit 897f173

File tree

249 files changed

+7310
-3422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+7310
-3422
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ BasedOnStyle: Microsoft
33
AccessModifierOffset: '-4'
44
AlignAfterOpenBracket: DontAlign
55
AlignEscapedNewlines: Left
6-
AllowShortFunctionsOnASingleLine: Inline
6+
AllowShortFunctionsOnASingleLine: None
77
AllowShortIfStatementsOnASingleLine: Never
88
AlwaysBreakAfterReturnType: None
99
AlwaysBreakTemplateDeclarations: 'Yes'

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,16 @@ vcpkg_installed/
387387
[Ss]ource/Mocha.Common/Glue/UnmanagedArgs.cs
388388
cvars.json
389389
[Ss]amples/mocha-minimal/code/*.csproj
390+
[Ss]amples/mocha-minimal/code/Properties
390391

391392
# Content meta files
392393
![Cc]ontent/**/*.meta
393394

394395
# Cmake build files
395396
[Cc]ompile/
397+
398+
# Server configuration
399+
server.cfg
400+
401+
# JetBrains IDEs
402+
Source/.idea

.gitmodules

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
[submodule "Source/Host/thirdparty/imgui"]
2-
path = Source/Mocha.Host/thirdparty/imgui
1+
[submodule "Source/Host/Thirdparty/imgui"]
2+
path = Source/Mocha.Host/Thirdparty/imgui
33
url = https://github.com/ocornut/imgui/
4-
[submodule "Source/Host/thirdparty/JoltPhysics"]
5-
path = Source/Mocha.Host/thirdparty/JoltPhysics
4+
[submodule "Source/Host/Thirdparty/JoltPhysics"]
5+
path = Source/Mocha.Host/Thirdparty/JoltPhysics
66
url = https://github.com/jrouwe/JoltPhysics/
7-
[submodule "Source/Host/thirdparty/vk-bootstrap"]
8-
path = Source/Mocha.Host/thirdparty/vk-bootstrap
7+
[submodule "Source/Host/Thirdparty/vk-bootstrap"]
8+
path = Source/Mocha.Host/Thirdparty/vk-bootstrap
99
url = https://github.com/charles-lunarg/vk-bootstrap
10-
[submodule "Source/Host/thirdparty/implot"]
11-
path = Source/Mocha.Host/thirdparty/implot
10+
[submodule "Source/Host/Thirdparty/implot"]
11+
path = Source/Mocha.Host/Thirdparty/implot
1212
url = https://github.com/epezent/implot
13-
[submodule "Source/Host/thirdparty/volk"]
14-
path = Source/Mocha.Host/thirdparty/volk
13+
[submodule "Source/Host/Thirdparty/volk"]
14+
path = Source/Mocha.Host/Thirdparty/volk
1515
url = https://github.com/zeux/volk
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"DiffuseTexture":"textures/dev/dev_floor.mtex","NormalTexture":null,"AmbientOcclusionTexture":null,"MetalnessTexture":null,"RoughnessTexture":null}
1+
{"DiffuseTexture":"textures/dev/floor_basecolor.mtex","NormalTexture":"textures/dev/floor_normal.mtex","AmbientOcclusionTexture":"textures/dev/floor_ambientocclusion.mtex","MetalnessTexture":"textures/dev/floor_metallic.mtex","RoughnessTexture":"textures/dev/floor_roughness.mtex"}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"DiffuseTexture": "textures/dev/dev_wall.mtex"
3-
}
1+
{"DiffuseTexture":"textures/dev/wall_basecolor.mtex","NormalTexture":"textures/dev/wall_normal.mtex","AmbientOcclusionTexture":"textures/dev/wall_ambientocclusion.mtex","MetalnessTexture":"textures/dev/wall_metallic.mtex","RoughnessTexture":"textures/dev/wall_roughness.mtex"}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"DiffuseTexture":"textures/dev/dev_white.mtex","NormalTexture":null,"AmbientOcclusionTexture":null,"MetalnessTexture":null,"RoughnessTexture":null}
1+
{"DiffuseTexture":"textures/dev/generic_basecolor.mtex","NormalTexture":"textures/dev/generic_normal.mtex","AmbientOcclusionTexture":"textures/dev/generic_ambientocclusion.mtex","MetalnessTexture":"textures/dev/generic_metallic.mtex","RoughnessTexture":"textures/dev/generic_roughness.mtex"}
-2.71 KB
Binary file not shown.
-9.68 KB
Binary file not shown.
-2.77 KB
Binary file not shown.
Loading
63.4 KB
Loading
1.17 MB
Loading
18.9 KB
Loading
156 KB
Loading
153 KB
Loading
Loading
63.4 KB
Loading
1.17 MB
Loading
18.9 KB
Loading
156 KB
Loading
Loading
Loading
63 KB
Loading
1.17 MB
Loading
18.9 KB
Loading
156 KB
Loading
153 KB
Loading

Samples/mocha-minimal/code/Game.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,36 @@ namespace Minimal;
55

66
public class Game : BaseGame
77
{
8-
[HotloadSkip]
9-
private UIManager Hud { get; set; }
8+
[HotloadSkip] private UIManager Hud { get; set; }
109

11-
public override void Startup()
10+
public string NetworkedString { get; set; }
11+
12+
public override void OnStartup()
1213
{
13-
// Set up UI
14-
Hud = new UIManager();
15-
Hud.SetTemplate( "ui/Game.html" );
14+
if ( Core.IsServer )
15+
{
16+
// We only want to create these entities on the server.
17+
// They will automatically be replicated to clients.
18+
19+
// Spawn a model to walk around in
20+
var map = new ModelEntity( "models/dev/dev_map.mmdl" );
21+
map.SetMeshPhysics( "models/dev/dev_map.mmdl" );
1622

17-
// Spawn a model to walk around in
18-
var map = new ModelEntity( "models/dev/dev_map.mmdl" );
19-
map.SetMeshPhysics( "models/dev/dev_map.mmdl" );
23+
// Spawn a player
24+
var player = new Player();
25+
player.Position = new Vector3( 0, 0, 50 );
26+
}
27+
else
28+
{
29+
// UI is client-only
30+
Hud = new UIManager();
31+
Hud.SetTemplate( "ui/Game.html" );
32+
}
33+
}
2034

21-
// Spawn a player
22-
var player = new Player();
35+
[Event.Tick]
36+
public void Tick()
37+
{
38+
DebugOverlay.ScreenText( $"Tick... ({GetType().Assembly.GetHashCode()})" );
2339
}
2440
}

Samples/mocha-minimal/code/Player.cs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
1-
using System.ComponentModel;
2-
3-
namespace Minimal;
1+
namespace Minimal;
42

53
public class Player : Mocha.Player
64
{
7-
private Vector3 PlayerBounds = new( 0.5f, 0.5f, 1.8f ); // Metres
8-
9-
public QuakeWalkController WalkController { get; private set; }
5+
public WalkController WalkController { get; private set; }
106

11-
[Category( "Player" )]
12-
public bool IsGrounded => WalkController.IsGrounded;
7+
public float Health { get; set; }
138

14-
[Category( "Player" )]
15-
public BaseEntity GroundEntity => WalkController.GroundEntity;
9+
protected override void Spawn()
10+
{
11+
// TODO: This would be better as just a ctor
12+
base.Spawn();
1613

17-
public float Health { get; set; }
14+
PlayerBounds = new( 0.5f, 0.5f, 1.8f ); // Metres
15+
SetCubePhysics( PlayerBounds, false );
16+
}
1817

1918
private void UpdateEyeTransform()
2019
{
21-
EyePosition = Position + Vector3.Up * PlayerHalfExtents.Z;
20+
EyePosition = Position + Vector3.Up * PlayerBounds.Z;
2221
EyeRotation = Input.Rotation;
2322
}
2423

2524
public override void Respawn()
2625
{
2726
base.Respawn();
2827

29-
PlayerHalfExtents = PlayerBounds / 2f;
30-
3128
WalkController = new( this );
3229
Velocity = Vector3.Zero;
33-
Position = new Vector3( 0.0f, 4.0f, 0.9f );
30+
Position = new Vector3( 0.0f, 4.0f, 5.0f );
3431
}
3532

36-
public override void Update()
33+
public void PredictedUpdate()
3734
{
3835
UpdateEyeTransform();
39-
40-
WalkController.Update();
4136
}
4237

4338
public override void FrameUpdate()
@@ -48,7 +43,6 @@ public override void FrameUpdate()
4843
Health = MathX.Sin01( Time.Now ) * 100f;
4944
}
5045

51-
float lastHeight = 1.8f;
5246
float lastFov = 90f;
5347

5448
private void UpdateCamera()
@@ -63,19 +57,11 @@ private void UpdateCamera()
6357
//
6458
Camera.Position = Position + LocalEyePosition;
6559

66-
// Smooth out z-axis so that stairs, crouching are not sudden changes
67-
Camera.Position = Camera.Position.WithZ( lastHeight.LerpTo( Camera.Position.Z, 10f * Time.Delta ) );
68-
lastHeight = Camera.Position.Z;
69-
7060
//
7161
// Field of view
7262
//
7363
float targetFov = 90f;
7464

75-
// Interpolate velocity when sprinting
76-
if ( WalkController?.Sprinting ?? false && Velocity.WithZ( 0 ).Length > 1.0f )
77-
targetFov = 100f;
78-
7965
Camera.FieldOfView = lastFov.LerpTo( targetFov, 10 * Time.Delta );
8066
lastFov = Camera.FieldOfView;
8167

0 commit comments

Comments
 (0)