1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-19 07:11:33 +00:00

Merge branch 'cs_ref_id' into 'master'

Use ESM::RefId as index key in collections

See merge request OpenMW/openmw!2740
This commit is contained in:
psi29a 2023-02-17 13:30:02 +00:00
commit 2fee5bdb73
30 changed files with 103 additions and 115 deletions

View file

@ -643,7 +643,7 @@ bool CSMFilter::Parser::parse(const std::string& filter, bool allowPredefined)
return false; return false;
} }
int index = mData.getFilters().searchId(token.mString); const int index = mData.getFilters().searchId(ESM::RefId::stringRefId(token.mString));
if (index == -1) if (index == -1)
{ {

View file

@ -87,7 +87,7 @@ void CSMTools::ReferenceCheckStage::perform(int stage, CSMDoc::Messages& message
messages.add(id, "Invalid faction rank", "", CSMDoc::Message::Severity_Error); messages.add(id, "Invalid faction rank", "", CSMDoc::Message::Severity_Error);
} }
if (!cellRef.mDestCell.empty() && mCells.searchId(cellRef.mDestCell) == -1) if (!cellRef.mDestCell.empty() && mCells.searchId(ESM::RefId::stringRefId(cellRef.mDestCell)) == -1)
messages.add( messages.add(
id, "Destination cell '" + cellRef.mDestCell + "' does not exist", "", CSMDoc::Message::Severity_Error); id, "Destination cell '" + cellRef.mDestCell + "' does not exist", "", CSMDoc::Message::Severity_Error);

View file

@ -78,7 +78,7 @@ int CSMTools::TopicInfoCheckStage::setup()
mCellNames.insert(regionRecord.get().mName); mCellNames.insert(regionRecord.get().mName);
} }
// Default cell name // Default cell name
int index = mGameSettings.searchId("sDefaultCellname"); const int index = mGameSettings.searchId(ESM::RefId::stringRefId("sDefaultCellname"));
if (index != -1) if (index != -1)
{ {
const CSMWorld::Record<ESM::GameSetting>& gmstRecord = mGameSettings.getRecord(index); const CSMWorld::Record<ESM::GameSetting>& gmstRecord = mGameSettings.getRecord(index);

View file

@ -86,7 +86,7 @@ namespace CSMWorld
private: private:
std::vector<std::unique_ptr<Record<ESXRecordT>>> mRecords; std::vector<std::unique_ptr<Record<ESXRecordT>>> mRecords;
std::map<std::string, int> mIndex; std::map<ESM::RefId, int> mIndex;
std::vector<Column<ESXRecordT>*> mColumns; std::vector<Column<ESXRecordT>*> mColumns;
// not implemented // not implemented
@ -148,10 +148,6 @@ namespace CSMWorld
///< Change the state of a record from base to modified, if it is not already. ///< Change the state of a record from base to modified, if it is not already.
/// \return True if the record was changed. /// \return True if the record was changed.
int searchId(std::string_view id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
int searchId(const ESM::RefId& id) const override; int searchId(const ESM::RefId& id) const override;
////< Search record with \a id. ////< Search record with \a id.
/// \return index of record (if found) or -1 (not found) /// \return index of record (if found) or -1 (not found)
@ -232,9 +228,9 @@ namespace CSMWorld
std::move(buffer.begin(), buffer.end(), mRecords.begin() + baseIndex); std::move(buffer.begin(), buffer.end(), mRecords.begin() + baseIndex);
// adjust index // adjust index
for (std::map<std::string, int>::iterator iter(mIndex.begin()); iter != mIndex.end(); ++iter) for (auto& [id, index] : mIndex)
if (iter->second >= baseIndex && iter->second < baseIndex + size) if (index >= baseIndex && index < baseIndex + size)
iter->second = newOrder.at(iter->second - baseIndex) + baseIndex; index = newOrder.at(index - baseIndex) + baseIndex;
} }
return true; return true;
@ -329,9 +325,9 @@ namespace CSMWorld
template <typename ESXRecordT, typename IdAccessorT> template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::add(const ESXRecordT& record) void Collection<ESXRecordT, IdAccessorT>::add(const ESXRecordT& record)
{ {
auto id = IdAccessorT().getId(record); const ESM::RefId id = IdAccessorT().getId(record);
auto iter = mIndex.find(Misc::StringUtils::lowerCase(id.getRefIdString())); auto iter = mIndex.find(id);
if (iter == mIndex.end()) if (iter == mIndex.end())
{ {
@ -438,7 +434,7 @@ namespace CSMWorld
{ {
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count); mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
typename std::map<std::string, int>::iterator iter = mIndex.begin(); auto iter = mIndex.begin();
while (iter != mIndex.end()) while (iter != mIndex.end())
{ {
@ -451,7 +447,7 @@ namespace CSMWorld
} }
else else
{ {
mIndex.erase(iter++); iter = mIndex.erase(iter);
} }
} }
else else
@ -474,11 +470,9 @@ namespace CSMWorld
} }
template <typename ESXRecordT, typename IdAccessorT> template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::searchId(std::string_view id) const int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
{ {
std::string id2 = Misc::StringUtils::lowerCase(id); const auto iter = mIndex.find(id);
std::map<std::string, int>::const_iterator iter = mIndex.find(id2);
if (iter == mIndex.end()) if (iter == mIndex.end())
return -1; return -1;
@ -486,13 +480,6 @@ namespace CSMWorld
return iter->second; return iter->second;
} }
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
{
return searchId(id.getRefIdString());
}
template <typename ESXRecordT, typename IdAccessorT> template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::replace(int index, std::unique_ptr<RecordBase> record) void Collection<ESXRecordT, IdAccessorT>::replace(int index, std::unique_ptr<RecordBase> record)
{ {
@ -549,7 +536,7 @@ namespace CSMWorld
throw std::runtime_error("index out of range"); throw std::runtime_error("index out of range");
std::unique_ptr<Record<ESXRecordT>> record2(static_cast<Record<ESXRecordT>*>(record.release())); std::unique_ptr<Record<ESXRecordT>> record2(static_cast<Record<ESXRecordT>*>(record.release()));
std::string id = Misc::StringUtils::lowerCase(IdAccessorT().getId(record2->get()).getRefIdString()); ESM::RefId id = IdAccessorT().getId(record2->get());
if (index == size) if (index == size)
mRecords.push_back(std::move(record2)); mRecords.push_back(std::move(record2));
@ -558,10 +545,10 @@ namespace CSMWorld
if (index < size - 1) if (index < size - 1)
{ {
for (std::map<std::string, int>::iterator iter(mIndex.begin()); iter != mIndex.end(); ++iter) for (auto& [key, value] : mIndex)
{ {
if (iter->second >= index) if (value >= index)
++(iter->second); ++value;
} }
} }

View file

@ -11,9 +11,9 @@ CSMWorld::CollectionBase::CollectionBase() {}
CSMWorld::CollectionBase::~CollectionBase() {} CSMWorld::CollectionBase::~CollectionBase() {}
int CSMWorld::CollectionBase::getInsertIndex(const std::string& id, UniversalId::Type type, RecordBase* record) const int CSMWorld::CollectionBase::getInsertIndex(const ESM::RefId& id, UniversalId::Type type, RecordBase* record) const
{ {
return getAppendIndex(ESM::RefId::stringRefId(id), type); return getAppendIndex(id, type);
} }
int CSMWorld::CollectionBase::searchColumnIndex(Columns::ColumnId id) const int CSMWorld::CollectionBase::searchColumnIndex(Columns::ColumnId id) const

View file

@ -65,10 +65,6 @@ namespace CSMWorld
virtual void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) = 0; virtual void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) = 0;
///< \param type Will be ignored, unless the collection supports multiple record types ///< \param type Will be ignored, unless the collection supports multiple record types
virtual int searchId(std::string_view id) const = 0;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
virtual int searchId(const ESM::RefId& id) const = 0; virtual int searchId(const ESM::RefId& id) const = 0;
////< Search record with \a id. ////< Search record with \a id.
/// \return index of record (if found) or -1 (not found) /// \return index of record (if found) or -1 (not found)
@ -107,7 +103,7 @@ namespace CSMWorld
/// \return Success? /// \return Success?
virtual int getInsertIndex( virtual int getInsertIndex(
const std::string& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const; const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None, RecordBase* record = nullptr) const;
///< Works like getAppendIndex unless an overloaded method uses the record pointer ///< Works like getAppendIndex unless an overloaded method uses the record pointer
/// to get additional info about the record that results in an alternative index. /// to get additional info about the record that results in an alternative index.

View file

@ -1072,13 +1072,14 @@ void CSMWorld::Data::loadFallbackEntries()
std::pair<std::string, std::string> doorMarkers[] = { std::make_pair("PrisonMarker", "marker_prison.nif") }; std::pair<std::string, std::string> doorMarkers[] = { std::make_pair("PrisonMarker", "marker_prison.nif") };
for (const auto& marker : staticMarkers) for (const auto& [id, model] : staticMarkers)
{ {
if (mReferenceables.searchId(marker.first) == -1) const ESM::RefId refId = ESM::RefId::stringRefId(id);
if (mReferenceables.searchId(refId) == -1)
{ {
ESM::Static newMarker; ESM::Static newMarker;
newMarker.mId = ESM::RefId::stringRefId(marker.first); newMarker.mId = refId;
newMarker.mModel = marker.second; newMarker.mModel = model;
newMarker.mRecordFlags = 0; newMarker.mRecordFlags = 0;
auto record = std::make_unique<CSMWorld::Record<ESM::Static>>(); auto record = std::make_unique<CSMWorld::Record<ESM::Static>>();
record->mBase = newMarker; record->mBase = newMarker;
@ -1087,13 +1088,14 @@ void CSMWorld::Data::loadFallbackEntries()
} }
} }
for (const auto& marker : doorMarkers) for (const auto& [id, model] : doorMarkers)
{ {
if (mReferenceables.searchId(marker.first) == -1) const ESM::RefId refId = ESM::RefId::stringRefId(id);
if (mReferenceables.searchId(refId) == -1)
{ {
ESM::Door newMarker; ESM::Door newMarker;
newMarker.mId = ESM::RefId::stringRefId(marker.first); newMarker.mId = refId;
newMarker.mModel = marker.second; newMarker.mModel = model;
newMarker.mRecordFlags = 0; newMarker.mRecordFlags = 0;
auto record = std::make_unique<CSMWorld::Record<ESM::Door>>(); auto record = std::make_unique<CSMWorld::Record<ESM::Door>>();
record->mBase = newMarker; record->mBase = newMarker;
@ -1280,25 +1282,24 @@ bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages)
bool isDeleted = false; bool isDeleted = false;
record.load(*mReader, isDeleted); record.load(*mReader, isDeleted);
const std::string& recordIdString = record.mId.getRefIdString();
if (isDeleted) if (isDeleted)
{ {
// record vector can be shuffled around which would make pointer to record invalid // record vector can be shuffled around which would make pointer to record invalid
mDialogue = nullptr; mDialogue = nullptr;
if (mJournals.tryDelete(recordIdString)) if (mJournals.tryDelete(record.mId))
{ {
removeDialogueInfos(record.mId, mJournalInfosByTopic, mJournalInfos); removeDialogueInfos(record.mId, mJournalInfosByTopic, mJournalInfos);
} }
else if (mTopics.tryDelete(recordIdString)) else if (mTopics.tryDelete(record.mId))
{ {
removeDialogueInfos(record.mId, mTopicInfosByTopic, mTopicInfos); removeDialogueInfos(record.mId, mTopicInfosByTopic, mTopicInfos);
} }
else else
{ {
messages.add(UniversalId::Type_None, messages.add(UniversalId::Type_None,
"Trying to delete dialogue record " + recordIdString + " which does not exist", "", "Trying to delete dialogue record " + record.mId.getRefIdString() + " which does not exist", "",
CSMDoc::Message::Severity_Warning); CSMDoc::Message::Severity_Warning);
} }
} }
@ -1378,13 +1379,15 @@ bool CSMWorld::Data::continueLoading(CSMDoc::Messages& messages)
bool CSMWorld::Data::hasId(const std::string& id) const bool CSMWorld::Data::hasId(const std::string& id) const
{ {
return getGlobals().searchId(id) != -1 || getGmsts().searchId(id) != -1 || getSkills().searchId(id) != -1 const ESM::RefId refId = ESM::RefId::stringRefId(id);
|| getClasses().searchId(id) != -1 || getFactions().searchId(id) != -1 || getRaces().searchId(id) != -1 return getGlobals().searchId(refId) != -1 || getGmsts().searchId(refId) != -1 || getSkills().searchId(refId) != -1
|| getSounds().searchId(id) != -1 || getScripts().searchId(id) != -1 || getRegions().searchId(id) != -1 || getClasses().searchId(refId) != -1 || getFactions().searchId(refId) != -1 || getRaces().searchId(refId) != -1
|| getBirthsigns().searchId(id) != -1 || getSpells().searchId(id) != -1 || getTopics().searchId(id) != -1 || getSounds().searchId(refId) != -1 || getScripts().searchId(refId) != -1 || getRegions().searchId(refId) != -1
|| getJournals().searchId(id) != -1 || getCells().searchId(id) != -1 || getEnchantments().searchId(id) != -1 || getBirthsigns().searchId(refId) != -1 || getSpells().searchId(refId) != -1
|| getBodyParts().searchId(id) != -1 || getSoundGens().searchId(id) != -1 || getTopics().searchId(refId) != -1 || getJournals().searchId(refId) != -1 || getCells().searchId(refId) != -1
|| getMagicEffects().searchId(id) != -1 || getReferenceables().searchId(id) != -1; || getEnchantments().searchId(refId) != -1 || getBodyParts().searchId(refId) != -1
|| getSoundGens().searchId(refId) != -1 || getMagicEffects().searchId(refId) != -1
|| getReferenceables().searchId(refId) != -1;
} }
int CSMWorld::Data::count(RecordBase::State state) const int CSMWorld::Data::count(RecordBase::State state) const

View file

@ -40,7 +40,7 @@ namespace CSMWorld
/// \return index /// \return index
int load(const ESXRecordT& record, bool base, int index = -2); int load(const ESXRecordT& record, bool base, int index = -2);
bool tryDelete(const std::string& id); bool tryDelete(const ESM::RefId& id);
///< Try deleting \a id. If the id does not exist or can't be deleted the call is ignored. ///< Try deleting \a id. If the id does not exist or can't be deleted the call is ignored.
/// ///
/// \return Has the ID been deleted? /// \return Has the ID been deleted?
@ -135,7 +135,7 @@ namespace CSMWorld
} }
template <typename ESXRecordT, typename IdAccessorT> template <typename ESXRecordT, typename IdAccessorT>
bool IdCollection<ESXRecordT, IdAccessorT>::tryDelete(const std::string& id) bool IdCollection<ESXRecordT, IdAccessorT>::tryDelete(const ESM::RefId& id)
{ {
int index = this->searchId(id); int index = this->searchId(id);

View file

@ -243,7 +243,8 @@ std::string CSMWorld::IdTable::getId(int row) const
/// This method can return only indexes to the top level table cells /// This method can return only indexes to the top level table cells
QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column) const QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column) const
{ {
int row = mIdCollection->searchId(id); const int row = mIdCollection->searchId(ESM::RefId::stringRefId(id));
if (row != -1) if (row != -1)
return index(row, column); return index(row, column);
@ -253,7 +254,8 @@ QModelIndex CSMWorld::IdTable::getModelIndex(const std::string& id, int column)
void CSMWorld::IdTable::setRecord( void CSMWorld::IdTable::setRecord(
const std::string& id, std::unique_ptr<RecordBase> record, CSMWorld::UniversalId::Type type) const std::string& id, std::unique_ptr<RecordBase> record, CSMWorld::UniversalId::Type type)
{ {
int index = mIdCollection->searchId(id); const ESM::RefId refId = ESM::RefId::stringRefId(id);
const int index = mIdCollection->searchId(refId);
if (index == -1) if (index == -1)
{ {
@ -263,7 +265,7 @@ void CSMWorld::IdTable::setRecord(
// //
// Use an alternative method to get the correct index. For non-Info records the // Use an alternative method to get the correct index. For non-Info records the
// record pointer is ignored and internally calls getAppendIndex. // record pointer is ignored and internally calls getAppendIndex.
int index2 = mIdCollection->getInsertIndex(id, type, record.get()); const int index2 = mIdCollection->getInsertIndex(refId, type, record.get());
beginInsertRows(QModelIndex(), index2, index2); beginInsertRows(QModelIndex(), index2, index2);
@ -377,9 +379,10 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import
for (const std::string& id : ids) for (const std::string& id : ids)
{ {
int plugin, index; int plugin, index;
LandTexture::parseUniqueRecordId(id, plugin, index); LandTexture::parseUniqueRecordId(id, plugin, index);
int oldRow = idCollection()->searchId(id);
const ESM::RefId refId = ESM::RefId::stringRefId(id);
const int oldRow = idCollection()->searchId(refId);
// If it does not exist or it is in the current plugin, it can be skipped. // If it does not exist or it is in the current plugin, it can be skipped.
if (oldRow < 0 || plugin == 0) if (oldRow < 0 || plugin == 0)
@ -403,12 +406,13 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import
do do
{ {
std::string newId = LandTexture::createUniqueRecordId(0, index); std::string newId = LandTexture::createUniqueRecordId(0, index);
int newRow = idCollection()->searchId(newId); const ESM::RefId newRefId = ESM::RefId::stringRefId(newId);
int newRow = idCollection()->searchId(newRefId);
if (newRow < 0) if (newRow < 0)
{ {
// Id not taken, clone it // Id not taken, clone it
cloneRecord(ESM::RefId::stringRefId(id), ESM::RefId::stringRefId(newId), UniversalId::Type_LandTexture); cloneRecord(refId, newRefId, UniversalId::Type_LandTexture);
results.createdRecords.push_back(newId); results.createdRecords.push_back(newId);
results.recordMapping.emplace_back(id, newId); results.recordMapping.emplace_back(id, newId);
reverseLookupMap.emplace(texture, newId); reverseLookupMap.emplace(texture, newId);

View file

@ -12,7 +12,7 @@
bool CSMWorld::InfoCollection::load(const Info& record, bool base) bool CSMWorld::InfoCollection::load(const Info& record, bool base)
{ {
int index = searchId(record.mId.getRefIdString()); const int index = searchId(record.mId);
if (index == -1) if (index == -1)
{ {
@ -48,7 +48,7 @@ void CSMWorld::InfoCollection::load(
bool isDeleted = false; bool isDeleted = false;
info.load(reader, isDeleted); info.load(reader, isDeleted);
std::string id = dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString(); const ESM::RefId id = ESM::RefId::stringRefId(dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString());
if (isDeleted) if (isDeleted)
{ {
@ -75,7 +75,7 @@ void CSMWorld::InfoCollection::load(
{ {
info.mTopicId = dialogue.mId; info.mTopicId = dialogue.mId;
info.mOriginalId = info.mId; info.mOriginalId = info.mId;
info.mId = ESM::RefId::stringRefId(id); info.mId = id;
if (load(info, base)) if (load(info, base))
infosByTopic[dialogue.mId].push_back(info.mId); infosByTopic[dialogue.mId].push_back(info.mId);

View file

@ -725,9 +725,9 @@ void CSMWorld::RefIdCollection::appendBlankRecord(const ESM::RefId& id, Universa
mData.appendRecord(type, id, false); mData.appendRecord(type, id, false);
} }
int CSMWorld::RefIdCollection::searchId(std::string_view id) const int CSMWorld::RefIdCollection::searchId(const ESM::RefId& id) const
{ {
RefIdData::LocalIndex localIndex = mData.searchId(ESM::RefId::stringRefId(id)); const RefIdData::LocalIndex localIndex = mData.searchId(id);
if (localIndex.first == -1) if (localIndex.first == -1)
return -1; return -1;
@ -735,11 +735,6 @@ int CSMWorld::RefIdCollection::searchId(std::string_view id) const
return mData.localToGlobalIndex(localIndex); return mData.localToGlobalIndex(localIndex);
} }
int CSMWorld::RefIdCollection::searchId(const ESM::RefId& id) const
{
return searchId(id.getRefIdString());
}
void CSMWorld::RefIdCollection::replace(int index, std::unique_ptr<RecordBase> record) void CSMWorld::RefIdCollection::replace(int index, std::unique_ptr<RecordBase> record)
{ {
mData.getRecord(mData.globalToLocalIndex(index)).assign(*record.release()); mData.getRecord(mData.globalToLocalIndex(index)).assign(*record.release());

View file

@ -89,10 +89,6 @@ namespace CSMWorld
void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type) override; void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type) override;
///< \param type Will be ignored, unless the collection supports multiple record types ///< \param type Will be ignored, unless the collection supports multiple record types
int searchId(std::string_view id) const override;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
int searchId(const ESM::RefId& id) const override; int searchId(const ESM::RefId& id) const override;
////< Search record with \a id. ////< Search record with \a id.
/// \return index of record (if found) or -1 (not found) /// \return index of record (if found) or -1 (not found)

View file

@ -32,7 +32,7 @@ bool CSMWorld::ScriptContext::canDeclareLocals() const
char CSMWorld::ScriptContext::getGlobalType(const std::string& name) const char CSMWorld::ScriptContext::getGlobalType(const std::string& name) const
{ {
int index = mData.getGlobals().searchId(name); const int index = mData.getGlobals().searchId(ESM::RefId::stringRefId(name));
if (index != -1) if (index != -1)
{ {

View file

@ -128,7 +128,7 @@ namespace CSVRender
{ {
const auto& bodyParts = mData.getBodyParts(); const auto& bodyParts = mData.getBodyParts();
int index = bodyParts.searchId(bodyPartId); const int index = bodyParts.searchId(ESM::RefId::stringRefId(bodyPartId));
if (index != -1 && !bodyParts.getRecord(index).isDeleted()) if (index != -1 && !bodyParts.getRecord(index).isDeleted())
return MeshPrefix + bodyParts.getRecord(index).get().mModel; return MeshPrefix + bodyParts.getRecord(index).get().mModel;
else else

View file

@ -57,7 +57,7 @@ namespace CSVRender
mWaterGroup = new osg::Group(); mWaterGroup = new osg::Group();
mWaterTransform->addChild(mWaterGroup); mWaterTransform->addChild(mWaterGroup);
int cellIndex = mData.getCells().searchId(mId); const int cellIndex = mData.getCells().searchId(ESM::RefId::stringRefId(mId));
if (cellIndex > -1) if (cellIndex > -1)
{ {
updateCellData(mData.getCells().getRecord(cellIndex)); updateCellData(mData.getCells().getRecord(cellIndex));

View file

@ -965,7 +965,7 @@ void CSVRender::InstanceMode::dropEvent(QDropEvent* event)
CSMWorld::IdTree& cellTable CSMWorld::IdTree& cellTable
= dynamic_cast<CSMWorld::IdTree&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells)); = dynamic_cast<CSMWorld::IdTree&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells));
bool noCell = document.getData().getCells().searchId(cellId) == -1; const bool noCell = document.getData().getCells().searchId(ESM::RefId::stringRefId(cellId)) == -1;
if (noCell) if (noCell)
{ {

View file

@ -77,7 +77,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
else else
{ {
// update // update
int index = cells.searchId(iter->first.getId(mWorldspace)); const int index = cells.searchId(ESM::RefId::stringRefId(iter->first.getId(mWorldspace)));
bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted; bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted;
@ -460,7 +460,7 @@ void CSVRender::PagedWorldspaceWidget::addCellToScene(const CSMWorld::CellCoordi
{ {
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells(); const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells();
int index = cells.searchId(coordinates.getId(mWorldspace)); const int index = cells.searchId(ESM::RefId::stringRefId(coordinates.getId(mWorldspace)));
bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted; bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted;

View file

@ -296,14 +296,14 @@ bool CSVRender::TerrainSelection::noCell(const std::string& cellId)
{ {
CSMDoc::Document& document = mWorldspaceWidget->getDocument(); CSMDoc::Document& document = mWorldspaceWidget->getDocument();
const CSMWorld::IdCollection<CSMWorld::Cell>& cellCollection = document.getData().getCells(); const CSMWorld::IdCollection<CSMWorld::Cell>& cellCollection = document.getData().getCells();
return cellCollection.searchId(cellId) == -1; return cellCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
} }
bool CSVRender::TerrainSelection::noLand(const std::string& cellId) bool CSVRender::TerrainSelection::noLand(const std::string& cellId)
{ {
CSMDoc::Document& document = mWorldspaceWidget->getDocument(); CSMDoc::Document& document = mWorldspaceWidget->getDocument();
const CSMWorld::IdCollection<CSMWorld::Land>& landCollection = document.getData().getLand(); const CSMWorld::IdCollection<CSMWorld::Land>& landCollection = document.getData().getLand();
return landCollection.searchId(cellId) == -1; return landCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
} }
bool CSVRender::TerrainSelection::noLandLoaded(const std::string& cellId) bool CSVRender::TerrainSelection::noLandLoaded(const std::string& cellId)

View file

@ -1326,14 +1326,14 @@ bool CSVRender::TerrainShapeMode::noCell(const std::string& cellId)
{ {
CSMDoc::Document& document = getWorldspaceWidget().getDocument(); CSMDoc::Document& document = getWorldspaceWidget().getDocument();
const CSMWorld::IdCollection<CSMWorld::Cell>& cellCollection = document.getData().getCells(); const CSMWorld::IdCollection<CSMWorld::Cell>& cellCollection = document.getData().getCells();
return cellCollection.searchId(cellId) == -1; return cellCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
} }
bool CSVRender::TerrainShapeMode::noLand(const std::string& cellId) bool CSVRender::TerrainShapeMode::noLand(const std::string& cellId)
{ {
CSMDoc::Document& document = getWorldspaceWidget().getDocument(); CSMDoc::Document& document = getWorldspaceWidget().getDocument();
const CSMWorld::IdCollection<CSMWorld::Land>& landCollection = document.getData().getLand(); const CSMWorld::IdCollection<CSMWorld::Land>& landCollection = document.getData().getLand();
return landCollection.searchId(cellId) == -1; return landCollection.searchId(ESM::RefId::stringRefId(cellId)) == -1;
} }
bool CSVRender::TerrainShapeMode::noLandLoaded(const std::string& cellId) bool CSVRender::TerrainShapeMode::noLandLoaded(const std::string& cellId)

View file

@ -32,7 +32,8 @@ namespace CSVRender
{ {
// The cell isn't guaranteed to have Land. This is because the terrain implementation // The cell isn't guaranteed to have Land. This is because the terrain implementation
// has to wrap the vertices of the last row and column to the next cell, which may be a nonexisting cell // has to wrap the vertices of the last row and column to the next cell, which may be a nonexisting cell
int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)); const int index
= mData.getLand().searchId(ESM::RefId::stringRefId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)));
if (index == -1) if (index == -1)
return nullptr; return nullptr;
@ -43,7 +44,8 @@ namespace CSVRender
const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin) const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
{ {
int row = mData.getLandTextures().searchId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index)); const int row = mData.getLandTextures().searchId(
ESM::RefId::stringRefId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index)));
if (row == -1) if (row == -1)
return nullptr; return nullptr;
@ -65,7 +67,8 @@ namespace CSVRender
{ {
float height = 0.f; float height = 0.f;
int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)); const int index
= mData.getLand().searchId(ESM::RefId::stringRefId(CSMWorld::Land::createUniqueRecordId(cellX, cellY)));
if (index == -1) // no land! if (index == -1) // no land!
return height; return height;

View file

@ -137,7 +137,7 @@ void CSVRender::TerrainTextureMode::primaryEditPressed(const WorldspaceHitResult
QUndoStack& undoStack = document.getUndoStack(); QUndoStack& undoStack = document.getUndoStack();
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture); int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr)
{ {
@ -186,7 +186,7 @@ bool CSVRender::TerrainTextureMode::primaryEditStartDrag(const QPoint& pos)
mDragMode = InteractionType_PrimaryEdit; mDragMode = InteractionType_PrimaryEdit;
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture); const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr)
{ {
@ -242,7 +242,7 @@ void CSVRender::TerrainTextureMode::drag(const QPoint& pos, int diffX, int diffY
CSMDoc::Document& document = getWorldspaceWidget().getDocument(); CSMDoc::Document& document = getWorldspaceWidget().getDocument();
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture); const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted() && hit.hit && hit.tag == nullptr)
{ {
@ -273,7 +273,7 @@ void CSVRender::TerrainTextureMode::dragCompleted(const QPoint& pos)
QUndoStack& undoStack = document.getUndoStack(); QUndoStack& undoStack = document.getUndoStack();
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = document.getData().getLandTextures();
int index = landtexturesCollection.searchId(mBrushTexture); const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{ {
@ -718,8 +718,9 @@ bool CSVRender::TerrainTextureMode::allowLandTextureEditing(std::string cellId)
CSMWorld::IdTree& cellTable CSMWorld::IdTree& cellTable
= dynamic_cast<CSMWorld::IdTree&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells)); = dynamic_cast<CSMWorld::IdTree&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_Cells));
bool noCell = document.getData().getCells().searchId(cellId) == -1; const ESM::RefId cellRefId = ESM::RefId::stringRefId(cellId);
bool noLand = document.getData().getLand().searchId(cellId) == -1; const bool noCell = document.getData().getCells().searchId(cellRefId) == -1;
const bool noLand = document.getData().getLand().searchId(cellRefId) == -1;
if (noCell) if (noCell)
{ {

View file

@ -77,7 +77,7 @@ CSVWidget::TextureBrushWindow::TextureBrushWindow(CSMDoc::Document& document, QW
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
int index = landtexturesCollection.searchId(mBrushTexture); const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{ {
@ -164,9 +164,11 @@ void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture)
int index = 0; int index = 0;
int pluginInDragged = 0; int pluginInDragged = 0;
CSMWorld::LandTexture::parseUniqueRecordId(brushTexture, pluginInDragged, index); CSMWorld::LandTexture::parseUniqueRecordId(brushTexture, pluginInDragged, index);
const ESM::RefId brushTextureRefId = ESM::RefId::stringRefId(brushTexture);
std::string newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, index); std::string newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, index);
int rowInBase = landtexturesCollection.searchId(brushTexture); ESM::RefId newBrushTextureRefId = ESM::RefId::stringRefId(newBrushTextureId);
int rowInNew = landtexturesCollection.searchId(newBrushTextureId); int rowInBase = landtexturesCollection.searchId(brushTextureRefId);
int rowInNew = landtexturesCollection.searchId(newBrushTextureRefId);
// Check if texture exists in current plugin, and clone if id found in base, otherwise reindex the texture // Check if texture exists in current plugin, and clone if id found in base, otherwise reindex the texture
// TO-DO: Handle case when texture is not found in neither base or plugin properly (finding new index is not enough) // TO-DO: Handle case when texture is not found in neither base or plugin properly (finding new index is not enough)
@ -181,10 +183,11 @@ void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture)
do do
{ {
newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, counter); newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, counter);
if (landtexturesCollection.searchId(brushTexture) != -1 newBrushTextureRefId = ESM::RefId::stringRefId(newBrushTextureId);
&& landtexturesCollection.getRecord(ESM::RefId::stringRefId(brushTexture)).isDeleted() == 0 if (landtexturesCollection.searchId(brushTextureRefId) != -1
&& landtexturesCollection.searchId(newBrushTextureId) != -1 && landtexturesCollection.getRecord(brushTextureRefId).isDeleted() == 0
&& landtexturesCollection.getRecord(ESM::RefId::stringRefId(newBrushTextureId)).isDeleted() == 0) && landtexturesCollection.searchId(newBrushTextureRefId) != -1
&& landtexturesCollection.getRecord(newBrushTextureRefId).isDeleted() == 0)
counter = (counter + 1) % maxCounter; counter = (counter + 1) % maxCounter;
else else
freeIndexFound = true; freeIndexFound = true;
@ -307,7 +310,7 @@ void CSVWidget::SceneToolTextureBrush::setButtonIcon(CSVWidget::BrushShape brush
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
int index = landtexturesCollection.searchId(mTextureBrushWindow->mBrushTexture); const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mTextureBrushWindow->mBrushTexture));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{ {
@ -339,7 +342,7 @@ void CSVWidget::SceneToolTextureBrush::updatePanel()
{ {
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures(); CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
int index = landtexturesCollection.searchId(mBrushHistory[i]); const int index = landtexturesCollection.searchId(ESM::RefId::stringRefId(mBrushHistory[i]));
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted()) if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
{ {

View file

@ -126,7 +126,7 @@ std::string CSVWorld::InfoCreator::getErrors() const
// We ignore errors from GenericCreator here, because they can never happen in an InfoCreator. // We ignore errors from GenericCreator here, because they can never happen in an InfoCreator.
std::string errors; std::string errors;
std::string topic = mTopic->text().toUtf8().constData(); const ESM::RefId topic = ESM::RefId::stringRefId(mTopic->text().toStdString());
if ((getCollectionId().getType() == CSMWorld::UniversalId::Type_TopicInfos ? getData().getTopics() if ((getCollectionId().getType() == CSMWorld::UniversalId::Type_TopicInfos ? getData().getTopics()
: getData().getJournals()) : getData().getJournals())

View file

@ -89,7 +89,7 @@ namespace CSVWorld
std::string LandCreator::getErrors() const std::string LandCreator::getErrors() const
{ {
if (getData().getLand().searchId(getId()) >= 0) if (getData().getLand().searchId(ESM::RefId::stringRefId(getId())) >= 0)
return "A land with that name already exists."; return "A land with that name already exists.";
return ""; return "";

View file

@ -72,7 +72,7 @@ namespace CSVWorld
std::string LandTextureCreator::getErrors() const std::string LandTextureCreator::getErrors() const
{ {
if (getData().getLandTextures().searchId(getId()) >= 0) if (getData().getLandTextures().searchId(ESM::RefId::stringRefId(getId())) >= 0)
{ {
return "Index is already in use"; return "Index is already in use";
} }

View file

@ -62,7 +62,7 @@ void CSVWorld::PathgridCreator::cloneMode(const std::string& originId, const CSM
std::string CSVWorld::PathgridCreator::getErrors() const std::string CSVWorld::PathgridCreator::getErrors() const
{ {
std::string cellId = getId(); const ESM::RefId cellId = ESM::RefId::stringRefId(getId());
// Check user input for any errors. // Check user input for any errors.
std::string errors; std::string errors;

View file

@ -22,7 +22,7 @@ CSVWorld::PreviewSubView::PreviewSubView(const CSMWorld::UniversalId& id, CSMDoc
{ {
QHBoxLayout* layout = new QHBoxLayout; QHBoxLayout* layout = new QHBoxLayout;
if (document.getData().getReferenceables().searchId(id.getId()) == -1) if (document.getData().getReferenceables().searchId(ESM::RefId::stringRefId(id.getId())) == -1)
{ {
std::string referenceableId = document.getData() std::string referenceableId = document.getData()
.getReferences() .getReferences()

View file

@ -65,7 +65,7 @@ std::string CSVWorld::ReferenceCreator::getErrors() const
// record is internal and requires neither user input nor verification. // record is internal and requires neither user input nor verification.
std::string errors; std::string errors;
std::string cell = mCell->text().toUtf8().constData(); const ESM::RefId cell = ESM::RefId::stringRefId(mCell->text().toStdString());
if (cell.empty()) if (cell.empty())
errors += "Missing Cell ID"; errors += "Missing Cell ID";

View file

@ -62,7 +62,7 @@ void CSVWorld::StartScriptCreator::cloneMode(const std::string& originId, const
std::string CSVWorld::StartScriptCreator::getErrors() const std::string CSVWorld::StartScriptCreator::getErrors() const
{ {
std::string scriptId = getId(); const ESM::RefId scriptId = ESM::RefId::stringRefId(getId());
// Check user input for any errors. // Check user input for any errors.
std::string errors; std::string errors;

View file

@ -152,7 +152,7 @@ void CSVWorld::Table::contextMenuEvent(QContextMenuEvent* event)
{ {
CSMWorld::UniversalId id = mModel->view(row).first; CSMWorld::UniversalId id = mModel->view(row).first;
int index = mDocument.getData().getCells().searchId(id.getId()); const int index = mDocument.getData().getCells().searchId(ESM::RefId::stringRefId(id.getId()));
// index==-1: the ID references a worldspace instead of a cell (ignore for now and go // index==-1: the ID references a worldspace instead of a cell (ignore for now and go
// ahead) // ahead)