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; } } } }
private void loading_done(ResourceInteractiveLoader loader) { _loading_thread.WaitToFinish(); EmitSignal(nameof(replace_main_scene), loader.GetResource()); // Issue: https://github.com/godotengine/godot/issues/33809 _res_loader.Dispose(); _res_loader = null; }
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; } } }
public override void _Process(float delta) { time += delta; //GAMETIME //LOADER if (riLoader == null) { SetProcess(false); return; } if (waitFrames > 0) { waitFrames--; return;//espera antes de cargar } //tiempo máximo de bloqueo de hilo float initTime = OS.GetTicksMsec(); while (OS.GetTicksMsec() < initTime + timeMaxLoad) { Error err = riLoader.Poll();//progresando... if (err == Error.FileEof) { //█OOOKKK PackedScene packedScene = (PackedScene)riLoader.GetResource(); riLoader = null; instanceScene(packedScene); break; } else if (err == Error.Ok) { updateLoadingProgress();//informa } else { GD.Print("ERROR");//ERROR riLoader = null; break; } } }
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; } } }
private void ThreadLoad() { ResourceInteractiveLoader ril = ResourceLoader.LoadInteractive(scenePath); int total = ril.GetStageCount(); instance.res = null; while (true) { Error err = ril.Poll(); if (err == Error.FileEof) { instance.res = ril.GetResource(); instance.canChange = true; break; } else if (err != Error.Ok) { GD.Print("ERROR LOADING"); break; } } }
public override void _Process(float delta) { if (loader == null) { return; } Error err = loader.Poll(); if (err == Error.FileEof) { Resource resource = loader.GetResource(); loader = null; setNewScene((PackedScene)resource); return; } else if (err == Error.Ok) { updateProgress(); return; } }
public override void _Process(float delta) { if (loader == null) { GD.Print("Loader done"); //no need for processing anymore SetProcess(false); return; } if (waitFrame > 0) { //buffer for loading animation scene to appear waitFrame -= 1; return; } var t = OS.GetTicksMsec(); while (OS.GetTicksMsec() < (t + maxWait)) { var loadStatus = loader.Poll(); if (loadStatus == Error.FileEof) { //load complete var scene = loader.GetResource() as PackedScene; Node newInstance = scene.Instance(); loader = null; //do any stuff specific to any nodes setNewScene(newInstance); } } }
/// <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); } }