functions return reference instead of ptr

because the function can never return an nullptr, we return a reference.
7344-support-launching-the-example-suite
florent.teppe 2 years ago
parent 2a6e301925
commit 53cc9f3614

@ -300,7 +300,7 @@ namespace MWClass
std::string Door::getDestination(const MWWorld::LiveCellRef<ESM::Door>& door)
{
std::string_view dest = MWBase::Environment::get().getWorld()->getCellName(
MWBase::Environment::get().getWorldModel()->getCell(door.mRef.getDestCell()));
&MWBase::Environment::get().getWorldModel()->getCell(door.mRef.getDestCell()));
return "#{sCell=" + std::string{ dest } + "}";
}

@ -584,7 +584,7 @@ namespace MWGui
{
if (!mInterior)
requestMapRender(
MWBase::Environment::get().getWorldModel()->getExterior(entry.mCellX, entry.mCellY));
&MWBase::Environment::get().getWorldModel()->getExterior(entry.mCellX, entry.mCellY));
osg::ref_ptr<osg::Texture2D> texture = mLocalMapRender->getMapTexture(entry.mCellX, entry.mCellY);
if (texture)
@ -633,7 +633,7 @@ namespace MWGui
for (MyGUI::Widget* widget : mExteriorDoorMarkerWidgets)
widget->setVisible(false);
MWWorld::CellStore* cell = worldModel->getInterior(mPrefix);
MWWorld::CellStore* cell = &worldModel->getInterior(mPrefix);
world->getDoorMarkers(cell, doors);
}
else
@ -641,7 +641,7 @@ namespace MWGui
for (MapEntry& entry : mMaps)
{
if (!entry.mMapTexture && !widgetCropped(entry.mMapWidget, mLocalMap))
world->getDoorMarkers(worldModel->getExterior(entry.mCellX, entry.mCellY), doors);
world->getDoorMarkers(&worldModel->getExterior(entry.mCellX, entry.mCellY), doors);
}
if (doors.empty())
return;

@ -130,9 +130,9 @@ namespace MWGui
= MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]);
if (cellname.empty())
{
MWWorld::CellStore* cell
MWWorld::CellStore& cell
= MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y());
cellname = MWBase::Environment::get().getWorld()->getCellName(cell);
cellname = MWBase::Environment::get().getWorld()->getCellName(&cell);
interior = false;
}
addDestination(ESM::RefId::stringRefId(cellname), transport[i].mPos, interior);

@ -84,9 +84,9 @@ namespace MWLua
WorldView* worldView = context.mWorldView;
addTimeBindings(api, context, true);
api["getCellByName"]
= [](std::string_view name) { return GCell{ MWBase::Environment::get().getWorldModel()->getCell(name) }; };
= [](std::string_view name) { return GCell{ &MWBase::Environment::get().getWorldModel()->getCell(name) }; };
api["getExteriorCell"]
= [](int x, int y) { return GCell{ MWBase::Environment::get().getWorldModel()->getExterior(x, y) }; };
= [](int x, int y) { return GCell{ &MWBase::Environment::get().getWorldModel()->getExterior(x, y) }; };
api["activeActors"] = GObjectList{ worldView->getActorsInScene() };
api["createObject"] = [](std::string_view recordId, sol::optional<int> count) -> GObject {
// Doesn't matter which cell to use because the new object will be in disabled state.

@ -59,9 +59,9 @@ namespace MWLua
if (name.empty())
cell = nullptr; // default exterior worldspace
else
cell = wm->getCell(name);
cell = &wm->getCell(name);
}
return wm->getCellByPosition(pos, cell);
return &wm->getCellByPosition(pos, cell);
}
void teleportPlayer(MWWorld::CellStore* destCell, const osg::Vec3f& pos, const osg::Vec3f& rot)

