Skip to content

Commit

Permalink
fix object removal
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-h committed Mar 17, 2024
1 parent e20e4e5 commit 37d0cae
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions libsave/src/GameTypes/Save/SaveGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,20 @@ bool SatisfactorySave::SaveGame::removeObject(const SaveObjectPtr& obj) {
}

bool SatisfactorySave::SaveGame::removeObjects(const SaveObjectList& objects) {
// ID's in info objects are not updated between deletions, therefore delete in reversed ID order.
std::unordered_map<int, std::vector<std::size_t>> remove_ids_map;
for (const auto& obj : objects) {
if (!info_map_.contains(obj)) {
return false;
}
}
for (const auto& obj : objects) {
const auto info = info_map_.at(obj);
if (info.level_idx == -1) {
auto& list = persistent_and_runtime_data_.save_objects;
list.erase(list.begin() + info.level_list_idx);
} else {
auto& list = per_level_data_.at(info.level_idx).save_objects;
list.erase(list.begin() + info.level_list_idx);
remove_ids_map[info.level_idx].push_back(info.level_list_idx);
}
for (auto& [level, remove_ids] : remove_ids_map) {
auto& list = (level == -1) ? persistent_and_runtime_data_.save_objects : per_level_data_.at(level).save_objects;
std::sort(remove_ids.begin(), remove_ids.end(), std::greater<>());
for (const auto& id : remove_ids) {
list.erase(list.begin() + id);
}
}
// TODO full reinit is very slow
Expand Down

0 comments on commit 37d0cae

Please sign in to comment.