Skip to content

Commit

Permalink
fix: unable to enter realm through url due to deocupled loading screen (
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia authored Jan 24, 2023
1 parent 8f53340 commit 153a747
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"references": [
"GUID:28f74c468a54948bfa9f625c5d428f56",
"GUID:b1087c5731ff68448a0a9c625bb7e52d",
"GUID:1e6b57fe78f7b724e9567f29f6a40c2c"
"GUID:1e6b57fe78f7b724e9567f29f6a40c2c",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using Cysharp.Threading.Tasks;
using DCL;
using UnityEngine;
using Object = UnityEngine.Object;
Expand All @@ -8,17 +10,25 @@ namespace MainScripts.DCL.Controllers.HUD.Preloading
public class PreloadingController : IDisposable
{
private GameObject view;
private BaseVariable<string> loadingMessage => DataStore.i.HUDs.loadingHUD.message;
private readonly DataStoreRef<DataStore_LoadingScreen> loadingScreenRef;

private BaseVariable<bool> isSignUpFlow => DataStore.i.common.isSignUpFlow;
private bool isDisposed = false;

public PreloadingController()
{
view = Object.Instantiate(GetView());
loadingMessage.OnChange += OnMessageChange;
loadingScreenRef.Ref.loadingHUD.message.OnChange += OnMessageChange;
loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange += OnDecoupledLoadingScreenVisibilityChange;
isSignUpFlow.OnChange += SignUpFlowChanged;
}

private void OnDecoupledLoadingScreenVisibilityChange(bool current, bool _)
{
if(current)
Dispose();
}

private GameObject GetView()
{
return Resources.Load<GameObject>("Preloading");
Expand All @@ -28,25 +38,29 @@ public void Dispose()
{
if (isDisposed) return;
isDisposed = true;
loadingMessage.OnChange -= OnMessageChange;
WaitForViewsToFadeOut();
}

async UniTask WaitForViewsToFadeOut()
{
//This wait will be removed when we merge both loading screen into a single decoupled loading screen
await UniTask.Delay(TimeSpan.FromSeconds(2), ignoreTimeScale: false);
loadingScreenRef.Ref.loadingHUD.message.OnChange -= OnMessageChange;
loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange -= OnDecoupledLoadingScreenVisibilityChange;
isSignUpFlow.OnChange -= SignUpFlowChanged;
Object.Destroy(view.gameObject);
}

private void OnMessageChange(string current, string previous)
{
if (current.Contains("%"))
{
Dispose();
}
}

private void SignUpFlowChanged(bool current, bool previous)
{
if (current)
{
Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public class ProfileHUDViewDesktop : ProfileHUDView

protected internal Button getButtonSignUp => buttonSignUp;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"GUID:760a1d365aad58044916992b072cf2a6",
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:4720e174f2805c74bb7aa94cc8bb5bf8",
"GUID:1e6b57fe78f7b724e9567f29f6a40c2c"
"GUID:1e6b57fe78f7b724e9567f29f6a40c2c",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using Object = UnityEngine.Object;

Expand All @@ -9,20 +11,19 @@ public class LoadingFlowController : IDisposable
private const float GENERAL_TIMEOUT_IN_SECONDS = 100;
private const int WEB_SOCKET_TIMEOUT = 15;

private readonly BaseVariable<Exception> fatalErrorMessage;
private readonly ILoadingFlowView view;
private readonly BaseVariable<bool> loadingHudVisible;
private readonly RendererState rendererState;
private readonly BaseVariable<bool> websocketCommunicationEstablished;
private float timerStart;
private bool isWatching;

public LoadingFlowController(BaseVariable<Exception> fatalErrorMessage,
private CancellationTokenSource disposeToken;

public LoadingFlowController(
BaseVariable<bool> loadingHudVisible,
RendererState rendererState,
BaseVariable<bool> websocketCommunicationEstablished)
{
this.fatalErrorMessage = fatalErrorMessage;
this.loadingHudVisible = loadingHudVisible;
this.rendererState = rendererState;
this.websocketCommunicationEstablished = websocketCommunicationEstablished;
Expand All @@ -42,9 +43,7 @@ private ILoadingFlowView CreateView()
private void OnLoadingHudVisibleChanged(bool current, bool previous)
{
if (current)
{
StartWatching();
}
else
{
view.Hide();
Expand All @@ -54,36 +53,13 @@ private void OnLoadingHudVisibleChanged(bool current, bool previous)

private void StartWatching()
{
isWatching = false;
timerStart = Time.unscaledTime;
fatalErrorMessage.OnChange += HandleFatalError;
}

private void HandleFatalError(Exception current, Exception previous)
{
if (current == null) return;

view.Show();
StopWatching();
}

private void StopWatching()
{
if (isWatching) return;
isWatching = true;
fatalErrorMessage.OnChange -= HandleFatalError;
disposeToken = new CancellationTokenSource();
ListenForTimeout();
}

public void Update()
{
if (isWatching) return;

if (IsTimeToShowTimeout())
{
view.Show();
StopWatching();
}
}
private void StopWatching() =>
DisposeCancellationToken();

private bool IsTimeToShowTimeout()
{
Expand All @@ -103,9 +79,35 @@ private void OnRendererStateChange(bool current, bool previous)

public void Dispose()
{
fatalErrorMessage.OnChange -= HandleFatalError;
loadingHudVisible.OnChange -= OnLoadingHudVisibleChanged;
rendererState.OnChange -= OnRendererStateChange;
DisposeCancellationToken();
}

private async UniTask ListenForTimeout()
{
while (true)
{
if (IsTimeToShowTimeout())
ShowTimeout();
await UniTask.Yield(cancellationToken: disposeToken.Token);
}
}

private void ShowTimeout()
{
view.Show();
StopWatching();
}

private void DisposeCancellationToken()
{
if (disposeToken == null) return;

disposeToken.Cancel();
disposeToken.Dispose();
disposeToken = null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using MainScripts.DCL.Controllers.SettingsDesktop;
using MainScripts.DCL.Utils;
using UnityEngine;
using RPC;

namespace DCL
{
Expand All @@ -20,6 +19,8 @@ public class MainDesktop : Main
private LoadingFlowController loadingFlowController;
private PreloadingController preloadingController;
private bool isConnectionLost;
private readonly DataStoreRef<DataStore_LoadingScreen> loadingScreenRef;

private BaseVariable<FeatureFlag> featureFlags => DataStore.i.featureFlags.flags;

protected override void Awake()
Expand Down Expand Up @@ -50,7 +51,22 @@ protected override void InitializeDataStore()
private void FeatureFlagsReady(FeatureFlag current, FeatureFlag previous)
{
DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider;
if (current.IsFeatureEnabled(DataStore.i.featureFlags.DECOUPLED_LOADING_SCREEN_FF))
{
loadingFlowController = new LoadingFlowController(
loadingScreenRef.Ref.decoupledLoadingHUD.visible,
CommonScriptableObjects.rendererState,
DataStore.i.wsCommunication.communicationEstablished);
}
else
{
loadingFlowController = new LoadingFlowController(
loadingScreenRef.Ref.loadingHUD.visible,
CommonScriptableObjects.rendererState,
DataStore.i.wsCommunication.communicationEstablished);
}
DataStore.i.featureFlags.flags.OnChange -= FeatureFlagsReady;

}

protected override void InitializeCommunication()
Expand Down Expand Up @@ -120,8 +136,7 @@ void OnCommunicationEstablished(bool current, bool previous)
protected override void Update()
{
base.Update();
loadingFlowController.Update();


if (isConnectionLost)
{
DesktopUtils.Quit();
Expand All @@ -137,18 +152,7 @@ protected override void Update()
SettingsDesktop.i.displaySettings.Save();
}
}

protected override void Start()
{
loadingFlowController = new LoadingFlowController(
DataStore.i.HUDs.loadingHUD.fatalError,
DataStore.i.HUDs.loadingHUD.visible,
CommonScriptableObjects.rendererState,
DataStore.i.wsCommunication.communicationEstablished);

base.Start();
}


protected override void InitializeSceneDependencies()
{
base.InitializeSceneDependencies();
Expand Down
4 changes: 2 additions & 2 deletions unity-renderer-desktop/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
"com.decentraland.rpc-csharp": "https://github.com/decentraland/rpc-csharp.git?path=rpc-csharp/src",
"com.decentraland.unity-shared-dependencies": "https://github.com/decentraland/unity-shared-dependencies.git",
"com.decentraland.unity-renderer": "git+https://github.com/decentraland/unity-renderer.git?path=unity-renderer/Assets#main",
"com.decentraland.unity-renderer": "git+https://github.com/decentraland/unity-renderer.git?path=unity-renderer/Assets#dev",
"com.decentraland.webgl-ime-input": "https://github.com/decentraland/webgl-ime-input.git",
"com.decentraland.videoplayer": "git+https://github.com/decentraland/DCLVideoPlayerUnity.git?path=Assets#main",
"com.unity.cinemachine": "2.8.9",
Expand Down Expand Up @@ -38,4 +38,4 @@
]
}
]
}
}
16 changes: 8 additions & 8 deletions unity-renderer-desktop/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"hash": "0edfd2eb04da488b3ea3b1bc744efb4df033b508"
},
"com.decentraland.unity-renderer": {
"version": "git+https://github.com/decentraland/unity-renderer.git?path=unity-renderer/Assets#main",
"version": "git+https://github.com/decentraland/unity-renderer.git?path=unity-renderer/Assets#dev",
"depth": 0,
"source": "git",
"dependencies": {
Expand Down Expand Up @@ -99,7 +99,7 @@
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.xr": "1.0.0"
},
"hash": "829857eb7be865f4abaac8561f74e1ad0d7f6f60"
"hash": "6b49fec8d985982d412bdefb913fd7220b72687a"
},
"com.decentraland.unity-shared-dependencies": {
"version": "https://github.com/decentraland/unity-shared-dependencies.git",
Expand Down Expand Up @@ -160,8 +160,8 @@
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "1.0.6",
"depth": 2,
"version": "2.0.2",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
Expand Down Expand Up @@ -291,11 +291,11 @@
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.31",
"depth": 1,
"version": "2.0.1-pre.18",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.6",
"com.unity.ext.nunit": "2.0.2",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
Expand Down Expand Up @@ -625,4 +625,4 @@
}
}
}
}
}
Binary file not shown.

0 comments on commit 153a747

Please sign in to comment.