mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:09:39 +00:00
Avoid redundant conversion from RefId to string and back
This commit is contained in:
parent
191f207e78
commit
d03bec60e9
4 changed files with 27 additions and 15 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <osg/Vec3d>
|
#include <osg/Vec3d>
|
||||||
|
|
||||||
|
#include <components/esm/refid.hpp>
|
||||||
#include <components/esm3/loadland.hpp>
|
#include <components/esm3/loadland.hpp>
|
||||||
#include <components/misc/constants.hpp>
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
|
@ -59,6 +60,11 @@ bool CSMWorld::CellCoordinates::isExteriorCell(const std::string& id)
|
||||||
return (!id.empty() && id[0] == '#');
|
return (!id.empty() && id[0] == '#');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSMWorld::CellCoordinates::isExteriorCell(const ESM::RefId& id)
|
||||||
|
{
|
||||||
|
return id.startsWith("#");
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<CSMWorld::CellCoordinates, bool> CSMWorld::CellCoordinates::fromId(const std::string& id)
|
std::pair<CSMWorld::CellCoordinates, bool> CSMWorld::CellCoordinates::fromId(const std::string& id)
|
||||||
{
|
{
|
||||||
// no worldspace for now, needs to be changed for 1.1
|
// no worldspace for now, needs to be changed for 1.1
|
||||||
|
|
|
@ -12,6 +12,11 @@ namespace osg
|
||||||
class Vec3d;
|
class Vec3d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
class RefId;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class CellCoordinates
|
class CellCoordinates
|
||||||
|
@ -41,6 +46,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
static bool isExteriorCell(const std::string& id);
|
static bool isExteriorCell(const std::string& id);
|
||||||
|
|
||||||
|
static bool isExteriorCell(const ESM::RefId& id);
|
||||||
|
|
||||||
/// \return first: CellCoordinates (or 0, 0 if cell does not have coordinates),
|
/// \return first: CellCoordinates (or 0, 0 if cell does not have coordinates),
|
||||||
/// second: is cell paged?
|
/// second: is cell paged?
|
||||||
///
|
///
|
||||||
|
|
|
@ -91,10 +91,10 @@ namespace CSMWorld
|
||||||
///
|
///
|
||||||
/// \return Success?
|
/// \return Success?
|
||||||
|
|
||||||
int cloneRecordImp(const std::string& origin, const std::string& dest, UniversalId::Type type);
|
int cloneRecordImp(const ESM::RefId& origin, const ESM::RefId& dest, UniversalId::Type type);
|
||||||
///< Returns the index of the clone.
|
///< Returns the index of the clone.
|
||||||
|
|
||||||
int touchRecordImp(const std::string& id);
|
int touchRecordImp(const ESM::RefId& id);
|
||||||
///< Returns the index of the record on success, -1 on failure.
|
///< Returns the index of the record on success, -1 on failure.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -227,29 +227,28 @@ namespace CSMWorld
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT>::cloneRecordImp(
|
int Collection<ESXRecordT>::cloneRecordImp(
|
||||||
const std::string& origin, const std::string& destination, UniversalId::Type type)
|
const ESM::RefId& origin, const ESM::RefId& destination, UniversalId::Type type)
|
||||||
{
|
{
|
||||||
auto copy = std::make_unique<Record<ESXRecordT>>();
|
auto copy = std::make_unique<Record<ESXRecordT>>();
|
||||||
copy->mModified = getRecord(ESM::RefId::stringRefId(origin)).get();
|
copy->mModified = getRecord(origin).get();
|
||||||
copy->mState = RecordBase::State_ModifiedOnly;
|
copy->mState = RecordBase::State_ModifiedOnly;
|
||||||
setRecordId(ESM::RefId::stringRefId(destination), copy->get());
|
setRecordId(destination, copy->get());
|
||||||
|
|
||||||
if (type == UniversalId::Type_Reference)
|
if (type == UniversalId::Type_Reference)
|
||||||
{
|
{
|
||||||
CSMWorld::CellRef* ptr = (CSMWorld::CellRef*)©->mModified;
|
CSMWorld::CellRef* ptr = (CSMWorld::CellRef*)©->mModified;
|
||||||
ptr->mRefNum.mIndex = 0;
|
ptr->mRefNum.mIndex = 0;
|
||||||
}
|
}
|
||||||
ESM::RefId destinationRefId = ESM::RefId::stringRefId(destination);
|
const int index = getAppendIndex(destination, type);
|
||||||
int index = getAppendIndex(destinationRefId, type);
|
insertRecord(std::move(copy), getAppendIndex(destination, type));
|
||||||
insertRecord(std::move(copy), getAppendIndex(destinationRefId, type));
|
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT>::touchRecordImp(const std::string& id)
|
int Collection<ESXRecordT>::touchRecordImp(const ESM::RefId& id)
|
||||||
{
|
{
|
||||||
int index = getIndex(ESM::RefId::stringRefId(id));
|
const int index = getIndex(id);
|
||||||
Record<ESXRecordT>& record = *mRecords.at(index);
|
Record<ESXRecordT>& record = *mRecords.at(index);
|
||||||
if (record.isDeleted())
|
if (record.isDeleted())
|
||||||
{
|
{
|
||||||
|
@ -269,27 +268,27 @@ namespace CSMWorld
|
||||||
void Collection<ESXRecordT>::cloneRecord(
|
void Collection<ESXRecordT>::cloneRecord(
|
||||||
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
||||||
{
|
{
|
||||||
cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
|
cloneRecordImp(origin, destination, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void Collection<Land>::cloneRecord(
|
inline void Collection<Land>::cloneRecord(
|
||||||
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
||||||
{
|
{
|
||||||
int index = cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
|
const int index = cloneRecordImp(origin, destination, type);
|
||||||
mRecords.at(index)->get().setPlugin(0);
|
mRecords.at(index)->get().setPlugin(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
bool Collection<ESXRecordT>::touchRecord(const ESM::RefId& id)
|
bool Collection<ESXRecordT>::touchRecord(const ESM::RefId& id)
|
||||||
{
|
{
|
||||||
return touchRecordImp(id.getRefIdString()) != -1;
|
return touchRecordImp(id) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline bool Collection<Land>::touchRecord(const ESM::RefId& id)
|
inline bool Collection<Land>::touchRecord(const ESM::RefId& id)
|
||||||
{
|
{
|
||||||
int index = touchRecordImp(id.getRefIdString());
|
const int index = touchRecordImp(id);
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
mRecords.at(index)->get().setPlugin(0);
|
mRecords.at(index)->get().setPlugin(0);
|
||||||
|
|
|
@ -737,7 +737,7 @@ void CSVRender::Object::apply(CSMWorld::CommandMacro& commands)
|
||||||
// Do cell check first so positions can be compared
|
// Do cell check first so positions can be compared
|
||||||
const CSMWorld::CellRef& ref = collection.getRecord(recordIndex).get();
|
const CSMWorld::CellRef& ref = collection.getRecord(recordIndex).get();
|
||||||
|
|
||||||
if (CSMWorld::CellCoordinates::isExteriorCell(ref.mCell.getRefIdString()))
|
if (CSMWorld::CellCoordinates::isExteriorCell(ref.mCell))
|
||||||
{
|
{
|
||||||
// Find cell index at new position
|
// Find cell index at new position
|
||||||
std::pair<int, int> cellIndex
|
std::pair<int, int> cellIndex
|
||||||
|
|
Loading…
Reference in a new issue