refactor: More init sequence refactors
This commit is contained in:
parent
284f8534ab
commit
f6d4d5ab22
@ -65,8 +65,8 @@ namespace hex::init {
|
||||
std::future<bool> processTasksAsync();
|
||||
|
||||
std::atomic<u32> m_totalTaskCount, m_completedTaskCount;
|
||||
std::atomic<bool> m_taskStatus;
|
||||
std::vector<Task> m_tasks;
|
||||
std::atomic<bool> m_taskStatus = true;
|
||||
std::list<Task> m_tasks;
|
||||
std::mutex m_tasksMutex;
|
||||
|
||||
std::string m_gpuVendor;
|
||||
|
@ -86,33 +86,6 @@ namespace hex::init {
|
||||
glfwSetWindowPos(window, monitorX + (mode->width - windowWidth) / 2, monitorY + (mode->height - windowHeight) / 2);
|
||||
}
|
||||
|
||||
std::future<bool> WindowSplash::processTasksAsync() {
|
||||
return std::async(std::launch::async, [this] {
|
||||
// Loop over all registered init tasks
|
||||
for (const auto &task : this->m_tasks) {
|
||||
|
||||
// Construct a new task callback
|
||||
this->createTask(task);
|
||||
}
|
||||
|
||||
// Check every 100ms if all tasks have run
|
||||
while (true) {
|
||||
{
|
||||
std::scoped_lock lock(this->m_tasksMutex);
|
||||
if (this->m_completedTaskCount >= this->m_totalTaskCount)
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(100ms);
|
||||
}
|
||||
|
||||
// Small extra delay so the last progress step is visible
|
||||
std::this_thread::sleep_for(100ms);
|
||||
|
||||
return this->m_taskStatus.load();
|
||||
});
|
||||
}
|
||||
|
||||
void WindowSplash::createTask(const Task& task) {
|
||||
auto runTask = [&, task] {
|
||||
try {
|
||||
@ -135,11 +108,12 @@ namespace hex::init {
|
||||
bool taskStatus = task.callback();
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
log::info("Task '{}' finished {} in {} ms",
|
||||
task.name,
|
||||
taskStatus ? "successfully" : "unsuccessfully",
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count()
|
||||
);
|
||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
|
||||
|
||||
if (taskStatus)
|
||||
log::info("Task '{}' finished successfully in {} ms", task.name, milliseconds);
|
||||
else
|
||||
log::warn("Task '{}' finished unsuccessfully in {} ms", task.name, milliseconds);
|
||||
|
||||
// Track the overall status of the tasks
|
||||
this->m_taskStatus = this->m_taskStatus && taskStatus;
|
||||
@ -169,6 +143,40 @@ namespace hex::init {
|
||||
}
|
||||
}
|
||||
|
||||
std::future<bool> WindowSplash::processTasksAsync() {
|
||||
return std::async(std::launch::async, [this] {
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Loop over all registered init tasks
|
||||
for (const auto &task : this->m_tasks) {
|
||||
|
||||
// Construct a new task callback
|
||||
this->createTask(task);
|
||||
}
|
||||
|
||||
// Check every 100ms if all tasks have run
|
||||
while (true) {
|
||||
{
|
||||
std::scoped_lock lock(this->m_tasksMutex);
|
||||
if (this->m_completedTaskCount >= this->m_totalTaskCount)
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(100ms);
|
||||
}
|
||||
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
|
||||
log::info("ImHex fully started in {}ms", milliseconds);
|
||||
|
||||
// Small extra delay so the last progress step is visible
|
||||
std::this_thread::sleep_for(100ms);
|
||||
|
||||
return this->m_taskStatus.load();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
FrameResult WindowSplash::fullFrame() {
|
||||
glfwSetWindowSize(this->m_window, 640_scaled, 400_scaled);
|
||||
|
@ -317,7 +317,7 @@ namespace hex::init {
|
||||
{ "Setting up environment", setupEnvironment, false },
|
||||
{ "Creating directories", createDirectories, false },
|
||||
{ "Loading settings", loadSettings, false },
|
||||
{ "Loading plugins", loadPlugins, true },
|
||||
{ "Loading plugins", loadPlugins, false },
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -596,21 +596,25 @@ namespace hex::plugin::builtin {
|
||||
const auto infoBannerPath = defaultPath / "info_banner.png";
|
||||
if (wolv::io::fs::exists(infoBannerPath)) {
|
||||
s_infoBannerTexture = ImGuiExt::Texture(wolv::util::toUTF8String(infoBannerPath).c_str());
|
||||
break;
|
||||
} else {
|
||||
TaskManager::createBackgroundTask("Load banner", [](auto&) {
|
||||
HttpRequest request("GET", ImHexApiURL + std::string("/info_banner"));
|
||||
auto response = request.downloadFile().get();
|
||||
|
||||
if (response.isSuccess()) {
|
||||
const auto &data = response.getData();
|
||||
TaskManager::doLater([data] {
|
||||
s_infoBannerTexture = ImGuiExt::Texture(data.data(), data.size());
|
||||
});
|
||||
}
|
||||
});
|
||||
if (s_infoBannerTexture.isValid())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s_infoBannerTexture.isValid()) {
|
||||
TaskManager::createBackgroundTask("Load banner", [](auto&) {
|
||||
HttpRequest request("GET", ImHexApiURL + std::string("/info_banner"));
|
||||
auto response = request.downloadFile().get();
|
||||
|
||||
if (response.isSuccess()) {
|
||||
const auto &data = response.getData();
|
||||
TaskManager::doLater([data] {
|
||||
s_infoBannerTexture = ImGuiExt::Texture(data.data(), data.size());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user