Switch to std::list for adding & removing assets in deterministic order (#2543)

This commit is contained in:
Gene Payne
2023-03-17 16:07:17 -06:00
committed by GitHub
parent 3c4e2bdfe9
commit 00c8543306
2 changed files with 7 additions and 16 deletions

View File

@@ -29,7 +29,7 @@
#include <filesystem>
#include <optional>
#include <unordered_map>
#include <unordered_set>
#include <list>
namespace openspace {
@@ -164,10 +164,10 @@ private:
/// This list contains all of the assets that are queued to be loading in the next
/// update call
std::unordered_set<std::string> _assetAddQueue;
std::list<std::string> _assetAddQueue;
/// The list contains all of the assets that should be removed in the next update call
std::unordered_set<std::string> _assetRemoveQueue;
std::list<std::string> _assetRemoveQueue;
/// This list contains all assets that need to be initialized in the next update call
std::vector<Asset*> _toBeInitialized;

View File

@@ -300,24 +300,15 @@ void AssetManager::update() {
void AssetManager::add(const std::string& path) {
ghoul_precondition(!path.empty(), "Path must not be empty");
// First check if the path is already in the remove queue. If so, remove it from there
const auto it = _assetRemoveQueue.find(path);
if (it != _assetRemoveQueue.end()) {
_assetRemoveQueue.erase(it);
}
_assetAddQueue.insert(path);
_assetRemoveQueue.remove(path);
_assetAddQueue.push_back(path);
}
void AssetManager::remove(const std::string& path) {
ghoul_precondition(!path.empty(), "Path must not be empty");
// First check if the path is already in the add queue. If so, remove it from there
const auto it = _assetAddQueue.find(path);
if (it != _assetAddQueue.end()) {
_assetAddQueue.erase(it);
}
_assetRemoveQueue.insert(path);
_assetAddQueue.remove(path);
_assetRemoveQueue.push_back(path);
}
std::vector<const Asset*> AssetManager::allAssets() const {