Example #1
0
        // NOTE: The boot up flow is inside the MainLoop as we want to be able to load configuration files
        // before executing any systems, however for web builds we must do such loading inside the mainloop to ensure
        // the browser doesn't hang while we wait on async work to complete
        private static void Main()
        {
            // Create main world
            m_World       = DefaultTinyWorldInitialization.InitializeWorld("main");
            m_Environment = m_World.GetOrCreateSystem <TinyEnvironment>();
            m_BootPhase   = BootPhase.Booting;

            // Setup systems
            DefaultTinyWorldInitialization.InitializeSystems(m_World);

            // Run program
            NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
            var windowSystem = m_World.GetExistingSystem <WindowSystem>();

            if (windowSystem != null)
            {
                windowSystem.InfiniteMainLoop(MainLoop);
            }
            else
            {
                Debug.Log("No window system found.");
            }

            // Free world and all systems/managers in it
            m_World.Dispose();
        }
Example #2
0
 private UnityInstance()
 {
     BurstInit();
     m_World = DefaultTinyWorldInitialization.InitializeWorld("main");
     DefaultTinyWorldInitialization.InitializeSystems(m_World);
     m_BootPhase            = BootPhase.Booting;
     m_Environment          = m_World.GetOrCreateSystem <TinyEnvironment>();
     m_EntityManager        = m_World.EntityManager;
     m_SceneStreamingSystem = m_World.GetExistingSystem <SceneStreamingSystem>();
 }
Example #3
0
        private void UpdateBooting()
        {
            // Destroy current config entity
            if (m_EntityManager.Exists(m_Environment.configEntity))
            {
                m_EntityManager.DestroyEntity(m_Environment.configEntity);
                m_Environment.configEntity = Entity.Null;
            }

            m_ConfigScene = SceneService.LoadConfigAsync(m_World);

            m_BootPhase = BootPhase.LoadingConfig;
        }
Example #4
0
        private void UpdateBooting()
        {
            // Destroy current config entity
            if (m_EntityManager.Exists(m_ConfigEntity))
            {
                m_EntityManager.DestroyEntity(m_ConfigEntity);
                m_ConfigEntity = Entity.Null;
            }

            LoadConfigScene();

            m_BootPhase = BootPhase.LoadingConfig;
        }
Example #5
0
        public void EndBootRequest()
        {
            lock (_locker)
            {
                if (_bootPhase != BootPhase.BootRequest)
                {
                    throw new InvalidOperationException("Invalid boot phase.");
                }
                _bootPhase = BootPhase.Booted;

                _startupProfiler = null;
            }
        }
Example #6
0
        private bool UpdateLoading()
        {
            // On all platforms but web, we can be certain that if we can't load the config scene in 5 seconds
            // we should abort as something is wrong.
#if !UNITY_WEBGL
#if DEBUG
            if (!Debugger.IsAttached)
#endif
            {
                if (m_ElapsedTimeInSeconds > 5.0)
                {
                    UnityEngine.Debug.LogError("Failed to load the configuration scene at boot. Shutting down....");
                    return(false);
                }
            }
#endif

            // Tick this world specifically to ensure our load requests are handled
            UpdateSceneSystems();

            if (IsSceneLoaded(m_ConfigScene))
            {
                if (m_ConfigEntity == Entity.Null)
                {
                    m_ConfigEntity = FindSingleEntityWith(typeof(ConfigurationTag), out m_EntityManager);
                    if (m_ConfigEntity == Entity.Null)
                    {
                        throw new Exception($"Failed to load boot configuration scene.");
                    }

                    return(true);
                }
                else if (!LoadStartupScenes())
                {
                    return(true);
                }
                else if (!IsStartupDataLoaded())
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }

            m_BootPhase = BootPhase.Running;
            return(true);
        }
