1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-25 12:41:01 +00:00

Merge branch 'worldmodel' into 'master'

Rename MWWorld::Cells -> WorldModel

See merge request OpenMW/openmw!2535
This commit is contained in:
psi29a 2022-12-19 07:37:07 +00:00
commit 0a32b5750b
13 changed files with 77 additions and 76 deletions

View File

@ -74,7 +74,7 @@ add_openmw_dir (mwsound
add_openmw_dir (mwworld add_openmw_dir (mwworld
refdata worldimp scene globals class action nullaction actionteleport refdata worldimp scene globals class action nullaction actionteleport
containerstore actiontalk actiontake manualref player cellvisitors failedaction containerstore actiontalk actiontake manualref player cellvisitors failedaction
cells localscripts customdata inventorystore ptr actionopen actionread actionharvest worldmodel localscripts customdata inventorystore ptr actionopen actionread actionharvest
actionequip timestamp actionalchemy cellstore actionapply actioneat actionequip timestamp actionalchemy cellstore actionapply actioneat
store esmstore fallback actionrepair actionsoulgem livecellref actiondoor store esmstore fallback actionrepair actionsoulgem livecellref actiondoor
contentloader esmloader actiontrap cellreflist cellref weather projectilemanager contentloader esmloader actiontrap cellreflist cellref weather projectilemanager

View File

@ -17,7 +17,7 @@ namespace l10n
namespace MWWorld namespace MWWorld
{ {
class Cells; class WorldModel;
class Scene; class Scene;
} }
@ -43,7 +43,7 @@ namespace MWBase
static Environment* sThis; static Environment* sThis;
World* mWorld = nullptr; World* mWorld = nullptr;
MWWorld::Cells* mWorldModel = nullptr; // TODO: rename Cells -> WorldModel MWWorld::WorldModel* mWorldModel = nullptr;
MWWorld::Scene* mWorldScene = nullptr; MWWorld::Scene* mWorldScene = nullptr;
SoundManager* mSoundManager = nullptr; SoundManager* mSoundManager = nullptr;
ScriptManager* mScriptManager = nullptr; ScriptManager* mScriptManager = nullptr;
@ -69,7 +69,7 @@ namespace MWBase
Environment& operator=(const Environment&) = delete; Environment& operator=(const Environment&) = delete;
void setWorld(World& value) { mWorld = &value; } void setWorld(World& value) { mWorld = &value; }
void setWorldModel(MWWorld::Cells& value) { mWorldModel = &value; } void setWorldModel(MWWorld::WorldModel& value) { mWorldModel = &value; }
void setWorldScene(MWWorld::Scene& value) { mWorldScene = &value; } void setWorldScene(MWWorld::Scene& value) { mWorldScene = &value; }
void setSoundManager(SoundManager& value) { mSoundManager = &value; } void setSoundManager(SoundManager& value) { mSoundManager = &value; }
@ -95,7 +95,7 @@ namespace MWBase
void setL10nManager(l10n::Manager& value) { mL10nManager = &value; } void setL10nManager(l10n::Manager& value) { mL10nManager = &value; }
Misc::NotNullPtr<World> getWorld() const { return mWorld; } Misc::NotNullPtr<World> getWorld() const { return mWorld; }
Misc::NotNullPtr<MWWorld::Cells> getWorldModel() const { return mWorldModel; } Misc::NotNullPtr<MWWorld::WorldModel> getWorldModel() const { return mWorldModel; }
Misc::NotNullPtr<MWWorld::Scene> getWorldScene() const { return mWorldScene; } Misc::NotNullPtr<MWWorld::Scene> getWorldScene() const { return mWorldScene; }
Misc::NotNullPtr<SoundManager> getSoundManager() const { return mSoundManager; } Misc::NotNullPtr<SoundManager> getSoundManager() const { return mSoundManager; }

View File

@ -22,11 +22,11 @@
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/cells.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/cellutils.hpp" #include "../mwworld/cellutils.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwrender/globalmap.hpp" #include "../mwrender/globalmap.hpp"
#include "../mwrender/localmap.hpp" #include "../mwrender/localmap.hpp"
@ -626,7 +626,7 @@ namespace MWGui
{ {
std::vector<MWBase::World::DoorMarker> doors; std::vector<MWBase::World::DoorMarker> doors;
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::Cells* worldModel = MWBase::Environment::get().getWorldModel(); MWWorld::WorldModel* worldModel = MWBase::Environment::get().getWorldModel();
mDoorMarkersToRecycle.insert( mDoorMarkersToRecycle.insert(
mDoorMarkersToRecycle.end(), mInteriorDoorMarkerWidgets.begin(), mInteriorDoorMarkerWidgets.end()); mDoorMarkersToRecycle.end(), mInteriorDoorMarkerWidgets.begin(), mInteriorDoorMarkerWidgets.end());

View File

@ -13,13 +13,13 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/actionteleport.hpp" #include "../mwworld/actionteleport.hpp"
#include "../mwworld/cells.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/cellutils.hpp" #include "../mwworld/cellutils.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/store.hpp" #include "../mwworld/store.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"

View File

@ -8,10 +8,10 @@
#include "../mwclass/container.hpp" #include "../mwclass/container.hpp"
#include "../mwworld/cells.hpp"
#include "../mwworld/cellutils.hpp" #include "../mwworld/cellutils.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/timestamp.hpp" #include "../mwworld/timestamp.hpp"
#include "../mwworld/worldmodel.hpp"
namespace MWLua namespace MWLua
{ {
@ -127,25 +127,25 @@ namespace MWLua
// sections. // sections.
MWWorld::CellStore* WorldView::findCell(const std::string& name, osg::Vec3f position) MWWorld::CellStore* WorldView::findCell(const std::string& name, osg::Vec3f position)
{ {
MWWorld::Cells* cells = MWBase::Environment::get().getWorldModel(); MWWorld::WorldModel* worldModel = MWBase::Environment::get().getWorldModel();
bool exterior = name.empty() || MWBase::Environment::get().getWorld()->getExterior(name); bool exterior = name.empty() || MWBase::Environment::get().getWorld()->getExterior(name);
if (exterior) if (exterior)
{ {
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(position.x(), position.y()); const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(position.x(), position.y());
return cells->getExterior(cellIndex.x(), cellIndex.y()); return worldModel->getExterior(cellIndex.x(), cellIndex.y());
} }
else else
return cells->getInterior(name); return worldModel->getInterior(name);
} }
MWWorld::CellStore* WorldView::findNamedCell(const std::string& name) MWWorld::CellStore* WorldView::findNamedCell(const std::string& name)
{ {
MWWorld::Cells* cells = MWBase::Environment::get().getWorldModel(); MWWorld::WorldModel* worldModel = MWBase::Environment::get().getWorldModel();
const ESM::Cell* esmCell = MWBase::Environment::get().getWorld()->getExterior(name); const ESM::Cell* esmCell = MWBase::Environment::get().getWorld()->getExterior(name);
if (esmCell) if (esmCell)
return cells->getExterior(esmCell->getGridX(), esmCell->getGridY()); return worldModel->getExterior(esmCell->getGridX(), esmCell->getGridY());
else else
return cells->getInterior(name); return worldModel->getInterior(name);
} }
MWWorld::CellStore* WorldView::findExteriorCell(int x, int y) MWWorld::CellStore* WorldView::findExteriorCell(int x, int y)

View File

@ -13,13 +13,13 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/cells.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/cellutils.hpp" #include "../mwworld/cellutils.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/manualref.hpp" #include "../mwworld/manualref.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/scene.hpp" #include "../mwworld/scene.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"

View File

@ -30,11 +30,11 @@
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/cells.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/scene.hpp" #include "../mwworld/scene.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"

View File

@ -8,10 +8,10 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwworld/cells.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/cellutils.hpp" #include "../mwworld/cellutils.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/worldmodel.hpp"
#include "player.hpp" #include "player.hpp"
@ -43,7 +43,7 @@ namespace MWWorld
void ActionTeleport::teleport(const Ptr& actor) void ActionTeleport::teleport(const Ptr& actor)
{ {
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
MWWorld::Cells* worldModel = MWBase::Environment::get().getWorldModel(); MWWorld::WorldModel* worldModel = MWBase::Environment::get().getWorldModel();
actor.getClass().getCreatureStats(actor).land(actor == world->getPlayerPtr()); actor.getClass().getCreatureStats(actor).land(actor == world->getPlayerPtr());
if (actor == world->getPlayerPtr()) if (actor == world->getPlayerPtr())
{ {

View File

@ -12,10 +12,10 @@
#include <components/esm3/player.hpp> #include <components/esm3/player.hpp>
#include <components/fallback/fallback.hpp> #include <components/fallback/fallback.hpp>
#include "../mwworld/cells.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwworld/magiceffects.hpp" #include "../mwworld/magiceffects.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"

View File

@ -160,7 +160,7 @@ namespace MWWorld
const std::filesystem::path& userDataPath) const std::filesystem::path& userDataPath)
: mResourceSystem(resourceSystem) : mResourceSystem(resourceSystem)
, mLocalScripts(mStore) , mLocalScripts(mStore)
, mCells(mStore, mReaders) , mWorldModel(mStore, mReaders)
, mSky(true) , mSky(true)
, mGodMode(false) , mGodMode(false)
, mScriptsEnabled(true) , mScriptsEnabled(true)
@ -328,7 +328,7 @@ namespace MWWorld
mPlayer->set(mStore.get<ESM::NPC>().find("player")); mPlayer->set(mStore.get<ESM::NPC>().find("player"));
} }
mCells.clear(); mWorldModel.clear();
mDoorStates.clear(); mDoorStates.clear();
@ -343,7 +343,7 @@ namespace MWWorld
int World::countSavedGameRecords() const int World::countSavedGameRecords() const
{ {
return mCells.countSavedGameRecords() + mStore.countSavedGameRecords() return mWorldModel.countSavedGameRecords() + mStore.countSavedGameRecords()
+ mGlobalVariables.countSavedGameRecords() + mProjectileManager->countSavedGameRecords() + mGlobalVariables.countSavedGameRecords() + mProjectileManager->countSavedGameRecords()
+ 1 // player record + 1 // player record
+ 1 // weather record + 1 // weather record
@ -355,7 +355,7 @@ namespace MWWorld
int World::countSavedGameCells() const int World::countSavedGameCells() const
{ {
return mCells.countSavedGameRecords(); return mWorldModel.countSavedGameRecords();
} }
void World::write(ESM::ESMWriter& writer, Loading::Listener& progress) const void World::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
@ -375,7 +375,7 @@ namespace MWWorld
mStore.write(writer, progress); // dynamic Store must be written (and read) before Cells, so that mStore.write(writer, progress); // dynamic Store must be written (and read) before Cells, so that
// references to custom made records will be recognized // references to custom made records will be recognized
mPlayer->write(writer, progress); mPlayer->write(writer, progress);
mCells.write(writer, progress); mWorldModel.write(writer, progress);
mGlobalVariables.write(writer, progress); mGlobalVariables.write(writer, progress);
mWeatherManager->write(writer, progress); mWeatherManager->write(writer, progress);
mProjectileManager->write(writer, progress); mProjectileManager->write(writer, progress);
@ -419,7 +419,8 @@ namespace MWWorld
break; break;
default: default:
if (!mStore.readRecord(reader, type) && !mGlobalVariables.readRecord(reader, type) if (!mStore.readRecord(reader, type) && !mGlobalVariables.readRecord(reader, type)
&& !mWeatherManager->readRecord(reader, type) && !mCells.readRecord(reader, type, contentFileMap) && !mWeatherManager->readRecord(reader, type)
&& !mWorldModel.readRecord(reader, type, contentFileMap)
&& !mProjectileManager->readRecord(reader, type)) && !mProjectileManager->readRecord(reader, type))
{ {
throw std::runtime_error("unknown record in saved game"); throw std::runtime_error("unknown record in saved game");
@ -695,7 +696,7 @@ namespace MWWorld
{ {
// TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is // TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is
// in) // in)
Ptr ptr = mCells.getPtr(lowerCaseName, *cellstore, false); Ptr ptr = mWorldModel.getPtr(lowerCaseName, *cellstore, false);
if (!ptr.isEmpty()) if (!ptr.isEmpty())
return ptr; return ptr;
@ -703,7 +704,7 @@ namespace MWWorld
if (!activeOnly) if (!activeOnly)
{ {
ret = mCells.getPtr(lowerCaseName); ret = mWorldModel.getPtr(lowerCaseName);
if (!ret.isEmpty()) if (!ret.isEmpty())
return ret; return ret;
} }
@ -745,7 +746,7 @@ namespace MWWorld
Ptr World::searchPtrViaRefNum(const std::string& id, const ESM::RefNum& refNum) Ptr World::searchPtrViaRefNum(const std::string& id, const ESM::RefNum& refNum)
{ {
return mCells.getPtr(id, refNum); return mWorldModel.getPtr(id, refNum);
} }
struct FindContainerVisitor struct FindContainerVisitor
@ -1262,7 +1263,7 @@ namespace MWWorld
const osg::Vec2i index = positionToCellIndex(position.x(), position.y()); const osg::Vec2i index = positionToCellIndex(position.x(), position.y());
CellStore* cell = ptr.getCell(); CellStore* cell = ptr.getCell();
CellStore* newCell = mCells.getExterior(index.x(), index.y()); CellStore* newCell = mWorldModel.getExterior(index.x(), index.y());
bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior()
&& mWorldScene->isCellActive(*newCell); && mWorldScene->isCellActive(*newCell);
@ -2200,7 +2201,7 @@ namespace MWWorld
if (cell->isExterior()) if (cell->isExterior())
{ {
const osg::Vec2i index = positionToCellIndex(pos.pos[0], pos.pos[1]); const osg::Vec2i index = positionToCellIndex(pos.pos[0], pos.pos[1]);
cell = mCells.getExterior(index.x(), index.y()); cell = mWorldModel.getExterior(index.x(), index.y());
} }
MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count); MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count);
@ -2789,7 +2790,7 @@ namespace MWWorld
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0; pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
MWWorld::CellStore* cellStore = mCells.getInterior(name); MWWorld::CellStore* cellStore = mWorldModel.getInterior(name);
if (!cellStore) if (!cellStore)
return false; return false;
@ -2820,12 +2821,12 @@ namespace MWWorld
{ {
ESM::Position doorDest = door->getDoorDest(); ESM::Position doorDest = door->getDoorDest();
const osg::Vec2i index = positionToCellIndex(doorDest.pos[0], doorDest.pos[1]); const osg::Vec2i index = positionToCellIndex(doorDest.pos[0], doorDest.pos[1]);
source = mCells.getExterior(index.x(), index.y()); source = mWorldModel.getExterior(index.x(), index.y());
} }
// door to interior // door to interior
else else
{ {
source = mCells.getInterior(door->getDestCell()); source = mWorldModel.getInterior(door->getDestCell());
} }
if (source) if (source)
{ {
@ -2872,7 +2873,7 @@ namespace MWWorld
if (xResult.ec == std::errc::result_out_of_range || yResult.ec == std::errc::result_out_of_range) 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."); throw std::runtime_error("Cell coordinates out of range.");
else if (xResult.ec == std::errc{} && yResult.ec == std::errc{}) else if (xResult.ec == std::errc{} && yResult.ec == std::errc{})
ext = mCells.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 // ignore std::errc::invalid_argument, as this means that name probably refers to a interior cell
// instead of comma separated coordinates // instead of comma separated coordinates
} }
@ -3291,7 +3292,7 @@ namespace MWWorld
nextCells.clear(); nextCells.clear();
for (const std::string& currentCell : currentCells) for (const std::string& currentCell : currentCells)
{ {
MWWorld::CellStore* next = mCells.getInterior(currentCell); MWWorld::CellStore* next = mWorldModel.getInterior(currentCell);
if (!next) if (!next)
continue; continue;
@ -3345,7 +3346,7 @@ namespace MWWorld
nextCells.clear(); nextCells.clear();
for (const std::string& cell : currentCells) for (const std::string& cell : currentCells)
{ {
MWWorld::CellStore* next = mCells.getInterior(cell); MWWorld::CellStore* next = mWorldModel.getInterior(cell);
checkedCells.insert(cell); checkedCells.insert(cell);
if (!next) if (!next)
continue; continue;
@ -3385,7 +3386,7 @@ namespace MWWorld
float closestDistance = std::numeric_limits<float>::max(); float closestDistance = std::numeric_limits<float>::max();
std::vector<MWWorld::Ptr> markers; std::vector<MWWorld::Ptr> markers;
mCells.getExteriorPtrs(id, markers); mWorldModel.getExteriorPtrs(id, markers);
for (const Ptr& marker : markers) for (const Ptr& marker : markers)
{ {
osg::Vec3f markerPos = marker.getRefData().getPosition().asVec3(); osg::Vec3f markerPos = marker.getRefData().getPosition().asVec3();
@ -3402,7 +3403,7 @@ namespace MWWorld
void World::rest(double hours) void World::rest(double hours)
{ {
mCells.rest(hours); mWorldModel.rest(hours);
} }
void World::rechargeItems(double duration, bool activeOnly) void World::rechargeItems(double duration, bool activeOnly)
@ -3418,7 +3419,7 @@ namespace MWWorld
} }
} }
else else
mCells.recharge(duration); mWorldModel.recharge(duration);
} }
void World::teleportToClosestMarker(const MWWorld::Ptr& ptr, std::string_view id) void World::teleportToClosestMarker(const MWWorld::Ptr& ptr, std::string_view id)
@ -3643,7 +3644,7 @@ namespace MWWorld
Log(Debug::Warning) << "Failed to confiscate items: prison marker not linked to prison interior"; Log(Debug::Warning) << "Failed to confiscate items: prison marker not linked to prison interior";
return; return;
} }
MWWorld::CellStore* prison = mCells.getInterior(prisonName); MWWorld::CellStore* prison = mWorldModel.getInterior(prisonName);
if (!prison) if (!prison)
{ {
Log(Debug::Warning) << "Failed to confiscate items: failed to load cell " << prisonName; Log(Debug::Warning) << "Failed to confiscate items: failed to load cell " << prisonName;
@ -3958,7 +3959,7 @@ namespace MWWorld
std::vector<MWWorld::Ptr> World::getAll(const std::string& id) std::vector<MWWorld::Ptr> World::getAll(const std::string& id)
{ {
return mCells.getAll(id); return mWorldModel.getAll(id);
} }
Misc::Rng::Generator& World::getPrng() Misc::Rng::Generator& World::getPrng()

View File

@ -10,7 +10,6 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "cells.hpp"
#include "contentloader.hpp" #include "contentloader.hpp"
#include "esmstore.hpp" #include "esmstore.hpp"
#include "globals.hpp" #include "globals.hpp"
@ -19,6 +18,7 @@
#include "ptr.hpp" #include "ptr.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "timestamp.hpp" #include "timestamp.hpp"
#include "worldmodel.hpp"
namespace osg namespace osg
{ {
@ -90,7 +90,7 @@ namespace MWWorld
LocalScripts mLocalScripts; LocalScripts mLocalScripts;
MWWorld::Globals mGlobalVariables; MWWorld::Globals mGlobalVariables;
Misc::Rng::Generator mPrng; Misc::Rng::Generator mPrng;
Cells mCells; WorldModel mWorldModel;
std::vector<int> mESMVersions; // the versions of esm files std::vector<int> mESMVersions; // the versions of esm files
std::string mCurrentWorldSpace; std::string mCurrentWorldSpace;
@ -188,7 +188,7 @@ namespace MWWorld
MWWorld::ConstPtr getClosestMarkerFromExteriorPosition(const osg::Vec3f& worldPos, std::string_view id); MWWorld::ConstPtr getClosestMarkerFromExteriorPosition(const osg::Vec3f& worldPos, std::string_view id);
public: public:
Cells& getWorldModel() { return mCells; } WorldModel& getWorldModel() { return mWorldModel; }
Scene& getWorldScene() { return *mWorldScene; } Scene& getWorldScene() { return *mWorldScene; }
// FIXME // FIXME

View File

@ -1,4 +1,4 @@
#include "cells.hpp" #include "worldmodel.hpp"
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/defs.hpp> #include <components/esm/defs.hpp>
@ -58,7 +58,7 @@ namespace
}; };
} }
MWWorld::CellStore* MWWorld::Cells::getCellStore(const ESM::Cell* cell) MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
{ {
if (cell->mData.mFlags & ESM::Cell::Interior) if (cell->mData.mFlags & ESM::Cell::Interior)
{ {
@ -84,7 +84,7 @@ MWWorld::CellStore* MWWorld::Cells::getCellStore(const ESM::Cell* cell)
} }
} }
void MWWorld::Cells::clear() void MWWorld::WorldModel::clear()
{ {
mInteriors.clear(); mInteriors.clear();
mExteriors.clear(); mExteriors.clear();
@ -92,7 +92,7 @@ void MWWorld::Cells::clear()
mIdCacheIndex = 0; mIdCacheIndex = 0;
} }
MWWorld::Ptr MWWorld::Cells::getPtrAndCache(std::string_view name, CellStore& cellStore) MWWorld::Ptr MWWorld::WorldModel::getPtrAndCache(std::string_view name, CellStore& cellStore)
{ {
Ptr ptr = getPtr(name, cellStore); Ptr ptr = getPtr(name, cellStore);
@ -107,7 +107,7 @@ MWWorld::Ptr MWWorld::Cells::getPtrAndCache(std::string_view name, CellStore& ce
return ptr; return ptr;
} }
void MWWorld::Cells::writeCell(ESM::ESMWriter& writer, CellStore& cell) const void MWWorld::WorldModel::writeCell(ESM::ESMWriter& writer, CellStore& cell) const
{ {
if (cell.getState() != CellStore::State_Loaded) if (cell.getState() != CellStore::State_Loaded)
cell.load(); cell.load();
@ -124,7 +124,7 @@ void MWWorld::Cells::writeCell(ESM::ESMWriter& writer, CellStore& cell) const
writer.endRecord(ESM::REC_CSTA); writer.endRecord(ESM::REC_CSTA);
} }
MWWorld::Cells::Cells(const MWWorld::ESMStore& store, ESM::ReadersCache& readers) MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCache& readers)
: mStore(store) : mStore(store)
, mReaders(readers) , mReaders(readers)
, mIdCacheIndex(0) , mIdCacheIndex(0)
@ -133,7 +133,7 @@ MWWorld::Cells::Cells(const MWWorld::ESMStore& store, ESM::ReadersCache& readers
mIdCache = IdCache(cacheSize, std::pair<std::string, CellStore*>("", (CellStore*)nullptr)); mIdCache = IdCache(cacheSize, std::pair<std::string, CellStore*>("", (CellStore*)nullptr));
} }
MWWorld::CellStore* MWWorld::Cells::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)); std::map<std::pair<int, int>, CellStore>::iterator result = mExteriors.find(std::make_pair(x, y));
@ -170,7 +170,7 @@ MWWorld::CellStore* MWWorld::Cells::getExterior(int x, int y)
return &result->second; return &result->second;
} }
MWWorld::CellStore* MWWorld::Cells::getInterior(std::string_view name) MWWorld::CellStore* MWWorld::WorldModel::getInterior(std::string_view name)
{ {
std::string lowerName = Misc::StringUtils::lowerCase(name); std::string lowerName = Misc::StringUtils::lowerCase(name);
std::map<std::string, CellStore>::iterator result = mInteriors.find(lowerName); std::map<std::string, CellStore>::iterator result = mInteriors.find(lowerName);
@ -190,7 +190,7 @@ MWWorld::CellStore* MWWorld::Cells::getInterior(std::string_view name)
return &result->second; return &result->second;
} }
void MWWorld::Cells::rest(double hours) void MWWorld::WorldModel::rest(double hours)
{ {
for (auto& interior : mInteriors) for (auto& interior : mInteriors)
{ {
@ -203,7 +203,7 @@ void MWWorld::Cells::rest(double hours)
} }
} }
void MWWorld::Cells::recharge(float duration) void MWWorld::WorldModel::recharge(float duration)
{ {
for (auto& interior : mInteriors) for (auto& interior : mInteriors)
{ {
@ -216,7 +216,7 @@ void MWWorld::Cells::recharge(float duration)
} }
} }
MWWorld::CellStore* MWWorld::Cells::getCell(const ESM::CellId& id) MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::CellId& id)
{ {
if (id.mPaged) if (id.mPaged)
return getExterior(id.mIndex.mX, id.mIndex.mY); return getExterior(id.mIndex.mX, id.mIndex.mY);
@ -224,7 +224,7 @@ MWWorld::CellStore* MWWorld::Cells::getCell(const ESM::CellId& id)
return getInterior(id.mWorldspace); return getInterior(id.mWorldspace);
} }
MWWorld::Ptr MWWorld::Cells::getPtr(std::string_view name, CellStore& cell, bool searchInContainers) MWWorld::Ptr MWWorld::WorldModel::getPtr(std::string_view name, CellStore& cell, bool searchInContainers)
{ {
if (cell.getState() == CellStore::State_Unloaded) if (cell.getState() == CellStore::State_Unloaded)
cell.preload(); cell.preload();
@ -250,7 +250,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr(std::string_view name, CellStore& cell, bool
return Ptr(); return Ptr();
} }
MWWorld::Ptr MWWorld::Cells::getPtr(const std::string& name) MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& name)
{ {
// First check the cache // First check the cache
for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter) for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter)
@ -307,7 +307,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr(const std::string& name)
return Ptr(); return Ptr();
} }
MWWorld::Ptr MWWorld::Cells::getPtr(const std::string& id, const ESM::RefNum& refNum) MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& id, const ESM::RefNum& refNum)
{ {
for (auto& pair : mInteriors) for (auto& pair : mInteriors)
{ {
@ -324,7 +324,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr(const std::string& id, const ESM::RefNum& re
return Ptr(); return Ptr();
} }
MWWorld::Ptr MWWorld::Cells::getPtr(CellStore& cellStore, const std::string& id, const ESM::RefNum& refNum) MWWorld::Ptr MWWorld::WorldModel::getPtr(CellStore& cellStore, const std::string& id, const ESM::RefNum& refNum)
{ {
if (cellStore.getState() == CellStore::State_Unloaded) if (cellStore.getState() == CellStore::State_Unloaded)
cellStore.preload(); cellStore.preload();
@ -338,7 +338,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr(CellStore& cellStore, const std::string& id,
return cellStore.searchViaRefNum(refNum); return cellStore.searchViaRefNum(refNum);
} }
void MWWorld::Cells::getExteriorPtrs(std::string_view name, std::vector<MWWorld::Ptr>& out) void MWWorld::WorldModel::getExteriorPtrs(std::string_view name, std::vector<MWWorld::Ptr>& out)
{ {
const MWWorld::Store<ESM::Cell>& cells = mStore.get<ESM::Cell>(); const MWWorld::Store<ESM::Cell>& cells = mStore.get<ESM::Cell>();
for (MWWorld::Store<ESM::Cell>::iterator iter = cells.extBegin(); iter != cells.extEnd(); ++iter) for (MWWorld::Store<ESM::Cell>::iterator iter = cells.extBegin(); iter != cells.extEnd(); ++iter)
@ -352,7 +352,7 @@ void MWWorld::Cells::getExteriorPtrs(std::string_view name, std::vector<MWWorld:
} }
} }
void MWWorld::Cells::getInteriorPtrs(const std::string& name, std::vector<MWWorld::Ptr>& out) void MWWorld::WorldModel::getInteriorPtrs(const std::string& name, std::vector<MWWorld::Ptr>& out)
{ {
const MWWorld::Store<ESM::Cell>& cells = mStore.get<ESM::Cell>(); const MWWorld::Store<ESM::Cell>& cells = mStore.get<ESM::Cell>();
for (MWWorld::Store<ESM::Cell>::iterator iter = cells.intBegin(); iter != cells.intEnd(); ++iter) for (MWWorld::Store<ESM::Cell>::iterator iter = cells.intBegin(); iter != cells.intEnd(); ++iter)
@ -366,7 +366,7 @@ void MWWorld::Cells::getInteriorPtrs(const std::string& name, std::vector<MWWorl
} }
} }
std::vector<MWWorld::Ptr> MWWorld::Cells::getAll(const std::string& id) std::vector<MWWorld::Ptr> MWWorld::WorldModel::getAll(const std::string& id)
{ {
PtrCollector visitor; PtrCollector visitor;
if (forEachInStore(id, visitor, mInteriors)) if (forEachInStore(id, visitor, mInteriors))
@ -374,7 +374,7 @@ std::vector<MWWorld::Ptr> MWWorld::Cells::getAll(const std::string& id)
return visitor.mPtrs; return visitor.mPtrs;
} }
int MWWorld::Cells::countSavedGameRecords() const int MWWorld::WorldModel::countSavedGameRecords() const
{ {
int count = 0; int count = 0;
@ -390,7 +390,7 @@ int MWWorld::Cells::countSavedGameRecords() const
return count; return count;
} }
void MWWorld::Cells::write(ESM::ESMWriter& writer, Loading::Listener& progress) const void MWWorld::WorldModel::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
{ {
for (std::map<std::pair<int, int>, CellStore>::iterator iter(mExteriors.begin()); iter != mExteriors.end(); ++iter) for (std::map<std::pair<int, int>, CellStore>::iterator iter(mExteriors.begin()); iter != mExteriors.end(); ++iter)
if (iter->second.hasState()) if (iter->second.hasState())
@ -410,18 +410,18 @@ void MWWorld::Cells::write(ESM::ESMWriter& writer, Loading::Listener& progress)
struct GetCellStoreCallback : public MWWorld::CellStore::GetCellStoreCallback struct GetCellStoreCallback : public MWWorld::CellStore::GetCellStoreCallback
{ {
public: public:
GetCellStoreCallback(MWWorld::Cells& cells) GetCellStoreCallback(MWWorld::WorldModel& worldModel)
: mCells(cells) : mWorldModel(worldModel)
{ {
} }
MWWorld::Cells& mCells; MWWorld::WorldModel& mWorldModel;
MWWorld::CellStore* getCellStore(const ESM::CellId& cellId) override MWWorld::CellStore* getCellStore(const ESM::CellId& cellId) override
{ {
try try
{ {
return mCells.getCell(cellId); return mWorldModel.getCell(cellId);
} }
catch (...) catch (...)
{ {
@ -430,7 +430,7 @@ public:
} }
}; };
bool MWWorld::Cells::readRecord(ESM::ESMReader& reader, uint32_t type, const std::map<int, int>& contentFileMap) bool MWWorld::WorldModel::readRecord(ESM::ESMReader& reader, uint32_t type, const std::map<int, int>& contentFileMap)
{ {
if (type == ESM::REC_CSTA) if (type == ESM::REC_CSTA)
{ {

View File

@ -1,5 +1,5 @@
#ifndef GAME_MWWORLD_CELLS_H #ifndef GAME_MWWORLD_WORLDMODEL_H
#define GAME_MWWORLD_CELLS_H #define GAME_MWWORLD_WORLDMODEL_H
#include <list> #include <list>
#include <map> #include <map>
@ -27,7 +27,7 @@ namespace MWWorld
class ESMStore; class ESMStore;
/// \brief Cell container /// \brief Cell container
class Cells class WorldModel
{ {
typedef std::vector<std::pair<std::string, CellStore*>> IdCache; typedef std::vector<std::pair<std::string, CellStore*>> IdCache;
const MWWorld::ESMStore& mStore; const MWWorld::ESMStore& mStore;
@ -37,8 +37,8 @@ namespace MWWorld
IdCache mIdCache; IdCache mIdCache;
std::size_t mIdCacheIndex; std::size_t mIdCacheIndex;
Cells(const Cells&); WorldModel(const WorldModel&);
Cells& operator=(const Cells&); WorldModel& operator=(const WorldModel&);
CellStore* getCellStore(const ESM::Cell* cell); CellStore* getCellStore(const ESM::Cell* cell);
@ -51,7 +51,7 @@ namespace MWWorld
public: public:
void clear(); void clear();
explicit Cells(const MWWorld::ESMStore& store, ESM::ReadersCache& reader); explicit WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCache& reader);
CellStore* getExterior(int x, int y); CellStore* getExterior(int x, int y);