1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-12 17:43:05 +00:00

Renamed string => Id, makes more sense considering the new underlying type

Fixes unnecessary copies, and issues with case sensitive comparisons.

fixed modification that wasn't necessary

Fixed type mismatch, and unecessary copy
This commit is contained in:
florent.teppe 2022-11-16 00:07:33 +01:00
parent 30a020883e
commit 0f3499f504
15 changed files with 55 additions and 47 deletions

View file

@ -111,7 +111,7 @@ namespace ESSImport
bool isDeleted = false;
npc.load(esm, isDeleted);
if (npc.mId != ESM::RefId::stringRefId("player"))
if (npc.mId != "player")
{
// Handles changes to the NPC struct, but since there is no index here
// it will apply to ALL instances of the class. seems to be the reason for the

View file

@ -68,7 +68,7 @@ bool CSMDoc::SavingState::isProjectFile() const
return mProjectFile;
}
std::map<std::string, std::deque<int>>& CSMDoc::SavingState::getSubRecords()
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp>& CSMDoc::SavingState::getSubRecords()
{
return mSubRecords;
}

View file

@ -9,8 +9,8 @@
#include <components/esm3/esmwriter.hpp>
#include <components/misc/algorithm.hpp>
#include <components/to_utf8/to_utf8.hpp>
namespace CSMDoc
{
class Operation;
@ -26,7 +26,7 @@ namespace CSMDoc
ESM::ESMWriter mWriter;
std::filesystem::path mProjectPath;
bool mProjectFile;
std::map<std::string, std::deque<int>> mSubRecords; // record ID, list of subrecords
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp> mSubRecords; // record ID, list of subrecords
public:
SavingState(Operation& operation, std::filesystem::path projectPath, ToUTF8::FromType encoding);
@ -47,7 +47,7 @@ namespace CSMDoc
bool isProjectFile() const;
///< Currently saving project file? (instead of content file)
std::map<std::string, std::deque<int>>& getSubRecords();
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp>& getSubRecords();
};
}

View file

@ -2098,30 +2098,30 @@ namespace CSMWorld
void set(Record<ESXRecordT>& record, const QVariant& data) override
{
ESM::RefId* string = nullptr;
ESM::RefId* id = nullptr;
ESXRecordT record2 = record.get();
switch (this->mColumnId)
{
case Columns::ColumnId_CastingObject:
string = &record2.mCasting;
id = &record2.mCasting;
break;
case Columns::ColumnId_HitObject:
string = &record2.mHit;
id = &record2.mHit;
break;
case Columns::ColumnId_AreaObject:
string = &record2.mArea;
id = &record2.mArea;
break;
case Columns::ColumnId_BoltObject:
string = &record2.mBolt;
id = &record2.mBolt;
break;
}
if (!string)
if (!id)
throw std::logic_error("Unsupported column ID");
*string = ESM::RefId::stringRefId(data.toString().toUtf8().constData());
*id = ESM::RefId::stringRefId(data.toString().toUtf8().constData());
record.setModified(record2);
}
@ -2141,56 +2141,56 @@ namespace CSMWorld
QVariant get(const Record<ESXRecordT>& record) const override
{
const ESM::RefId* string = nullptr;
const ESM::RefId* id = nullptr;
switch (this->mColumnId)
{
case Columns::ColumnId_CastingSound:
string = &record.get().mCastSound;
id = &record.get().mCastSound;
break;
case Columns::ColumnId_HitSound:
string = &record.get().mHitSound;
id = &record.get().mHitSound;
break;
case Columns::ColumnId_AreaSound:
string = &record.get().mAreaSound;
id = &record.get().mAreaSound;
break;
case Columns::ColumnId_BoltSound:
string = &record.get().mBoltSound;
id = &record.get().mBoltSound;
break;
}
if (!string)
if (!id)
throw std::logic_error("Unsupported column ID");
return QString::fromUtf8(string->getRefIdString().c_str());
return QString::fromUtf8(id->getRefIdString().c_str());
}
void set(Record<ESXRecordT>& record, const QVariant& data) override
{
ESM::RefId* string = nullptr;
ESM::RefId* id = nullptr;
ESXRecordT record2 = record.get();
switch (this->mColumnId)
{
case Columns::ColumnId_CastingSound:
string = &record2.mCastSound;
id = &record2.mCastSound;
break;
case Columns::ColumnId_HitSound:
string = &record2.mHitSound;
id = &record2.mHitSound;
break;
case Columns::ColumnId_AreaSound:
string = &record2.mAreaSound;
id = &record2.mAreaSound;
break;
case Columns::ColumnId_BoltSound:
string = &record2.mBoltSound;
id = &record2.mBoltSound;
break;
}
if (!string)
if (!id)
throw std::logic_error("Unsupported column ID");
*string = ESM::RefId::stringRefId(data.toString().toUtf8().constData());
*id = ESM::RefId::stringRefId(data.toString().toUtf8().constData());
record.setModified(record2);
}

