From 53cc9f3614c35d79922692b17f3a022e543253a8 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 20 Apr 2023 15:55:40 +0200 Subject: [PATCH 1/3] functions return reference instead of ptr because the function can never return an nullptr, we return a reference. --- apps/openmw/mwclass/door.cpp | 2 +- apps/openmw/mwgui/mapwindow.cpp | 6 +- apps/openmw/mwgui/travelwindow.cpp | 4 +- apps/openmw/mwlua/luabindings.cpp | 4 +- apps/openmw/mwlua/objectbindings.cpp | 4 +- apps/openmw/mwlua/types/door.cpp | 10 +-- .../mwscript/transformationextensions.cpp | 12 +-- apps/openmw/mwstate/statemanagerimp.cpp | 4 +- apps/openmw/mwworld/actionteleport.cpp | 4 +- apps/openmw/mwworld/player.cpp | 4 +- apps/openmw/mwworld/scene.cpp | 54 ++++++------- apps/openmw/mwworld/worldimp.cpp | 78 ++++++++----------- apps/openmw/mwworld/worldmodel.cpp | 44 +++++------ apps/openmw/mwworld/worldmodel.hpp | 12 +-- 14 files changed, 112 insertions(+), 130 deletions(-) diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 5dca37a047..089d4b18f4 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -300,7 +300,7 @@ namespace MWClass std::string Door::getDestination(const MWWorld::LiveCellRef& 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 } + "}"; } diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 3877ee885d..d076578090 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -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 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; diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 26d5c250a4..5430de11e2 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -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); diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index 0bc8f20dc4..65f5737e85 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -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 count) -> GObject { // Doesn't matter which cell to use because the new object will be in disabled state. diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 1500727790..68db67f0b7 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -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) diff --git a/apps/openmw/mwlua/types/door.cpp b/apps/openmw/mwlua/types/door.cpp index ee6f99078f..c823222885 100644 --- a/apps/openmw/mwlua/types/door.cpp +++ b/apps/openmw/mwlua/types/door.cpp @@ -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(); diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 6ae9c77ca2..f27721c2ef 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -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(); diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index b51ab11a11..38bba75c05 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -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(); diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp index 2db14338d6..03efcff742 100644 --- a/apps/openmw/mwworld/actionteleport.cpp +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -34,7 +34,7 @@ namespace MWWorld // Find any NPCs that are following the actor and teleport them with him std::set 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::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)) diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 5a7215b78f..f280f02318 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -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 { diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 92cbd468e9..2262a2d9c4 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -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(¤t); 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(¤t, 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))); } } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index ffb8311e96..423990befc 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -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 sortedDoors; - for (const MWWorld::LiveCellRef& door : cellStore->getReadOnlyDoors().mList) + for (const MWWorld::LiveCellRef& 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& destDoor : source.getReadOnlyDoors().mList) { - // Find door leading to our current teleport door - // and use its destination to position inside cell. - for (const MWWorld::LiveCellRef& 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& stat4 : cellStore->getReadOnlyEsm4Statics().mList) + for (const MWWorld::LiveCellRef& 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::List& statics4 = cellStore->getReadOnlyEsm4Statics().mList; + const MWWorld::CellRefList::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::List& statics = cellStore->getReadOnlyStatics().mList; + const MWWorld::CellRefList::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& ref : next->getReadOnlyDoors().mList) + for (const MWWorld::LiveCellRef& 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& ref : next->getReadOnlyDoors().mList) + for (const MWWorld::LiveCellRef& 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); diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index e3973f27c9..84bee5bbde 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -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, 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()) 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().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& cells = mStore.get(); for (MWWorld::Store::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 (...) { diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index db8c103777..c9c7cf52ea 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -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); From a3a2685b9ab40a10359ff9cb9ea94c6c6f0e323b Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 20 Apr 2023 16:16:17 +0200 Subject: [PATCH 2/3] More MWWorld::CellStore* -> MWWorld::CellStore& --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwgui/mapwindow.cpp | 4 +- apps/openmw/mwworld/scene.cpp | 74 ++++++++++++++++---------------- apps/openmw/mwworld/scene.hpp | 6 +-- apps/openmw/mwworld/worldimp.cpp | 8 ++-- apps/openmw/mwworld/worldimp.hpp | 2 +- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index c33655ee65..7d486b8b2f 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -157,7 +157,7 @@ namespace MWBase virtual bool isCellQuasiExterior() const = 0; - virtual void getDoorMarkers(MWWorld::CellStore* cell, std::vector& out) = 0; + virtual void getDoorMarkers(MWWorld::CellStore& cell, std::vector& out) = 0; ///< get a list of teleport door markers for a given cell, to be displayed on the local map virtual void setGlobalInt(MWWorld::GlobalVariableName name, int value) = 0; diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index d076578090..e6216ca951 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -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; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 2262a2d9c4..e7bede2bed 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -377,19 +377,19 @@ namespace MWWorld mRendering.notifyWorldSpaceChanged(); } - void Scene::loadCell(CellStore* cell, Loading::Listener* loadingListener, bool respawn, const osg::Vec3f& position, + void Scene::loadCell(CellStore& cell, Loading::Listener* loadingListener, bool respawn, const osg::Vec3f& position, const DetourNavigator::UpdateGuard* navigatorUpdateGuard) { using DetourNavigator::HeightfieldShape; - assert(mActiveCells.find(cell) == mActiveCells.end()); - mActiveCells.insert(cell); + assert(mActiveCells.find(&cell) == mActiveCells.end()); + mActiveCells.insert(&cell); - Log(Debug::Info) << "Loading cell " << cell->getCell()->getDescription(); + Log(Debug::Info) << "Loading cell " << cell.getCell()->getDescription(); - const int cellX = cell->getCell()->getGridX(); - const int cellY = cell->getCell()->getGridY(); - const MWWorld::Cell& cellVariant = *cell->getCell(); + const int cellX = cell.getCell()->getGridX(); + const int cellY = cell.getCell()->getGridY(); + const MWWorld::Cell& cellVariant = *cell.getCell(); if (cellVariant.isExterior()) { @@ -440,22 +440,22 @@ namespace MWWorld }, [&](const ESM4::Cell& cell) {}, }, - *cell->getCell()); + *cell.getCell()); // register local scripts // do this before insertCell, to make sure we don't add scripts from levelled creature spawning twice - mWorld.getLocalScripts().addCell(cell); + mWorld.getLocalScripts().addCell(&cell); if (respawn) - cell->respawn(); + cell.respawn(); - insertCell(*cell, loadingListener, navigatorUpdateGuard); + insertCell(cell, loadingListener, navigatorUpdateGuard); - mRendering.addCell(cell); + mRendering.addCell(&cell); - MWBase::Environment::get().getWindowManager()->addCell(cell); - bool waterEnabled = cellVariant.hasWater() || cell->isExterior(); - float waterLevel = cell->getWaterLevel(); + MWBase::Environment::get().getWindowManager()->addCell(&cell); + bool waterEnabled = cellVariant.hasWater() || cell.isExterior(); + float waterLevel = cell.getWaterLevel(); mRendering.setWaterEnabled(waterEnabled); if (waterEnabled) { @@ -477,10 +477,10 @@ namespace MWWorld else mPhysics->disableWater(); - if (!cell->isExterior() && !cellVariant.isQuasiExterior()) + if (!cell.isExterior() && !cellVariant.isQuasiExterior()) mRendering.configureAmbient(cellVariant); - mPreloader->notifyLoaded(cell); + mPreloader->notifyLoaded(&cell); } void Scene::clear() @@ -615,7 +615,7 @@ namespace MWWorld if (!isCellInCollection(x, y, mActiveCells)) { CellStore& cell = mWorld.getWorldModel().getExterior(x, y); - loadCell(&cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get()); + loadCell(cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get()); } } @@ -682,7 +682,7 @@ namespace MWWorld 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(); @@ -740,7 +740,7 @@ namespace MWWorld 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(); @@ -772,21 +772,21 @@ namespace MWWorld mRendering.getResourceSystem()->setExpiryDelay(Settings::Manager::getFloat("cache expiry delay", "Cells")); } - void Scene::changePlayerCell(CellStore* cell, const ESM::Position& pos, bool adjustPlayerPos) + void Scene::changePlayerCell(CellStore& cell, const ESM::Position& pos, bool adjustPlayerPos) { - mCurrentCell = cell; + mCurrentCell = &cell; - mRendering.enableTerrain(cell->isExterior()); + mRendering.enableTerrain(cell.isExterior()); MWWorld::Ptr old = mWorld.getPlayerPtr(); - mWorld.getPlayer().setCell(cell); + mWorld.getPlayer().setCell(&cell); MWWorld::Ptr player = mWorld.getPlayerPtr(); mRendering.updatePlayerPtr(player); // The player is loaded before the scene and by default it is grounded, with the scene fully loaded, // we validate and correct this. Only run once, during initial cell load. - if (old.mCell == cell) + if (old.mCell == &cell) mPhysics->traceDown(player, player.getRefData().getPosition().asVec3(), 10.f); if (adjustPlayerPos) @@ -897,11 +897,11 @@ namespace MWWorld // 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()); @@ -934,7 +934,7 @@ namespace MWWorld changeCellGrid(position.asVec3(), cellIndex.x(), cellIndex.y(), changeEvent); - changePlayerCell(¤t, 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,17 +1177,17 @@ namespace MWWorld + mPreloadDistance; if (dist < loadDist) - preloadCell(&mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy)); + preloadCell(mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy)); } } } - void Scene::preloadCell(CellStore* cell, bool preloadSurrounding) + void Scene::preloadCell(CellStore& cell, bool preloadSurrounding) { - if (preloadSurrounding && cell->isExterior()) + if (preloadSurrounding && cell.isExterior()) { - int x = cell->getCell()->getGridX(); - int y = cell->getCell()->getGridY(); + int x = cell.getCell()->getGridX(); + int y = cell.getCell()->getGridY(); unsigned int numpreloaded = 0; for (int dx = -mHalfGridSize; dx <= mHalfGridSize; ++dx) { @@ -1201,7 +1201,7 @@ namespace MWWorld } } else - mPreloader->preload(cell, mRendering.getReferenceTime()); + mPreloader->preload(&cell, mRendering.getReferenceTime()); } void Scene::preloadTerrain(const osg::Vec3f& pos, bool sync) @@ -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))); } } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 0383d0c888..06b4221332 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -134,7 +134,7 @@ namespace MWWorld osg::Vec2i getNewGridCenter(const osg::Vec3f& pos, const osg::Vec2i* currentGridCenter = nullptr) const; void unloadCell(CellStore* cell, const DetourNavigator::UpdateGuard* navigatorUpdateGuard); - void loadCell(CellStore* cell, Loading::Listener* loadingListener, bool respawn, const osg::Vec3f& position, + void loadCell(CellStore& cell, Loading::Listener* loadingListener, bool respawn, const osg::Vec3f& position, const DetourNavigator::UpdateGuard* navigatorUpdateGuard); public: @@ -143,13 +143,13 @@ namespace MWWorld ~Scene(); - void preloadCell(MWWorld::CellStore* cell, bool preloadSurrounding = false); + void preloadCell(MWWorld::CellStore& cell, bool preloadSurrounding = false); void preloadTerrain(const osg::Vec3f& pos, bool sync = false); void reloadTerrain(); void playerMoved(const osg::Vec3f& pos); - void changePlayerCell(CellStore* newCell, const ESM::Position& position, bool adjustPlayerPos); + void changePlayerCell(CellStore& newCell, const ESM::Position& position, bool adjustPlayerPos); CellStore* getCurrentCell(); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 423990befc..250dd97b97 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -507,7 +507,7 @@ namespace MWWorld { if (getPlayerPtr().getCell()->isExterior()) mWorldScene->preloadTerrain(getPlayerPtr().getRefData().getPosition().asVec3()); - mWorldScene->preloadCell(getPlayerPtr().getCell(), true); + mWorldScene->preloadCell(*getPlayerPtr().getCell(), true); } break; default: @@ -1183,7 +1183,7 @@ namespace MWWorld else { if (mWorldScene->isCellActive(*newCell)) - mWorldScene->changePlayerCell(newCell, pos, false); + mWorldScene->changePlayerCell(*newCell, pos, false); else mWorldScene->changeToExteriorCell(newCell->getCell()->getId(), pos, false); } @@ -2086,10 +2086,10 @@ namespace MWWorld } }; - void World::getDoorMarkers(CellStore* cell, std::vector& out) + void World::getDoorMarkers(CellStore& cell, std::vector& out) { GetDoorMarkerVisitor visitor{ out }; - cell->forEachType(visitor); + cell.forEachType(visitor); } void World::setWaterHeight(const float height) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 7b24beb9d6..47ed94bdfa 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -245,7 +245,7 @@ namespace MWWorld bool isCellQuasiExterior() const override; - void getDoorMarkers(MWWorld::CellStore* cell, std::vector& out) override; + void getDoorMarkers(MWWorld::CellStore& cell, std::vector& out) override; ///< get a list of teleport door markers for a given cell, to be displayed on the local map void setGlobalInt(GlobalVariableName name, int value) override; From 5bb9bfd224a4c245b25f8deac3bd138cab450758 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 20 Apr 2023 16:27:50 +0200 Subject: [PATCH 3/3] CellPreloader::preload(CellStore& --- apps/openmw/mwworld/cellpreloader.cpp | 10 +++++----- apps/openmw/mwworld/cellpreloader.hpp | 2 +- apps/openmw/mwworld/scene.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 713fbbf05f..42ae70d45a 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -259,20 +259,20 @@ namespace MWWorld mPreloadCells.clear(); } - void CellPreloader::preload(CellStore* cell, double timestamp) + void CellPreloader::preload(CellStore& cell, double timestamp) { if (!mWorkQueue) { Log(Debug::Error) << "Error: can't preload, no work queue set"; return; } - if (cell->getState() == CellStore::State_Unloaded) + if (cell.getState() == CellStore::State_Unloaded) { Log(Debug::Error) << "Error: can't preload objects for unloaded cell"; return; } - PreloadMap::iterator found = mPreloadCells.find(cell); + PreloadMap::iterator found = mPreloadCells.find(&cell); if (found != mPreloadCells.end()) { // already preloaded, nothing to do other than updating the timestamp @@ -304,11 +304,11 @@ namespace MWWorld return; } - osg::ref_ptr item(new PreloadItem(cell, mResourceSystem->getSceneManager(), mBulletShapeManager, + osg::ref_ptr item(new PreloadItem(&cell, mResourceSystem->getSceneManager(), mBulletShapeManager, mResourceSystem->getKeyframeManager(), mTerrain, mLandManager, mPreloadInstances)); mWorkQueue->addWorkItem(item); - mPreloadCells[cell] = PreloadEntry(timestamp, item); + mPreloadCells[&cell] = PreloadEntry(timestamp, item); } void CellPreloader::notifyLoaded(CellStore* cell) diff --git a/apps/openmw/mwworld/cellpreloader.hpp b/apps/openmw/mwworld/cellpreloader.hpp index bd4d712c39..544be9be55 100644 --- a/apps/openmw/mwworld/cellpreloader.hpp +++ b/apps/openmw/mwworld/cellpreloader.hpp @@ -43,7 +43,7 @@ namespace MWWorld /// Ask a background thread to preload rendering meshes and collision shapes for objects in this cell. /// @note The cell itself must be in State_Loaded or State_Preloaded. - void preload(MWWorld::CellStore* cell, double timestamp); + void preload(MWWorld::CellStore& cell, double timestamp); void notifyLoaded(MWWorld::CellStore* cell); diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index e7bede2bed..aaa3e5b026 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -1194,14 +1194,14 @@ 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; } } } else - mPreloader->preload(&cell, mRendering.getReferenceTime()); + mPreloader->preload(cell, mRendering.getReferenceTime()); } void Scene::preloadTerrain(const osg::Vec3f& pos, bool sync)