Skip to content

Commit 20a9502

Browse files
authored
Merge branch 'Facepunch:master' into nodeeditor-valueeditor-additions
2 parents bb77846 + 22dc5b1 commit 20a9502

File tree

50 files changed

+875
-423
lines changed

Some content is hidden

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

50 files changed

+875
-423
lines changed

.github/workflows/pull_request.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
with:
1414
github-token: ${{ secrets.GITHUB_TOKEN }}
1515
script: |
16-
const requiredChecks = ['Tests', 'Formatting'];
16+
const requiredChecks = ['format', 'tests'];
1717
1818
const pr = context.payload.pull_request;
1919
if (!pr) {
@@ -33,16 +33,8 @@ jobs:
3333
3434
if (!match || match.conclusion !== 'success') {
3535
const status = match ? (match.conclusion ?? match.status ?? 'unknown') : 'missing';
36-
core.warning(`Required check '${requiredCheck}' did not pass (${status}). Removing triaged label.`);
37-
38-
await github.rest.issues.removeLabel({
39-
owner: context.repo.owner,
40-
repo: context.repo.repo,
41-
issue_number: pr.number,
42-
name: 'triaged'
43-
});
44-
45-
throw new Error('Cannot triage until required checks succeed.');
36+
core.warning(`Required check '${requiredCheck}' did not pass (${status}).`);
37+
throw new Error('Cannot triage until required checks succeed. Remove and re-add the triaged label to retry.');
4638
}
4739
}
4840

.github/workflows/pull_request_checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions:
88
contents: read
99

1010
jobs:
11-
format:
11+
tests:
1212
runs-on: [ windows-latest ]
1313
steps:
1414
- name: Full Checkout

engine/Definitions/engine/engine.globals.def

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,6 @@ native static class global as NativeEngine.EngineGlobal
6666
bool SourceEngineFrame( CMaterialSystem2AppSystemDict appDict, double currentTime, double previousTime );
6767
void SourceEngineShutdown( CMaterialSystem2AppSystemDict appDict, bool forced );
6868

69-
inline void UpdateWindowSize()
70-
{
71-
VideoModeChange_t* pModeChange = g_pEngineServiceMgr->GetVideoModeChange();
72-
if ( pModeChange )
73-
{
74-
g_pRenderService->SetVideoMode( pModeChange->m_deviceInfo );
75-
pModeChange->ModeChangeComplete();
76-
}
77-
78-
SwapChainHandle_t m_hSwapChain = g_pEngineServiceMgr->GetEngineSwapChain();
79-
RenderViewport_t renderViewport;
80-
renderViewport.Init( 0, 0, 512, 512, 0, 1 );
81-
82-
CRenderContextPtr pRenderContext( g_pRenderDevice, RenderTargetDesc_t( m_hSwapChain, RENDER_SRGB ), "Clear" );
83-
pRenderContext->Clear( Vector4D( 0, 0, 0, 0 ) );
84-
pRenderContext->SetViewports( 1, &renderViewport );
85-
86-
pRenderContext->Submit();
87-
g_pRenderDevice->Present( m_hSwapChain );
88-
}
89-
9069
inline float GetDiagonalDpi()
9170
{
9271
return Plat_GetDPI();

engine/Sandbox.Engine/Scene/GameObjectSystems/NetworkDebugSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ internal enum MessageType
2323
Snapshot,
2424
SyncVars,
2525
Culling,
26-
StringTable
26+
StringTable,
27+
UserCommands
2728
}
2829

2930
internal class Sample

engine/Sandbox.Engine/Scene/Networking/SceneNetworkSystem.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Sandbox;
1111
[Expose]
1212
public partial class SceneNetworkSystem : GameNetworkSystem
1313
{
14-
internal static SceneNetworkSystem Instance { get; private set; }
14+
internal static SceneNetworkSystem Instance { get; set; }
1515
internal DeltaSnapshotSystem DeltaSnapshots { get; private set; }
1616

1717
private List<NetworkObject> BatchSpawnList { get; set; } = [];
@@ -602,7 +602,13 @@ public override void OnHostChanged( Connection previousHost, Connection newHost
602602
}
603603
}
604604

605+
foreach ( var connection in Connection.All )
606+
{
607+
connection.Input.Clear();
608+
}
609+
605610
DeltaSnapshots?.Reset();
611+
UserCommand.Reset();
606612
}
607613

608614
public override void OnBecameHost( Connection previousHost )

engine/Sandbox.Engine/Scene/Scene/Scene.Network.cs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,48 @@ internal void DoOrphanedActions( Connection connection )
9090

