Skip to content

Commit 2f6fece

Browse files
committed
Revert "Start moving world objects to C# and call them Actors"
This reverts commit 35f73bb. # Conflicts: # Source/Mocha.Hotload/Main.cs
1 parent f3abaa1 commit 2f6fece

Some content is hidden

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

53 files changed

+2205
-297
lines changed

Samples/mocha-minimal/code/BaseController.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

Samples/mocha-minimal/code/Game.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
global using Mocha;
22
global using Mocha.Common;
3-
using Mocha.Glue;
43

54
namespace Minimal;
65

76
public class Game : BaseGame
87
{
8+
[HotloadSkip] private UIManager Hud { get; set; }
9+
10+
public string NetworkedString { get; set; }
11+
912
public override void OnStartup()
1013
{
1114
// Spawn a model to walk around in
12-
var map = new StaticMeshActor( "models/dev/dev_map.mmdl" );
13-
// map.SetMeshPhysics( "models/dev/dev_map.mmdl" );
15+
var map = new ModelEntity( "models/dev/dev_map.mmdl" );
16+
map.SetMeshPhysics( "models/dev/dev_map.mmdl" );
1417

1518
// Spawn a player
1619
var player = new Player();
1720
player.Position = new Vector3( 0, 5, 10 );
21+
22+
Hud = new UIManager();
23+
Hud.SetTemplate( "ui/Game.html" );
24+
}
25+
26+
[Event.Tick]
27+
public void Tick()
28+
{
29+
DebugOverlay.ScreenText( $"Tick... ({GetType().Assembly.GetHashCode()})" );
1830
}
1931
}

Samples/mocha-minimal/code/Player.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class Player : Mocha.Player
44
{
5-
public BaseController WalkController { get; private set; }
5+
public WalkController WalkController { get; private set; }
66

77
public float Health { get; set; }
88

@@ -12,7 +12,7 @@ protected override void Spawn()
1212
base.Spawn();
1313

1414
PlayerBounds = new( 0.5f, 0.5f, 1.8f ); // Metres
15-
// SetCubePhysics( PlayerBounds, false );
15+
SetCubePhysics( PlayerBounds, false );
1616
}
1717

1818
private void UpdateEyeTransform()
@@ -25,32 +25,18 @@ public override void Respawn()
2525
{
2626
base.Respawn();
2727

28-
WalkController = new NoClipController( this );
29-
// Velocity = Vector3.Zero;
28+
WalkController = new( this );
29+
Velocity = Vector3.Zero;
3030
Position = new Vector3( 0.0f, 4.0f, 5.0f );
3131
}
3232

33-
[Event.Tick]
3433
public void PredictedUpdate()
3534
{
3635
UpdateEyeTransform();
37-
WalkController.PredictedUpdate();
3836
}
3937

40-
bool wasCrouch = false;
41-
4238
public override void FrameUpdate()
4339
{
44-
if ( Input.Crouch && !wasCrouch )
45-
{
46-
if ( WalkController is WalkController )
47-
WalkController = new NoClipController( this );
48-
else
49-
WalkController = new WalkController( this );
50-
}
51-
52-
wasCrouch = Input.Crouch;
53-
5440
UpdateCamera();
5541
UpdateEyeTransform();
5642

Samples/mocha-minimal/code/WalkController.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Minimal;
77
* once it's done
88
*/
99

10-
public class WalkController : BaseController
10+
public class WalkController
1111
{
1212
public float Friction => 12.0f;
1313
public float GroundAccelerate => 50.0f;
@@ -19,7 +19,7 @@ public class WalkController : BaseController
1919
public float MaxAngle => 60.0f;
2020

2121
private bool IsGrounded => GroundEntity != null;
22-
private Actor GroundEntity;
22+
private BaseEntity GroundEntity;
2323

2424
private Player Player { get; set; }
2525

@@ -28,12 +28,15 @@ public class WalkController : BaseController
2828
public WalkController( Player player )
2929
{
3030
Player = player;
31-
// Player.IgnoreRigidbodyRotation = true;
31+
Player.IgnoreRigidbodyRotation = true;
3232

3333
Event.Register( this );
34+
35+
Player.Position = new Vector3( 0, 5, 10 );
3436
}
3537

36-
public override void PredictedUpdate()
38+
[Event.Tick]
39+
public void PredictedUpdate()
3740
{
3841
DebugOverlay.ScreenText( $"--------------------------------------------------------------------------------" );
3942
DebugOverlay.ScreenText( $"{(Core.IsClient ? "Client" : "Server")}" );
@@ -66,17 +69,12 @@ public override void PredictedUpdate()
6669
Velocity.Z -= 9.8f * Time.Delta;
6770
}
6871

69-
// Player.Velocity = Velocity * 10f;
72+
Player.Velocity = Velocity * 10f;
7073
Move();
7174

7275
DebugOverlay.ScreenText( $"--------------------------------------------------------------------------------" );
7376
}
7477

75-
~WalkController()
76-
{
77-
Event.Unregister( this );
78-
}
79-
8078
private Vector3 GetWishDir()
8179
{
8280
var eulerRotation = Input.Rotation.ToEulerAngles();
@@ -118,7 +116,7 @@ private Vector3 MoveAir( Vector3 accelDir, Vector3 prevVelocity )
118116

119117
public Mocha.TraceResult TraceBBox( Vector3 start, Vector3 end )
120118
{
121-
return Cast.Ray( start, end ).WithHalfExtents( Player.PlayerBounds ).Run();//.Ignore( Player ).Run();
119+
return Cast.Ray( start, end ).WithHalfExtents( Player.PlayerBounds ).Ignore( Player ).Run();
122120
}
123121

124122
private void CheckGrounded()
@@ -128,9 +126,9 @@ private void CheckGrounded()
128126
// Grounded only counts if the normal is facing upwards
129127
var angle = Vector3.GetAngle( tr.Normal, Vector3.Up );
130128

131-
//if ( tr.Hit && angle < MaxAngle )
132-
// GroundEntity = tr.Entity;
133-
//else
129+
if ( tr.Hit && angle < MaxAngle )
130+
GroundEntity = tr.Entity;
131+
else
134132
GroundEntity = null;
135133
}
136134

Source/Mocha.Common/Entities/EntityRegistry.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Mocha.Common;
44

5-
public sealed class EntityRegistry : IEnumerable<IActor>
5+
public sealed class EntityRegistry : IEnumerable<IEntity>
66
{
77
private static EntityRegistry? s_instance;
88
public static EntityRegistry Instance
@@ -14,9 +14,9 @@ public static EntityRegistry Instance
1414
}
1515
}
1616

