Get Rid of ESM::CellId almost everywhere

it was a competing concept from using RefIds for cell.
There is almost no point to it now, except to load older data.
depth-refraction
florent.teppe 2 years ago
parent fb6701ac1a
commit c2182c2fcc

@ -2,6 +2,7 @@
#include <cmath>
#include <components/esm3/loadcell.hpp>
#include <components/misc/constants.hpp>
#include <components/misc/strings/lower.hpp>
@ -60,20 +61,19 @@ namespace ESSImport
const PCDT::PNAM::MarkLocation& mark = pcdt.mPNAM.mMarkLocation;
ESM::CellId cell;
cell.mPaged = true;
cell.mIndex.mX = mark.mCellX;
cell.mIndex.mY = mark.mCellY;
ESM::RefId cell;
// TODO: Figure out a better way to detect interiors. (0, 0) is a valid exterior cell.
if (mark.mCellX == 0 && mark.mCellY == 0)
{
cell.mWorldspace = pcdt.mMNAM;
cell.mPaged = false;
cell = ESM::RefId::stringRefId(pcdt.mMNAM);
}
else
{
cell = ESM::Cell::generateIdForExteriorCell(mark.mCellX, mark.mCellY);
}
out.mMarkedCell = cell.getCellRefId();
out.mMarkedCell = cell;
out.mMarkedPosition.pos[0] = mark.mX;
out.mMarkedPosition.pos[1] = mark.mY;
out.mMarkedPosition.pos[2] = mark.mZ;

@ -419,8 +419,13 @@ namespace ESSImport
= static_cast<int>(std::floor(context.mPlayer.mObject.mPosition.pos[1] / Constants::CellSizeInUnits));
cellId.mIndex.mX = cellX;
cellId.mIndex.mY = cellY;
context.mPlayer.mCellId = ESM::Cell::generateIdForExteriorCell(cellX, cellY);
}
else
{
context.mPlayer.mCellId = ESM::RefId::stringRefId(cellId.mWorldspace);
}
context.mPlayer.mCellId = cellId.getCellRefId();
context.mPlayer.save(writer);
writer.endRecord(ESM::REC_PLAY);

@ -6,6 +6,7 @@
#include <components/esm3/controlsstate.hpp>
#include <components/esm3/dialoguestate.hpp>
#include <components/esm3/globalmap.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadnpc.hpp>
#include <components/esm3/player.hpp>
@ -59,10 +60,7 @@ namespace ESSImport
, mHour(0.f)
, mNextActorId(0)
{
ESM::CellId playerCellId;
playerCellId.mPaged = true;
playerCellId.mIndex.mX = playerCellId.mIndex.mY = 0;
mPlayer.mCellId = playerCellId.getCellRefId();
mPlayer.mCellId = ESM::Cell::generateIdForExteriorCell(0, 0);
mPlayer.mLastKnownExteriorPosition[0] = mPlayer.mLastKnownExteriorPosition[1]
= mPlayer.mLastKnownExteriorPosition[2] = 0.0f;
mPlayer.mHasMark = 0;

@ -264,7 +264,7 @@ namespace NavMeshTool
const osg::Vec2i cellPosition(cell.mData.mX, cell.mData.mY);
const std::size_t cellObjectsBegin = data.mObjects.size();
const auto cellNameLowerCase
= Misc::StringUtils::lowerCase(cell.isExterior() ? ESM::CellId::sDefaultWorldspace : cell.mName);
= Misc::StringUtils::lowerCase(cell.isExterior() ? ESM::Cell::sDefaultWorldspace : cell.mName);
WorldspaceNavMeshInput& navMeshInput = [&]() -> WorldspaceNavMeshInput& {
auto it = navMeshInputs.find(cellNameLowerCase);
if (it == navMeshInputs.end())

@ -16,7 +16,7 @@
#include <apps/opencs/model/world/record.hpp>
#include <apps/opencs/model/world/universalid.hpp>
#include <components/esm3/cellid.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/misc/strings/lower.hpp>
#include "collectionbase.hpp"
@ -337,7 +337,7 @@ std::pair<CSMWorld::UniversalId, std::string> CSMWorld::IdTable::view(int row) c
return std::make_pair(UniversalId::Type_None, "");
if (id[0] == '#')
id = ESM::CellId::sDefaultWorldspace;
id = ESM::Cell::sDefaultWorldspace;
return std::make_pair(UniversalId(UniversalId::Type_Scene, id), hint);
}

@ -307,7 +307,7 @@ void CSVWorld::RegionMap::view()
}
emit editRequest(
CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::CellId::sDefaultWorldspace), hint.str());
CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::Cell::sDefaultWorldspace), hint.str());
}
void CSVWorld::RegionMap::viewInTable()

