Skip to content

Commit

Permalink
Merge pull request #58 from xezno/engine-refactor
Browse files Browse the repository at this point in the history
Large-scale engine refactor
  • Loading branch information
xezno authored Apr 5, 2023
2 parents 520cd40 + de35d9d commit 897f173
Show file tree
Hide file tree
Showing 249 changed files with 7,310 additions and 3,422 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BasedOnStyle: Microsoft
AccessModifierOffset: '-4'
AlignAfterOpenBracket: DontAlign
AlignEscapedNewlines: Left
AllowShortFunctionsOnASingleLine: Inline
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: 'Yes'
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,16 @@ vcpkg_installed/
[Ss]ource/Mocha.Common/Glue/UnmanagedArgs.cs
cvars.json
[Ss]amples/mocha-minimal/code/*.csproj
[Ss]amples/mocha-minimal/code/Properties

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

# Cmake build files
[Cc]ompile/

# Server configuration
server.cfg

# JetBrains IDEs
Source/.idea
20 changes: 10 additions & 10 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[submodule "Source/Host/thirdparty/imgui"]
path = Source/Mocha.Host/thirdparty/imgui
[submodule "Source/Host/Thirdparty/imgui"]
path = Source/Mocha.Host/Thirdparty/imgui
url = https://github.com/ocornut/imgui/
[submodule "Source/Host/thirdparty/JoltPhysics"]
path = Source/Mocha.Host/thirdparty/JoltPhysics
[submodule "Source/Host/Thirdparty/JoltPhysics"]
path = Source/Mocha.Host/Thirdparty/JoltPhysics
url = https://github.com/jrouwe/JoltPhysics/
[submodule "Source/Host/thirdparty/vk-bootstrap"]
path = Source/Mocha.Host/thirdparty/vk-bootstrap
[submodule "Source/Host/Thirdparty/vk-bootstrap"]
path = Source/Mocha.Host/Thirdparty/vk-bootstrap
url = https://github.com/charles-lunarg/vk-bootstrap
[submodule "Source/Host/thirdparty/implot"]
path = Source/Mocha.Host/thirdparty/implot
[submodule "Source/Host/Thirdparty/implot"]
path = Source/Mocha.Host/Thirdparty/implot
url = https://github.com/epezent/implot
[submodule "Source/Host/thirdparty/volk"]
path = Source/Mocha.Host/thirdparty/volk
[submodule "Source/Host/Thirdparty/volk"]
path = Source/Mocha.Host/Thirdparty/volk
url = https://github.com/zeux/volk
2 changes: 1 addition & 1 deletion Content/core/materials/dev/dev_floor.mmat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"DiffuseTexture":"textures/dev/dev_floor.mtex","NormalTexture":null,"AmbientOcclusionTexture":null,"MetalnessTexture":null,"RoughnessTexture":null}
{"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"}
4 changes: 1 addition & 3 deletions Content/core/materials/dev/dev_wall.mmat
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"DiffuseTexture": "textures/dev/dev_wall.mtex"
}
{"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"}
2 changes: 1 addition & 1 deletion Content/core/materials/dev/dev_white.mmat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"DiffuseTexture":"textures/dev/dev_white.mtex","NormalTexture":null,"AmbientOcclusionTexture":null,"MetalnessTexture":null,"RoughnessTexture":null}
{"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"}
Binary file removed Content/core/textures/dev/dev_floor.png
Binary file not shown.
Binary file removed Content/core/textures/dev/dev_wall.png
Binary file not shown.
Binary file removed Content/core/textures/dev/dev_white.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/floor_basecolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/floor_height.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/floor_metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/floor_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/floor_roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/generic_basecolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/generic_height.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/generic_metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/generic_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/generic_roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/wall_basecolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/wall_height.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/wall_metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/wall_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/core/textures/dev/wall_roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 27 additions & 11 deletions Samples/mocha-minimal/code/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,36 @@ namespace Minimal;

public class Game : BaseGame
{
[HotloadSkip]
private UIManager Hud { get; set; }
[HotloadSkip] private UIManager Hud { get; set; }

public override void Startup()
public string NetworkedString { get; set; }

public override void OnStartup()
{
// Set up UI
Hud = new UIManager();
Hud.SetTemplate( "ui/Game.html" );
if ( Core.IsServer )
{
// We only want to create these entities on the server.
// They will automatically be replicated to clients.

// Spawn a model to walk around in
var map = new ModelEntity( "models/dev/dev_map.mmdl" );
map.SetMeshPhysics( "models/dev/dev_map.mmdl" );

// Spawn a model to walk around in
var map = new ModelEntity( "models/dev/dev_map.mmdl" );
map.SetMeshPhysics( "models/dev/dev_map.mmdl" );
// Spawn a player
var player = new Player();
player.Position = new Vector3( 0, 0, 50 );
}
else
{
// UI is client-only
Hud = new UIManager();
Hud.SetTemplate( "ui/Game.html" );
}
}

// Spawn a player
var player = new Player();
[Event.Tick]
public void Tick()
{
DebugOverlay.ScreenText( $"Tick... ({GetType().Assembly.GetHashCode()})" );
}
}
40 changes: 13 additions & 27 deletions Samples/mocha-minimal/code/Player.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
using System.ComponentModel;

namespace Minimal;
namespace Minimal;

public class Player : Mocha.Player
{
private Vector3 PlayerBounds = new( 0.5f, 0.5f, 1.8f ); // Metres

public QuakeWalkController WalkController { get; private set; }
public WalkController WalkController { get; private set; }

[Category( "Player" )]
public bool IsGrounded => WalkController.IsGrounded;
public float Health { get; set; }

[Category( "Player" )]
public BaseEntity GroundEntity => WalkController.GroundEntity;
protected override void Spawn()
{
// TODO: This would be better as just a ctor
base.Spawn();

public float Health { get; set; }
PlayerBounds = new( 0.5f, 0.5f, 1.8f ); // Metres
SetCubePhysics( PlayerBounds, false );
}

private void UpdateEyeTransform()
{
EyePosition = Position + Vector3.Up * PlayerHalfExtents.Z;
EyePosition = Position + Vector3.Up * PlayerBounds.Z;
EyeRotation = Input.Rotation;
}

public override void Respawn()
{
base.Respawn();

PlayerHalfExtents = PlayerBounds / 2f;

WalkController = new( this );
Velocity = Vector3.Zero;
Position = new Vector3( 0.0f, 4.0f, 0.9f );
Position = new Vector3( 0.0f, 4.0f, 5.0f );
}

public override void Update()
public void PredictedUpdate()
{
UpdateEyeTransform();

WalkController.Update();
}

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

float lastHeight = 1.8f;
float lastFov = 90f;

private void UpdateCamera()
Expand All @@ -63,19 +57,11 @@ private void UpdateCamera()
//
Camera.Position = Position + LocalEyePosition;

// Smooth out z-axis so that stairs, crouching are not sudden changes
Camera.Position = Camera.Position.WithZ( lastHeight.LerpTo( Camera.Position.Z, 10f * Time.Delta ) );
lastHeight = Camera.Position.Z;

//
// Field of view
//
float targetFov = 90f;

// Interpolate velocity when sprinting
if ( WalkController?.Sprinting ?? false && Velocity.WithZ( 0 ).Length > 1.0f )
targetFov = 100f;

Camera.FieldOfView = lastFov.LerpTo( targetFov, 10 * Time.Delta );
lastFov = Camera.FieldOfView;

Expand Down
Loading

0 comments on commit 897f173

Please sign in to comment.