Skip to content

Commit afb663d

Browse files
CarsonKomponhandsomematt
authored andcommitted
Engine Overlays are still drawn properly when in a loading state
1 parent b9a092e commit afb663d

File tree

2 files changed

+11
-56
lines changed

2 files changed

+11
-56
lines changed

engine/Sandbox.Engine/Game/Game/Game.Scene.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ public static bool ChangeScene( SceneLoadOptions options )
3535
if ( !Networking.IsHost )
3636
return false;
3737

38-
// Tell clients the host is about to load a new scene before we start,
39-
// so we show a loading screen immediately rather than freezing silently.
40-
SceneNetworkSystem.Instance?.NotifySceneChangeStarting( options );
41-
4238
// We don't want to send any networked messages to do with deletion or creation
4339
// of GameObjects here. Because the client will destroy their scene locally
4440
// anyway. This saves us sending a message for potentially 100s of objects.
@@ -69,6 +65,14 @@ internal static void Render( SwapChainHandle_t swapChain )
6965
if ( ActiveScene.IsLoading || LoadingScreen.IsVisible || Networking.IsConnecting )
7066
{
7167
ActiveScene.RenderEnvmaps();
68+
69+
// Make sure overlays are rendered even when we are loading
70+
if ( ActiveScene.Camera is not null )
71+
{
72+
ActiveScene.Camera.SceneCamera.EnableEngineOverlays = true;
73+
ActiveScene.Camera.AddToRenderList( swapChain, default );
74+
}
75+
7276
return;
7377
}
7478

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

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ internal SceneNetworkSystem( Internal.TypeLibrary typeLibrary, NetworkSystem sys
4646
AddHandler<SceneRpcMsg>( OnSceneRpc );
4747
AddHandler<StaticRpcMsg>( OnStaticRpc );
4848
AddHandler<LoadSceneBeginMsg>( OnLoadSceneMsg );
49-
AddHandler<LoadSceneNotifyMsg>( OnLoadSceneNotifyMsg );
5049
AddHandler<LoadSceneSnapshotMsg>( OnLoadSceneSnapshotMsg );
5150
AddHandler<LoadSceneRequestSnapshotMsg>( OnLoadSceneRequestSnapshotMsg );
5251
AddHandler<SceneLoadedMsg>( OnSceneLoadedMsg );
@@ -85,35 +84,6 @@ internal static IDisposable SuppressDestroyMessages()
8584

8685
private readonly Dictionary<Guid, Guid> PendingSceneLoads = new();
8786

88-
/// <summary>
89-
/// Notify all connected clients that the host is loading a new scene.
90-
/// Sent before <see cref="LoadSceneBroadcast"/> so clients can show a loading screen immediately rather than freezing with no feedback.
91-
/// </summary>
92-
internal void NotifySceneChangeStarting( SceneLoadOptions options )
93-
{
94-
if ( !Networking.IsActive || !Networking.IsHost )
95-
return;
96-
97-
var msg = new LoadSceneNotifyMsg { ShowLoadingScreen = options.ShowLoadingScreen };
98-
99-
var bs = ByteStream.Create( 64 );
100-
bs.Write( InternalMessageType.Packed );
101-
Networking.System.Serialize( msg, ref bs );
102-
103-
foreach ( var c in Connection.All )
104-
{
105-
if ( c == Connection.Local )
106-
continue;
107-
108-
if ( c.State < Connection.ChannelState.Snapshot )
109-
continue;
110-
111-
c.SendStream( bs );
112-
}
113-
114-
bs.Dispose();
115-
}
116-
11787
/// <summary>
11888
/// Load a scene for all other clients. This can only be called by the host.
11989
/// </summary>
@@ -332,27 +302,14 @@ private async Task OnLoadSceneRequestSnapshotMsg( LoadSceneRequestSnapshotMsg ms
332302
bs.Dispose();
333303
}
334304

335-
/// <summary>
336-
/// Called when the host notifies us it is about to begin loading a new scene.
337-
/// </summary>
338-
private void OnLoadSceneNotifyMsg( LoadSceneNotifyMsg msg, Connection connection, Guid msgId )
339-
{
340-
if ( Game.IsEditor )
341-
return;
342-
343-
if ( msg.ShowLoadingScreen )
344-
{
345-
LoadingScreen.IsVisible = true;
346-
LoadingScreen.Title = "Loading Scene";
347-
}
348-
}
349-
350305
/// <summary>
351306
/// Called when the host has told us to load a new scene.
352307
/// </summary>
353308
private async Task OnLoadSceneMsg( LoadSceneBeginMsg msg, Connection connection, Guid msgId )
354309
{
355-
if ( !Game.IsEditor && msg.ShowLoadingScreen )
310+
// Always show the loading screen on clients when the host changes scene,
311+
// so they see feedback immediately instead of a frozen frame.
312+
if ( !Game.IsEditor )
356313
{
357314
LoadingScreen.IsVisible = true;
358315
LoadingScreen.Title = "Loading Scene";
@@ -1420,12 +1377,6 @@ struct ObjectRefreshMsg
14201377
public Guid Guid { get; set; }
14211378
}
14221379

1423-
[Expose]
1424-
struct LoadSceneNotifyMsg
1425-
{
1426-
public bool ShowLoadingScreen { get; set; }
1427-
}
1428-
14291380
[Expose]
14301381
struct LoadSceneBeginMsg
14311382
{

0 commit comments

Comments
 (0)