Example #7
0
        public void BeginBootRequest()
        {
            lock (_locker)
            {
                if (_bootPhase != BootPhase.Boot)
                {
                    throw new InvalidOperationException("Invalid boot phase.");
                }
                _bootPhase = BootPhase.BootRequest;

                // assign the profiler to be the current MiniProfiler for the request
                // is's already active, starting and all
                HttpContext.Current.Items[":mini-profiler:"] = _startupProfiler;
            }
        }
Example #8
0
        public void EndBootRequest()
        {
            _locker.EnterWriteLock();
            try
            {
                if (_bootPhase != BootPhase.BootRequest)
                {
                    throw new InvalidOperationException("Invalid boot phase.");
                }
                _bootPhase = BootPhase.Booted;

                _startupProfiler = null;
            }
            finally
            {
                _locker.ExitWriteLock();
            }
        }
Example #9
0
        private void UpdateLoadingConfig()
        {
            // Tick this world specifically to ensure our load requests are handled
            m_SceneStreamingSystem.Update();

            var configStatus = SceneService.GetSceneStatus(m_World, m_ConfigScene);

            if (configStatus == SceneStatus.Loaded)
            {
                if (m_Environment.configEntity == Entity.Null)
                {
                    using (var configurationQuery = m_EntityManager.CreateEntityQuery(typeof(ConfigurationTag)))
                    {
                        if (configurationQuery.CalculateEntityCount() == 0)
                        {
                            throw new Exception($"Failed to load boot configuration scene.");
                        }

                        using (var configEntityList = configurationQuery.ToEntityArray(Allocator.Temp))
                        {
                            // Set new config entity
                            if (configEntityList.Length > 1)
                            {
                                throw new Exception(
                                          $"More than one configuration entity found in boot configuration scene.");
                            }

                            m_Environment.configEntity = configEntityList[0];
                        }
                    }
                }
            }
            else if (configStatus == SceneStatus.FailedToLoad)
            {
                throw new Exception($"Failed to load the boot configuration scene.");
            }
            else
            {
                return;
            }

            LoadStartupScenes(m_Environment);
            m_BootPhase = BootPhase.Running;
        }
Example #10
0
        private UnityInstance()
        {
            m_World = DefaultWorldInitialization.Initialize("Default World");

            m_BootPhase     = BootPhase.Booting;
            m_RunState      = RunState.Resuming;
            m_EntityManager = m_World.EntityManager;

            m_StartTimeInSeconds           = 0;
            m_ElapsedTimeInSeconds         = 0;
            m_PreviousElapsedTimeInSeconds = 0;

            m_SceneSystemGroup = m_World.GetOrCreateSystem <SceneSystemGroup>();
            m_SceneSystem      = m_World.GetOrCreateSystem <SceneSystem>();

            m_TimeData = (TimeData *)UnsafeUtility.Malloc(
                UnsafeUtility.SizeOf <TimeData>(),
                0,
                Collections.Allocator.Persistent);
        }
Example #11
0
        private UnityInstance()
        {
            m_World = DefaultWorldInitialization.Initialize("Default World");

            m_BootPhase     = BootPhase.Booting;
            m_RunState      = RunState.Resuming;
            m_EntityManager = m_World.EntityManager;

            m_StartTimeInSeconds           = 0;
            m_ElapsedTimeInSeconds         = 0;
            m_PreviousElapsedTimeInSeconds = 0;

            // try to find SceneSystemGroup in worlds
            foreach (var w in World.All)
            {
                m_SceneSystemGroup = w.GetExistingSystem <SceneSystemGroup>();
                m_SceneSystem      = w.GetExistingSystem <SceneSystem>();

                if (m_SceneSystemGroup != null)
                {
                    break;
                }
            }

            // if cannot find - create in the default world
            if (m_SceneSystemGroup == null)
            {
                m_SceneSystemGroup = m_World.GetOrCreateSystem <SceneSystemGroup>();
                m_SceneSystem      = m_World.GetOrCreateSystem <SceneSystem>();
            }

            m_TimeData = (TimeData *)UnsafeUtility.Malloc(
                UnsafeUtility.SizeOf <TimeData>(),
                0,
                Collections.Allocator.Persistent);
        }