@ -49,7 +49,7 @@ CSVWorld::SceneSubView::SceneSubView(const CSMWorld::UniversalId& id, CSMDoc::Do
CSVRender::WorldspaceWidget* worldspaceWidget = nullptr;
widgetType whatWidget;
if (Misc::StringUtils::ciEqual(id.getId(), ESM::CellId::sDefaultWorldspace))
if (Misc::StringUtils::ciEqual(id.getId(), ESM::Cell::sDefaultWorldspace))
{
whatWidget = widget_Paged;
@ -170,7 +170,7 @@ void CSVWorld::SceneSubView::cellSelectionChanged(const CSMWorld::UniversalId& i
void CSVWorld::SceneSubView::cellSelectionChanged(const CSMWorld::CellSelection& selection)
{
setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::CellId::sDefaultWorldspace));
setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::Cell::sDefaultWorldspace));
int size = selection.getSize();
std::ostringstream stream;

@ -351,12 +351,17 @@ namespace MWGui
{
for (int dY = -mCellDistance; dY <= mCellDistance; ++dY)
{
ESM::CellId cellId;
cellId.mPaged = !mInterior;
cellId.mWorldspace = (mInterior ? mPrefix : ESM::CellId::sDefaultWorldspace);
cellId.mIndex.mX = mCurX + dX;
cellId.mIndex.mY = mCurY + dY;
ESM::RefId cellRefId = cellId.getCellRefId();
ESM::RefId cellRefId;
if (mInterior)
{
cellRefId = ESM::RefId::stringRefId(mPrefix);
}
else
{
cellRefId = ESM::Cell::generateIdForExteriorCell(mCurX + dX, mCurY + dY);
}
CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(cellRefId);
for (CustomMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second;
++it)
@ -885,18 +890,17 @@ namespace MWGui
mEditingMarker.mWorldX = worldPos.x();
mEditingMarker.mWorldY = worldPos.y();
ESM::CellId clickedId;
ESM::RefId clickedId;
clickedId.mPaged = !mInterior;
if (mInterior)
clickedId.mWorldspace = LocalMapBase::mPrefix;
{
clickedId = ESM::RefId::stringRefId(LocalMapBase::mPrefix);
}
else
{
clickedId.mWorldspace = ESM::CellId::sDefaultWorldspace;
clickedId.mIndex.mX = x;
clickedId.mIndex.mY = y;
clickedId = ESM::Cell::generateIdForExteriorCell(x, y);
}
mEditingMarker.mCell = clickedId.getCellRefId();
mEditingMarker.mCell = clickedId;
mEditNoteDialog.setVisible(true);
mEditNoteDialog.showDeleteButton(false);
@ -1122,12 +1126,7 @@ namespace MWGui
void MapWindow::setGlobalMapMarkerTooltip(MyGUI::Widget* markerWidget, int x, int y)
{
ESM::CellId cellId;
cellId.mIndex.mX = x;
cellId.mIndex.mY = y;
cellId.mWorldspace = ESM::CellId::sDefaultWorldspace;
cellId.mPaged = true;
ESM::RefId cellRefId = cellId.getCellRefId();
ESM::RefId cellRefId = ESM::Cell::generateIdForExteriorCell(x, y);
CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(cellRefId);
std::vector<std::string> destNotes;
for (CustomMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second; ++it)

@ -195,15 +195,19 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
MWBase::Environment::get().getWindowManager()->fadeScreenOut(1);
ESM::CellId cellId;
ESM::RefId cellId;
osg::Vec2i posCell = MWWorld::positionToCellIndex(pos.pos[0], pos.pos[1]);
cellId.mPaged = !interior;
cellId.mWorldspace = Misc::StringUtils::lowerCase(cellname);
cellId.mIndex.mX = posCell.x();
cellId.mIndex.mY = posCell.y();
if (interior)
{
cellId = ESM::RefId::stringRefId(cellname);
}
else
{
cellId = ESM::Cell::generateIdForExteriorCell(posCell.x(), posCell.y());
}
// Teleports any followers, too.
MWWorld::ActionTeleport action(cellId.getCellRefId(), pos, true);
MWWorld::ActionTeleport action(cellId, pos, true);
action.execute(player);
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0);

@ -40,7 +40,7 @@ namespace MWWorld
, mNameID(cell.mName)
, mRegion(cell.mRegion)
, mId(cell.mId)
, mParent(ESM::RefId::stringRefId(ESM::CellId::sDefaultWorldspace))
, mParent(ESM::RefId::stringRefId(ESM::Cell::sDefaultWorldspace))
, mMood{
.mAmbiantColor = cell.mAmbi.mAmbient,
.mDirectionalColor = cell.mAmbi.mSunlight,

@ -3,7 +3,7 @@
#include <cassert>
#include <components/debug/debuglog.hpp>
#include <components/esm3/cellid.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/esm3/objectstate.hpp>
#include <apps/openmw/mwworld/cellutils.hpp>
@ -90,11 +90,7 @@ namespace MWWorld
else
{
const osg::Vec2i index = positionToCellIndex(ref.mDoorDest.pos[0], ref.mDoorDest.pos[1]);
ESM::CellId cellId;
cellId.mPaged = true;
cellId.mIndex.mX = index.x();
cellId.mIndex.mY = index.y();
return cellId.getCellRefId();
return ESM::Cell::generateIdForExteriorCell(index.x(), index.y());
}
};

@ -380,10 +380,8 @@ namespace MWWorld
pos.rot[2] = 0;
osg::Vec2i exteriorCellPos = positionToCellIndex(pos.pos[0], pos.pos[1]);
ESM::CellId cellId;
cellId.mPaged = true;
cellId.mIndex = { exteriorCellPos.x(), exteriorCellPos.y() };
mWorldScene->changeToExteriorCell(cellId.getCellRefId(), pos, true);
ESM::RefId cellId = ESM::Cell::generateIdForExteriorCell(exteriorCellPos.x(), exteriorCellPos.y());
mWorldScene->changeToExteriorCell(cellId, pos, true);
}
}
@ -979,7 +977,7 @@ namespace MWWorld
mPhysics->clearQueuedMovement();
mDiscardMovements = true;
if (changeEvent && mCurrentWorldSpace != ESM::CellId::sDefaultWorldspace)
if (changeEvent && mCurrentWorldSpace != ESM::Cell::sDefaultWorldspace)
{
// changed worldspace
mProjectileManager->clear();
@ -987,10 +985,8 @@ namespace MWWorld
}
removeContainerScripts(getPlayerPtr());
osg::Vec2i exteriorCellPos = positionToCellIndex(position.pos[0], position.pos[1]);
ESM::CellId cellId;
cellId.mPaged = true;
cellId.mIndex = { exteriorCellPos.x(), exteriorCellPos.y() };
mWorldScene->changeToExteriorCell(cellId.getCellRefId(), position, adjustPlayerPos, changeEvent);
ESM::RefId cellId = ESM::Cell::generateIdForExteriorCell(exteriorCellPos.x(), exteriorCellPos.y());
mWorldScene->changeToExteriorCell(cellId, position, adjustPlayerPos, changeEvent);
addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell());
mRendering->getCamera()->instantTransition();
}