9191
/// <summary>
9292
/// Send all of our visibility origins to other clients. These are points we can observe from, which helps
93-
/// to determine the visibility of network objects.
93+
/// to determine the visibility of network objects and sends a user command.
9494
/// </summary>
95-
private void SendClientTick( SceneNetworkSystem system )
95+
internal void SendClientTick( SceneNetworkSystem system )
9696
{
97-
var lc = Connection.Local;
98-
using var msg = ByteStream.Create( 256 );
99-
msg.Write( InternalMessageType.ClientTick );
97+
var localConnection = Connection.Local;
10098

101-
// client visibility origins
102-
{
103-
// Conna: in the future we might support multiple visibility origins. For now though, we'll just
104-
// use the main camera position as our primary viewing source.
105-
if ( lc.VisibilityOrigins.Length == 0 )
106-
lc.VisibilityOrigins = new Vector3[1];
99+
// Conna: in the future we might support multiple visibility origins. For now though, we'll just
100+
// use the main camera position as our primary viewing source.
101+
if ( localConnection.VisibilityOrigins.Length == 0 )
102+
localConnection.VisibilityOrigins = new Vector3[1];
103+
104+
localConnection.VisibilityOrigins[0] = Camera?.WorldPosition ?? default;
107105

108-
lc.VisibilityOrigins[0] = Camera?.WorldPosition ?? default;
106+
var userCommand = UserCommand.Create();
107+
localConnection.BuildUserCommand( ref userCommand );
109108

110-
msg.Write( (char)lc.VisibilityOrigins.Length );
109+
foreach ( var connection in system.GetFilteredConnections() )
110+
{
111+
var msg = ByteStream.Create( 256 );
112+
msg.Write( InternalMessageType.ClientTick );
111113

112-
for ( var i = 0; i < lc.VisibilityOrigins.Length; i++ )
114+
// Broadcast our visibility origins to everyone
113115
{
114-
var source = lc.VisibilityOrigins[i];
115-
msg.Write( source.x );
116-
msg.Write( source.y );
117-
msg.Write( source.z );
116+
msg.Write( (char)localConnection.VisibilityOrigins.Length );
117+
118+
for ( var i = 0; i < localConnection.VisibilityOrigins.Length; i++ )
119+
{
120+
var source = localConnection.VisibilityOrigins[i];
121+
msg.Write( source.x );
122+
msg.Write( source.y );
123+
msg.Write( source.z );
124+
}
118125
}
119-
}
120126

121-
system.BroadcastRaw( msg, null, NetFlags.UnreliableNoDelay );
127+
if ( connection.IsHost )
128+
{
129+
userCommand.Serialize( ref msg );
130+
}
131+
132+
connection.SendRawMessage( msg, NetFlags.UnreliableNoDelay );
133+
msg.Dispose();
134+
}
122135
}
123136

124137
/// <summary>

engine/Sandbox.Engine/Scene/Scene/Scene.Tick.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ internal void InternalFixedUpdate()
321321
Signal( GameObjectSystem.Stage.FinishFixedUpdate );
322322
}
323323

324-
324+
Connection.ClearFixedUpdateContextInput();
325325
}
326-
327326
}

engine/Sandbox.Engine/Systems/Input/Input.Actions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static partial class Input
1010
/// </summary>
1111
public static bool UsingController { get; internal set; } = false;
1212