Example #12
0
 public WebProfilerProvider()
 {
     // booting...
     _bootPhase = BootPhase.Boot;
 }
Example #13
0
        private bool UpdateLoading()
        {
            // On all platforms but web, we can be certain that if we can't load the config scene in 5 seconds
            // we should abort as something is wrong.
#if !UNITY_WEBGL
#if DEBUG
            if (!Debugger.IsAttached)
#endif
            {
                if (m_ElapsedTimeInSeconds > 5.0)
                {
                    UnityEngine.Debug.LogError("Failed to load the configuration scene at boot. Shutting down....");
                    return(false);
                }
            }
#endif

            // Tick this world specifically to ensure our load requests are handled
            UpdateSceneSystems();

            if (IsSceneLoaded(m_ConfigScene))
            {
                if (m_ConfigEntity == Entity.Null)
                {
                    using (var configurationQuery = m_EntityManager.CreateEntityQuery(typeof(ConfigurationTag)))
                    {
                        if (configurationQuery.CalculateEntityCount() == 0)
                        {
                            throw new Exception($"Failed to load boot configuration scene.");
                        }

                        using (var configEntityList = configurationQuery.ToEntityArray(Allocator.TempJob))
                        {
                            // Set new config entity
                            if (configEntityList.Length > 1)
                            {
                                throw new Exception($"More than one configuration entity found in boot configuration scene.");
                            }

                            m_ConfigEntity = configEntityList[0];
                        }
                    }
                    return(true);
                }
                else if (!LoadStartupScenes())
                {
                    return(true);
                }
                else if (!IsStartupDataLoaded())
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }

            m_BootPhase = BootPhase.Running;
            return(true);
        }
Example #14
0
        private static bool MainLoop()
        {
            if (m_BootPhase == BootPhase.Running)
            {
                m_World.Update();
            }
            else if (m_BootPhase == BootPhase.Booting)
            {
                var em = m_World.EntityManager;

                // Destroy current config entity
                if (em.Exists(m_Environment.configEntity))
                {
                    em.DestroyEntity(m_Environment.configEntity);
                    m_Environment.configEntity = Entity.Null;
                }

                m_ConfigScene = SceneService.LoadConfigAsync();

                m_BootPhase = BootPhase.LoadingConfig;
            }
            else if (m_BootPhase == BootPhase.LoadingConfig)
            {
                var em = m_World.EntityManager;
                var sceneStreamingSystem = m_World.GetOrCreateSystem <SceneStreamingSystem>();

                // Tick this world specifically to ensure our request is handled
                sceneStreamingSystem.Update();

                var sceneStatus = SceneService.GetSceneStatus(m_ConfigScene);
                if (sceneStatus == SceneStatus.Loaded)
                {
                    using (var configurationQuery = em.CreateEntityQuery(typeof(ConfigurationTag)))
                    {
                        if (configurationQuery.CalculateLength() == 0)
                        {
                            throw new Exception($"Failed to load boot configuration scene.");
                        }

                        using (var configEntityList = configurationQuery.ToEntityArray(Allocator.Temp))
                        {
                            // Set new config entity
                            if (configEntityList.Length > 1)
                            {
                                throw new Exception($"More than one configuration entity found in boot configuration scene.");
                            }
                            m_Environment.configEntity = configEntityList[0];
                        }
                    }

                    LoadStartupScenes();

                    m_BootPhase = BootPhase.Running;
                }
                else if (sceneStatus == SceneStatus.FailedToLoad)
                {
                    throw new Exception($"Failed to load the boot configuration scene.");
                }
            }
            else
            {
                throw new Exception("Invalid BootPhase specified");
            }

            return(!m_World.QuitUpdate);
        }