Skip to content

Commit

Permalink
Remove workaround for counting Morrowind override records
Browse files Browse the repository at this point in the history
It's not necessary now that esplugin can count override records for Morrowind plugins, and the handling of the case when not all masters are loaded is ineffective now that fully loading Morrowind plugins will fail if their masters are not also loaded.
  • Loading branch information
Ortham committed Jun 28, 2024
1 parent f6d4cea commit 46bac43
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 188 deletions.
33 changes: 0 additions & 33 deletions src/api/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,39 +382,6 @@ bool Plugin::DoRecordsOverlap(const PluginInterface& plugin) const {
return false;
}

size_t Plugin::GetOverlapSize(
const std::vector<const PluginInterface*>& plugins) const {
if (plugins.empty()) {
return 0;
}

std::vector<::Plugin*> esPlugins;
for (const auto& plugin : plugins) {
const auto otherPlugin = dynamic_cast<const Plugin* const>(plugin);

if (otherPlugin == nullptr) {
const auto logger = getLogger();
if (logger) {
logger->error(
"Tried to check how many records overlapped with a non-Plugin "
"implementation of PluginSortingInterface.");
}
throw std::invalid_argument(
"Tried to check how many records overlapped with a non-Plugin "
"implementation of PluginSortingInterface.");
}

esPlugins.push_back(otherPlugin->esPlugin.get());
}

size_t overlapSize = 0;
const auto ret = esp_plugin_records_overlap_size(
esPlugin.get(), esPlugins.data(), esPlugins.size(), &overlapSize);
HandleEspluginError("get overlap size for \"" + name_ + "\"", ret);

return overlapSize;
}

size_t Plugin::GetOverrideRecordCount() const {
size_t overrideRecordCount;
const auto ret =
Expand Down
5 changes: 0 additions & 5 deletions src/api/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class PluginSortingInterface : public PluginInterface {
virtual size_t GetOverrideRecordCount() const = 0;
virtual uint32_t GetRecordAndGroupCount() const = 0;

virtual size_t GetOverlapSize(
const std::vector<const PluginInterface*>& plugins) const = 0;

virtual size_t GetAssetCount() const = 0;
virtual bool DoAssetsOverlap(const PluginSortingInterface& plugin) const = 0;
};
Expand Down Expand Up @@ -81,8 +78,6 @@ class Plugin final : public PluginSortingInterface {
bool IsEmpty() const override;
bool LoadsArchive() const override;
bool DoRecordsOverlap(const PluginInterface& plugin) const override;
size_t GetOverlapSize(
const std::vector<const PluginInterface*>& plugins) const override;

// Load ordering functions.
size_t GetOverrideRecordCount() const override;
Expand Down
25 changes: 1 addition & 24 deletions src/api/sorting/plugin_sorting_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,7 @@ PluginSortingData::PluginSortingData(
}
}

if (gameType == GameType::tes3) {
auto masterNames = plugin->GetMasters();
if (masterNames.empty()) {
overrideRecordCount_ = 0;
} else {
auto masters = GetPluginsSubset(loadedPlugins, masterNames);
if (masters.size() == masterNames.size()) {
overrideRecordCount_ = plugin->GetOverlapSize(masters);
} else {
// Not all masters are loaded, fall back to using the plugin's
// total record count (Morrowind doesn't have groups). This is OK
// because plugins with missing masters can't be loaded by the game,
// so the correctness of their load order positions is less important
// (it may not matter at all, depending on the sophistication/usage of
// merge patches in Morrowind). It's better for LOOT to sort a load
// order with missing masters with potentially poorer results than
// for it to error out, as masters may be missing for a variety of
// development & testing reasons.
overrideRecordCount_ = plugin->GetRecordAndGroupCount();
}
}
} else {
overrideRecordCount_ = plugin->GetOverrideRecordCount();
}
overrideRecordCount_ = plugin->GetOverrideRecordCount();
}