@ -448,10 +448,7 @@ namespace
refId = RecordType::indexToRefId(index);
else if constexpr (std::is_same_v<RecordType, ESM::Cell>)
{
ESM::CellId cellId;
cellId.mPaged = true;
cellId.mIndex = { 0, 0 };
refId = cellId.getCellRefId();
refId = ESM::Cell::generateIdForExteriorCell(0, 0);
}
else
refId = ESM::StringRefId(stringId);

@ -7,8 +7,6 @@
namespace ESM
{
const std::string CellId::sDefaultWorldspace = "sys::default";
void CellId::load(ESMReader& esm)
{
mWorldspace = esm.getHNString("SPAC");
@ -34,18 +32,6 @@ namespace ESM
esm.writeHNT("CIDX", mIndex, 8);
}
ESM::RefId CellId::getCellRefId() const
{
if (mPaged)
{
return ESM::RefId::stringRefId("#" + std::to_string(mIndex.mX) + "," + std::to_string(mIndex.mY));
}
else
{
return ESM::RefId::stringRefId(mWorldspace);
}
}
CellId CellId::extractFromRefId(const ESM::RefId& id)
{
// This is bad and that code should not be merged.

@ -21,11 +21,8 @@ namespace ESM
CellIndex mIndex;
bool mPaged;
static const std::string sDefaultWorldspace;
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
ESM::RefId getCellRefId() const;
// TODO tetramir: this probably shouldn't exist, needs it because some CellIds are saved on disk
static CellId extractFromRefId(const ESM::RefId& id);

@ -4,6 +4,7 @@
#include "savedgame.hpp"
#include <components/esm3/cellid.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/files/conversion.hpp>
#include <components/files/openfile.hpp>
#include <components/misc/strings/algorithm.hpp>
@ -93,7 +94,14 @@ namespace ESM
{
ESM::CellId cellId;
cellId.load(*this);
return cellId.getCellRefId();
if (cellId.mPaged)
{
return ESM::Cell::generateIdForExteriorCell(cellId.mIndex.mX, cellId.mIndex.mY);
}
else
{
return ESM::RefId::stringRefId(cellId.mWorldspace);
}
}
return getHNRefId("NAME");
}

@ -40,6 +40,8 @@ namespace ESM
namespace ESM
{
const std::string Cell::sDefaultWorldspace = "sys::default";
// Some overloaded compare operators.
bool operator==(const MovedCellRef& ref, const RefNum& refNum)
{
@ -59,26 +61,23 @@ namespace ESM
const ESM::RefId& Cell::updateId()
{
CellId cellid;
cellid.mPaged = !(mData.mFlags & Interior);
if (cellid.mPaged)
if (mData.mFlags & Interior)
{
cellid.mWorldspace = CellId::sDefaultWorldspace;
cellid.mIndex.mX = mData.mX;
cellid.mIndex.mY = mData.mY;
mId = ESM::RefId::stringRefId(mName);
}
else
{
cellid.mWorldspace = Misc::StringUtils::lowerCase(mName);
cellid.mIndex.mX = 0;
cellid.mIndex.mY = 0;
mId = generateIdForExteriorCell(getGridX(), getGridY());
}
mId = cellid.getCellRefId();
return mId;
}
ESM::RefId Cell::generateIdForExteriorCell(int x, int y)
{
return ESM::RefId::stringRefId("#" + std::to_string(x) + "," + std::to_string(y));
}
void Cell::loadNameAndData(ESMReader& esm, bool& isDeleted)
{
isDeleted = false;

@ -67,6 +67,8 @@ namespace ESM
*/
struct Cell
{
static const std::string sDefaultWorldspace;
constexpr static RecNameInts sRecordId = REC_CELL;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
@ -191,6 +193,8 @@ namespace ESM
///< Set record to default state (does not touch the ID/index).
const ESM::RefId& updateId();
static ESM::RefId generateIdForExteriorCell(int x, int y);
};
}
#endif

Loading…
Cancel
Save