@ -47,9 +47,8 @@ namespace MWLua
const MWWorld::CellRef& cellRef = doorPtr(o).getCellRef();
if (!cellRef.getTeleport())
return sol::nil;
MWWorld::CellStore* cell = MWBase::Environment::get().getWorldModel()->getCell(cellRef.getDestCell());
assert(cell);
return o.getCell(lua, cell);
MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getCell(cellRef.getDestCell());
return o.getCell(lua, &cell);
};
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
@ -84,9 +83,8 @@ namespace MWLua
const MWWorld::CellRef& cellRef = door4Ptr(o).getCellRef();
if (!cellRef.getTeleport())
return sol::nil;
MWWorld::CellStore* cell = MWBase::Environment::get().getWorldModel()->getCell(cellRef.getDestCell());
assert(cell);
return o.getCell(lua, cell);
MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getCell(cellRef.getDestCell());
return o.getCell(lua, &cell);
};
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();

@ -398,11 +398,11 @@ namespace MWScript
MWWorld::CellStore* store = nullptr;
try
{
store = worldModel->getCell(cellID);
store = &worldModel->getCell(cellID);
if (store->isExterior())
{
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
store = worldModel->getExterior(cellIndex.x(), cellIndex.y());
store = &worldModel->getExterior(cellIndex.x(), cellIndex.y());
}
}
catch (std::exception&)
@ -417,7 +417,7 @@ namespace MWScript
if (!isPlayer)
return;
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
store = worldModel->getExterior(cellIndex.x(), cellIndex.y());
store = &worldModel->getExterior(cellIndex.x(), cellIndex.y());
}
if (store)
{
@ -474,7 +474,7 @@ namespace MWScript
if (isPlayer)
{
MWWorld::CellStore* cell
= MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y());
= &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y());
ptr = world->moveObject(ptr, cell, osg::Vec3(x, y, z));
}
else
@ -518,7 +518,7 @@ namespace MWScript
MWWorld::CellStore* store = nullptr;
try
{
store = MWBase::Environment::get().getWorldModel()->getCell(cellName);
store = &MWBase::Environment::get().getWorldModel()->getCell(cellName);
}
catch (std::exception&)
{
@ -568,7 +568,7 @@ namespace MWScript
if (player.getCell()->isExterior())
{
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
store = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y());
store = &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y());
}
else
store = player.getCell();

@ -563,7 +563,7 @@ void MWState::StateManager::loadGame(const Character* character, const std::file
{
// Cell no longer exists (i.e. changed game files), choose a default cell
Log(Debug::Warning) << "Warning: Player character's cell no longer exists, changing to the default cell";
MWWorld::CellStore* cell = MWBase::Environment::get().getWorldModel()->getExterior(0, 0);
MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(0, 0);
float x, y;
MWBase::Environment::get().getWorld()->indexToPosition(0, 0, x, y, false);
ESM::Position pos;
@ -573,7 +573,7 @@ void MWState::StateManager::loadGame(const Character* character, const std::file
pos.rot[0] = 0;
pos.rot[1] = 0;
pos.rot[2] = 0;
MWBase::Environment::get().getWorld()->changeToCell(cell->getCell()->getId(), pos, true, false);
MWBase::Environment::get().getWorld()->changeToCell(cell.getCell()->getId(), pos, true, false);
}
MWBase::Environment::get().getWorld()->updateProjectilesCasters();

@ -34,7 +34,7 @@ namespace MWWorld
// Find any NPCs that are following the actor and teleport them with him
std::set<MWWorld::Ptr> followers;
bool toExterior = MWBase::Environment::get().getWorldModel()->getCell(mCellId)->isExterior();
bool toExterior = MWBase::Environment::get().getWorldModel()->getCell(mCellId).isExterior();
getFollowers(actor, followers, toExterior, true);
for (std::set<MWWorld::Ptr>::iterator it = followers.begin(); it != followers.end(); ++it)
@ -66,7 +66,7 @@ namespace MWWorld
}
else
teleported = world->moveObject(actor, worldModel->getCell(mCellId), mPosition.asVec3(), true, true);
teleported = world->moveObject(actor, &worldModel->getCell(mCellId), mPosition.asVec3(), true, true);
}
if (!world->isWaterWalkingCastableOnTarget(teleported) && MWMechanics::hasWaterWalking(teleported))

