mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Issue #41. Fixed priority data not being used to create edges in graph.
This commit is contained in:
+49
-9
@@ -63,15 +63,9 @@ namespace boss {
|
||||
std::string key;
|
||||
std::string value;
|
||||
//Priority values should override the number of override records as the deciding factor if they differ.
|
||||
if (it->MustLoadAfter(*jt) || jt->MustLoadAfter(*it))
|
||||
if (it->MustLoadAfter(*jt) || jt->MustLoadAfter(*it) || it->Priority() != jt->Priority())
|
||||
continue;
|
||||
if (it->Priority() < jt->Priority()) {
|
||||
key = jt->Name();
|
||||
value = it->Name();
|
||||
} else if (jt->Priority() < it->Priority()) {
|
||||
key = it->Name();
|
||||
value = jt->Name();
|
||||
} else if (it->NumOverrideFormIDs() >= jt->NumOverrideFormIDs()) {
|
||||
if (it->NumOverrideFormIDs() >= jt->NumOverrideFormIDs()) {
|
||||
key = jt->Name();
|
||||
value = it->Name();
|
||||
} else {
|
||||
@@ -89,6 +83,37 @@ namespace boss {
|
||||
}
|
||||
}
|
||||
|
||||
void CalcPriorityMap(const std::list<Plugin>& plugins, boost::unordered_map< std::string, std::vector<std::string> >& priorityMap) {
|
||||
for (list<Plugin>::const_iterator it=plugins.begin(),
|
||||
endit=plugins.end();
|
||||
it != endit;
|
||||
++it) {
|
||||
list<Plugin>::const_iterator jt = it;
|
||||
++jt;
|
||||
for (; jt != endit; ++jt) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Checking for priority difference between \"" << it->Name() << "\" and \"" << jt->Name() << "\".";
|
||||
if (it->MustLoadAfter(*jt) || jt->MustLoadAfter(*it) || it->Priority() == jt->Priority())
|
||||
continue;
|
||||
|
||||
std::string key;
|
||||
std::string value;
|
||||
if (it->Priority() < jt->Priority()) {
|
||||
key = jt->Name();
|
||||
value = it->Name();
|
||||
} else if (jt->Priority() < it->Priority()) {
|
||||
key = it->Name();
|
||||
value = jt->Name();
|
||||
}
|
||||
boost::unordered_map< string, vector<string> >::iterator mapIt = priorityMap.find(key);
|
||||
if (mapIt == priorityMap.end()) {
|
||||
priorityMap.insert(pair<string, vector<string> >(key, vector<string>(1, value)));
|
||||
} else {
|
||||
mapIt->second.push_back(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GetVertexByName(const PluginGraph& graph, const std::string& name, vertex_t& vertex) {
|
||||
vertex_it vit, vit_end;
|
||||
boost::tie(vit, vit_end) = boost::vertices(graph);
|
||||
@@ -165,7 +190,7 @@ namespace boss {
|
||||
boost::depth_first_search(graph, visitor(vis).vertex_index_map(v_index_map));
|
||||
}
|
||||
|
||||
void AddNonOverlapEdges(PluginGraph& graph) {
|
||||
void AddNonOverlapEdges(PluginGraph& graph, const boost::unordered_map< std::string, std::vector<std::string> >& priorityMap) {
|
||||
//First find the position of the first non-master.
|
||||
boss::vertex_it vitFirstNonMaster, vit, vitend;
|
||||
for (boost::tie(vit, vitend) = boost::vertices(graph); vit != vitend; ++vit) {
|
||||
@@ -228,6 +253,21 @@ namespace boss {
|
||||
boost::add_edge(parentVertex, *vit, graph);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Adding in-edges for priority differences.";
|
||||
boost::unordered_map< string, vector<string> >::const_iterator priorityIt = priorityMap.find(graph[*vit]->Name());
|
||||
if (priorityIt != priorityMap.end()) {
|
||||
for (vector<string>::const_iterator it=priorityIt->second.begin(), itend=priorityIt->second.end(); it != itend; ++it) {
|
||||
if (boss::GetVertexByName(graph, *it, parentVertex) &&
|
||||
!boost::edge(parentVertex, *vit, graph).second &&
|
||||
!EdgeCreatesCycle(graph, parentVertex, *vit)) { //No edge going the other way, OK to add this edge.
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Adding edge from \"" << graph[parentVertex]->Name() << "\" to \"" << graph[*vit]->Name() << "\".";
|
||||
|
||||
boost::add_edge(parentVertex, *vit, graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -58,6 +58,8 @@ namespace boss {
|
||||
//The map maps each plugin name to a vector of names of plugins that overlap with it and should load before it.
|
||||
void CalcPluginOverlaps(const std::list<Plugin>& plugins, boost::unordered_map< std::string, std::vector<std::string> >& overlapMap);
|
||||
|
||||
void CalcPriorityMap(const std::list<Plugin>& plugins, boost::unordered_map< std::string, std::vector<std::string> >& priorityMap);
|
||||
|
||||
bool GetVertexByName(const PluginGraph& graph, const std::string& name, vertex_t& vertex);
|
||||
|
||||
void SaveGraph(const PluginGraph& graph, const boost::filesystem::path outpath);
|
||||
@@ -66,7 +68,7 @@ namespace boss {
|
||||
|
||||
void CheckForCycles(const PluginGraph& graph);
|
||||
|
||||
void AddNonOverlapEdges(PluginGraph& graph);
|
||||
void AddNonOverlapEdges(PluginGraph& graph, const boost::unordered_map< std::string, std::vector<std::string> >& priorityMap);
|
||||
|
||||
void AddOverlapEdges(PluginGraph& graph, const boost::unordered_map< std::string, std::vector<std::string> >& overlapMap);
|
||||
|
||||
|
||||
+6
-3
@@ -600,17 +600,20 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) {
|
||||
|
||||
progDia->Pulse();
|
||||
|
||||
//First sort the plugins list so that masters come before non-masters.
|
||||
BOOST_LOG_TRIVIAL(trace) << "Moving masters before non-masters.";
|
||||
plugins.sort(boss::master_sort);
|
||||
|
||||
progDia->Pulse();
|
||||
|
||||
//Now build overlap map.
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Building plugin overlap map.";
|
||||
boost::unordered_map< string, vector<string> > overlapMap;
|
||||
CalcPluginOverlaps(plugins, overlapMap);
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Building plugin priority map.";
|
||||
boost::unordered_map< string, vector<string> > priorityMap;
|
||||
CalcPriorityMap(plugins, priorityMap);
|
||||
|
||||
progDia->Pulse();
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Building the plugin dependency graph...";
|
||||
@@ -625,7 +628,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) {
|
||||
boost::add_vertex(it, graph);
|
||||
}
|
||||
|
||||
AddNonOverlapEdges(graph);
|
||||
AddNonOverlapEdges(graph, priorityMap);
|
||||
AddOverlapEdges(graph, overlapMap);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user