13-
static ulong Actions
13+
internal static ulong Actions
1414
{
1515
get => CurrentContext.ActionsCurrent;
1616
set => CurrentContext.ActionsCurrent = value;
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
namespace Sandbox;
2+
3+
public abstract partial class Connection
4+
{
5+
/// <summary>
6+
/// Build the <see cref="UserCommand"/> for this <see cref="Connection"/>.
7+
/// </summary>
8+
internal void BuildUserCommand( ref UserCommand cmd )
9+
{
10+
cmd.Actions = Sandbox.Input.Actions;
11+
}
12+
13+
/// <summary>
14+
/// Clear pending pressed and released actions for all connections in the Update context.
15+
/// </summary>
16+
internal static void ClearUpdateContextInput()
17+
{
18+
foreach ( var connection in All )
19+
{
20+
connection.Input.ClearUpdateContext();
21+
}
22+
}
23+
24+
/// <summary>
25+
/// Clear pending pressed and released actions for all connections in the Fixed Update context.
26+
/// </summary>
27+
internal static void ClearFixedUpdateContextInput()
28+
{
29+
foreach ( var connection in All )
30+
{
31+
connection.Input.ClearFixedUpdateContext();
32+
}
33+
}
34+
35+
internal struct InputState
36+
{
37+
internal struct Context
38+
{
39+
public ulong Pressed;
40+
public ulong Released;
41+
42+
/// <summary>
43+
/// Clear the state of this input context.
44+
/// </summary>
45+
public void Clear()
46+
{
47+
Released = 0;
48+
Pressed = 0;
49+
}
50+
}
51+
52+
private UserCommand _lastUserCommand;
53+
54+
public ulong Actions;
55+
56+
private Context _fixedUpdateContext;
57+
private Context _updateContext;
58+
59+
public Context GetCurrentContext()
60+
{
61+
var isFixedUpdate = Game.ActiveScene?.IsFixedUpdate ?? false;
62+
return isFixedUpdate ? _fixedUpdateContext : _updateContext;
63+
}
64+
65+
public void ApplyUserCommand( in UserCommand cmd )
66+
{
67+
var commandNumberDelta = cmd.CommandNumber - _lastUserCommand.CommandNumber;
68+
69+
// Drop duplicates or commands that are too far behind (wrap-aware)
70+
if ( commandNumberDelta is 0 or > 0x7FFFFFFF )
71+
return;
72+
73+
var pressed = (~_lastUserCommand.Actions) & cmd.Actions;
74+
var released = _lastUserCommand.Actions & ~cmd.Actions;
75+
76+
if ( pressed != 0 )
77+
{
78+
_fixedUpdateContext.Pressed |= pressed;
79+
_updateContext.Pressed |= pressed;
80+
}
81+
82+
if ( released != 0 )
83+
{
84+
_fixedUpdateContext.Released |= released;
85+
_updateContext.Released |= released;
86+
}
87+
88+
Actions = cmd.Actions;
89+
90+
_lastUserCommand = cmd;
91+
}
92+
93+
public void ClearFixedUpdateContext()
94+
{
95+
_fixedUpdateContext.Clear();
96+
}
97+
98+
public void ClearUpdateContext()
99+
{
100+
_updateContext.Clear();
101+
}
102+
103+
public void Clear()
104+
{
105+
_lastUserCommand = default;
106+
}
107+
}
108+
109+
internal InputState Input;
110+
111+
/// <summary>
112+
/// Action is currently pressed down for this <see cref="Connection"/>.
113+
/// </summary>
114+
public bool Down( [InputAction] string action )
115+
{
116+
// If we're the host, just use our local input instead.
117+
if ( IsHost )
118+
return Sandbox.Input.Down( action );
119+
120+
if ( string.IsNullOrWhiteSpace( action ) )
121+
return false;
122+
123+
var index = Sandbox.Input.GetActionIndex( action );
124+
if ( index == -1 )
125+
return false;
126+
127+
var mask = 1UL << index;
128+
return (Input.Actions & mask) != 0;
129+
}
130+
131+
/// <summary>
132+
/// Action was pressed for this <see cref="Connection"/> within the current update context.
133+
/// </summary>
134+
public bool Pressed( [InputAction] string action )
135+
{
136+
// If we're the host, just use our local input instead.
137+
if ( IsHost )
138+
return Sandbox.Input.Pressed( action );
139+
140+
if ( string.IsNullOrWhiteSpace( action ) )
141+
return false;
142+
143+
var index = Sandbox.Input.GetActionIndex( action );
144+
if ( index == -1 )
145+
return false;
146+
147+
var mask = 1UL << index;
148+
var context = Input.GetCurrentContext();
149+
150+
return (context.Pressed & mask) != 0;
151+
}
152+
153+
/// <summary>
154+
/// Action was released for this <see cref="Connection"/> within the current update context.
155+
/// </summary>
156+
public bool Released( [InputAction] string action )
157+
{
158+
// If we're the host, just use our local input instead.
159+
if ( IsHost )
160+
return Sandbox.Input.Released( action );
161+
162+
if ( string.IsNullOrWhiteSpace( action ) )
163+
return false;
164+
165+
var index = Sandbox.Input.GetActionIndex( action );
166+
if ( index == -1 )
167+
return false;
168+
169+
var mask = 1UL << index;
170+
var context = Input.GetCurrentContext();
171+
172+
return (context.Released & mask) != 0;
173+
}
174+
}

engine/Sandbox.Engine/Systems/Networking/System/NetworkSystem.Message.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,11 @@ private void OnReceiveCullStateChange( ByteStream data, Connection source )
291291
GameSystem?.OnCullStateChangeMessage( data, source );
292292
}
293293

294-
private void OnReceiveClientTick( ByteStream data, Connection source )
294+
internal void OnReceiveClientTick( ByteStream data, Connection source )
295295
{
296-
// visibility
296+
NetworkDebugSystem.Current?.Record( NetworkDebugSystem.MessageType.UserCommands, data.Length );
297+
298+
// Read and apply visibility origins from the client
297299
{
298300
var count = data.Read<char>();
299301

@@ -317,6 +319,21 @@ private void OnReceiveClientTick( ByteStream data, Connection source )
317319
}
318320
}
319321
}
322+
323+
// Read and apply the user command from this client
324+
{
325+
if ( data.ReadRemaining == 0 )
326+
return;
327+
328+
// We should reject user commands from clients if we're not the host
329+
if ( !Networking.IsHost )
330+
return;
331+
332+
// This is a user command directly from another client
333+
UserCommand cmd = default;
334+
cmd.Deserialize( ref data );
335+
source.Input.ApplyUserCommand( cmd );
336+
}
320337
}
321338

322339
private void OnHeartbeatPingMessage( ByteStream data, Connection source )

0 commit comments

Comments
 (0)