@ -367,7 +367,7 @@ namespace MWWorld
try
{
mCellStore = MWBase::Environment::get().getWorldModel()->getCell(player.mCellId);
mCellStore = &MWBase::Environment::get().getWorldModel()->getCell(player.mCellId);
}
catch (...)
{
@ -401,7 +401,7 @@ namespace MWWorld
if (player.mHasMark)
{
mMarkedPosition = player.mMarkedPosition;
mMarkedCell = MWBase::Environment::get().getWorldModel()->getCell(player.mMarkedCell);
mMarkedCell = &MWBase::Environment::get().getWorldModel()->getCell(player.mMarkedCell);
}
else
{

@ -554,7 +554,7 @@ namespace MWWorld
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(mWorld.getWorldModel()
.getExterior(playerCellX, playerCellY)
->getCell()
.getCell()
->getWorldSpace()
.serializeText()),
navigatorUpdateGuard.get());
@ -580,7 +580,7 @@ namespace MWWorld
{
if (!isCellInCollection(x, y, collection))
{
refsToLoad += mWorld.getWorldModel().getExterior(x, y)->count();
refsToLoad += mWorld.getWorldModel().getExterior(x, y).count();
cellsPositionsToLoad.emplace_back(x, y);
}
}
@ -614,8 +614,8 @@ namespace MWWorld
{
if (!isCellInCollection(x, y, mActiveCells))
{
CellStore* cell = mWorld.getWorldModel().getExterior(x, y);
loadCell(cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get());
CellStore& cell = mWorld.getWorldModel().getExterior(x, y);
loadCell(&cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get());
}
}
@ -623,8 +623,8 @@ namespace MWWorld
navigatorUpdateGuard.reset();
CellStore* current = mWorld.getWorldModel().getExterior(playerCellX, playerCellY);
MWBase::Environment::get().getWindowManager()->changeCell(current);
CellStore& current = mWorld.getWorldModel().getExterior(playerCellX, playerCellY);
MWBase::Environment::get().getWindowManager()->changeCell(&current);
if (changeEvent)
mCellChanged = true;
@ -676,13 +676,13 @@ namespace MWWorld
loadingListener->setLabel(
"Testing exterior cells (" + std::to_string(i) + "/" + std::to_string(cells.getExtSize()) + ")...");
CellStore* cell = mWorld.getWorldModel().getExterior(it->mData.mX, it->mData.mY);
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell->getCell()->getWorldSpace().serializeText()),
CellStore& cell = mWorld.getWorldModel().getExterior(it->mData.mX, it->mData.mY);
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()),
navigatorUpdateGuard.get());
const osg::Vec3f position
= osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits;
mNavigator.updateBounds(position, navigatorUpdateGuard.get());
loadCell(cell, nullptr, false, position, navigatorUpdateGuard.get());
loadCell(&cell, nullptr, false, position, navigatorUpdateGuard.get());
mNavigator.update(position, navigatorUpdateGuard.get());
navigatorUpdateGuard.reset();
@ -734,13 +734,13 @@ namespace MWWorld
loadingListener->setLabel(
"Testing interior cells (" + std::to_string(i) + "/" + std::to_string(cells.getIntSize()) + ")...");
CellStore* cell = mWorld.getWorldModel().getInterior(it->mName);
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell->getCell()->getWorldSpace().serializeText()),
CellStore& cell = mWorld.getWorldModel().getInterior(it->mName);
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()),
navigatorUpdateGuard.get());
ESM::Position position;
mWorld.findInteriorPosition(it->mName, position);
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
loadCell(cell, nullptr, false, position.asVec3(), navigatorUpdateGuard.get());
loadCell(&cell, nullptr, false, position.asVec3(), navigatorUpdateGuard.get());
mNavigator.update(position.asVec3(), navigatorUpdateGuard.get());
navigatorUpdateGuard.reset();
@ -857,7 +857,7 @@ namespace MWWorld
void Scene::changeToInteriorCell(
std::string_view cellName, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent)
{
CellStore* cell = mWorld.getWorldModel().getInterior(cellName);
CellStore& cell = mWorld.getWorldModel().getInterior(cellName);
bool useFading = (mCurrentCell != nullptr);
if (useFading)
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
@ -866,7 +866,7 @@ namespace MWWorld
loadingListener->setLabel("#{OMWEngine:LoadingInterior}");
Loading::ScopedLoad load(loadingListener);
if (mCurrentCell != nullptr && *mCurrentCell == *cell)
if (mCurrentCell != nullptr && *mCurrentCell == cell)
{
mWorld.moveObject(mWorld.getPlayerPtr(), position.asVec3());
mWorld.rotateObject(mWorld.getPlayerPtr(), position.asRotationVec3());
@ -889,19 +889,19 @@ namespace MWWorld
}
assert(mActiveCells.empty());
loadingListener->setProgressRange(cell->count());
loadingListener->setProgressRange(cell.count());
mNavigator.setWorldspace(
Misc::StringUtils::lowerCase(cell->getCell()->getWorldSpace().serializeText()), navigatorUpdateGuard.get());
Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), navigatorUpdateGuard.get());
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
// Load cell.
mPagedRefs.clear();
loadCell(cell, loadingListener, changeEvent, position.asVec3(), navigatorUpdateGuard.get());
loadCell(&cell, loadingListener, changeEvent, position.asVec3(), navigatorUpdateGuard.get());
navigatorUpdateGuard.reset();
changePlayerCell(cell, position, adjustPlayerPos);
changePlayerCell(&cell, position, adjustPlayerPos);
// adjust fog
mRendering.configureFog(*mCurrentCell->getCell());
@ -919,7 +919,7 @@ namespace MWWorld
MWBase::Environment::get().getWindowManager()->changeCell(mCurrentCell);
MWBase::Environment::get().getWorld()->getPostProcessor()->setExteriorFlag(cell->getCell()->isQuasiExterior());
MWBase::Environment::get().getWorld()->getPostProcessor()->setExteriorFlag(cell.getCell()->isQuasiExterior());
}
void Scene::changeToExteriorCell(
@ -928,13 +928,13 @@ namespace MWWorld
if (changeEvent)
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
CellStore* current = mWorld.getWorldModel().getCell(extCellId);
CellStore& current = mWorld.getWorldModel().getCell(extCellId);
const osg::Vec2i cellIndex(current->getCell()->getGridX(), current->getCell()->getGridY());
const osg::Vec2i cellIndex(current.getCell()->getGridX(), current.getCell()->getGridY());
changeCellGrid(position.asVec3(), cellIndex.x(), cellIndex.y(), changeEvent);
changePlayerCell(current, position, adjustPlayerPos);
changePlayerCell(&current, position, adjustPlayerPos);
if (changeEvent)
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
@ -1133,7 +1133,7 @@ namespace MWWorld
{
try
{
preloadCell(mWorld.getWorldModel().getCell(door.getCellRef().getDestCell()));
preloadCell(&mWorld.getWorldModel().getCell(door.getCellRef().getDestCell()));
}
catch (std::exception&)
{
@ -1177,7 +1177,7 @@ namespace MWWorld
+ mPreloadDistance;
if (dist < loadDist)
preloadCell(mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy));
preloadCell(&mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy));
}
}
}
@ -1194,7 +1194,7 @@ namespace MWWorld
for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy)
{
mPreloader->preload(
mWorld.getWorldModel().getExterior(x + dx, y + dy), mRendering.getReferenceTime());
&mWorld.getWorldModel().getExterior(x + dx, y + dy), mRendering.getReferenceTime());
if (++numpreloaded >= mPreloader->getMaxCacheSize())
break;
}
@ -1274,12 +1274,12 @@ namespace MWWorld
for (ESM::Transport::Dest& dest : listVisitor.mList)
{
if (!dest.mCellName.empty())
preloadCell(mWorld.getWorldModel().getInterior(dest.mCellName));
preloadCell(&mWorld.getWorldModel().getInterior(dest.mCellName));
else
{
osg::Vec3f pos = dest.mPos.asVec3();
const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y());
preloadCell(mWorld.getWorldModel().getExterior(cellIndex.x(), cellIndex.y()), true);
preloadCell(&mWorld.getWorldModel().getExterior(cellIndex.x(), cellIndex.y()), true);
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
}
}

