| | 1 | | using System; |
| | 2 | | using DCL.SettingsCommon; |
| | 3 | | using DCL.Components; |
| | 4 | | using MainScripts.DCL.Controllers.HUD.Preloading; |
| | 5 | | using MainScripts.DCL.Controllers.LoadingFlow; |
| | 6 | | using MainScripts.DCL.Controllers.SettingsDesktop; |
| | 7 | | using MainScripts.DCL.Utils; |
| | 8 | | using UnityEngine; |
| | 9 | | using RPC; |
| | 10 | |
|
| | 11 | | namespace DCL |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// This is the MainDesktop entry point. |
| | 15 | | /// Most of the application subsystems should be initialized from this class Awake() event. |
| | 16 | | /// </summary> |
| | 17 | | public class MainDesktop : Main |
| | 18 | | { |
| | 19 | | [SerializeField] private bool logWs = false; |
| | 20 | | private LoadingFlowController loadingFlowController; |
| | 21 | | private PreloadingController preloadingController; |
| | 22 | | private bool isConnectionLost; |
| 0 | 23 | | private BaseVariable<FeatureFlag> featureFlags => DataStore.i.featureFlags.flags; |
| | 24 | |
|
| | 25 | | protected override void Awake() |
| | 26 | | { |
| 0 | 27 | | CommandLineParserUtils.ParseArguments(); |
| 0 | 28 | | isConnectionLost = false; |
| | 29 | |
|
| 0 | 30 | | DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider; |
| | 31 | |
|
| 0 | 32 | | featureFlags.OnChange += FeatureFlagsReady; |
| | 33 | |
|
| 0 | 34 | | InitializeSettings(); |
| | 35 | |
|
| 0 | 36 | | base.Awake(); |
| 0 | 37 | | DataStore.i.wsCommunication.communicationEstablished.OnChange += OnCommunicationEstablished; |
| 0 | 38 | | DataStore.i.performance.multithreading.Set(true); |
| 0 | 39 | | DataStore.i.performance.maxDownloads.Set(50); |
| 0 | 40 | | Texture.allowThreadedTextureCreation = true; |
| 0 | 41 | | } |
| | 42 | |
|
| | 43 | | protected override void InitializeDataStore() |
| | 44 | | { |
| 0 | 45 | | DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettingsDesktop.GLTF_TEX_MAX_SIZE_DESKTOP); |
| 0 | 46 | | DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettingsDesktop.GENERAL_TEX_MAX_SIZE_DESKTOP) |
| 0 | 47 | | DataStore.i.avatarConfig.useHologramAvatar.Set(true); |
| 0 | 48 | | } |
| | 49 | |
|
| | 50 | | private void FeatureFlagsReady(FeatureFlag current, FeatureFlag previous) |
| | 51 | | { |
| 0 | 52 | | DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider; |
| 0 | 53 | | DataStore.i.featureFlags.flags.OnChange -= FeatureFlagsReady; |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | protected override void InitializeCommunication() |
| | 57 | | { |
| 0 | 58 | | DataStore.i.debugConfig.logWs = logWs; |
| | 59 | | // TODO(Brian): Remove this branching once we finish migrating all tests out of the |
| | 60 | | // IntegrationTestSuite_Legacy base class. |
| 0 | 61 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| | 62 | | { |
| 0 | 63 | | var withSSL = true; |
| 0 | 64 | | int startPort = CommandLineParserUtils.startPort; |
| | 65 | |
|
| | 66 | | #if UNITY_EDITOR |
| 0 | 67 | | withSSL = DebugConfigComponent.i.webSocketSSL; |
| 0 | 68 | | startPort = 5000; |
| | 69 | | #endif |
| | 70 | |
|
| 0 | 71 | | int endPort = startPort + 100; |
| 0 | 72 | | kernelCommunication = new WebSocketCommunication(withSSL, startPort, endPort); |
| | 73 | | } |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | protected override void SetupPlugins() |
| | 77 | | { |
| 0 | 78 | | pluginSystem = PluginSystemFactoryDesktop.Create(); |
| 0 | 79 | | pluginSystem.Initialize(); |
| 0 | 80 | | } |
| | 81 | |
|
| | 82 | | private void InitializeSettings() |
| | 83 | | { |
| 0 | 84 | | Settings.CreateSharedInstance(new DefaultSettingsFactory() |
| | 85 | | .WithGraphicsQualitySettingsPresetPath("DesktopGraphicsQualityPresets")); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | protected override void Dispose() |
| | 89 | | { |
| | 90 | | try |
| | 91 | | { |
| 0 | 92 | | DataStore.i.wsCommunication.communicationEstablished.OnChange -= OnCommunicationEstablished; |
| | 93 | |
|
| 0 | 94 | | base.Dispose(); |
| 0 | 95 | | DesktopDestroy(); |
| 0 | 96 | | } |
| | 97 | | catch (Exception e) |
| | 98 | | { |
| 0 | 99 | | Debug.LogException(e); |
| 0 | 100 | | } |
| 0 | 101 | | } |
| | 102 | |
|
| | 103 | | private void DesktopDestroy() |
| | 104 | | { |
| 0 | 105 | | loadingFlowController.Dispose(); |
| 0 | 106 | | preloadingController.Dispose(); |
| | 107 | | #if !AV_PRO_PRESENT |
| 0 | 108 | | DCLVideoPlayer.StopAllThreads(); |
| | 109 | | #endif |
| 0 | 110 | | } |
| | 111 | |
|
| | 112 | | void OnCommunicationEstablished(bool current, bool previous) |
| | 113 | | { |
| 0 | 114 | | if (current == false && previous) |
| | 115 | | { |
| 0 | 116 | | isConnectionLost = true; |
| | 117 | | } |
| 0 | 118 | | } |
| | 119 | |
|
| | 120 | | protected override void Update() |
| | 121 | | { |
| 0 | 122 | | base.Update(); |
| 0 | 123 | | loadingFlowController.Update(); |
| | 124 | |
|
| 0 | 125 | | if (isConnectionLost) |
| | 126 | | { |
| 0 | 127 | | DesktopUtils.Quit(); |
| | 128 | | } |
| | 129 | |
|
| | 130 | | // TODO: Remove this after we refactor InputController to support overrides from desktop or to use the lates |
| | 131 | | // This shortcut will help some users to fix the small resolution bugs that may happen if the player prefs a |
| 0 | 132 | | if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) |
| | 133 | | && Input.GetKeyDown(KeyCode.F11)) |
| | 134 | | { |
| 0 | 135 | | DisplaySettings newDisplaySettings = new DisplaySettings { windowMode = WindowMode.Borderless }; |
| 0 | 136 | | SettingsDesktop.i.displaySettings.Apply(newDisplaySettings); |
| 0 | 137 | | SettingsDesktop.i.displaySettings.Save(); |
| | 138 | | } |
| 0 | 139 | | } |
| | 140 | |
|
| | 141 | | protected override void Start() |
| | 142 | | { |
| 0 | 143 | | loadingFlowController = new LoadingFlowController( |
| | 144 | | DataStore.i.HUDs.loadingHUD.fatalError, |
| | 145 | | DataStore.i.HUDs.loadingHUD.visible, |
| | 146 | | CommonScriptableObjects.rendererState, |
| | 147 | | DataStore.i.wsCommunication.communicationEstablished); |
| | 148 | |
|
| 0 | 149 | | base.Start(); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | protected override void InitializeSceneDependencies() |
| | 153 | | { |
| 0 | 154 | | base.InitializeSceneDependencies(); |
| 0 | 155 | | preloadingController = new PreloadingController(); |
| 0 | 156 | | } |
| | 157 | |
|
| | 158 | | protected override void SetupServices() |
| | 159 | | { |
| 0 | 160 | | Environment.Setup(ServiceLocatorDesktopFactory.CreateDefault()); |
| 0 | 161 | | } |
| | 162 | | } |
| | 163 | | } |