diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index d9e6536fa2..ca84b1e9ee 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -177,12 +177,12 @@ namespace MWBase virtual char getGlobalVariableType(std::string_view name) const = 0; ///< Return ' ', if there is no global variable with this name. - virtual const ESM::RefId& getCellName(const MWWorld::CellStore* cell = nullptr) const = 0; + virtual std::string_view getCellName(const MWWorld::CellStore* cell = nullptr) const = 0; ///< Return name of the cell. /// /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. - virtual const ESM::RefId getCellName(const ESM::Cell* cell) const = 0; + virtual std::string_view getCellName(const ESM::Cell* cell) const = 0; virtual void removeRefScript(MWWorld::RefData* ref) = 0; //< Remove the script attached to ref from mLocalScripts diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 884285cd17..7ede0eef92 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -299,7 +299,7 @@ namespace MWClass std::string Door::getDestination(const MWWorld::LiveCellRef& door) { - auto dest = door.mRef.getDestCell(); + std::string_view dest = door.mRef.getDestCell().getRefIdString(); if (dest.empty()) { // door leads to exterior, use cell name (if any), otherwise translated region name @@ -310,7 +310,7 @@ namespace MWClass dest = world->getCellName(cell); } - return "#{sCell=" + dest.getRefIdString() + "}"; + return "#{sCell=" + std::string{ dest } + "}"; } MWWorld::Ptr Door::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 38a3e70ba7..3821862ecb 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -196,8 +196,7 @@ bool MWDialogue::Filter::testPlayer(const ESM::DialInfo& info) const if (!info.mCell.empty()) { // supports partial matches, just like getPcCell - std::string_view playerCell - = MWBase::Environment::get().getWorld()->getCellName(player.getCell()).getRefIdString(); + std::string_view playerCell = MWBase::Environment::get().getWorld()->getCellName(player.getCell()); if (!Misc::StringUtils::ciStartsWith(playerCell, info.mCell.getRefIdString())) return false; } @@ -554,8 +553,7 @@ bool MWDialogue::Filter::getSelectStructBoolean(const SelectWrapper& select) con case SelectWrapper::Function_NotCell: { - std::string_view actorCell - = MWBase::Environment::get().getWorld()->getCellName(mActor.getCell()).getRefIdString(); + std::string_view actorCell = MWBase::Environment::get().getWorld()->getCellName(mActor.getCell()); return !Misc::StringUtils::ciStartsWith(actorCell, select.getName()); } case SelectWrapper::Function_SameGender: diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 30881ac730..adc6d9d614 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -330,7 +330,7 @@ namespace MWGui continue; if (mGenderIndex != (bodypart.mData.mFlags & ESM::BodyPart::BPF_Female)) continue; - bool firstPerson = idString.ends_with("1st"); + bool firstPerson = Misc::StringUtils::ciEndsWith(idString, "1st"); if (firstPerson) continue; if (bodypart.mRace == mCurrentRaceId) diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 95832c92bb..3cfe3210ef 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -123,7 +123,7 @@ namespace MWGui for (unsigned int i = 0; i < transport.size(); i++) { - ESM::RefId cellname = transport[i].mCellName; + std::string_view cellname = transport[i].mCellName.getRefIdString(); bool interior = true; const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); @@ -134,7 +134,7 @@ namespace MWGui cellname = MWBase::Environment::get().getWorld()->getCellName(cell); interior = false; } - addDestination(cellname, transport[i].mPos, interior); + addDestination(ESM::RefId::stringRefId(cellname), transport[i].mPos, interior); } updateLabels(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 71db4c4a12..4bbd729f47 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -933,7 +933,7 @@ namespace MWGui { mMap->requestMapRender(cell); - std::string name = MWBase::Environment::get().getWorld()->getCellName(cell).getRefIdString(); + std::string name{ MWBase::Environment::get().getWorld()->getCellName(cell) }; mMap->setCellName(name); mHud->setCellName(name); diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index 9db82c0350..a651d18c1f 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -29,9 +29,14 @@ namespace MWMechanics || (effectId >= ESM::MagicEffect::SummonFabricant && effectId <= ESM::MagicEffect::SummonCreature05)); } - const ESM::RefId& getSummonedCreature(int effectId) + static const std::map& getSummonMap() { - static const std::map summonMap{ + static std::map summonMap; + + if (summonMap.size() > 0) + return summonMap; + + const std::map summonMapToGameSetting{ { ESM::MagicEffect::SummonAncestralGhost, "sMagicAncestralGhostID" }, { ESM::MagicEffect::SummonBonelord, "sMagicBonelordID" }, { ESM::MagicEffect::SummonBonewalker, "sMagicLeastBonewalkerID" }, @@ -56,16 +61,25 @@ namespace MWMechanics { ESM::MagicEffect::SummonCreature05, "sMagicCreature05ID" }, }; + for (const auto& it : summonMapToGameSetting) + { + summonMap[it.first] = ESM::RefId::stringRefId(MWBase::Environment::get() + .getWorld() + ->getStore() + .get() + .find(it.second) + ->mValue.getString()); + } + return summonMap; + } + + const ESM::RefId& getSummonedCreature(int effectId) + { + const auto& summonMap = getSummonMap(); auto it = summonMap.find(effectId); if (it != summonMap.end()) { - static ESM::RefId val = ESM::RefId::stringRefId(MWBase::Environment::get() - .getWorld() - ->getStore() - .get() - .find(it->second) - ->mValue.getString()); - return val; + return it->second; } return ESM::RefId::sEmpty; } diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 55b9641ff1..21437f0da1 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -165,7 +165,7 @@ namespace MWScript } const MWWorld::CellStore* cell = MWMechanics::getPlayer().getCell(); - std::string_view current = MWBase::Environment::get().getWorld()->getCellName(cell).getRefIdString(); + std::string_view current = MWBase::Environment::get().getWorld()->getCellName(cell); bool match = Misc::StringUtils::ciCompareLen(name, current, name.length()) == 0; runtime.push(match ? 1 : 0); diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 544902805f..7508d4a785 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -414,7 +414,7 @@ namespace MWScript std::string_view InterpreterContext::getCurrentCellName() const { - return MWBase::Environment::get().getWorld()->getCellName().getRefIdString(); + return MWBase::Environment::get().getWorld()->getCellName(); } void InterpreterContext::executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index d5582e7eb3..4dfe127411 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -210,7 +210,7 @@ namespace MWScript return iter->second; } - throw std::logic_error("script " + std::string{ name.getRefIdString() } + " does not exist"); + throw std::logic_error("script " + name.getRefIdString() + " does not exist"); } GlobalScripts& ScriptManager::getGlobalScripts() diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 89f37eb82f..6f5c63d3a8 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -222,7 +222,7 @@ void MWState::StateManager::saveGame(const std::string& description, const Slot* else profile.mPlayerClassId = classId; - profile.mPlayerCell = world.getCellName(); + profile.mPlayerCell = ESM::RefId::stringRefId(world.getCellName()); profile.mInGameTime = world.getEpochTimeStamp(); profile.mTimePlayed = mTimePlayed; profile.mDescription = description; diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 9f4bb8ccaa..11e58c0edb 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -957,7 +957,7 @@ namespace MWWorld Store::Store() {} - // Magic effect + // Game Settings //========================================================================= const ESM::GameSetting* Store::search(const ESM::RefId& id) const @@ -973,9 +973,10 @@ namespace MWWorld const ESM::GameSetting* Store::search(std::string_view id) const { return TypedDynamicStore::search(ESM::RefId::stringRefId(id)); - ; } + // Magic effect + //========================================================================= Store::Store() {} // Attribute diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 91cd49606d..328610bc40 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -572,7 +572,7 @@ namespace MWWorld if (cell) return cell; // treat "Wilderness" like an empty string - const ESM::RefId defaultName + static const ESM::RefId defaultName = ESM::RefId::stringRefId(mStore.get().find("sDefaultCellname")->mValue.getString()); if (cellName == defaultName) { @@ -584,7 +584,7 @@ namespace MWWorld // didn't work -> now check for regions for (const ESM::Region& region : mStore.get()) { - if (Misc::StringUtils::ciEqual(cellName.getRefIdString(), region.mName)) + if (cellName == ESM::RefId::stringRefId(region.mName)) { return mStore.get().searchExtByRegion(region.mId); } @@ -656,24 +656,25 @@ namespace MWWorld return mCurrentDate->getMonthName(month); } - const ESM::RefId& World::getCellName(const MWWorld::CellStore* cell) const + std::string_view World::getCellName(const MWWorld::CellStore* cell) const { if (!cell) cell = mWorldScene->getCurrentCell(); return getCellName(cell->getCell()); } - const ESM::RefId World::getCellName(const ESM::Cell* cell) const + std::string_view World::getCellName(const ESM::Cell* cell) const { if (cell) { if (!cell->isExterior() || !cell->mName.empty()) - return cell->mName; + return cell->mName.getRefIdString(); if (const ESM::Region* region = mStore.get().search(cell->mRegion)) - return ESM::RefId::stringRefId(region->mName); + return region->mName; } - return ESM::RefId::stringRefId(mStore.get().find("sDefaultCellname")->mValue.getString()); + + return mStore.get().find("sDefaultCellname")->mValue.getString(); } void World::removeRefScript(MWWorld::RefData* ref) @@ -1422,7 +1423,7 @@ namespace MWWorld esmPos.pos[0] = traced.x(); esmPos.pos[1] = traced.y(); esmPos.pos[2] = traced.z(); - const ESM::RefId* cell; + const ESM::RefId* cell = &ESM::RefId::sEmpty; if (!actor.getCell()->isExterior()) cell = &actor.getCell()->getCell()->mName; MWWorld::ActionTeleport(*cell, esmPos, false).execute(actor); @@ -3430,7 +3431,7 @@ namespace MWWorld return; } - const ESM::RefId* cellName; + const ESM::RefId* cellName = &ESM::RefId::sEmpty; if (!closestMarker.mCell->isExterior()) cellName = &closestMarker.mCell->getCell()->mName; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index d833438978..3a1759e595 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -267,12 +267,12 @@ namespace MWWorld char getGlobalVariableType(std::string_view name) const override; ///< Return ' ', if there is no global variable with this name. - const ESM::RefId& getCellName(const MWWorld::CellStore* cell = nullptr) const override; + std::string_view getCellName(const MWWorld::CellStore* cell = nullptr) const override; ///< Return name of the cell. /// /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. - const ESM::RefId getCellName(const ESM::Cell* cell) const override; + std::string_view getCellName(const ESM::Cell* cell) const override; void removeRefScript(MWWorld::RefData* ref) override; //< Remove the script attached to ref from mLocalScripts diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index a39f049c4f..85ab83cda3 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -65,7 +65,7 @@ MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell) auto result = mInteriors.find(cell->mName); if (result == mInteriors.end()) - result = mInteriors.emplace(std::move(cell->mName), CellStore(cell, mStore, mReaders)).first; + result = mInteriors.emplace(cell->mName, CellStore(cell, mStore, mReaders)).first; return &result->second; } diff --git a/components/esm/refid.cpp b/components/esm/refid.cpp index 488c54f37e..ec18c4c642 100644 --- a/components/esm/refid.cpp +++ b/components/esm/refid.cpp @@ -18,7 +18,7 @@ namespace ESM bool RefId::operator>(const RefId& rhs) const { - return Misc::StringUtils::ciMore(mId, rhs.mId); + return Misc::StringUtils::ciGreater(mId, rhs.mId); } std::ostream& operator<<(std::ostream& os, const RefId& refId) diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index f2eb91c05c..8141058da7 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -20,14 +20,14 @@ namespace Misc::StringUtils return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharLess()); } - struct CiCharMore + struct CiCharGreater { bool operator()(char x, char y) const { return toLower(x) > toLower(y); } }; - inline bool ciMore(std::string_view x, std::string_view y) + inline bool ciGreater(std::string_view x, std::string_view y) { - return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharMore()); + return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharGreater()); } inline bool ciEqual(std::string_view x, std::string_view y)