@ -994,7 +994,7 @@ namespace MWWorld
void World::changeToCell(
const ESM::RefId& cellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent)
{
const MWWorld::Cell* destinationCell = getWorldModel().getCell(cellId)->getCell();
const MWWorld::Cell* destinationCell = getWorldModel().getCell(cellId).getCell();
bool exteriorCell = destinationCell->isExterior();
mPhysics->clearQueuedMovement();
@ -1271,12 +1271,12 @@ namespace MWWorld
const osg::Vec2i index = positionToCellIndex(position.x(), position.y());
CellStore* cell = ptr.getCell();
CellStore* newCell = mWorldModel.getExterior(index.x(), index.y());
bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior()
&& mWorldScene->isCellActive(*newCell);
CellStore& newCell = mWorldModel.getExterior(index.x(), index.y());
bool isCellActive
= getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() && mWorldScene->isCellActive(newCell);
if (cell->isExterior() || (moveToActive && isCellActive && ptr.getClass().isActor()))
cell = newCell;
cell = &newCell;
return moveObject(ptr, cell, position, movePhysics);
}
@ -2177,7 +2177,7 @@ namespace MWWorld
if (cell->isExterior())
{
const osg::Vec2i index = positionToCellIndex(pos.pos[0], pos.pos[1]);
cell = mWorldModel.getExterior(index.x(), index.y());
cell = &mWorldModel.getExterior(index.x(), index.y());
}
MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count);
@ -2767,14 +2767,11 @@ namespace MWWorld
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
MWWorld::CellStore* cellStore = mWorldModel.getInterior(name);
MWWorld::CellStore& cellStore = mWorldModel.getInterior(name);
if (!cellStore)
return ESM::RefId::sEmpty;
ESM::RefId cellId = cellStore->getCell()->getId();
ESM::RefId cellId = cellStore.getCell()->getId();
std::vector<const MWWorld::CellRef*> sortedDoors;
for (const MWWorld::LiveCellRef<ESM::Door>& door : cellStore->getReadOnlyDoors().mList)
for (const MWWorld::LiveCellRef<ESM::Door>& door : cellStore.getReadOnlyDoors().mList)
{
if (!door.mRef.getTeleport())
continue;
@ -2792,27 +2789,23 @@ namespace MWWorld
for (const MWWorld::CellRef* door : sortedDoors)
{
MWWorld::CellStore* source = nullptr;
source = mWorldModel.getCell(door->getDestCell());
MWWorld::CellStore& source = mWorldModel.getCell(door->getDestCell());
if (source)
// Find door leading to our current teleport door
// and use its destination to position inside cell.
for (const MWWorld::LiveCellRef<ESM::Door>& destDoor : source.getReadOnlyDoors().mList)
{
// Find door leading to our current teleport door
// and use its destination to position inside cell.
for (const MWWorld::LiveCellRef<ESM::Door>& destDoor : source->getReadOnlyDoors().mList)
if (name == destDoor.mRef.getDestCell())
{
if (name == destDoor.mRef.getDestCell())
{
/// \note Using _any_ door pointed to the interior,
/// not the one pointed to current door.
pos = destDoor.mRef.getDoorDest();
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
return cellId;
}
/// \note Using _any_ door pointed to the interior,
/// not the one pointed to current door.
pos = destDoor.mRef.getDoorDest();
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
return cellId;
}
}
}
for (const MWWorld::LiveCellRef<ESM4::Static>& stat4 : cellStore->getReadOnlyEsm4Statics().mList)
for (const MWWorld::LiveCellRef<ESM4::Static>& stat4 : cellStore.getReadOnlyEsm4Statics().mList)
{
if (Misc::StringUtils::lowerCase(stat4.mBase->mEditorId) == "cocmarkerheading")
{
@ -2823,7 +2816,7 @@ namespace MWWorld
}
}
// Fall back to the first static location.
const MWWorld::CellRefList<ESM4::Static>::List& statics4 = cellStore->getReadOnlyEsm4Statics().mList;
const MWWorld::CellRefList<ESM4::Static>::List& statics4 = cellStore.getReadOnlyEsm4Statics().mList;
if (!statics4.empty())
{
pos = statics4.begin()->mRef.getPosition();
@ -2831,7 +2824,7 @@ namespace MWWorld
return cellId;
}
// Fall back to the first static location.
const MWWorld::CellRefList<ESM::Static>::List& statics = cellStore->getReadOnlyStatics().mList;
const MWWorld::CellRefList<ESM::Static>::List& statics = cellStore.getReadOnlyStatics().mList;
if (!statics.empty())
{
pos = statics.begin()->mRef.getPosition();
@ -2849,7 +2842,7 @@ namespace MWWorld
const MWWorld::Cell* ext = nullptr;
try
{
ext = mWorldModel.getCell(nameId)->getCell();
ext = mWorldModel.getCell(nameId).getCell();
if (!ext->isExterior())
return ESM::RefId();
}
@ -2868,7 +2861,7 @@ namespace MWWorld
if (xResult.ec == std::errc::result_out_of_range || yResult.ec == std::errc::result_out_of_range)
throw std::runtime_error("Cell coordinates out of range.");
else if (xResult.ec == std::errc{} && yResult.ec == std::errc{})
ext = mWorldModel.getExterior(x, y)->getCell();
ext = mWorldModel.getExterior(x, y).getCell();
// ignore std::errc::invalid_argument, as this means that name probably refers to a interior cell
// instead of comma separated coordinates
}
@ -3288,12 +3281,10 @@ namespace MWWorld
nextCells.clear();
for (const auto& currentCell : currentCells)
{
MWWorld::CellStore* next = mWorldModel.getCell(currentCell);
if (!next)
continue;
MWWorld::CellStore& next = mWorldModel.getCell(currentCell);
// Check if any door in the cell leads to an exterior directly
for (const MWWorld::LiveCellRef<ESM::Door>& ref : next->getReadOnlyDoors().mList)
for (const MWWorld::LiveCellRef<ESM::Door>& ref : next.getReadOnlyDoors().mList)
{
if (!ref.mRef.getTeleport())
continue;
@ -3342,19 +3333,17 @@ namespace MWWorld
std::swap(currentCells, nextCells);
for (const auto& cell : currentCells)
{
MWWorld::CellStore* next = mWorldModel.getCell(cell);
MWWorld::CellStore& next = mWorldModel.getCell(cell);
checkedCells.insert(cell);
if (!next)
continue;
closestMarker = next->searchConst(id);
closestMarker = next.searchConst(id);
if (!closestMarker.isEmpty())
{
return closestMarker;
}
// Check if any door in the cell leads to an exterior directly
for (const MWWorld::LiveCellRef<ESM::Door>& ref : next->getReadOnlyDoors().mList)
for (const MWWorld::LiveCellRef<ESM::Door>& ref : next.getReadOnlyDoors().mList)
{
if (!ref.mRef.getTeleport())
continue;
@ -3638,14 +3627,9 @@ namespace MWWorld
Log(Debug::Warning) << "Failed to confiscate items: prison marker not linked to prison interior";
return;
}
MWWorld::CellStore* prison = mWorldModel.getCell(prisonName);
if (!prison)
{
Log(Debug::Warning) << "Failed to confiscate items: failed to load cell " << prisonName;
return;
}
MWWorld::CellStore& prison = mWorldModel.getCell(prisonName);
MWWorld::Ptr closestChest = prison->search(ESM::RefId::stringRefId("stolen_goods"));
MWWorld::Ptr closestChest = prison.search(ESM::RefId::stringRefId("stolen_goods"));
if (!closestChest.isEmpty()) // Found a close chest
{
MWBase::Environment::get().getMechanicsManager()->confiscateStolenItems(ptr, closestChest);

@ -62,7 +62,7 @@ namespace
};
}
MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
MWWorld::CellStore& MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
{
CellStore* cellStore = &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second;
if (cell->mData.mFlags & ESM::Cell::Interior)
@ -72,7 +72,7 @@ MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
if (result == mInteriors.end())
result = mInteriors.emplace(cell->mName, cellStore).first;
return result->second;
return *result->second;
}
else
{
@ -82,7 +82,7 @@ MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
if (result == mExteriors.end())
result = mExteriors.emplace(std::make_pair(cell->getGridX(), cell->getGridY()), cellStore).first;
return result->second;
return *result->second;
}
}
@ -160,7 +160,7 @@ MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCach
{
}
MWWorld::CellStore* MWWorld::WorldModel::getExterior(int x, int y)
MWWorld::CellStore& MWWorld::WorldModel::getExterior(int x, int y)
{
std::map<std::pair<int, int>, CellStore*>::iterator result = mExteriors.find(std::make_pair(x, y));
@ -192,7 +192,7 @@ MWWorld::CellStore* MWWorld::WorldModel::getExterior(int x, int y)
result->second->load();
}
return result->second;
return *result->second;
}
MWWorld::CellStore* MWWorld::WorldModel::getInteriorOrNull(std::string_view name)
@ -217,19 +217,19 @@ MWWorld::CellStore* MWWorld::WorldModel::getInteriorOrNull(std::string_view name
return result->second;
}
MWWorld::CellStore* MWWorld::WorldModel::getInterior(std::string_view name)
MWWorld::CellStore& MWWorld::WorldModel::getInterior(std::string_view name)
{
CellStore* res = getInteriorOrNull(name);
if (res == nullptr)
throw std::runtime_error("Interior not found: '" + std::string(name) + "'");
return res;
return *res;
}
MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::RefId& id)
MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id)
{
auto result = mCells.find(id);
if (result != mCells.end())
return &result->second;
return result->second;
if (const auto* exteriorId = id.getIf<ESM::ESM3ExteriorCellRefId>())
return getExterior(exteriorId->getX(), exteriorId->getY());
@ -259,13 +259,13 @@ MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::RefId& id)
{
newCellStore->load();
}
return newCellStore;
return *newCellStore;
}
MWWorld::CellStore* MWWorld::WorldModel::getCell(std::string_view name)
MWWorld::CellStore& MWWorld::WorldModel::getCell(std::string_view name)
{
if (CellStore* res = getInteriorOrNull(name)) // first try interiors
return res;
return *res;
// try named exteriors
const ESM::Cell* cell = mStore.get<ESM::Cell>().searchExtByName(name);
@ -296,11 +296,11 @@ MWWorld::CellStore* MWWorld::WorldModel::getCell(std::string_view name)
return getExterior(cell->getGridX(), cell->getGridY());
}
MWWorld::CellStore* MWWorld::WorldModel::getCellByPosition(
MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition(
const osg::Vec3f& pos, MWWorld::CellStore* cellInSameWorldSpace)
{
if (cellInSameWorldSpace && !cellInSameWorldSpace->isExterior())
return cellInSameWorldSpace;
return *cellInSameWorldSpace;
const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y());
return getExterior(cellIndex.x(), cellIndex.y());
}
@ -363,9 +363,9 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name)
for (iter = cells.extBegin(); iter != cells.extEnd(); ++iter)
{
CellStore* cellStore = getCellStore(&(*iter));
CellStore& cellStore = getCellStore(&(*iter));
Ptr ptr = getPtrAndCache(name, *cellStore);
Ptr ptr = getPtrAndCache(name, cellStore);
if (!ptr.isEmpty())
return ptr;
@ -373,9 +373,9 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name)
for (iter = cells.intBegin(); iter != cells.intEnd(); ++iter)
{
CellStore* cellStore = getCellStore(&(*iter));
CellStore& cellStore = getCellStore(&(*iter));
Ptr ptr = getPtrAndCache(name, *cellStore);
Ptr ptr = getPtrAndCache(name, cellStore);
if (!ptr.isEmpty())
return ptr;
@ -390,9 +390,9 @@ void MWWorld::WorldModel::getExteriorPtrs(const ESM::RefId& name, std::vector<MW
const MWWorld::Store<ESM::Cell>& cells = mStore.get<ESM::Cell>();
for (MWWorld::Store<ESM::Cell>::iterator iter = cells.extBegin(); iter != cells.extEnd(); ++iter)
{
CellStore* cellStore = getCellStore(&(*iter));
CellStore& cellStore = getCellStore(&(*iter));
Ptr ptr = getPtrAndCache(name, *cellStore);
Ptr ptr = getPtrAndCache(name, cellStore);
if (!ptr.isEmpty())
out.push_back(ptr);
@ -441,7 +441,7 @@ public:
{
try
{
return mWorldModel.getCell(cellId);
return &mWorldModel.getCell(cellId);
}
catch (...)
{
@ -461,7 +461,7 @@ bool MWWorld::WorldModel::readRecord(ESM::ESMReader& reader, uint32_t type, cons
try
{
cellStore = getCell(state.mId);
cellStore = &getCell(state.mId);
}
catch (...)
{

@ -49,7 +49,7 @@ namespace MWWorld
std::size_t mPtrIndexUpdateCounter = 0;
ESM::RefNum mLastGeneratedRefnum;
CellStore* getCellStore(const ESM::Cell* cell);
CellStore& getCellStore(const ESM::Cell* cell);
CellStore* getInteriorOrNull(std::string_view name);
Ptr getPtrAndCache(const ESM::RefId& name, CellStore& cellStore);
@ -63,16 +63,16 @@ namespace MWWorld
void clear();
CellStore* getExterior(int x, int y);
CellStore* getInterior(std::string_view name);
CellStore* getCell(std::string_view name); // interior or named exterior
CellStore* getCell(const ESM::RefId& Id);
CellStore& getExterior(int x, int y);
CellStore& getInterior(std::string_view name);
CellStore& getCell(std::string_view name); // interior or named exterior
CellStore& getCell(const ESM::RefId& Id);
// Returns the cell that is in the same worldspace as `cellInSameWorldSpace`
// (in case of nullptr - default exterior worldspace) and contains given position.
// Interiors are single-cell worldspaces, so in case of an interior it just returns
// the same cell.
CellStore* getCellByPosition(const osg::Vec3f& pos, CellStore* cellInSameWorldSpace = nullptr);
CellStore& getCellByPosition(const osg::Vec3f& pos, CellStore* cellInSameWorldSpace = nullptr);
void registerPtr(const MWWorld::Ptr& ptr);
void deregisterPtr(const MWWorld::Ptr& ptr);

Loading…
Cancel
Save