View file

@ -290,7 +290,8 @@ void CSMWorld::CommandDispatcher::executeExtendedDelete()
if (record.mState == RecordBase::State_Deleted)
continue;
if (!std::binary_search(mSelection.begin(), mSelection.end(), record.get().mCell.getRefIdString()))
if (!std::binary_search(mSelection.begin(), mSelection.end(),
Misc::StringUtils::lowerCase(record.get().mCell.getRefIdString())))
continue;
macro.push(new CSMWorld::DeleteCommand(model, record.get().mId.getRefIdString()));
@ -320,7 +321,8 @@ void CSMWorld::CommandDispatcher::executeExtendedRevert()
{
const Record<CellRef>& record = collection.getRecord(i);
if (!std::binary_search(mSelection.begin(), mSelection.end(), record.get().mCell.getRefIdString()))
if (!std::binary_search(mSelection.begin(), mSelection.end(),
Misc::StringUtils::lowerCase(record.get().mCell.getRefIdString())))
continue;
macro.push(new CSMWorld::RevertCommand(model, record.get().mId.getRefIdString()));

View file

@ -33,6 +33,7 @@
#include <components/esm3/loadspel.hpp>
#include <components/esm3/loadsscr.hpp>
#include <components/files/multidircollection.hpp>
#include <components/misc/algorithm.hpp>
#include <components/to_utf8/to_utf8.hpp>
#include "cell.hpp"
@ -122,7 +123,7 @@ namespace CSMWorld
const ESM::Dialogue* mDialogue; // last loaded dialogue
bool mBase;
bool mProject;
std::map<std::string, std::map<unsigned int, unsigned int>> mRefLoadCache;
std::map<std::string, std::map<unsigned int, unsigned int>, Misc::StringUtils::CiComp> mRefLoadCache;
int mReaderIndex;
bool mFsStrict;

View file

@ -131,7 +131,7 @@ void CSMWorld::ScriptContext::clear()
bool CSMWorld::ScriptContext::clearLocals(const std::string& script)
{
std::map<std::string, Compiler::Locals>::iterator iter = mLocals.find(Misc::StringUtils::lowerCase(script));
std::map<std::string, Compiler::Locals>::iterator iter = mLocals.find(script);
if (iter != mLocals.end())
{

View file

@ -8,6 +8,7 @@
#include <components/compiler/context.hpp>
#include <components/compiler/locals.hpp>
#include <components/misc/algorithm.hpp>
namespace CSMWorld
{
@ -18,7 +19,7 @@ namespace CSMWorld
const Data& mData;
mutable std::vector<ESM::RefId> mIds;
mutable bool mIdsUpdated;
mutable std::map<std::string, Compiler::Locals> mLocals;
mutable std::map<std::string, Compiler::Locals, Misc::StringUtils::CiComp> mLocals;
public:
ScriptContext(const Data& data);

View file

@ -95,7 +95,7 @@ bool CSVRender::Cell::addObjects(int start, int end)
for (int i = start; i <= end; ++i)
{
auto cellId = collection.getRecord(i).get().mCell;
const auto& cellId = collection.getRecord(i).get().mCell;
CSMWorld::RecordBase::State state = collection.getRecord(i).mState;

View file

@ -12,6 +12,7 @@
#include "../../model/world/cellcoordinates.hpp"
#include "instancedragmodes.hpp"
#include <components/esm/refid.hpp>
#include <components/misc/algorithm.hpp>
class QModelIndex;
@ -47,7 +48,7 @@ namespace CSVRender
CSMWorld::Data& mData;
ESM::RefId mId;
osg::ref_ptr<osg::Group> mCellNode;
std::map<std::string, Object*> mObjects;
std::map<std::string, Object*, Misc::StringUtils::CiComp> mObjects;
std::unique_ptr<Terrain::TerrainGrid> mTerrain;
CSMWorld::CellCoordinates mCoordinates;
std::unique_ptr<CellArrow> mCellArrows[4];

View file

@ -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 std::string& 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 std::string& 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
@ -660,7 +660,8 @@ namespace MWBase
virtual DetourNavigator::Navigator* getNavigator() const = 0;
virtual void updateActorPath(const MWWorld::ConstPtr& actor, const std::deque<osg::Vec3f>& path,
const DetourNavigator::AgentBounds& agentBounds, const osg::Vec3f& start, const osg::Vec3f& end) const = 0;
const DetourNavigator::AgentBounds& agentBounds, const osg::Vec3f& start, const osg::Vec3f& end) const
= 0;
virtual void removeActorPath(const MWWorld::ConstPtr& actor) const = 0;
@ -669,10 +670,12 @@ namespace MWBase
virtual DetourNavigator::AgentBounds getPathfindingAgentBounds(const MWWorld::ConstPtr& actor) const = 0;
virtual bool hasCollisionWithDoor(
const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const = 0;
const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const
= 0;
virtual bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius,
std::span<const MWWorld::ConstPtr> ignore, std::vector<MWWorld::Ptr>* occupyingActors = nullptr) const = 0;
std::span<const MWWorld::ConstPtr> ignore, std::vector<MWWorld::Ptr>* occupyingActors = nullptr) const
= 0;
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0;

View file

@ -792,9 +792,9 @@ namespace MWGui
int incr = next ? 1 : -1;
bool found = false;
ESM::RefId lastId;
const ESM::RefId* lastId = nullptr;
if (selected != -1)
lastId = model.getItem(selected).mBase.getCellRef().getRefId();
lastId = &model.getItem(selected).mBase.getCellRef().getRefId();
ItemModel::ModelIndex cycled = selected;
for (unsigned int i = 0; i < model.getItemCount(); ++i)
{
@ -805,10 +805,10 @@ namespace MWGui
// skip different stacks of the same item, or we will get stuck as stacking/unstacking them may change their
// relative ordering
if (lastId == item.getCellRef().getRefId())
if (*lastId == item.getCellRef().getRefId())
continue;
lastId = item.getCellRef().getRefId();
lastId = &item.getCellRef().getRefId();
if (item.getClass().getType() == ESM::Weapon::sRecordId && isRightHandWeapon(item)
&& item.getClass().canBeEquipped(item, player).first)

View file

@ -933,7 +933,7 @@ namespace MWGui
{
mMap->requestMapRender(cell);
std::string name = MWBase::Environment::get().getWorld()->getCellName(cell);
std::string name = std::string(MWBase::Environment::get().getWorld()->getCellName(cell));
mMap->setCellName(name);
mHud->setCellName(name);

View file

@ -655,14 +655,14 @@ namespace MWWorld
return mCurrentDate->getMonthName(month);
}
const std::string& 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 std::string& World::getCellName(const ESM::Cell* cell) const
std::string_view World::getCellName(const ESM::Cell* cell) const
{
if (cell)
{

View file

@ -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 std::string& 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 std::string& 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