Finality Engine
Loading...
Searching...
No Matches
ImportProgress.h
Go to the documentation of this file.
1
6#pragma once
8#include <imgui.h>
9#include <deque>
10#include <functional>
11#include <Core/Log.h>
12
13namespace FINALITY
14{
17 {
18 std::deque<std::pair<std::string, std::function<void()>>> Jobs;
19 int Frames = 0;
20 public:
21 bool IsBusy() const { return !Jobs.empty(); }
22 void Clear() { Jobs.clear(); Frames = 0; }
23 void Queue(std::string name, std::function<void()> work) { Jobs.emplace_back(std::move(name), std::move(work)); }
24 void Import(const std::filesystem::path& source, const std::filesystem::path& destination)
25 { Queue(source.filename().string(), [source,destination] { AssetRegistry::Import(source,destination); }); }
26 void Update()
27 {
28 if (Jobs.empty()) { Frames = 0; return; }
29 if (++Frames < 3) return;
30 auto job = std::move(Jobs.front()); Jobs.pop_front(); Frames = 0;
31 try { job.second(); } catch (const std::exception& error) { Logger::GetClientLogger()->error("Import failed: {}", error.what()); }
32 }
33 void Draw(bool compiling, const std::string& compilation)
34 {
35 const bool importing = !Jobs.empty();
36 const char* title = importing ? "Importing Assets" : "Compiling Scripts";
37 if (importing || compiling) ImGui::OpenPopup(title);
38 for (const char* popup : {"Importing Assets", "Compiling Scripts"})
39 {
40 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, {0.5f,0.5f});
41 ImGui::SetNextWindowSize({480,120});
42 if (ImGui::BeginPopupModal(popup, nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings))
43 {
44 const bool importPopup = std::string_view(popup) == "Importing Assets";
45 if ((importPopup && !importing) || (!importPopup && !compiling)) ImGui::CloseCurrentPopup();
46 else
47 {
48 ImGui::TextWrapped("%s", importPopup ? Jobs.front().first.c_str() : compilation.c_str());
49 ImGui::ProgressBar(-static_cast<float>(ImGui::GetTime()), {-1,0}, "Working...");
50 }
51 ImGui::EndPopup();
52 }
53 }
54 }
55 };
56}
Tracks project assets, metadata and reference resolution.
void Import(const std::filesystem::path &source, const std::filesystem::path &destination)
void Queue(std::string name, std::function< void()> work)
void Draw(bool compiling, const std::string &compilation)
static std::shared_ptr< spdlog::logger > & GetClientLogger()
Definition Log.h:55