Skip to content

Commit

Permalink
generateResourceID now considers the model resource id rather than th…
Browse files Browse the repository at this point in the history
…e UniqueResourceID
  • Loading branch information
3dJan committed Sep 17, 2024
1 parent 6f6e534 commit a255f08
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Source/Model/Classes/NMR_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,33 @@ namespace NMR {
}
}


// Retrieve a unique Resource ID
ModelResourceID CModel::generateResourceID()
{
ModelResourceID highestID = 0;

if (m_ResourceMap.empty())
if(m_ResourceMap.empty())
{
return 1;
}

// find the lowest unoccupied ModelResourceID
std::unordered_set<ModelResourceID> occupiedIDs;
for(const auto &entry : m_ResourceMap)
{
return 1;
occupiedIDs.insert(
entry.second->getPackageResourceID()->getModelResourceID());
}

highestID = std::max_element(m_ResourceMap.begin(), m_ResourceMap.end(),
[](const auto &a, const auto &b) {
return a.first < b.first;
})->first;
ModelResourceID newResourceID = 1;

// Loop until we find an unoccupied resource ID
while(occupiedIDs.find(newResourceID) != occupiedIDs.end())
{
++newResourceID;
}

return highestID + 1;
return newResourceID;
}

void CModel::updateUniqueResourceID(UniqueResourceID nOldID, UniqueResourceID nNewID)
Expand Down

0 comments on commit a255f08

Please sign in to comment.