Exemple #1
0
        public static bool PreExecToExecWhenFinished(ref List <Action> ___toExecuteWhenFinished)
        {
            if (_hasBeenCalled || !ShouldInterceptNext)
            {
                return(true);
            }

            _hasBeenCalled      = true;
            ShouldInterceptNext = false;
            _numTasksToRun      = ___toExecuteWhenFinished.Count;

            _finishedExecuting = false;

            if (_numTasksToRun == 0)
            {
                _numTasksToRun     = 1;
                _finishedExecuting = true;
                return(false);
            }

            Log.Message($"[BetterLoading] Processing {___toExecuteWhenFinished.Count} post-finalize tasks.");

            BetterLoadingMain.LoadingScreen.StartCoroutine
            (
                ToExecuteWhenFinishedHandler.ExecuteToExecuteWhenFinishedTheGoodVersion
                (
                    ___toExecuteWhenFinished,
                    false,
                    currentAction => _currentAction = currentAction,
                    () => _numTasksRun++,
                    () =>
            {
                Log.Message("[BetterLoading] Finished post-finalize callbacks, releasing lock.");
                _finishedExecuting = true;
            })
            );

            LongEventHandler.QueueLongEvent(() =>
            {
                Thread.Sleep(500);

                Log.Message("[BetterLoading] Blocking loading screen from being dismissed until post-finalize actions are complete.");
                while (!_finishedExecuting)
                {
                    Thread.Sleep(500); //Wait
                }

                Log.Message("Obtained lock, assuming we're done with post-finalize.");

                Thread.Sleep(0);

                _finishedExecuting = true;
            }, null, true, null);
            return(false);
        }
Exemple #2
0
        public static bool PreExecToExecWhenFinished(ref List <Action> ___toExecuteWhenFinished)
        {
            if (_hasBeenCalled)
            {
                return(true);
            }

            _done = false;

            _numTasksToRun = ___toExecuteWhenFinished.Count;

            //Redirect all actions via us
            Log.Message($"[BetterLoading] Processing {___toExecuteWhenFinished.Count} post-load tasks.");
            // ___toExecuteWhenFinished = ___toExecuteWhenFinished.Select(GetExecAction).ToList();

            _hasBeenCalled = true;

            BetterLoadingMain.LoadingScreen.StartCoroutine
            (
                ToExecuteWhenFinishedHandler.ExecuteToExecuteWhenFinishedTheGoodVersion
                (
                    ___toExecuteWhenFinished,
                    true,
                    currentAction => _currentAction = currentAction,
                    () => _numTasksRun++,
                    () => _finishedExecuting = true
                )
            );

            var finalTask = ___toExecuteWhenFinished.Last();

            LongEventHandler.QueueLongEvent(() =>
            {
                Log.Message("[BetterLoading] Blocking loading screen from being dismissed until post-load actions are complete.");
                Thread.Sleep(1000);

                while (!_finishedExecuting)
                {
                    Thread.Sleep(2000); //Wait
                }

                Log.Message($"Obtained synclock, assuming post-load actions are complete and starting static constructors");

                finalTask();

                Thread.Sleep(0);

                _done = true;
            }, null, true, null);
            return(false);
        }