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