From 021a7e503390a24078a31b731dcfb1db0a4e6691 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Sat, 20 Jul 2013 22:11:18 +0100 Subject: [PATCH] Plugin loading is now multithreaded. Performance improvement is limited when Skyrim.esm is hundreds or thousands of times larger than most other plugins though. Will have to speed up the actual reading code to do significantly better, I think. --- src/gui/main.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gui/main.cpp b/src/gui/main.cpp index eb6a3d41..3680df71 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -53,11 +53,14 @@ #include #include #include +#include #include #include #include +#define BOOST_THREAD_VERSION 4 + IMPLEMENT_APP(BossGUI); using namespace boss; @@ -67,6 +70,20 @@ using boost::format; namespace fs = boost::filesystem; namespace loc = boost::locale; + +struct plugin_loader { + plugin_loader(boss::Plugin& plugin, boss::Game& game, const string& filename, bool b) : _plugin(plugin), _game(game), _filename(filename), _b(b) {} + + void operator () () { + _plugin = boss::Plugin(_game, _filename, _b); + } + + boss::Plugin& _plugin; + boss::Game& _game; + string _filename; + bool _b; +}; + bool BossGUI::OnInit() { //Check if GUI is already running. @@ -394,17 +411,22 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { // Get a list of the plugins. list plugins; + boost::thread_group group; for (fs::directory_iterator it(_game.DataPath()); it != fs::directory_iterator(); ++it) { if (fs::is_regular_file(it->status()) && IsPlugin(it->path().string())) { string filename = it->path().filename().string(); BOOST_LOG_TRIVIAL(trace) << "Reading plugin: " << filename; - boss::Plugin plugin(_game, filename, false); - plugins.push_back(plugin); + + plugins.push_back(boss::Plugin()); + + plugin_loader pl(plugins.back(), _game, filename, false); + group.create_thread(pl); progDia->Pulse(); } } + group.join_all(); if (fs::exists(_game.MasterlistPath())) { BOOST_LOG_TRIVIAL(trace) << "Parsing masterlist...";