17-
private readonly List<IActor> _entities = new();
17+
private readonly List<IEntity> _entities = new();
1818

19-
public void RegisterEntity( IActor entity )
19+
public void RegisterEntity( IEntity entity )
2020
{
2121
// Don't add duplicates
2222
if ( _entities.Contains( entity ) )
@@ -25,15 +25,15 @@ public void RegisterEntity( IActor entity )
2525
_entities.Add( entity );
2626
}
2727

28-
public void UnregisterEntity( IActor entity )
28+
public void UnregisterEntity( IEntity entity )
2929
{
3030
_entities.Remove( entity );
3131
}
3232

33-
public IEnumerator<IActor> GetEnumerator() => _entities.GetEnumerator();
33+
public IEnumerator<IEntity> GetEnumerator() => _entities.GetEnumerator();
3434
IEnumerator IEnumerable.GetEnumerator() => _entities.GetEnumerator();
3535

36-
public IActor this[int index]
36+
public IEntity this[int index]
3737
{
3838
get => _entities.ElementAt( index );
3939
set => _entities[index] = value;

Source/Mocha.Common/Entities/IActor.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Mocha.Common;
2+
3+
public interface IEntity
4+
{
5+
string Name { get; set; }
6+
uint NativeHandle { get; }
7+
8+
Vector3 Position { get; set; }
9+
Rotation Rotation { get; set; }
10+
Vector3 Scale { get; set; }
11+
12+
void Delete();
13+
void Delete( bool immediate );
14+
bool IsValid();
15+
void Update();
16+
}

Source/Mocha.Common/Types/Transform.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,4 @@ public Transform( Transform other )
1919
Rotation = other.Rotation;
2020
Scale = other.Scale;
2121
}
22-
23-
public Transform WithPosition( Vector3 position )
24-
{
25-
var tx = new Transform
26-
{
27-
Position = position,
28-
Rotation = Rotation,
29-
Scale = Scale
30-
};
31-
32-
return tx;
33-
}
34-
35-
public Transform WithRotation( Rotation rotation )
36-
{
37-
var tx = new Transform
38-
{
39-
Position = Position,
40-
Rotation = rotation,
41-
Scale = Scale
42-
};
43-
44-
return tx;
45-
}
46-
47-
public Transform WithScale( Vector3 scale )
48-
{
49-
var tx = new Transform
50-
{
51-
Position = Position,
52-
Rotation = Rotation,
53-
Scale = scale
54-
};
55-
56-
return tx;
57-
}
58-
59-
public static Transform Default => new Transform()
60-
{
61-
Position = Vector3.Zero,
62-
Rotation = Rotation.Identity,
63-
Scale = Vector3.One
64-
};
6522
}

Source/Mocha.Editor/Editor/Windows/ConsoleWindow.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ private void DrawEntityList()
9797
{
9898
if ( ImGui.BeginTabItem( $"{FontAwesome.Ghost}" ) )
9999
{
100-
foreach ( var actor in Actor.All )
100+
foreach ( var entity in BaseEntity.All )
101101
{
102-
if ( ImGui.Selectable( actor.Name ) )
103-
InspectorWindow.SetSelectedObject( actor );
102+
if ( ImGui.Selectable( entity.Name ) )
103+
InspectorWindow.SetSelectedObject( entity );
104104
}
105105

106106
ImGui.EndTabItem();
@@ -134,6 +134,8 @@ void ShowNode( LayoutNode node )
134134
}
135135
}
136136

137+
ShowNode( UIManager.Instance.RootPanel );
138+
137139
ImGui.EndTabItem();
138140
}
139141
}

Source/Mocha.Engine/BaseGame.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public BaseGame()
2121

2222
private void TryCallMethodOnEntity( string methodName )
2323
{
24-
Actor.All.ToList().ForEach( entity =>
24+
BaseEntity.All.ToList().ForEach( entity =>
2525
{
2626
var method = entity.GetType().GetMethod( methodName )!;
2727
var methodHash = HashCode.Combine( method, entity );
@@ -50,6 +50,8 @@ private void TryCallMethodOnEntity( string methodName )
5050

5151
public void FrameUpdate()
5252
{
53+
UIManager.Instance.Render();
54+
5355
TryCallMethodOnEntity( "FrameUpdate" );
5456
}
5557

0 commit comments

Comments
 (0)