std::string PluginSortingData::GetName() const { return plugin_->GetName(); }
Expand Down
91 changes: 0 additions & 91 deletions src/tests/api/internals/plugin_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ class OtherPluginType final : public PluginSortingInterface {
size_t GetOverrideRecordCount() const override { return 0; };
uint32_t GetRecordAndGroupCount() const override { return 0; };

size_t GetOverlapSize(
const std::vector<const PluginInterface*>&) const override {
return 0;
};

size_t GetAssetCount() const override { return 0; };
bool DoAssetsOverlap(const PluginSortingInterface&) const override {
return true;
Expand Down Expand Up @@ -672,92 +667,6 @@ TEST_P(PluginTest,
EXPECT_TRUE(plugin2.DoRecordsOverlap(plugin1));
}

TEST_P(PluginTest,
getOverlapSizeShouldThrowIfGivenAVectorContainingANonPluginObject) {
Plugin plugin1(
game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsm, false);
OtherPluginType plugin2;

EXPECT_THROW(plugin1.GetOverlapSize({&plugin2, &plugin2}),
std::invalid_argument);
EXPECT_EQ(0, plugin2.GetOverlapSize({&plugin1}));
}

TEST_P(PluginTest, getOverlapSizeShouldCountEachRecordOnce) {
const auto plugin1Name =
GetParam() == GameType::starfield ? blankFullEsm : blankEsm;

Plugin plugin1(
game_.GetType(), game_.GetCache(), game_.DataPath() / plugin1Name, false);
Plugin plugin2(game_.GetType(),
game_.GetCache(),
game_.DataPath() / (blankMasterDependentEsm + ".ghost"),
false);

if (GetParam() == GameType::starfield) {
plugin1.ResolveRecordIds(nullptr);

const auto pluginsMetadata = Plugin::GetPluginsMetadata({&plugin1});
plugin2.ResolveRecordIds(pluginsMetadata.get());

EXPECT_EQ(1, plugin1.GetOverlapSize({&plugin2, &plugin2}));
} else {
EXPECT_EQ(4, plugin1.GetOverlapSize({&plugin2, &plugin2}));
}
}

TEST_P(PluginTest, getOverlapSizeShouldCheckAgainstAllGivenPlugins) {
const auto plugin1Name =
GetParam() == GameType::starfield ? blankFullEsm : blankEsm;

Plugin plugin1(
game_.GetType(), game_.GetCache(), game_.DataPath() / plugin1Name, false);
Plugin plugin2(
game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsp, false);
Plugin plugin3(game_.GetType(),
game_.GetCache(),
game_.DataPath() / (blankMasterDependentEsm + ".ghost"),
false);

if (GetParam() == GameType::starfield) {
plugin1.ResolveRecordIds(nullptr);
plugin2.ResolveRecordIds(nullptr);

const auto pluginsMetadata = Plugin::GetPluginsMetadata({&plugin1});
plugin3.ResolveRecordIds(pluginsMetadata.get());

EXPECT_EQ(1, plugin1.GetOverlapSize({&plugin2, &plugin3}));
} else {
EXPECT_EQ(4, plugin1.GetOverlapSize({&plugin2, &plugin3}));
}
}

TEST_P(PluginTest,
getOverlapSizeShouldReturnZeroForPluginsWithOnlyHeadersLoaded) {
Plugin plugin1(
game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsm, true);
Plugin plugin2(game_.GetType(),
game_.GetCache(),
game_.DataPath() / (blankMasterDependentEsm + ".ghost"),
true);

EXPECT_EQ(0, plugin1.GetOverlapSize({&plugin2}));
}

TEST_P(PluginTest, getOverlapSizeShouldReturnZeroForPluginsThatDoNotOverlap) {
Plugin plugin1(
game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsm, false);
Plugin plugin2(
game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsp, false);

if (GetParam() == GameType::starfield) {
plugin1.ResolveRecordIds(nullptr);
plugin2.ResolveRecordIds(nullptr);
}

EXPECT_EQ(0, plugin1.GetOverlapSize({&plugin2}));
}

TEST_P(PluginTest, getRecordAndGroupCountShouldReturnTheHeaderFieldValue) {
Plugin plugin(
game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsm, true);
Expand Down
5 changes: 0 additions & 5 deletions src/tests/api/internals/sorting/plugin_graph_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class TestPlugin : public PluginSortingInterface {

uint32_t GetRecordAndGroupCount() const override { return uint32_t(); }

size_t GetOverlapSize(
const std::vector<const PluginInterface*>&) const override {
return size_t();
}

size_t GetAssetCount() const override { return assetCount_; };

bool DoAssetsOverlap(const PluginSortingInterface& plugin) const override {
Expand Down
30 changes: 0 additions & 30 deletions src/tests/api/internals/sorting/plugin_sorting_data_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,36 +150,6 @@ TEST_P(PluginSortingDataTest,
getLoadedPlugins());
EXPECT_EQ(4, plugin.GetOverrideRecordCount());
}

TEST_P(
PluginSortingDataTest,
constructorShouldUseTotalRecordCountAsOverrideRecordCountForTes3PluginWithAMasterThatIsNotLoaded) {
if (GetParam() != GameType::tes3) {
return;
}

ASSERT_NO_THROW(loadInstalledPlugins(game_, false));
auto loadedPlugins = getLoadedPlugins();

// Pretend that blankEsm isn't loaded.
for (auto it = loadedPlugins.begin(); it != loadedPlugins.end();) {
if ((*it)->GetName() == blankEsm) {
it = loadedPlugins.erase(it);
} else {
++it;
}
}

auto plugin = PluginSortingData(
dynamic_cast<const Plugin *>(game_.GetPlugin(blankMasterDependentEsm)),
PluginMetadata(),
PluginMetadata(),
getLoadOrder(),
game_.GetType(),
loadedPlugins);

EXPECT_EQ(10, plugin.GetOverrideRecordCount());
}
}
}

Expand Down

0 comments on commit 46bac43

Please sign in to comment.