コード例 #1
0
    public override void _Process(float delta)
    {
        if (loader != null)
        {
            float timeUp = OS.GetTicksMsec() + maxTime;
            Error err    = Error.Ok;
            while (err != Error.FileEof && OS.GetTicksMsec() <= timeUp)
            {
                err = loader.Poll();
                switch (err)
                {
                case Error.FileEof:
                    PackedScene scene = loader.GetResource() as PackedScene;
                    GetTree().ChangeSceneTo(scene);
                    SetProcess(false);
                    break;

                case Error.Ok:
                    progressBar.Value = loader.GetStage() / (float)loader.GetStageCount();
                    break;

                default:
                    GD.Print(err);
                    GetTree().Quit();
                    break;
                }
            }
        }
    }
コード例 #2
0
 private void interactive_load(ResourceInteractiveLoader loader)
 {
     while (true)
     {
         var status = loader.Poll();
         if (status == Error.Ok)
         {
             _loadingProgress.Value = (loader.GetStage() * 100) / loader.GetStageCount();
             continue;
         }
         else if (status == Error.FileEof)
         {
             _loadingProgress.Value = 100;
             _loadingDoneTimer.Start();
             break;
         }
         else
         {
             GD.Print($"Error while loading level: {status}");
             _main.Show();
             _loading.Hide();
             break;
         }
     }
 }
コード例 #3
0
    private void updateLoadingProgress()
    {
        float progress = (float)(riLoader.GetStage()) / riLoader.GetStageCount();

        GD.Print("progress " + progress);
        pBarr.Value = (progress);
    }
コード例 #4
0
    private void ThreadLoad(string ResPath)
    {
        ResourceInteractiveLoader RIL = ResourceLoader.LoadInteractive(ResPath);

        if (RIL == null)
        {
            return;
        }

        int StageCount = 0;

        while (true)
        {
            uint  TimeElapsed  = OS.GetTicksMsec() - TimeStart;
            float TimeProgress = (float)TimeElapsed / (float)(MinimumTime * 1000f) * (float)MaxValue;

            if (StageCount < RIL.GetStageCount())
            {
                StageCount = RIL.GetStage();
            }

            float LoadProgress = (float)StageCount / (float)RIL.GetStageCount() * (float)MaxValue;
            CallDeferred("set_value", (TimeProgress < LoadProgress)?TimeProgress:LoadProgress);

            //Take a break
            OS.DelayMsec(100);

            if (Value >= MaxValue)
            {
                CallDeferred("ThreadDone", RIL.GetResource() as PackedScene);
                return;
            }

            if (StageCount >= RIL.GetStageCount())
            {
                continue;
            }

            //Poll current stats
            Error PollData = RIL.Poll();

            if (PollData == Error.FileEof)
            {
                StageCount = RIL.GetStageCount();
                continue;
            }

            if (PollData != Error.Ok)
            {
                GD.Print("Error Loading");
                return;
            }
        }
    }
コード例 #5
0
    public override void _Process(float delta)
    {
        if (this.loader == null)
        {
            SetProcess(false);
            return;
        }
        Error error = this.loader.Poll();

        this.loadingLabel.Text = loader.GetStage() + " / " + loader.GetStageCount();
        if (error == Error.FileEof)
        {
            GetTree().QueueDelete(GetTree().Root.GetChild(0));
            GetTree().Root.AddChild(((PackedScene)this.loader.GetResource()).Instance());
            this.loader = null;
        }
    }
コード例 #6
0
    public override void _Process(float delta)
    {
        if (loader == null)
        {
            SetProcess(false);
            return;
        }

        if (wait_frames < 0)
        {
            wait_frames -= 0;
            return;
        }

        var t = OS.GetTicksMsec();

        while (OS.GetTicksMsec() < t + time_max)
        {
            var err = loader.Poll();

            if (err == Error.FileEof)
            {
                Progres = ToLoad;
                var resource = loader.GetResource();
                AlreadyLoaded.Add(current, resource);
                loader = null;
                GetTree().ChangeSceneTo(resource as PackedScene);
                break;
            }
            else if (err == Error.Ok)
            {
                Progres = loader.GetStage();
                ToLoad  = loader.GetStageCount();
            }
            else
            {
                loader = null;
                break;
            }
        }
    }
コード例 #7
0
ファイル: Loader.cs プロジェクト: ojas-sanghi/2021-BOTS
    public void updateProgress()
    {
        var loadProgress = ((float)loader.GetStage()) / loader.GetStageCount();

        progress.Value = loadProgress * 100;
    }
コード例 #8
0
        /// <summary>
        /// Interactively loads a packedScene and in the end _replaces_ the whole Main scene to the loaded scene
        /// NOTE: This method doesn't simply load
        /// </summary>
        /// <returns></returns>
        private IEnumerator <float> LoadSceneAndMakeItMainScene()
        {
            while (true)
            {
                if (_loader == null)
                {
                    if (Math.Abs(GetLoadScreen().GetProgressBar().Value - 1f) < 0.01f)
                    {
                        break;
                    }
                    else if (Log.LoggingLevel > LoggingLevel.None)
                    {
                        Log.Error("Loader was NULL, couldn't load the scene", true);
                    }

                    break;
                }

                uint startTicksMs = OS.GetTicksMsec();

                while (OS.GetTicksMsec() < startTicksMs + _maxFrameTime)
                {
                    if (_loader != null)
                    {
                        Error error = _loader.Poll();

                        if (error == Error.FileEof)
                        {
                            PackedScene scene = (PackedScene)_loader.GetResource();
                            if (Log.LoggingLevel > LoggingLevel.Default)
                            {
                                Log.Print("FileEOF, loaded resource = " + scene.ResourceName + " (" + scene.ResourcePath + ")", true);
                            }
                            GetTree().ChangeSceneTo(scene);
                            FinishProgress();
                            break;
                        }
                        else if (error == Error.Ok)
                        {
                            UpdateProgess();
                        }
                        else // Means there was an error while loading
                        {
                            if (Log.LoggingLevel > LoggingLevel.None)
                            {
                                Log.Crash("Error while loading a scene (" + error + ") at stage: " + _loader.GetStage() + "/" + _loader.GetStageCount(), true);
                            }

                            FailLoading();
                            break;
                        }
                    }
                    else
                    {
                        if (Log.LoggingLevel > LoggingLevel.None)
                        {
                            Log.Error("Loader was flushed in middle of interactive loading ... ?", true);
                        }

                        break;
                    }
                }

                yield return(0.0005f);
            }
        }