From 7693f712bcc5e661961157b03dd2ade794b7ea24 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 21 Feb 2014 11:35:46 +0100 Subject: [PATCH 1/9] started making CellStore into a proper class; encapsulated mCell member --- apps/openmw/mwdialogue/filter.cpp | 4 +- apps/openmw/mwgui/mapwindow.cpp | 2 +- apps/openmw/mwgui/travelwindow.cpp | 6 ++- apps/openmw/mwgui/waitdialog.cpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 16 ++++---- apps/openmw/mwmechanics/aiactivate.cpp | 10 ++--- apps/openmw/mwmechanics/aicombat.cpp | 30 +++++++------- apps/openmw/mwmechanics/aiescort.cpp | 22 +++++----- apps/openmw/mwmechanics/aifollow.cpp | 8 ++-- apps/openmw/mwmechanics/aitravel.cpp | 10 ++--- apps/openmw/mwmechanics/aiwander.cpp | 10 ++--- apps/openmw/mwmechanics/pathfinding.cpp | 8 ++-- apps/openmw/mwmechanics/spellcasting.cpp | 2 +- apps/openmw/mwrender/animation.cpp | 4 +- apps/openmw/mwrender/debugging.cpp | 16 ++++---- apps/openmw/mwrender/localmap.cpp | 8 ++-- apps/openmw/mwrender/renderingmanager.cpp | 20 ++++----- apps/openmw/mwscript/cellextensions.cpp | 10 ++--- apps/openmw/mwsound/soundmanagerimp.cpp | 4 +- apps/openmw/mwstate/statemanagerimp.cpp | 2 +- apps/openmw/mwworld/cells.cpp | 4 +- apps/openmw/mwworld/cellstore.cpp | 5 +++ apps/openmw/mwworld/cellstore.hpp | 23 +++++++---- apps/openmw/mwworld/physicssystem.cpp | 2 +- apps/openmw/mwworld/player.cpp | 4 +- apps/openmw/mwworld/scene.cpp | 50 +++++++++++------------ apps/openmw/mwworld/weather.cpp | 4 +- apps/openmw/mwworld/worldimp.cpp | 20 ++++----- 28 files changed, 161 insertions(+), 145 deletions(-) diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 3d45b85ce..846cff114 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -110,7 +110,7 @@ bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const // check cell if (!info.mCell.empty()) - if (!Misc::StringUtils::ciEqual(player.getCell()->mCell->mName, info.mCell)) + if (!Misc::StringUtils::ciEqual(player.getCell()->getCell()->mName, info.mCell)) return false; return true; @@ -445,7 +445,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_NotCell: - return !Misc::StringUtils::ciEqual(mActor.getCell()->mCell->mName, select.getName()); + return !Misc::StringUtils::ciEqual(mActor.getCell()->getCell()->mName, select.getName()); case SelectWrapper::Function_NotLocal: { diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 1b4af6d82..267c761e2 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -356,7 +356,7 @@ namespace MWGui ESM::Position markedPosition; MWBase::Environment::get().getWorld()->getPlayer().getMarkedPosition(markedCell, markedPosition); if (markedCell && markedCell->isExterior() == !mInterior - && (!mInterior || Misc::StringUtils::ciEqual(markedCell->mCell->mName, mPrefix))) + && (!mInterior || Misc::StringUtils::ciEqual(markedCell->getCell()->mName, mPrefix))) { MarkerPosition markerPos; MyGUI::IntPoint widgetPos = getMarkerPosition(markedPosition.pos[0], markedPosition.pos[1], markerPos); diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index c314ce1fd..348178d81 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -109,7 +109,11 @@ namespace MWGui int x,y; MWBase::Environment::get().getWorld()->positionToIndex(mPtr.get()->mBase->mTransport[i].mPos.pos[0], mPtr.get()->mBase->mTransport[i].mPos.pos[1],x,y); - if(cellname == "") {cellname = MWBase::Environment::get().getWorld()->getExterior(x,y)->mCell->mName; interior= false;} + if (cellname == "") + { + cellname = MWBase::Environment::get().getWorld()->getExterior(x,y)->getCell()->mName; + interior = false; + } addDestination(cellname,mPtr.get()->mBase->mTransport[i].mPos,interior); } diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 3c1a4b3fa..fd487c87f 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -129,7 +129,7 @@ namespace MWGui MWWorld::Ptr player = world->getPlayerPtr(); if (mSleeping && player.getCell()->isExterior()) { - std::string regionstr = player.getCell()->mCell->mRegion; + std::string regionstr = player.getCell()->getCell()->mRegion; if (!regionstr.empty()) { const ESM::Region *region = world->getStore().get().find (regionstr); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 5448bc3c4..ba9684589 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -739,22 +739,22 @@ namespace MWGui mMap->setCellName( name ); mHud->setCellName( name ); - if (cell->mCell->isExterior()) + if (cell->getCell()->isExterior()) { - if (!cell->mCell->mName.empty()) - mMap->addVisitedLocation ("#{sCell=" + name + "}", cell->mCell->getGridX (), cell->mCell->getGridY ()); + if (!cell->getCell()->mName.empty()) + mMap->addVisitedLocation ("#{sCell=" + name + "}", cell->getCell()->getGridX (), cell->getCell()->getGridY ()); - mMap->cellExplored(cell->mCell->getGridX(), cell->mCell->getGridY()); + mMap->cellExplored (cell->getCell()->getGridX(), cell->getCell()->getGridY()); mMap->setCellPrefix("Cell"); mHud->setCellPrefix("Cell"); - mMap->setActiveCell( cell->mCell->getGridX(), cell->mCell->getGridY() ); - mHud->setActiveCell( cell->mCell->getGridX(), cell->mCell->getGridY() ); + mMap->setActiveCell (cell->getCell()->getGridX(), cell->getCell()->getGridY()); + mHud->setActiveCell (cell->getCell()->getGridX(), cell->getCell()->getGridY()); } else { - mMap->setCellPrefix( cell->mCell->mName ); - mHud->setCellPrefix( cell->mCell->mName ); + mMap->setCellPrefix (cell->getCell()->mName ); + mHud->setCellPrefix (cell->getCell()->mName ); Ogre::Vector3 worldPos; if (!MWBase::Environment::get().getWorld()->findInteriorPositionInWorldSpace(cell, worldPos)) diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index 1f3c58521..ea146625a 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -33,12 +33,12 @@ bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration) MWBase::World *world = MWBase::Environment::get().getWorld(); ESM::Position pos = actor.getRefData().getPosition(); Movement &movement = actor.getClass().getMovementSettings(actor); - const ESM::Cell *cell = actor.getCell()->mCell; + const ESM::Cell *cell = actor.getCell()->getCell(); MWWorld::Ptr player = world->getPlayerPtr(); - if(cell->mData.mX != player.getCell()->mCell->mData.mX) + if(cell->mData.mX != player.getCell()->getCell()->mData.mX) { - int sideX = sgn(cell->mData.mX - player.getCell()->mCell->mData.mX); + int sideX = sgn(cell->mData.mX - player.getCell()->getCell()->mData.mX); //check if actor is near the border of an inactive cell. If so, stop walking. if(sideX * (pos.pos[0] - cell->mData.mX*ESM::Land::REAL_SIZE) > sideX * (ESM::Land::REAL_SIZE/2.0f - 200.0f)) @@ -47,9 +47,9 @@ bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration) return false; } } - if(cell->mData.mY != player.getCell()->mCell->mData.mY) + if(cell->mData.mY != player.getCell()->getCell()->mData.mY) { - int sideY = sgn(cell->mData.mY - player.getCell()->mCell->mData.mY); + int sideY = sgn(cell->mData.mY - player.getCell()->getCell()->mData.mY); //check if actor is near the border of an inactive cell. If so, stop walking. if(sideY * (pos.pos[1] - cell->mData.mY*ESM::Land::REAL_SIZE) > sideY * (ESM::Land::REAL_SIZE/2.0f - 200.0f)) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 3653587f8..b0e0c2f7b 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -34,9 +34,9 @@ namespace namespace MWMechanics { AiCombat::AiCombat(const MWWorld::Ptr& actor) : - mTarget(actor), - mTimerAttack(0), - mTimerReact(0), + mTarget(actor), + mTimerAttack(0), + mTimerReact(0), mTimerCombatMove(0), mFollowTarget(false), mReadyToAttack(false), @@ -77,7 +77,7 @@ namespace MWMechanics if (zTurn(actor, Ogre::Degree(mTargetAngle))) mRotate = false; } - + mTimerAttack -= duration; actor.getClass().getCreatureStats(actor).setAttackingOrSpell(mStrike); @@ -105,7 +105,7 @@ namespace MWMechanics //Also it seems that this time is different for slash/thrust/chop mTimerAttack = 0.35f * static_cast(rand())/RAND_MAX; mStrike = true; - + //say a provoking combat phrase if (actor.getClass().isNpc()) { @@ -126,7 +126,7 @@ namespace MWMechanics mTimerAttack = -attackPeriod; mStrike = false; } - + const MWWorld::Class &cls = actor.getClass(); const ESM::Weapon *weapon = NULL; MWMechanics::WeaponType weaptype; @@ -138,14 +138,14 @@ namespace MWMechanics { MWMechanics::DrawState_ state = actor.getClass().getCreatureStats(actor).getDrawState(); if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing) - actor.getClass().getNpcStats(actor).setDrawState(MWMechanics::DrawState_Weapon); + actor.getClass().getNpcStats(actor).setDrawState(MWMechanics::DrawState_Weapon); //Get weapon speed and range - MWWorld::ContainerStoreIterator weaponSlot = + MWWorld::ContainerStoreIterator weaponSlot = MWMechanics::getActiveWeapon(cls.getNpcStats(actor), cls.getInventoryStore(actor), &weaptype); if (weaptype == WeapType_HandToHand) { - const MWWorld::Store &gmst = + const MWWorld::Store &gmst = MWBase::Environment::get().getWorld()->getStore().get(); weapRange = gmst.find("fHandToHandReach")->getFloat(); } @@ -246,12 +246,12 @@ namespace MWMechanics mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]); //try shortcut - if(vDir.length() < mPathFinder.getDistToNext(pos.pos[0],pos.pos[1],pos.pos[2]) && MWBase::Environment::get().getWorld()->getLOS(actor, mTarget)) + if(vDir.length() < mPathFinder.getDistToNext(pos.pos[0],pos.pos[1],pos.pos[2]) && MWBase::Environment::get().getWorld()->getLOS(actor, mTarget)) mTargetAngle = Ogre::Radian( Ogre::Math::ACos(vDir.y / vDir.length()) * sgn(Ogre::Math::ASin(vDir.x / vDir.length())) ).valueDegrees(); else mTargetAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); mRotate = true; - + mMovement.mPosition[1] = 1; mReadyToAttack = false; } @@ -305,13 +305,13 @@ namespace MWMechanics float dist = Ogre::Math::Abs((newPathTarget - currPathTarget).length()); float targetPosThreshold; - bool isOutside = actor.getCell()->mCell->isExterior(); + bool isOutside = actor.getCell()->getCell()->isExterior(); if (isOutside) targetPosThreshold = 300; else targetPosThreshold = 100; - if(dist > targetPosThreshold) + if(dist > targetPosThreshold) { //construct new path only if target has moved away more than on ESM::Position pos = actor.getRefData().getPosition(); @@ -328,7 +328,7 @@ namespace MWMechanics PathFinder newPathFinder; newPathFinder.buildPath(start, dest, actor.getCell(), isOutside); - //TO EXPLORE: + //TO EXPLORE: //maybe here is a mistake (?): PathFinder::getPathSize() returns number of grid points in the path, //not the actual path length. Here we should know if the new path is actually more effective. //if(pathFinder2.getPathSize() < mPathFinder.getPathSize()) @@ -391,7 +391,7 @@ void chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement int thrust = (weapon->mData.mThrust[0] + weapon->mData.mThrust[1])/2; float total = slash + chop + thrust; - + float roll = static_cast(rand())/RAND_MAX; if(roll <= static_cast(slash)/total) { diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index bac258425..a58bfef05 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -86,25 +86,25 @@ namespace MWMechanics MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); ESM::Position pos = actor.getRefData().getPosition(); - bool cellChange = actor.getCell()->mCell->mData.mX != mCellX || actor.getCell()->mCell->mData.mY != mCellY; + bool cellChange = actor.getCell()->getCell()->mData.mX != mCellX || actor.getCell()->getCell()->mData.mY != mCellY; - if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX) + if(actor.getCell()->getCell()->mData.mX != player.getCell()->getCell()->mData.mX) { - int sideX = sgn(actor.getCell()->mCell->mData.mX - player.getCell()->mCell->mData.mX); + int sideX = sgn(actor.getCell()->getCell()->mData.mX - player.getCell()->getCell()->mData.mX); // Check if actor is near the border of an inactive cell. If so, pause walking. - if(sideX * (pos.pos[0] - actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE) > sideX * (ESM::Land::REAL_SIZE / - 2.0 - 200)) + if(sideX * (pos.pos[0] - actor.getCell()->getCell()->mData.mX * ESM::Land::REAL_SIZE) > sideX * (ESM::Land::REAL_SIZE / + 2.0 - 200)) { MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; return false; } } - if(actor.getCell()->mCell->mData.mY != player.getCell()->mCell->mData.mY) + if(actor.getCell()->getCell()->mData.mY != player.getCell()->getCell()->mData.mY) { - int sideY = sgn(actor.getCell()->mCell->mData.mY - player.getCell()->mCell->mData.mY); + int sideY = sgn(actor.getCell()->getCell()->mData.mY - player.getCell()->getCell()->mData.mY); // Check if actor is near the border of an inactive cell. If so, pause walking. - if(sideY*(pos.pos[1] - actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE) > sideY * (ESM::Land::REAL_SIZE / - 2.0 - 200)) + if(sideY*(pos.pos[1] - actor.getCell()->getCell()->mData.mY * ESM::Land::REAL_SIZE) > sideY * (ESM::Land::REAL_SIZE / + 2.0 - 200)) { MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; return false; @@ -114,8 +114,8 @@ namespace MWMechanics if(!mPathFinder.isPathConstructed() || cellChange) { - mCellX = actor.getCell()->mCell->mData.mX; - mCellY = actor.getCell()->mCell->mData.mY; + mCellX = actor.getCell()->getCell()->mData.mX; + mCellY = actor.getCell()->getCell()->mData.mY; ESM::Pathgrid::Point dest; dest.mX = mX; diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index cf5291fd3..ef6ead9d7 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -33,16 +33,16 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) if((pos.pos[0]-mX)*(pos.pos[0]-mX) + (pos.pos[1]-mY)*(pos.pos[1]-mY) + - (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < 100*100) + (pos.pos[2]-mZ)*(pos.pos[2]-mZ) < 100*100) { if(actor.getCell()->isExterior()) { - if(mCellId == "") + if(mCellId == "") return true; } else { - if(mCellId == actor.getCell()->mCell->mName) + if(mCellId == actor.getCell()->getCell()->mName) return true; } } @@ -67,7 +67,7 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) { ESM::Pathgrid::Point lastPos = mPathFinder.getPath().back(); - if((dest.mX - lastPos.mX)*(dest.mX - lastPos.mX) + if((dest.mX - lastPos.mX)*(dest.mX - lastPos.mX) +(dest.mY - lastPos.mY)*(dest.mY - lastPos.mY) +(dest.mZ - lastPos.mZ)*(dest.mZ - lastPos.mZ) > 100*100) diff --git a/apps/openmw/mwmechanics/aitravel.cpp b/apps/openmw/mwmechanics/aitravel.cpp index 03052f327..41226ad79 100644 --- a/apps/openmw/mwmechanics/aitravel.cpp +++ b/apps/openmw/mwmechanics/aitravel.cpp @@ -36,12 +36,12 @@ namespace MWMechanics MWBase::World *world = MWBase::Environment::get().getWorld(); ESM::Position pos = actor.getRefData().getPosition(); Movement &movement = actor.getClass().getMovementSettings(actor); - const ESM::Cell *cell = actor.getCell()->mCell; + const ESM::Cell *cell = actor.getCell()->getCell(); MWWorld::Ptr player = world->getPlayerPtr(); - if(cell->mData.mX != player.getCell()->mCell->mData.mX) + if(cell->mData.mX != player.getCell()->getCell()->mData.mX) { - int sideX = sgn(cell->mData.mX - player.getCell()->mCell->mData.mX); + int sideX = sgn(cell->mData.mX - player.getCell()->getCell()->mData.mX); //check if actor is near the border of an inactive cell. If so, stop walking. if(sideX * (pos.pos[0] - cell->mData.mX*ESM::Land::REAL_SIZE) > sideX * (ESM::Land::REAL_SIZE/2.0f - 200.0f)) @@ -50,9 +50,9 @@ namespace MWMechanics return false; } } - if(cell->mData.mY != player.getCell()->mCell->mData.mY) + if(cell->mData.mY != player.getCell()->getCell()->mData.mY) { - int sideY = sgn(cell->mData.mY - player.getCell()->mCell->mData.mY); + int sideY = sgn(cell->mData.mY - player.getCell()->getCell()->mData.mY); //check if actor is near the border of an inactive cell. If so, stop walking. if(sideY * (pos.pos[1] - cell->mData.mY*ESM::Land::REAL_SIZE) > sideY * (ESM::Land::REAL_SIZE/2.0f - 200.0f)) diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 77316fedf..012f71b72 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -103,10 +103,10 @@ namespace MWMechanics if(!mStoredAvailableNodes) { mStoredAvailableNodes = true; - mPathgrid = world->getStore().get().search(*actor.getCell()->mCell); + mPathgrid = world->getStore().get().search(*actor.getCell()->getCell()); - mCellX = actor.getCell()->mCell->mData.mX; - mCellY = actor.getCell()->mCell->mData.mY; + mCellX = actor.getCell()->getCell()->mData.mX; + mCellY = actor.getCell()->getCell()->mData.mY; if(!mPathgrid) mDistance = 0; @@ -117,7 +117,7 @@ namespace MWMechanics { mXCell = 0; mYCell = 0; - if(actor.getCell()->mCell->isExterior()) + if(actor.getCell()->getCell()->isExterior()) { mXCell = mCellX * ESM::Land::REAL_SIZE; mYCell = mCellY * ESM::Land::REAL_SIZE; @@ -157,7 +157,7 @@ namespace MWMechanics mDistance = 0; // Don't try to move if you are in a new cell (ie: positioncell command called) but still play idles. - if(mDistance && (mCellX != actor.getCell()->mCell->mData.mX || mCellY != actor.getCell()->mCell->mData.mY)) + if(mDistance && (mCellX != actor.getCell()->getCell()->mData.mX || mCellY != actor.getCell()->getCell()->mData.mY)) mDistance = 0; if(mChooseAction) diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 4407363a6..2503181ae 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -299,14 +299,14 @@ namespace MWMechanics if(!allowShortcuts) { const ESM::Pathgrid *pathGrid = - MWBase::Environment::get().getWorld()->getStore().get().search(*mCell->mCell); + MWBase::Environment::get().getWorld()->getStore().get().search(*mCell->getCell()); float xCell = 0; float yCell = 0; if (mCell->isExterior()) { - xCell = mCell->mCell->mData.mX * ESM::Land::REAL_SIZE; - yCell = mCell->mCell->mData.mY * ESM::Land::REAL_SIZE; + xCell = mCell->getCell()->mData.mX * ESM::Land::REAL_SIZE; + yCell = mCell->getCell()->mData.mY * ESM::Land::REAL_SIZE; } int startNode = getClosestPoint(pathGrid, startPoint.mX - xCell, startPoint.mY - yCell,startPoint.mZ); int endNode = getClosestPoint(pathGrid, endPoint.mX - xCell, endPoint.mY - yCell, endPoint.mZ); @@ -393,7 +393,7 @@ namespace MWMechanics { std::list::const_iterator oldStart = path.begin(); std::list::iterator iter = ++mPath.begin(); - + if( (*iter).mX == oldStart->mX && (*iter).mY == oldStart->mY && (*iter).mZ == oldStart->mZ diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index fe395e566..30072a8cc 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -503,7 +503,7 @@ namespace MWMechanics MWBase::Environment::get().getWorld()->getPlayer().getMarkedPosition(markedCell, markedPosition); if (markedCell) { - MWWorld::ActionTeleport action(markedCell->isExterior() ? "" : markedCell->mCell->mName, + MWWorld::ActionTeleport action(markedCell->isExterior() ? "" : markedCell->getCell()->mName, markedPosition); action.execute(target); } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 44bba90d0..820857137 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -334,7 +334,7 @@ void Animation::addExtraLight(Ogre::SceneManager *sceneMgr, NifOgre::ObjectScene )); objlist->mControllers.push_back(Ogre::Controller(src, dest, func)); - bool interior = !(mPtr.isInCell() && mPtr.getCell()->mCell->isExterior()); + bool interior = !(mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior()); bool quadratic = fallback->getFallbackBool("LightAttenuation_OutQuadInLin") ? !interior : fallback->getFallbackBool("LightAttenuation_UseQuadratic"); @@ -1070,7 +1070,7 @@ bool Animation::allowSwitchViewMode() const { for (AnimStateMap::const_iterator stateiter = mStates.begin(); stateiter != mStates.end(); ++stateiter) { - if(stateiter->second.mPriority > MWMechanics::Priority_Movement + if(stateiter->second.mPriority > MWMechanics::Priority_Movement && stateiter->second.mPriority < MWMechanics::Priority_Torch) return false; } diff --git a/apps/openmw/mwrender/debugging.cpp b/apps/openmw/mwrender/debugging.cpp index 2b61e109b..0cfcf826f 100644 --- a/apps/openmw/mwrender/debugging.cpp +++ b/apps/openmw/mwrender/debugging.cpp @@ -230,22 +230,22 @@ void Debugging::togglePathgrid() void Debugging::enableCellPathgrid(MWWorld::CellStore *store) { const ESM::Pathgrid *pathgrid = - MWBase::Environment::get().getWorld()->getStore().get().search(*store->mCell); + MWBase::Environment::get().getWorld()->getStore().get().search(*store->getCell()); if (!pathgrid) return; Vector3 cellPathGridPos(0, 0, 0); - if (store->mCell->isExterior()) + if (store->getCell()->isExterior()) { - cellPathGridPos.x = store->mCell->mData.mX * ESM::Land::REAL_SIZE; - cellPathGridPos.y = store->mCell->mData.mY * ESM::Land::REAL_SIZE; + cellPathGridPos.x = store->getCell()->mData.mX * ESM::Land::REAL_SIZE; + cellPathGridPos.y = store->getCell()->mData.mY * ESM::Land::REAL_SIZE; } SceneNode *cellPathGrid = mPathGridRoot->createChildSceneNode(cellPathGridPos); cellPathGrid->attachObject(createPathgridLines(pathgrid)); cellPathGrid->attachObject(createPathgridPoints(pathgrid)); - if (store->mCell->isExterior()) + if (store->getCell()->isExterior()) { - mExteriorPathgridNodes[std::make_pair(store->mCell->getGridX(), store->mCell->getGridY())] = cellPathGrid; + mExteriorPathgridNodes[std::make_pair(store->getCell()->getGridX(), store->getCell()->getGridY())] = cellPathGrid; } else { @@ -256,10 +256,10 @@ void Debugging::enableCellPathgrid(MWWorld::CellStore *store) void Debugging::disableCellPathgrid(MWWorld::CellStore *store) { - if (store->mCell->isExterior()) + if (store->getCell()->isExterior()) { ExteriorPathgridNodes::iterator it = - mExteriorPathgridNodes.find(std::make_pair(store->mCell->getGridX(), store->mCell->getGridY())); + mExteriorPathgridNodes.find(std::make_pair(store->getCell()->getGridX(), store->getCell()->getGridY())); if (it != mExteriorPathgridNodes.end()) { destroyCellPathgridNode(it->second); diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index f147ae7b7..554ba22fa 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -115,8 +115,8 @@ void LocalMap::requestMap(MWWorld::CellStore* cell, float zMin, float zMax) mCameraRotNode->setOrientation(Quaternion::IDENTITY); mCellCamera->setOrientation(Quaternion(Ogre::Math::Cos(Ogre::Degree(0)/2.f), 0, 0, -Ogre::Math::Sin(Ogre::Degree(0)/2.f))); - int x = cell->mCell->getGridX(); - int y = cell->mCell->getGridY(); + int x = cell->getCell()->getGridX(); + int y = cell->getCell()->getGridY(); std::string name = "Cell_"+coordStr(x, y); @@ -182,7 +182,7 @@ void LocalMap::requestMap(MWWorld::CellStore* cell, const int segsX = std::ceil( length.x / sSize ); const int segsY = std::ceil( length.y / sSize ); - mInteriorName = cell->mCell->mName; + mInteriorName = cell->getCell()->mName; for (int x=0; xmCell->mName + "_" + coordStr(x,y)); + cell->getCell()->mName + "_" + coordStr(x,y)); } } } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 0a82d67fb..0311c90b3 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -422,9 +422,9 @@ void RenderingManager::postRenderTargetUpdate(const RenderTargetEvent &evt) void RenderingManager::waterAdded (MWWorld::CellStore *store) { - if(store->mCell->mData.mFlags & ESM::Cell::HasWater) + if (store->getCell()->mData.mFlags & ESM::Cell::HasWater) { - mWater->changeCell(store->mCell); + mWater->changeCell (store->getCell()); mWater->setActive(true); } else @@ -501,9 +501,9 @@ bool RenderingManager::toggleRenderMode(int mode) void RenderingManager::configureFog(MWWorld::CellStore &mCell) { Ogre::ColourValue color; - color.setAsABGR (mCell.mCell->mAmbi.mFog); + color.setAsABGR (mCell.getCell()->mAmbi.mFog); - configureFog(mCell.mCell->mAmbi.mFogDensity, color); + configureFog (mCell.getCell()->mAmbi.mFogDensity, color); } void RenderingManager::configureFog(const float density, const Ogre::ColourValue& colour) @@ -553,8 +553,8 @@ void RenderingManager::setAmbientMode() void RenderingManager::configureAmbient(MWWorld::CellStore &mCell) { - if (mCell.mCell->mData.mFlags & ESM::Cell::Interior) - mAmbientColor.setAsABGR (mCell.mCell->mAmbi.mAmbient); + if (mCell.getCell()->mData.mFlags & ESM::Cell::Interior) + mAmbientColor.setAsABGR (mCell.getCell()->mAmbi.mAmbient); setAmbientMode(); // Create a "sun" that shines light downwards. It doesn't look @@ -564,10 +564,10 @@ void RenderingManager::configureAmbient(MWWorld::CellStore &mCell) mSun = mRendering.getScene()->createLight(); mSun->setType(Ogre::Light::LT_DIRECTIONAL); } - if (mCell.mCell->mData.mFlags & ESM::Cell::Interior) + if (mCell.getCell()->mData.mFlags & ESM::Cell::Interior) { Ogre::ColourValue colour; - colour.setAsABGR (mCell.mCell->mAmbi.mSunlight); + colour.setAsABGR (mCell.getCell()->mAmbi.mSunlight); mSun->setDiffuseColour (colour); mSun->setDirection(0,-1,0); } @@ -650,12 +650,12 @@ void RenderingManager::setGlare(bool glare) void RenderingManager::requestMap(MWWorld::CellStore* cell) { - if (cell->mCell->isExterior()) + if (cell->getCell()->isExterior()) { assert(mTerrain); Ogre::AxisAlignedBox dims = mObjects->getDimensions(cell); - Ogre::Vector2 center(cell->mCell->getGridX() + 0.5, cell->mCell->getGridY() + 0.5); + Ogre::Vector2 center (cell->getCell()->getGridX() + 0.5, cell->getCell()->getGridY() + 0.5); dims.merge(mTerrain->getWorldBoundingBox(center)); if (dims.isFinite()) diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index a0acfa4da..2140076c3 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -88,7 +88,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { bool interior = - !MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->mCell->isExterior(); + !MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell()->isExterior(); runtime.push (interior ? 1 : 0); } @@ -103,7 +103,7 @@ namespace MWScript std::string name = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - const ESM::Cell *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->mCell; + const ESM::Cell *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell(); std::string current = cell->mName; @@ -131,7 +131,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); - if (cell->mCell->hasWater()) + if (cell->getCell()->hasWater()) runtime.push (cell->mWaterLevel); else runtime.push (-std::numeric_limits().max()); @@ -148,7 +148,7 @@ namespace MWScript MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); - if (cell->mCell->isExterior()) + if (cell->getCell()->isExterior()) throw std::runtime_error("Can't set water level in exterior cell"); cell->mWaterLevel = level; @@ -166,7 +166,7 @@ namespace MWScript MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); - if (cell->mCell->isExterior()) + if (cell->getCell()->isExterior()) throw std::runtime_error("Can't set water level in exterior cell"); cell->mWaterLevel +=level; diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index fd3fe4c0a..13e152e68 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -480,7 +480,7 @@ namespace MWSound static float sTimePassed = 0.0; MWBase::World *world = MWBase::Environment::get().getWorld(); const MWWorld::Ptr player = world->getPlayerPtr(); - const ESM::Cell *cell = player.getCell()->mCell; + const ESM::Cell *cell = player.getCell()->getCell(); sTimePassed += duration; if(!cell->isExterior() || sTimePassed < sTimeToNextEnvSound) @@ -548,7 +548,7 @@ namespace MWSound MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - const ESM::Cell *cell = player.getCell()->mCell; + const ESM::Cell *cell = player.getCell()->getCell(); Environment env = Env_Normal; if((cell->mData.mFlags&cell->HasWater) && mListenerPos.z < cell->mWater) diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index ba0e1d056..8c59247f4 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -301,7 +301,7 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - ESM::CellId cellId = ptr.getCell()->mCell->getCellId(); + ESM::CellId cellId = ptr.getCell()->getCell()->getCellId(); MWBase::Environment::get().getWorld()->changeToCell (cellId, ptr.getRefData().getPosition()); } diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 965c9fc5d..cdfbb7b45 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -83,8 +83,8 @@ bool MWWorld::Cells::hasState (const CellStore& cellStore) const if (cellStore.mState==CellStore::State_Loaded) return true; - if (cellStore.mCell->mData.mFlags & ESM::Cell::Interior) - return cellStore.mCell->mData.mFlags & ESM::Cell::HasWater; + if (cellStore.getCell()->mData.mFlags & ESM::Cell::Interior) + return cellStore.getCell()->mData.mFlags & ESM::Cell::HasWater; else return false; } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 42c954afb..c3c3eb6e9 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -145,6 +145,11 @@ namespace MWWorld mWaterLevel = cell->mWater; } + const ESM::Cell *CellStore::getCell() const + { + return mCell; + } + void CellStore::load (const MWWorld::ESMStore &store, std::vector &esm) { if (mState!=State_Loaded) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index a4f219013..b90ea72a5 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -49,19 +49,26 @@ namespace MWWorld } }; - /// A storage struct for one single cell reference. + /// \brief Mutable state of a cell class CellStore { - public: + public: - enum State - { - State_Unloaded, State_Preloaded, State_Loaded - }; + enum State + { + State_Unloaded, State_Preloaded, State_Loaded + }; - CellStore (const ESM::Cell *cell_); + private: + + const ESM::Cell *mCell; + + public: + + CellStore (const ESM::Cell *cell_); + + const ESM::Cell *getCell() const; - const ESM::Cell *mCell; State mState; std::vector mIds; diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index a7103b991..56d19c8be 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -574,7 +574,7 @@ namespace MWWorld for(;iter != mMovementQueue.end();iter++) { float waterlevel = -std::numeric_limits::max(); - const ESM::Cell *cell = iter->first.getCell()->mCell; + const ESM::Cell *cell = iter->first.getCell()->getCell(); if(cell->hasWater()) waterlevel = cell->mWater; diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index c1cce84fc..ba816d6d5 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -191,7 +191,7 @@ namespace MWWorld ESM::Player player; mPlayer.save (player.mObject); - player.mCellId = mCellStore->mCell->getCellId(); + player.mCellId = mCellStore->getCell()->getCellId(); player.mBirthsign = mSign; @@ -203,7 +203,7 @@ namespace MWWorld { player.mHasMark = true; player.mMarkedPosition = mMarkedPosition; - player.mMarkedCell = mMarkedCell->mCell->getCellId(); + player.mMarkedCell = mMarkedCell->getCell()->getCellId(); } else player.mHasMark = false; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 167adf301..06141db54 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -97,15 +97,15 @@ namespace MWWorld } } - if ((*iter)->mCell->isExterior()) + if ((*iter)->getCell()->isExterior()) { ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().get().search( - (*iter)->mCell->getGridX(), - (*iter)->mCell->getGridY() + (*iter)->getCell()->getGridX(), + (*iter)->getCell()->getGridY() ); if (land) - mPhysics->removeHeightField( (*iter)->mCell->getGridX(), (*iter)->mCell->getGridY() ); + mPhysics->removeHeightField ((*iter)->getCell()->getGridX(), (*iter)->getCell()->getGridY()); } mRendering.removeCell(*iter); @@ -128,18 +128,18 @@ namespace MWWorld float worldsize = ESM::Land::REAL_SIZE; // Load terrain physics first... - if (cell->mCell->isExterior()) + if (cell->getCell()->isExterior()) { ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().get().search( - cell->mCell->getGridX(), - cell->mCell->getGridY() + cell->getCell()->getGridX(), + cell->getCell()->getGridY() ); if (land) { mPhysics->addHeightField ( land->mLandData->mHeights, - cell->mCell->getGridX(), - cell->mCell->getGridY(), + cell->getCell()->getGridX(), + cell->getCell()->getGridY(), 0, worldsize / (verts-1), verts) @@ -218,10 +218,10 @@ namespace MWWorld int numUnload = 0; while (active!=mActiveCells.end()) { - if ((*active)->mCell->isExterior()) + if ((*active)->getCell()->isExterior()) { - if (std::abs (X-(*active)->mCell->getGridX())<=1 && - std::abs (Y-(*active)->mCell->getGridY())<=1) + if (std::abs (X-(*active)->getCell()->getGridX())<=1 && + std::abs (Y-(*active)->getCell()->getGridY())<=1) { // keep cells within the new 3x3 grid ++active; @@ -235,10 +235,10 @@ namespace MWWorld active = mActiveCells.begin(); while (active!=mActiveCells.end()) { - if ((*active)->mCell->isExterior()) + if ((*active)->getCell()->isExterior()) { - if (std::abs (X-(*active)->mCell->getGridX())<=1 && - std::abs (Y-(*active)->mCell->getGridY())<=1) + if (std::abs (X-(*active)->getCell()->getGridX())<=1 && + std::abs (Y-(*active)->getCell()->getGridY())<=1) { // keep cells within the new 3x3 grid ++active; @@ -257,10 +257,10 @@ namespace MWWorld while (iter!=mActiveCells.end()) { - assert ((*iter)->mCell->isExterior()); + assert ((*iter)->getCell()->isExterior()); - if (x==(*iter)->mCell->getGridX() && - y==(*iter)->mCell->getGridY()) + if (x==(*iter)->getCell()->getGridX() && + y==(*iter)->getCell()->getGridY()) break; ++iter; @@ -280,10 +280,10 @@ namespace MWWorld while (iter!=mActiveCells.end()) { - assert ((*iter)->mCell->isExterior()); + assert ((*iter)->getCell()->isExterior()); - if (x==(*iter)->mCell->getGridX() && - y==(*iter)->mCell->getGridY()) + if (x==(*iter)->getCell()->getGridX() && + y==(*iter)->getCell()->getGridY()) break; ++iter; @@ -302,10 +302,10 @@ namespace MWWorld while (iter!=mActiveCells.end()) { - assert ((*iter)->mCell->isExterior()); + assert ((*iter)->getCell()->isExterior()); - if (X==(*iter)->mCell->getGridX() && - Y==(*iter)->mCell->getGridY()) + if (X==(*iter)->getCell()->getGridX() && + Y==(*iter)->getCell()->getGridY()) break; ++iter; @@ -407,7 +407,7 @@ namespace MWWorld loadingListener->setProgressRange(refsToLoad); // Load cell. - std::cout << "cellName: " << cell->mCell->mName << std::endl; + std::cout << "cellName: " << cell->getCell()->mName << std::endl; //Loading Interior loading text diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index b00ad15ca..c79d7ee4f 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -664,7 +664,7 @@ void WeatherManager::changeWeather(const std::string& region, const unsigned int mRegionOverrides[Misc::StringUtils::lowerCase(region)] = weather; - std::string playerRegion = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->mCell->mRegion; + std::string playerRegion = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell()->mRegion; if (Misc::StringUtils::ciEqual(region, playerRegion)) setWeather(weather); } @@ -695,7 +695,7 @@ void WeatherManager::switchToNextWeather(bool instantly) MWBase::World* world = MWBase::Environment::get().getWorld(); if (world->isCellExterior() || world->isCellQuasiExterior()) { - std::string regionstr = Misc::StringUtils::lowerCase(world->getPlayerPtr().getCell()->mCell->mRegion); + std::string regionstr = Misc::StringUtils::lowerCase(world->getPlayerPtr().getCell()->getCell()->mRegion); if (mWeatherUpdateTime <= 0 || regionstr != mCurrentRegion) { diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index be6c0b338..4c97c594d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -506,10 +506,10 @@ namespace MWWorld if (!cell) cell = mWorldScene->getCurrentCell(); - if (!cell->mCell->isExterior() || !cell->mCell->mName.empty()) - return cell->mCell->mName; + if (!cell->getCell()->isExterior() || !cell->getCell()->mName.empty()) + return cell->getCell()->mName; - if (const ESM::Region* region = getStore().get().search (cell->mCell->mRegion)) + if (const ESM::Region* region = getStore().get().search (cell->getCell()->mRegion)) return region->mName; return getStore().get().find ("sDefaultCellname")->mValue.getString(); @@ -946,11 +946,11 @@ namespace MWWorld if (isPlayer) { if (!newCell.isExterior()) - changeToInteriorCell(Misc::StringUtils::lowerCase(newCell.mCell->mName), pos); + changeToInteriorCell(Misc::StringUtils::lowerCase(newCell.getCell()->mName), pos); else { - int cellX = newCell.mCell->getGridX(); - int cellY = newCell.mCell->getGridY(); + int cellX = newCell.getCell()->getGridX(); + int cellY = newCell.getCell()->getGridY(); mWorldScene->changeCell(cellX, cellY, pos, false); } addContainerScripts (getPlayerPtr(), &newCell); @@ -1465,7 +1465,7 @@ namespace MWWorld CellStore *currentCell = mWorldScene->getCurrentCell(); if (currentCell) { - return currentCell->mCell->isExterior(); + return currentCell->getCell()->isExterior(); } return false; } @@ -1475,7 +1475,7 @@ namespace MWWorld CellStore *currentCell = mWorldScene->getCurrentCell(); if (currentCell) { - if (!(currentCell->mCell->mData.mFlags & ESM::Cell::QuasiEx)) + if (!(currentCell->getCell()->mData.mFlags & ESM::Cell::QuasiEx)) return false; else return true; @@ -1757,7 +1757,7 @@ namespace MWWorld bool World::isUnderwater(const MWWorld::CellStore* cell, const Ogre::Vector3 &pos) const { - if (!(cell->mCell->mData.mFlags & ESM::Cell::HasWater)) { + if (!(cell->getCell()->mData.mFlags & ESM::Cell::HasWater)) { return false; } return pos.z < cell->mWaterLevel; @@ -1816,7 +1816,7 @@ namespace MWWorld const OEngine::Physic::PhysicActor *physactor = mPhysEngine->getCharacter(refdata.getHandle()); if((!physactor->getOnGround()&&physactor->getCollisionMode()) || isUnderwater(currentCell, playerPos)) return 2; - if((currentCell->mCell->mData.mFlags&ESM::Cell::NoSleep) || + if((currentCell->getCell()->mData.mFlags&ESM::Cell::NoSleep) || Class::get(player).getNpcStats(player).isWerewolf()) return 1; From 8ea686c6c8be5ce8105194c135f92fc2cffc9919 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 14:26:36 +0100 Subject: [PATCH 2/9] encapsulated mState --- apps/openmw/mwworld/cells.cpp | 12 ++++++------ apps/openmw/mwworld/cellstore.cpp | 5 +++++ apps/openmw/mwworld/cellstore.hpp | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index cdfbb7b45..c3bc135a1 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -80,7 +80,7 @@ void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, const CellStore& cell) c bool MWWorld::Cells::hasState (const CellStore& cellStore) const { - if (cellStore.mState==CellStore::State_Loaded) + if (cellStore.getState()==CellStore::State_Loaded) return true; if (cellStore.getCell()->mData.mFlags & ESM::Cell::Interior) @@ -122,7 +122,7 @@ MWWorld::CellStore *MWWorld::Cells::getExterior (int x, int y) std::make_pair (x, y), CellStore (cell))).first; } - if (result->second.mState!=CellStore::State_Loaded) + if (result->second.getState()!=CellStore::State_Loaded) { // Multiple plugin support for landscape data is much easier than for references. The last plugin wins. result->second.load (mStore, mReader); @@ -143,7 +143,7 @@ MWWorld::CellStore *MWWorld::Cells::getInterior (const std::string& name) result = mInteriors.insert (std::make_pair (lowerName, CellStore (cell))).first; } - if (result->second.mState!=CellStore::State_Loaded) + if (result->second.getState()!=CellStore::State_Loaded) { result->second.load (mStore, mReader); } @@ -162,10 +162,10 @@ MWWorld::CellStore *MWWorld::Cells::getCell (const ESM::CellId& id) MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell, bool searchInContainers) { - if (cell.mState==CellStore::State_Unloaded) + if (cell.getState()==CellStore::State_Unloaded) cell.preload (mStore, mReader); - if (cell.mState==CellStore::State_Preloaded) + if (cell.getState()==CellStore::State_Preloaded) { if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), name)) { @@ -375,7 +375,7 @@ bool MWWorld::Cells::readRecord (ESM::ESMReader& reader, int32_t type, state.load (reader); cellStore->loadState (state); - if (cellStore->mState!=CellStore::State_Loaded) + if (cellStore->getState()!=CellStore::State_Loaded) cellStore->load (mStore, mReader); cellStore->readReferences (reader, contentFileMap); diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index c3c3eb6e9..16f317f08 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -150,6 +150,11 @@ namespace MWWorld return mCell; } + CellStore::State CellStore::getState() const + { + return mState; + } + void CellStore::load (const MWWorld::ESMStore &store, std::vector &esm) { if (mState!=State_Loaded) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index b90ea72a5..ef16c64c2 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -62,6 +62,7 @@ namespace MWWorld private: const ESM::Cell *mCell; + State mState; public: @@ -69,7 +70,8 @@ namespace MWWorld const ESM::Cell *getCell() const; - State mState; + State getState() const; + std::vector mIds; float mWaterLevel; From 79e723ad06eaeca8d073eb0d78e6c5bc756dc029 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 16:46:07 +0100 Subject: [PATCH 3/9] encapsulated mIds --- apps/openmw/mwworld/cells.cpp | 63 ++----------------------- apps/openmw/mwworld/cellstore.cpp | 78 +++++++++++++++++++++++++++++++ apps/openmw/mwworld/cellstore.hpp | 10 +++- 3 files changed, 91 insertions(+), 60 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index c3bc135a1..8ce7d4fe8 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -167,7 +167,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell, if (cell.getState()==CellStore::State_Preloaded) { - if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), name)) + if (cell.hasId (name)) { cell.load (mStore, mReader); } @@ -175,65 +175,10 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell, return Ptr(); } - if (MWWorld::LiveCellRef *ref = cell.mActivators.find (name)) - return Ptr (ref, &cell); + Ptr ptr = cell.search (name); - if (MWWorld::LiveCellRef *ref = cell.mPotions.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mAppas.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mArmors.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mBooks.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mClothes.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mContainers.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mCreatures.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mDoors.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mIngreds.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mCreatureLists.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mItemLists.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mLights.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mLockpicks.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mMiscItems.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mNpcs.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mProbes.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mRepairs.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mStatics.find (name)) - return Ptr (ref, &cell); - - if (MWWorld::LiveCellRef *ref = cell.mWeapons.find (name)) - return Ptr (ref, &cell); + if (!ptr.isEmpty()) + return ptr; if (searchInContainers) return cell.searchInContainer (name); diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 16f317f08..e95fd226b 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -1,6 +1,7 @@ #include "cellstore.hpp" #include +#include #include #include @@ -155,6 +156,83 @@ namespace MWWorld return mState; } + bool CellStore::hasId (const std::string& id) const + { + if (mState==State_Unloaded) + return false; + + if (mState==State_Preloaded) + return std::binary_search (mIds.begin(), mIds.end(), id); + + /// \todo address const-issues + return const_cast (this)->search (id).isEmpty(); + } + + Ptr CellStore::search (const std::string& id) + { + if (LiveCellRef *ref = mActivators.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mPotions.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mAppas.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mArmors.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mBooks.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mClothes.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mContainers.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mCreatures.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mDoors.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mIngreds.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mCreatureLists.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mItemLists.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mLights.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mLockpicks.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mMiscItems.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mNpcs.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mProbes.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mRepairs.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mStatics.find (id)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mWeapons.find (id)) + return Ptr (ref, this); + + return Ptr(); + } + void CellStore::load (const MWWorld::ESMStore &store, std::vector &esm) { if (mState!=State_Loaded) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index ef16c64c2..66f5bbf8d 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -14,6 +14,7 @@ namespace ESM namespace MWWorld { + class Ptr; /// A list of cell references template @@ -63,6 +64,7 @@ namespace MWWorld const ESM::Cell *mCell; State mState; + std::vector mIds; public: @@ -72,7 +74,13 @@ namespace MWWorld State getState() const; - std::vector mIds; + bool hasId (const std::string& id) const; + ///< May return true for deleted IDs when in preload state. Will return false, if cell is + /// unloaded. + + Ptr search (const std::string& id); + ///< Will return an empty Ptr if cell is not loaded. Does not check references in + /// containers. float mWaterLevel; From b72c1c2c58531d6bcd1179eeeb4eb278043ee987 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 17:34:18 +0100 Subject: [PATCH 4/9] encapsulated water level --- apps/openmw/mwscript/cellextensions.cpp | 10 +++++----- apps/openmw/mwworld/cellstore.cpp | 10 ++++++++++ apps/openmw/mwworld/cellstore.hpp | 5 ++++- apps/openmw/mwworld/worldimp.cpp | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 2140076c3..4d1c15f1e 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -132,7 +132,7 @@ namespace MWScript { MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell(); if (cell->getCell()->hasWater()) - runtime.push (cell->mWaterLevel); + runtime.push (cell->getWaterLevel()); else runtime.push (-std::numeric_limits().max()); } @@ -151,8 +151,8 @@ namespace MWScript if (cell->getCell()->isExterior()) throw std::runtime_error("Can't set water level in exterior cell"); - cell->mWaterLevel = level; - MWBase::Environment::get().getWorld()->setWaterHeight(cell->mWaterLevel); + cell->setWaterLevel (level); + MWBase::Environment::get().getWorld()->setWaterHeight (cell->getWaterLevel()); } }; @@ -169,8 +169,8 @@ namespace MWScript if (cell->getCell()->isExterior()) throw std::runtime_error("Can't set water level in exterior cell"); - cell->mWaterLevel +=level; - MWBase::Environment::get().getWorld()->setWaterHeight(cell->mWaterLevel); + cell->setWaterLevel (cell->getWaterLevel()+level); + MWBase::Environment::get().getWorld()->setWaterHeight(cell->getWaterLevel()); } }; diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index e95fd226b..ceb27274e 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -233,6 +233,16 @@ namespace MWWorld return Ptr(); } + float CellStore::getWaterLevel() const + { + return mWaterLevel; + } + + void CellStore::setWaterLevel (float level) + { + mWaterLevel = level; + } + void CellStore::load (const MWWorld::ESMStore &store, std::vector &esm) { if (mState!=State_Loaded) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 66f5bbf8d..428890764 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -65,6 +65,7 @@ namespace MWWorld const ESM::Cell *mCell; State mState; std::vector mIds; + float mWaterLevel; public: @@ -82,7 +83,9 @@ namespace MWWorld ///< Will return an empty Ptr if cell is not loaded. Does not check references in /// containers. - float mWaterLevel; + float getWaterLevel() const; + + void setWaterLevel (float level); // Lists for each individual object type CellRefList mActivators; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 4c97c594d..e258d8503 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1760,7 +1760,7 @@ namespace MWWorld if (!(cell->getCell()->mData.mFlags & ESM::Cell::HasWater)) { return false; } - return pos.z < cell->mWaterLevel; + return pos.z < cell->getWaterLevel(); } bool World::isOnGround(const MWWorld::Ptr &ptr) const From f2208671446d3a89276c0d5fa4f28c8ce2d764f9 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 18:17:41 +0100 Subject: [PATCH 5/9] make Ptr a bit more pointer-like --- apps/openmw/mwworld/cellstore.cpp | 24 ++++++------------------ apps/openmw/mwworld/ptr.cpp | 5 +++++ apps/openmw/mwworld/ptr.hpp | 3 +++ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index ceb27274e..91bda79af 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -342,26 +342,14 @@ namespace MWWorld Ptr CellStore::searchInContainer (const std::string& id) { - { - Ptr ptr = searchInContainerList (mContainers, id); + if (Ptr ptr = searchInContainerList (mContainers, id)) + return ptr; - if (!ptr.isEmpty()) - return ptr; - } + if (Ptr ptr = searchInContainerList (mCreatures, id)) + return ptr; - { - Ptr ptr = searchInContainerList (mCreatures, id); - - if (!ptr.isEmpty()) - return ptr; - } - - { - Ptr ptr = searchInContainerList (mNpcs, id); - - if (!ptr.isEmpty()) - return ptr; - } + if (Ptr ptr = searchInContainerList (mNpcs, id)) + return ptr; return Ptr(); } diff --git a/apps/openmw/mwworld/ptr.cpp b/apps/openmw/mwworld/ptr.cpp index 67bfe4900..3920a3e79 100644 --- a/apps/openmw/mwworld/ptr.cpp +++ b/apps/openmw/mwworld/ptr.cpp @@ -55,3 +55,8 @@ MWWorld::ContainerStore *MWWorld::Ptr::getContainerStore() const { return mContainerStore; } + +MWWorld::Ptr::operator const void *() +{ + return mRef; +} \ No newline at end of file diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 1212619d0..4529ae279 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -74,6 +74,9 @@ namespace MWWorld ContainerStore *getContainerStore() const; ///< May return a 0-pointer, if reference is not in a container. + + operator const void *(); + ///< Return a 0-pointer, if Ptr is empty; return a non-0-pointer, if Ptr is not empty }; inline bool operator== (const Ptr& left, const Ptr& right) From 367919200fea6be12f3db2e47b83316ac6bcfa27 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 20:11:05 +0100 Subject: [PATCH 6/9] moved CellRefList into a separate file --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwbase/world.hpp | 6 +++ apps/openmw/mwclass/creature.cpp | 1 + apps/openmw/mwclass/creature.hpp | 5 ++ apps/openmw/mwclass/door.hpp | 2 + apps/openmw/mwclass/npc.cpp | 1 + apps/openmw/mwclass/static.cpp | 3 +- apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 5 ++ apps/openmw/mwdialogue/filter.cpp | 3 +- apps/openmw/mwgui/bookwindow.cpp | 6 ++- apps/openmw/mwgui/charactercreation.hpp | 3 ++ apps/openmw/mwgui/console.cpp | 2 + apps/openmw/mwgui/levelupdialog.cpp | 2 + apps/openmw/mwgui/mapwindow.cpp | 2 + apps/openmw/mwgui/merchantrepair.cpp | 3 ++ apps/openmw/mwgui/scrollwindow.cpp | 2 + apps/openmw/mwgui/sortfilteritemmodel.cpp | 13 +++++ apps/openmw/mwgui/spellbuyingwindow.cpp | 2 + apps/openmw/mwgui/tradeitemmodel.cpp | 2 + apps/openmw/mwgui/travelwindow.cpp | 2 + apps/openmw/mwgui/waitdialog.cpp | 1 + apps/openmw/mwgui/windowmanagerimp.cpp | 1 + apps/openmw/mwinput/inputmanagerimp.cpp | 13 +++-- apps/openmw/mwmechanics/activespells.cpp | 10 +++- apps/openmw/mwmechanics/aiactivate.cpp | 6 +-- apps/openmw/mwmechanics/aicombat.cpp | 2 + apps/openmw/mwmechanics/aiescort.cpp | 9 ++-- apps/openmw/mwmechanics/aifollow.cpp | 12 +++-- apps/openmw/mwmechanics/aitravel.cpp | 2 + apps/openmw/mwmechanics/aiwander.cpp | 10 ++-- apps/openmw/mwmechanics/alchemy.hpp | 53 ++++++++++--------- apps/openmw/mwmechanics/character.cpp | 11 ++-- apps/openmw/mwmechanics/combat.cpp | 1 + apps/openmw/mwmechanics/disease.hpp | 1 + apps/openmw/mwmechanics/pathfinding.cpp | 8 +-- apps/openmw/mwmechanics/pickpocket.cpp | 3 ++ apps/openmw/mwmechanics/repair.cpp | 1 + apps/openmw/mwmechanics/security.cpp | 1 + apps/openmw/mwmechanics/spellcasting.cpp | 1 + apps/openmw/mwmechanics/spellcasting.hpp | 10 ++++ apps/openmw/mwmechanics/spells.hpp | 2 + apps/openmw/mwrender/activatoranimation.cpp | 4 +- apps/openmw/mwrender/animation.cpp | 12 ++++- apps/openmw/mwrender/animation.hpp | 4 ++ apps/openmw/mwrender/creatureanimation.cpp | 4 +- apps/openmw/mwrender/debugging.cpp | 4 +- apps/openmw/mwrender/localmap.cpp | 5 +- apps/openmw/mwrender/objects.cpp | 4 ++ apps/openmw/mwrender/renderingmanager.cpp | 1 + apps/openmw/mwscript/cellextensions.cpp | 1 + apps/openmw/mwscript/containerextensions.cpp | 4 +- apps/openmw/mwscript/miscextensions.cpp | 4 ++ apps/openmw/mwsound/soundmanagerimp.cpp | 1 + apps/openmw/mwstate/statemanagerimp.cpp | 1 + apps/openmw/mwworld/actioneat.cpp | 6 ++- apps/openmw/mwworld/cellreflist.hpp | 44 +++++++++++++++ apps/openmw/mwworld/cells.cpp | 1 + apps/openmw/mwworld/cells.hpp | 1 + apps/openmw/mwworld/cellstore.hpp | 35 +----------- apps/openmw/mwworld/containerstore.hpp | 13 +++++ apps/openmw/mwworld/inventorystore.hpp | 5 ++ apps/openmw/mwworld/physicssystem.cpp | 4 +- apps/openmw/mwworld/player.cpp | 7 +-- apps/openmw/mwworld/ptr.hpp | 8 ++- apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/scene.hpp | 5 ++ apps/openmw/mwworld/weather.cpp | 1 + 67 files changed, 295 insertions(+), 111 deletions(-) create mode 100644 apps/openmw/mwworld/cellreflist.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 84d116848..be583ea74 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -57,7 +57,7 @@ add_openmw_dir (mwworld cells localscripts customdata weather inventorystore ptr actionopen actionread actionequip timestamp actionalchemy cellstore actionapply actioneat esmstore store recordcmp fallback actionrepair actionsoulgem livecellref actiondoor - contentloader esmloader omwloader actiontrap + contentloader esmloader omwloader actiontrap cellreflist ) add_openmw_dir (mwclass diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 3d033838c..fd3978943 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -39,6 +39,12 @@ namespace ESM struct Spell; struct NPC; struct CellId; + struct Armor; + struct Weapon; + struct Clothing; + struct Enchantment; + struct Book; + struct EffectList; } namespace MWRender diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 81ca0ce2b..516a4c510 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -22,6 +22,7 @@ #include "../mwworld/customdata.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/physicssystem.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwrender/renderinginterface.hpp" #include "../mwrender/actors.hpp" diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index adaf62a96..6df6db297 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -3,6 +3,11 @@ #include "../mwworld/class.hpp" +namespace ESM +{ + struct GameSetting; +} + namespace MWClass { class Creature : public MWWorld::Class diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index 05ba0248b..2ac342a61 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -1,6 +1,8 @@ #ifndef GAME_MWCLASS_DOOR_H #define GAME_MWCLASS_DOOR_H +#include + #include "../mwworld/class.hpp" namespace MWClass diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 3a95f3c29..e00c3b720 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -30,6 +30,7 @@ #include "../mwworld/inventorystore.hpp" #include "../mwworld/customdata.hpp" #include "../mwworld/physicssystem.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwrender/actors.hpp" #include "../mwrender/renderinginterface.hpp" diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index bd7deca88..f8677dc20 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -5,6 +5,7 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/physicssystem.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwrender/objects.hpp" #include "../mwrender/renderinginterface.hpp" @@ -25,7 +26,7 @@ namespace MWClass if(!model.empty()) physics.addObject(ptr); } - + std::string Static::getModel(const MWWorld::Ptr &ptr) const { MWWorld::LiveCellRef *ref = diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index cf8ea1176..b9284dc1a 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -13,6 +13,11 @@ #include "../mwscript/compilercontext.hpp" +namespace ESM +{ + struct Dialogue; +} + namespace MWDialogue { class DialogueManager : public MWBase::DialogueManager diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 846cff114..18ae7dd1b 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -8,8 +8,9 @@ #include "../mwbase/dialoguemanager.hpp" #include "../mwworld/class.hpp" -#include "../mwworld/containerstore.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/cellstore.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/creaturestats.hpp" diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp index 98d963b22..884d567c5 100644 --- a/apps/openmw/mwgui/bookwindow.cpp +++ b/apps/openmw/mwgui/bookwindow.cpp @@ -2,6 +2,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/soundmanager.hpp" @@ -169,7 +171,7 @@ namespace MWGui } ++i; } - + //If it is the last page, hide the button "Next Page" if ( (mCurrentPage+1)*2 == mPages.size() || (mCurrentPage+1)*2 == mPages.size() + 1) @@ -194,7 +196,7 @@ namespace MWGui if (button->getAlign().isRight()) button->setPosition(button->getPosition() + MyGUI::IntPoint(diff.width,0)); } - + void BookWindow::nextPage() { if ((mCurrentPage+1)*2 < mPages.size()) diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp index 924f40c28..03898093d 100644 --- a/apps/openmw/mwgui/charactercreation.hpp +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -1,6 +1,9 @@ #ifndef CHARACTER_CREATION_HPP #define CHARACTER_CREATION_HPP +#include +#include + #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index f3805b255..01eb770f7 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -8,6 +8,8 @@ #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwworld/esmstore.hpp" + namespace MWGui { class ConsoleInterpreterContext : public MWScript::InterpreterContext diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index f56d80883..2f11a4d12 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -8,6 +8,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/fallback.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 267c761e2..51e160d26 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -7,7 +7,9 @@ #include "../mwbase/windowmanager.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" + #include "../mwworld/player.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwrender/globalmap.hpp" diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 3c3335d8b..2a48e62a9 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -1,5 +1,7 @@ #include "merchantrepair.hpp" +#include + #include #include "../mwbase/world.hpp" @@ -10,6 +12,7 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" namespace MWGui { diff --git a/apps/openmw/mwgui/scrollwindow.cpp b/apps/openmw/mwgui/scrollwindow.cpp index e1970004c..a084e6453 100644 --- a/apps/openmw/mwgui/scrollwindow.cpp +++ b/apps/openmw/mwgui/scrollwindow.cpp @@ -1,5 +1,7 @@ #include "scrollwindow.hpp" +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/soundmanager.hpp" diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 3cf514dc5..74a4f88e7 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -1,5 +1,18 @@ #include "sortfilteritemmodel.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "../mwworld/class.hpp" namespace diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 68aecf28d..77df46514 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -10,6 +10,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/creaturestats.hpp" diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index 88c14b791..c9c65a152 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -1,5 +1,7 @@ #include "tradeitemmodel.hpp" +#include + #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/inventorystore.hpp" diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 348178d81..89d73215d 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -13,6 +13,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" namespace MWGui { diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index fd487c87f..9417d2a4b 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -10,6 +10,7 @@ #include "../mwbase/mechanicsmanager.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index ba9684589..f44078256 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -18,6 +18,7 @@ #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" +#include "../mwworld/cellstore.hpp" #include "console.hpp" #include "journalwindow.hpp" diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 66d93469c..314053799 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -15,13 +15,16 @@ #include "../engine.hpp" -#include "../mwworld/player.hpp" -#include "../mwworld/class.hpp" -#include "../mwworld/inventorystore.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/statemanager.hpp" + +#include "../mwworld/player.hpp" +#include "../mwworld/class.hpp" +#include "../mwworld/inventorystore.hpp" +#include "../mwworld/esmstore.hpp" + #include "../mwmechanics/creaturestats.hpp" using namespace ICS; @@ -169,7 +172,7 @@ namespace MWInput switch (action) { case A_GameMenu: - if(!(MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_Running + if(!(MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_Running && MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_MainMenu)) toggleMainMenu (); break; @@ -283,7 +286,7 @@ namespace MWInput // Disable movement in Gui mode if (MWBase::Environment::get().getWindowManager()->isGuiMode() - || MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_Running) + || MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_Running) return; diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 994798b0b..0c5bd9afa 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -1,8 +1,14 @@ #include "activespells.hpp" +#include + +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "../mwworld/esmstore.hpp" + namespace MWMechanics { void ActiveSpells::update() const @@ -40,7 +46,7 @@ namespace MWMechanics void ActiveSpells::rebuildEffects() const { MWWorld::TimeStamp now = MWBase::Environment::get().getWorld()->getTimeStamp(); - + mEffects = MagicEffects(); for (TIterator iter (begin()); iter!=end(); ++iter) @@ -59,7 +65,7 @@ namespace MWMechanics if (end>now) mEffects.add(effectIt->mKey, MWMechanics::EffectParam(effectIt->mMagnitude)); } - } + } } ActiveSpells::ActiveSpells() diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index ea146625a..bdd7c8f3b 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -1,14 +1,14 @@ #include "aiactivate.hpp" -#include - -#include "movement.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" + #include "../mwworld/class.hpp" #include "../mwworld/action.hpp" +#include "../mwworld/cellstore.hpp" #include "steering.hpp" +#include "movement.hpp" namespace { diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index b0e0c2f7b..5be90bf2c 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -7,6 +7,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/timestamp.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index a58bfef05..b54f1d39c 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -1,14 +1,15 @@ #include "aiescort.hpp" -#include "movement.hpp" - -#include "../mwworld/class.hpp" -#include "../mwworld/timestamp.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" +#include "../mwworld/cellstore.hpp" +#include "../mwworld/class.hpp" +#include "../mwworld/timestamp.hpp" + #include "steering.hpp" +#include "movement.hpp" namespace { diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index ef6ead9d7..284937546 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -1,12 +1,14 @@ #include "aifollow.hpp" -#include -#include "../mwbase/world.hpp" -#include "../mwbase/environment.hpp" -#include "../mwworld/class.hpp" -#include "movement.hpp" #include +#include "../mwbase/world.hpp" +#include "../mwbase/environment.hpp" + +#include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" + +#include "movement.hpp" #include "steering.hpp" MWMechanics::AiFollow::AiFollow(const std::string &actorId,float duration, float x, float y, float z) diff --git a/apps/openmw/mwmechanics/aitravel.cpp b/apps/openmw/mwmechanics/aitravel.cpp index 41226ad79..1fd719c60 100644 --- a/apps/openmw/mwmechanics/aitravel.cpp +++ b/apps/openmw/mwmechanics/aitravel.cpp @@ -2,7 +2,9 @@ #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" + #include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" #include "steering.hpp" #include "movement.hpp" diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 012f71b72..9a95822f5 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -1,17 +1,19 @@ #include "aiwander.hpp" -#include "movement.hpp" +#include -#include "../mwworld/class.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/dialoguemanager.hpp" -#include "creaturestats.hpp" -#include +#include "../mwworld/class.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" +#include "creaturestats.hpp" #include "steering.hpp" +#include "movement.hpp" namespace { diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 957e3122c..31cafa4dc 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -8,6 +8,11 @@ #include "../mwworld/ptr.hpp" +namespace ESM +{ + struct Potion; +} + namespace MWMechanics { struct EffectKey; @@ -16,29 +21,29 @@ namespace MWMechanics class Alchemy { public: - + typedef std::vector TToolsContainer; typedef TToolsContainer::const_iterator TToolsIterator; - + typedef std::vector TIngredientsContainer; typedef TIngredientsContainer::const_iterator TIngredientsIterator; typedef std::vector TEffectsContainer; typedef TEffectsContainer::const_iterator TEffectsIterator; - + enum Result { Result_Success, - + Result_NoMortarAndPestle, Result_LessThanTwoIngredients, Result_NoName, Result_NoEffects, Result_RandomFailure }; - + private: - + MWWorld::Ptr mAlchemist; TToolsContainer mTools; TIngredientsContainer mIngredients; @@ -51,61 +56,61 @@ namespace MWMechanics void applyTools (int flags, float& value) const; void updateEffects(); - + const ESM::Potion *getRecord() const; ///< Return existing recrod for created potion (may return 0) - + void removeIngredients(); ///< Remove selected ingredients from alchemist's inventory, cleanup selected ingredients and /// update effect list accordingly. void addPotion (const std::string& name); ///< Add a potion to the alchemist's inventory. - + void increaseSkill(); ///< Increase alchemist's skill. - + float getChance() const; ///< Return chance of success. - + int countIngredients() const; - + public: - + void setAlchemist (const MWWorld::Ptr& npc); ///< Set alchemist and configure alchemy setup accordingly. \a npc may be empty to indicate that /// there is no alchemist (alchemy session has ended). - + TToolsIterator beginTools() const; ///< \attention Iterates over tool slots, not over tools. Some of the slots may be empty. - + TToolsIterator endTools() const; - + TIngredientsIterator beginIngredients() const; ///< \attention Iterates over ingredient slots, not over ingredients. Some of the slots may be empty. - + TIngredientsIterator endIngredients() const; - + void clear(); ///< Remove alchemist, tools and ingredients. - + int addIngredient (const MWWorld::Ptr& ingredient); ///< Add ingredient into the next free slot. /// /// \return Slot index or -1, if adding failed because of no free slot or the ingredient type being /// listed already. - + void removeIngredient (int index); ///< Remove ingredient from slot (calling this function on an empty slot is a no-op). - + TEffectsIterator beginEffects() const; - + TEffectsIterator endEffects() const; - + std::string getPotionName() const; ///< Return the name of the potion that would be created when calling create (if a record for such /// a potion already exists) or return an empty string. - + Result create (const std::string& name); ///< Try to create a potion from the ingredients, place it in the inventory of the alchemist and /// adjust the skills of the alchemist accordingly. diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index c2a26ced3..d19f32507 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -36,6 +36,7 @@ #include "../mwworld/class.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/esmstore.hpp" namespace { @@ -562,7 +563,7 @@ bool CharacterController::updateWeaponState() getWeaponGroup(weaptype, weapgroup); mAnimation->showWeapons(false); mAnimation->setWeaponGroup(weapgroup); - + mAnimation->play(weapgroup, Priority_Weapon, MWRender::Animation::Group_UpperBody, true, 1.0f, "equip start", "equip stop", 0.0f, 0); @@ -751,7 +752,7 @@ bool CharacterController::updateWeaponState() MWRender::Animation::Group_UpperBody, false, weapSpeed, mAttackType+" start", mAttackType+" min attack", 0.0f, 0); - mUpperBodyState = UpperCharState_StartToMinAttack; + mUpperBodyState = UpperCharState_StartToMinAttack; } } @@ -855,7 +856,7 @@ bool CharacterController::updateWeaponState() mUpperBodyState = UpperCharState_WeapEquiped; //don't allow to continue playing hit animation on UpperBody after actor had attacked during it - if(mHitState == CharState_Hit) + if(mHitState == CharState_Hit) { mAnimation->changeGroups(mCurrentHit, MWRender::Animation::Group_LowerBody); //commenting out following 2 lines will give a bit different combat dynamics(slower) @@ -932,7 +933,7 @@ bool CharacterController::updateWeaponState() weapSpeed, start, stop, 0.0f, 0); } } - + //if playing combat animation and lowerbody is not busy switch to whole body animation if((weaptype != WeapType_None || UpperCharState_UnEquipingWeap) && animPlaying) { @@ -1431,7 +1432,7 @@ void CharacterController::updateVisibility() void CharacterController::determineAttackType() { float * move = mPtr.getClass().getMovementSettings(mPtr).mPosition; - + if(mPtr.getClass().hasInventoryStore(mPtr)) { if (move[0] && !move[1]) //sideway diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 204264106..6aeb90dad 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -10,6 +10,7 @@ #include "../mwworld/class.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwbase/windowmanager.hpp" diff --git a/apps/openmw/mwmechanics/disease.hpp b/apps/openmw/mwmechanics/disease.hpp index d3ea825cf..5f73e8acd 100644 --- a/apps/openmw/mwmechanics/disease.hpp +++ b/apps/openmw/mwmechanics/disease.hpp @@ -6,6 +6,7 @@ #include "../mwbase/world.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/spells.hpp" #include "../mwmechanics/creaturestats.hpp" diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 2503181ae..efa2bdf69 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -1,13 +1,15 @@ #include "pathfinding.hpp" -#include "../mwbase/world.hpp" -#include "../mwbase/environment.hpp" +#include #include "OgreMath.h" #include "OgreVector3.h" +#include "../mwbase/world.hpp" +#include "../mwbase/environment.hpp" -#include +#include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" namespace { diff --git a/apps/openmw/mwmechanics/pickpocket.cpp b/apps/openmw/mwmechanics/pickpocket.cpp index 53681caf8..14abcd643 100644 --- a/apps/openmw/mwmechanics/pickpocket.cpp +++ b/apps/openmw/mwmechanics/pickpocket.cpp @@ -1,8 +1,11 @@ #include "pickpocket.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/esmstore.hpp" + #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" + #include "npcstats.hpp" namespace MWMechanics diff --git a/apps/openmw/mwmechanics/repair.cpp b/apps/openmw/mwmechanics/repair.cpp index 1b17f8305..48179d344 100644 --- a/apps/openmw/mwmechanics/repair.cpp +++ b/apps/openmw/mwmechanics/repair.cpp @@ -10,6 +10,7 @@ #include "../mwworld/containerstore.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 2e5eaecfd..edec45e15 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -2,6 +2,7 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 30072a8cc..9745cdebe 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -14,6 +14,7 @@ #include "../mwworld/actionteleport.hpp" #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwrender/animation.hpp" diff --git a/apps/openmw/mwmechanics/spellcasting.hpp b/apps/openmw/mwmechanics/spellcasting.hpp index 74dc490ea..44402fe7b 100644 --- a/apps/openmw/mwmechanics/spellcasting.hpp +++ b/apps/openmw/mwmechanics/spellcasting.hpp @@ -5,6 +5,16 @@ #include +#include + +namespace ESM +{ + struct Spell; + struct Ingredient; + struct Potion; + struct EffectList; +} + namespace MWMechanics { class EffectKey; diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index cc239a650..354b1fd0b 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -4,6 +4,8 @@ #include #include +#include + #include "../mwworld/ptr.hpp" #include "magiceffects.hpp" diff --git a/apps/openmw/mwrender/activatoranimation.cpp b/apps/openmw/mwrender/activatoranimation.cpp index 7f4be9a68..de0457e57 100644 --- a/apps/openmw/mwrender/activatoranimation.cpp +++ b/apps/openmw/mwrender/activatoranimation.cpp @@ -1,9 +1,11 @@ #include "activatoranimation.hpp" -#include "renderconst.hpp" +#include #include "../mwbase/world.hpp" +#include "renderconst.hpp" + namespace MWRender { diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 820857137..2ddea7682 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -11,18 +11,26 @@ #include #include +#include +#include +#include +#include + #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" #include "../mwbase/world.hpp" -#include - #include "../mwmechanics/character.hpp" #include "../mwmechanics/creaturestats.hpp" + #include "../mwworld/class.hpp" #include "../mwworld/fallback.hpp" +#include "../mwworld/cellstore.hpp" +#include "../mwworld/esmstore.hpp" #include "renderconst.hpp" diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index c0cb18010..564bb73ef 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -8,6 +8,10 @@ #include "../mwworld/ptr.hpp" +namespace ESM +{ + struct Light; +} namespace MWRender { diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index e2aa9a2b8..8ef584154 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -4,12 +4,14 @@ #include #include -#include "renderconst.hpp" +#include #include "../mwbase/world.hpp" #include "../mwworld/class.hpp" +#include "renderconst.hpp" + namespace MWRender { diff --git a/apps/openmw/mwrender/debugging.cpp b/apps/openmw/mwrender/debugging.cpp index 0cfcf826f..241f7e470 100644 --- a/apps/openmw/mwrender/debugging.cpp +++ b/apps/openmw/mwrender/debugging.cpp @@ -13,12 +13,12 @@ #include #include -#include "../mwworld/esmstore.hpp" - #include "../mwbase/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwbase/environment.hpp" #include "../mwworld/ptr.hpp" +#include "../mwworld/cellstore.hpp" +#include "../mwworld/esmstore.hpp" #include "renderconst.hpp" diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 554ba22fa..772813c73 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -7,12 +7,13 @@ #include #include -#include "../mwworld/esmstore.hpp" - #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" + #include "renderconst.hpp" #include "renderingmanager.hpp" diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index e721477ee..c97e5279a 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -11,11 +11,15 @@ #include #include +#include +#include + #include #include #include "../mwworld/ptr.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" #include "renderconst.hpp" #include "animation.hpp" diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 0311c90b3..844be52d8 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -24,6 +24,7 @@ #include "../mwworld/esmstore.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwbase/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwbase/environment.hpp" diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 4d1c15f1e..903612258 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -13,6 +13,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwworld/player.hpp" +#include "../mwworld/cellstore.hpp" #include "interpretercontext.hpp" diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index fc21c5712..d489bfaf1 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -284,7 +286,7 @@ namespace MWScript virtual void execute(Interpreter::Runtime &runtime) { MWWorld::Ptr ptr = R()(runtime); - + const std::string &name = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 0c60e1c94..fa8441aa5 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -13,12 +13,16 @@ #include #include +#include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/scriptmanager.hpp" #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/creaturestats.hpp" diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 13e152e68..0720e798a 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -9,6 +9,7 @@ #include "../mwbase/statemanager.hpp" #include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" #include "sound_output.hpp" #include "sound_decoder.hpp" diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 8c59247f4..2ca7d76b3 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -23,6 +23,7 @@ #include "../mwworld/player.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwmechanics/npcstats.hpp" diff --git a/apps/openmw/mwworld/actioneat.cpp b/apps/openmw/mwworld/actioneat.cpp index f5d7e2636..020bdb0ff 100644 --- a/apps/openmw/mwworld/actioneat.cpp +++ b/apps/openmw/mwworld/actioneat.cpp @@ -3,6 +3,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -19,10 +21,10 @@ namespace MWWorld // apply to actor std::string id = Class::get (getTarget()).getId (getTarget()); - + if (Class::get (actor).apply (actor, id, actor)) Class::get (actor).skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1); - } + } ActionEat::ActionEat (const MWWorld::Ptr& object) : Action (false, object) {} } diff --git a/apps/openmw/mwworld/cellreflist.hpp b/apps/openmw/mwworld/cellreflist.hpp new file mode 100644 index 000000000..8240fbd2d --- /dev/null +++ b/apps/openmw/mwworld/cellreflist.hpp @@ -0,0 +1,44 @@ +#ifndef GAME_MWWORLD_CELLREFLIST_H +#define GAME_MWWORLD_CELLREFLIST_H + +#include + +#include "livecellref.hpp" + +namespace MWWorld +{ + /// \brief Collection of references of one type + template + struct CellRefList + { + typedef LiveCellRef LiveRef; + typedef std::list List; + List mList; + + /// Search for the given reference in the given reclist from + /// ESMStore. Insert the reference into the list if a match is + /// found. If not, throw an exception. + /// Moved to cpp file, as we require a custom compare operator for it, + /// and the build will fail with an ugly three-way cyclic header dependence + /// so we need to pass the instantiation of the method to the linker, when + /// all methods are known. + void load (ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore); + + LiveRef *find (const std::string& name) + { + for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter) + if (iter->mData.getCount() > 0 && iter->mRef.mRefID == name) + return &*iter; + + return 0; + } + + LiveRef &insert (const LiveRef &item) + { + mList.push_back(item); + return mList.back(); + } + }; +} + +#endif diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 8ce7d4fe8..74df0f79d 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -11,6 +11,7 @@ #include "class.hpp" #include "esmstore.hpp" #include "containerstore.hpp" +#include "cellstore.hpp" MWWorld::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell) { diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index 7ee8a3f6c..0df55b586 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -12,6 +12,7 @@ namespace ESM class ESMReader; class ESMWriter; struct CellId; + struct Cell; } namespace MWWorld diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 428890764..c576a0609 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -6,6 +6,7 @@ #include "livecellref.hpp" #include "esmstore.hpp" +#include "cellreflist.hpp" namespace ESM { @@ -16,40 +17,6 @@ namespace MWWorld { class Ptr; - /// A list of cell references - template - struct CellRefList - { - typedef LiveCellRef LiveRef; - typedef std::list List; - List mList; - - // Search for the given reference in the given reclist from - // ESMStore. Insert the reference into the list if a match is - // found. If not, throw an exception. - // Moved to cpp file, as we require a custom compare operator for it, - // and the build will fail with an ugly three-way cyclic header dependence - // so we need to pass the instantiation of the method to the lnker, when - // all methods are known. - void load(ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore); - - LiveRef *find (const std::string& name) - { - for (typename std::list::iterator iter (mList.begin()); iter!=mList.end(); ++iter) - { - if (iter->mData.getCount() > 0 && iter->mRef.mRefID == name) - return &*iter; - } - - return 0; - } - - LiveRef &insert(const LiveRef &item) { - mList.push_back(item); - return mList.back(); - } - }; - /// \brief Mutable state of a cell class CellStore { diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index acf429891..dd0c1b002 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -3,6 +3,19 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "ptr.hpp" namespace ESM diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 714ba47da..b4b275b6a 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -5,6 +5,11 @@ #include "../mwmechanics/magiceffects.hpp" +namespace ESM +{ + struct MagicEffect; +} + namespace MWMechanics { class NpcStats; diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 56d19c8be..1a16870da 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -15,13 +15,15 @@ #include +#include + #include "../mwbase/world.hpp" // FIXME #include "../mwbase/environment.hpp" #include "../mwmechanics/creaturestats.hpp" -#include #include "../mwworld/esmstore.hpp" +#include "../mwworld/cellstore.hpp" #include "ptr.hpp" #include "class.hpp" diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index ba816d6d5..6d551ecf1 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -7,19 +7,20 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/soundmanager.hpp" -#include "../mwworld/ptr.hpp" -#include "../mwworld/inventorystore.hpp" - #include "../mwmechanics/movement.hpp" #include "../mwmechanics/npcstats.hpp" #include "class.hpp" +#include "ptr.hpp" +#include "inventorystore.hpp" +#include "cellstore.hpp" namespace MWWorld { diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 4529ae279..b83069283 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -1,12 +1,18 @@ #ifndef GAME_MWWORLD_PTR_H #define GAME_MWWORLD_PTR_H -#include "cellstore.hpp" +#include + +#include +#include + +#include "cellreflist.hpp" #include "livecellref.hpp" namespace MWWorld { class ContainerStore; + class CellStore; /// \brief Pointer to a LiveCellRef diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 06141db54..248d452c1 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -17,8 +17,8 @@ #include "localscripts.hpp" #include "esmstore.hpp" #include "class.hpp" - #include "cellfunctors.hpp" +#include "cellstore.hpp" namespace { diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 665274831..af833f331 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -21,6 +21,11 @@ namespace Files class Collections; } +namespace Loading +{ + class Listener; +} + namespace Render { class OgreRenderer; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index c79d7ee4f..5f38ee286 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -9,6 +9,7 @@ #include "player.hpp" #include "esmstore.hpp" #include "fallback.hpp" +#include "cellstore.hpp" using namespace Ogre; using namespace MWWorld; From 83ded18af0f3cec9fa23ca2e41a6d04078b4601d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 21:21:27 +0100 Subject: [PATCH 7/9] encapsulated reference collections --- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/apparatus.cpp | 2 +- apps/openmw/mwclass/armor.cpp | 10 +- apps/openmw/mwclass/book.cpp | 2 +- apps/openmw/mwclass/clothing.cpp | 2 +- apps/openmw/mwclass/container.cpp | 2 +- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/door.cpp | 2 +- apps/openmw/mwclass/ingredient.cpp | 10 +- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 2 +- apps/openmw/mwclass/misc.cpp | 4 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwclass/probe.cpp | 2 +- apps/openmw/mwclass/repair.cpp | 2 +- apps/openmw/mwclass/static.cpp | 2 +- apps/openmw/mwclass/weapon.cpp | 2 +- apps/openmw/mwworld/cellreflist.hpp | 10 ++ apps/openmw/mwworld/cellstore.cpp | 90 +++++++++++++ apps/openmw/mwworld/cellstore.hpp | 184 +++++++++++++++++++++++---- apps/openmw/mwworld/localscripts.cpp | 40 +++--- apps/openmw/mwworld/scene.cpp | 110 +++++++++------- apps/openmw/mwworld/scene.hpp | 2 - apps/openmw/mwworld/worldimp.cpp | 81 +----------- 25 files changed, 374 insertions(+), 197 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 8bc104d25..16ab6321d 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -128,6 +128,6 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mActivators.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index b3a1af288..8580d61ce 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -148,7 +148,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mAppas.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } bool Apparatus::canSell (const MWWorld::Ptr& item, int npcServices) const diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index e3974f243..550151e43 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -333,11 +333,11 @@ namespace MWClass if(weapon->getTypeName() == typeid(ESM::Weapon).name() && (weapon->get()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand || - weapon->get()->mBase->mData.mType == ESM::Weapon::BluntTwoClose || - weapon->get()->mBase->mData.mType == ESM::Weapon::BluntTwoWide || + weapon->get()->mBase->mData.mType == ESM::Weapon::BluntTwoClose || + weapon->get()->mBase->mData.mType == ESM::Weapon::BluntTwoWide || weapon->get()->mBase->mData.mType == ESM::Weapon::SpearTwoWide || - weapon->get()->mBase->mData.mType == ESM::Weapon::AxeTwoHand || - weapon->get()->mBase->mData.mType == ESM::Weapon::MarksmanBow || + weapon->get()->mBase->mData.mType == ESM::Weapon::AxeTwoHand || + weapon->get()->mBase->mData.mType == ESM::Weapon::MarksmanBow || weapon->get()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)) { return std::make_pair(3,""); @@ -363,7 +363,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mArmors.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } int Armor::getEnchantmentPoints (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 0e6506514..ebc3b18e6 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -186,7 +186,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mBooks.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } int Book::getEnchantmentPoints (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index ab98d05ae..18a40d5d3 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -276,7 +276,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mClothes.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } int Clothing::getEnchantmentPoints (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 546d6538c..715784b7c 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -257,7 +257,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mContainers.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } void Container::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 516a4c510..2939a5431 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -680,7 +680,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mCreatures.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } bool Creature::isFlying(const MWWorld::Ptr &ptr) const diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index e9ac39f1d..3cd8237e7 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -258,6 +258,6 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mDoors.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index faf29bc83..e15424c38 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -30,7 +30,7 @@ namespace MWClass return ref->mBase->mId; } - + void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const { const std::string model = getModel(ptr); @@ -89,16 +89,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - + boost::shared_ptr Ingredient::use (const MWWorld::Ptr& ptr) const { boost::shared_ptr action (new MWWorld::ActionEat (ptr)); action->setSound ("Swallow"); - return action; + return action; } - + void Ingredient::registerSelf() { boost::shared_ptr instance (new Ingredient); @@ -189,7 +189,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mIngreds.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } bool Ingredient::canSell (const MWWorld::Ptr& item, int npcServices) const diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index ddb2c16d6..72de620e4 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -227,7 +227,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mLights.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } void Light::ensureCustomData (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 795b66052..60ffec7b9 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -169,7 +169,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mLockpicks.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } bool Lockpick::canSell (const MWWorld::Ptr& item, int npcServices) const diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index e58716f1c..e568bf869 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -218,13 +218,13 @@ namespace MWClass MWWorld::ManualRef newRef(store, base); MWWorld::LiveCellRef *ref = newRef.getPtr().get(); - newPtr = MWWorld::Ptr(&cell.mMiscItems.insert(*ref), &cell); + newPtr = MWWorld::Ptr(&cell.get().insert(*ref), &cell); newPtr.getCellRef().mGoldValue = goldAmount; newPtr.getRefData().setCount(1); } else { MWWorld::LiveCellRef *ref = ptr.get(); - newPtr = MWWorld::Ptr(&cell.mMiscItems.insert(*ref), &cell); + newPtr = MWWorld::Ptr(&cell.get().insert(*ref), &cell); } return newPtr; } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index e00c3b720..20c7d9a0e 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1253,7 +1253,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mNpcs.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } int Npc::getSkill(const MWWorld::Ptr& ptr, int skill) const diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index d68db4e45..216f815cd 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -185,7 +185,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mPotions.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } bool Potion::canSell (const MWWorld::Ptr& item, int npcServices) const diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 4209c1431..d376270cb 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -168,7 +168,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mProbes.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } bool Probe::canSell (const MWWorld::Ptr& item, int npcServices) const diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 5f2065c3c..af79a9691 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -163,7 +163,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mRepairs.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } boost::shared_ptr Repair::use (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index f8677dc20..4ac41350f 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -58,6 +58,6 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mStatics.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index af0234cd5..e9b0c8f3c 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -426,7 +426,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return MWWorld::Ptr(&cell.mWeapons.insert(*ref), &cell); + return MWWorld::Ptr(&cell.get().insert(*ref), &cell); } int Weapon::getEnchantmentPoints (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwworld/cellreflist.hpp b/apps/openmw/mwworld/cellreflist.hpp index 8240fbd2d..264929bfb 100644 --- a/apps/openmw/mwworld/cellreflist.hpp +++ b/apps/openmw/mwworld/cellreflist.hpp @@ -38,6 +38,16 @@ namespace MWWorld mList.push_back(item); return mList.back(); } + + LiveCellRef *searchViaHandle (const std::string& handle) + { + for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter) + if (iter->mData.getCount()>0 && iter->mData.getBaseNode() && + iter->mData.getHandle()==handle) + return &*iter; + + return 0; + } }; } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 91bda79af..8b0740d3b 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -233,6 +233,71 @@ namespace MWWorld return Ptr(); } + Ptr CellStore::searchViaHandle (const std::string& handle) + { + if (LiveCellRef *ref = mActivators.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mPotions.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mAppas.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mArmors.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mBooks.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mClothes.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mContainers.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mCreatures.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mDoors.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mIngreds.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mCreatureLists.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mItemLists.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mLights.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mLockpicks.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mMiscItems.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mNpcs.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mProbes.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mRepairs.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mStatics.searchViaHandle (handle)) + return Ptr (ref, this); + + if (LiveCellRef *ref = mWeapons.searchViaHandle (handle)) + return Ptr (ref, this); + + return Ptr(); + } + float CellStore::getWaterLevel() const { return mWaterLevel; @@ -243,6 +308,31 @@ namespace MWWorld mWaterLevel = level; } + int CellStore::count() const + { + return + mActivators.mList.size() + + mPotions.mList.size() + + mAppas.mList.size() + + mArmors.mList.size() + + mBooks.mList.size() + + mClothes.mList.size() + + mContainers.mList.size() + + mDoors.mList.size() + + mIngreds.mList.size() + + mCreatureLists.mList.size() + + mItemLists.mList.size() + + mLights.mList.size() + + mLockpicks.mList.size() + + mMiscItems.mList.size() + + mProbes.mList.size() + + mRepairs.mList.size() + + mStatics.mList.size() + + mWeapons.mList.size() + + mCreatures.mList.size() + + mNpcs.mList.size(); + } + void CellStore::load (const MWWorld::ESMStore &store, std::vector &esm) { if (mState!=State_Loaded) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index c576a0609..5ff63c582 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "livecellref.hpp" #include "esmstore.hpp" @@ -34,6 +35,27 @@ namespace MWWorld std::vector mIds; float mWaterLevel; + CellRefList mActivators; + CellRefList mPotions; + CellRefList mAppas; + CellRefList mArmors; + CellRefList mBooks; + CellRefList mClothes; + CellRefList mContainers; + CellRefList mCreatures; + CellRefList mDoors; + CellRefList mIngreds; + CellRefList mCreatureLists; + CellRefList mItemLists; + CellRefList mLights; + CellRefList mLockpicks; + CellRefList mMiscItems; + CellRefList mNpcs; + CellRefList mProbes; + CellRefList mRepairs; + CellRefList mStatics; + CellRefList mWeapons; + public: CellStore (const ESM::Cell *cell_); @@ -50,31 +72,16 @@ namespace MWWorld ///< Will return an empty Ptr if cell is not loaded. Does not check references in /// containers. + Ptr searchViaHandle (const std::string& handle); + ///< Will return an empty Ptr if cell is not loaded. + float getWaterLevel() const; void setWaterLevel (float level); - // Lists for each individual object type - CellRefList mActivators; - CellRefList mPotions; - CellRefList mAppas; - CellRefList mArmors; - CellRefList mBooks; - CellRefList mClothes; - CellRefList mContainers; - CellRefList mCreatures; - CellRefList mDoors; - CellRefList mIngreds; - CellRefList mCreatureLists; - CellRefList mItemLists; - CellRefList mLights; - CellRefList mLockpicks; - CellRefList mMiscItems; - CellRefList mNpcs; - CellRefList mProbes; - CellRefList mRepairs; - CellRefList mStatics; - CellRefList mWeapons; + int count() const; + ///< Return total number of references, including deleted ones. + void load (const MWWorld::ESMStore &store, std::vector &esm); @@ -83,6 +90,8 @@ namespace MWWorld /// Call functor (ref) for each reference. functor must return a bool. Returning /// false will abort the iteration. /// \return Iteration completed? + /// + /// \note Creatures and NPCs are handled last. template bool forEach (Functor& functor) { @@ -94,19 +103,19 @@ namespace MWWorld forEachImp (functor, mBooks) && forEachImp (functor, mClothes) && forEachImp (functor, mContainers) && - forEachImp (functor, mCreatures) && forEachImp (functor, mDoors) && forEachImp (functor, mIngreds) && - forEachImp (functor, mCreatureLists) && forEachImp (functor, mItemLists) && forEachImp (functor, mLights) && forEachImp (functor, mLockpicks) && forEachImp (functor, mMiscItems) && - forEachImp (functor, mNpcs) && forEachImp (functor, mProbes) && forEachImp (functor, mRepairs) && forEachImp (functor, mStatics) && - forEachImp (functor, mWeapons); + forEachImp (functor, mWeapons) && + forEachImp (functor, mCreatures) && + forEachImp (functor, mNpcs) && + forEachImp (functor, mCreatureLists); } bool operator==(const CellStore &cell) { @@ -133,6 +142,11 @@ namespace MWWorld void readReferences (ESM::ESMReader& reader, const std::map& contentFileMap); + template + CellRefList& get() { + throw std::runtime_error ("Storage for this type not exist in cells"); + } + private: template @@ -159,6 +173,126 @@ namespace MWWorld /// /// Invalid \a ref objects are silently dropped. }; + + template<> + inline CellRefList& CellStore::get() + { + return mActivators; + } + + template<> + inline CellRefList& CellStore::get() + { + return mPotions; + } + + template<> + inline CellRefList& CellStore::get() + { + return mAppas; + } + + template<> + inline CellRefList& CellStore::get() + { + return mArmors; + } + + template<> + inline CellRefList& CellStore::get() + { + return mBooks; + } + + template<> + inline CellRefList& CellStore::get() + { + return mClothes; + } + + template<> + inline CellRefList& CellStore::get() + { + return mContainers; + } + + template<> + inline CellRefList& CellStore::get() + { + return mCreatures; + } + + template<> + inline CellRefList& CellStore::get() + { + return mDoors; + } + + template<> + inline CellRefList& CellStore::get() + { + return mIngreds; + } + + template<> + inline CellRefList& CellStore::get() + { + return mCreatureLists; + } + + template<> + inline CellRefList& CellStore::get() + { + return mItemLists; + } + + template<> + inline CellRefList& CellStore::get() + { + return mLights; + } + + template<> + inline CellRefList& CellStore::get() + { + return mLockpicks; + } + + template<> + inline CellRefList& CellStore::get() + { + return mMiscItems; + } + + template<> + inline CellRefList& CellStore::get() + { + return mNpcs; + } + + template<> + inline CellRefList& CellStore::get() + { + return mProbes; + } + + template<> + inline CellRefList& CellStore::get() + { + return mRepairs; + } + + template<> + inline CellRefList& CellStore::get() + { + return mStatics; + } + + template<> + inline CellRefList& CellStore::get() + { + return mWeapons; + } } #endif diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp index 997e9e32c..844e2b18b 100644 --- a/apps/openmw/mwworld/localscripts.cpp +++ b/apps/openmw/mwworld/localscripts.cpp @@ -101,26 +101,26 @@ void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr) void MWWorld::LocalScripts::addCell (CellStore *cell) { - listCellScripts (*this, cell->mActivators, cell); - listCellScripts (*this, cell->mPotions, cell); - listCellScripts (*this, cell->mAppas, cell); - listCellScripts (*this, cell->mArmors, cell); - listCellScripts (*this, cell->mBooks, cell); - listCellScripts (*this, cell->mClothes, cell); - listCellScripts (*this, cell->mContainers, cell); - listCellScriptsCont (*this, cell->mContainers, cell); - listCellScripts (*this, cell->mCreatures, cell); - listCellScriptsCont (*this, cell->mCreatures, cell); - listCellScripts (*this, cell->mDoors, cell); - listCellScripts (*this, cell->mIngreds, cell); - listCellScripts (*this, cell->mLights, cell); - listCellScripts (*this, cell->mLockpicks, cell); - listCellScripts (*this, cell->mMiscItems, cell); - listCellScripts (*this, cell->mNpcs, cell); - listCellScriptsCont (*this, cell->mNpcs, cell); - listCellScripts (*this, cell->mProbes, cell); - listCellScripts (*this, cell->mRepairs, cell); - listCellScripts (*this, cell->mWeapons, cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScriptsCont (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScriptsCont (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScriptsCont (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); + listCellScripts (*this, cell->get(), cell); } void MWWorld::LocalScripts::clear() diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 248d452c1..10afbc675 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -22,6 +22,63 @@ namespace { + struct InsertFunctor + { + MWWorld::CellStore& mCell; + bool mRescale; + Loading::Listener& mLoadingListener; + MWWorld::PhysicsSystem& mPhysics; + MWRender::RenderingManager& mRendering; + + InsertFunctor (MWWorld::CellStore& cell, bool rescale, Loading::Listener& loadingListener, + MWWorld::PhysicsSystem& physics, MWRender::RenderingManager& rendering); + + bool operator() (const MWWorld::Ptr& ptr); + }; + + InsertFunctor::InsertFunctor (MWWorld::CellStore& cell, bool rescale, + Loading::Listener& loadingListener, MWWorld::PhysicsSystem& physics, + MWRender::RenderingManager& rendering) + : mCell (cell), mRescale (rescale), mLoadingListener (loadingListener), + mPhysics (physics), mRendering (rendering) + {} + + bool InsertFunctor::InsertFunctor::operator() (const MWWorld::Ptr& ptr) + { + if (mRescale) + { + if (ptr.getCellRef().mScale<0.5) + ptr.getCellRef().mScale = 0.5; + else if (ptr.getCellRef().mScale>2) + ptr.getCellRef().mScale = 2; + } + + if (ptr.getRefData().getCount() && ptr.getRefData().isEnabled()) + { + try + { + mRendering.addObject (ptr); + ptr.getClass().insertObject (ptr, mPhysics); + + float ax = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[0]).valueDegrees(); + float ay = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[1]).valueDegrees(); + float az = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[2]).valueDegrees(); + MWBase::Environment::get().getWorld()->localRotateObject (ptr, ax, ay, az); + + MWBase::Environment::get().getWorld()->scaleObject (ptr, ptr.getCellRef().mScale); + ptr.getClass().adjustPosition (ptr); + } + catch (const std::exception& e) + { + std::string error ("error during rendering: "); + std::cerr << error + e.what() << std::endl; + } + } + + mLoadingListener.increaseProgress (1); + + return true; + } template void insertCellRefList(MWRender::RenderingManager& rendering, @@ -267,7 +324,7 @@ namespace MWWorld } if (iter==mActiveCells.end()) - refsToLoad += countRefs(*MWBase::Environment::get().getWorld()->getExterior(x, y)); + refsToLoad += MWBase::Environment::get().getWorld()->getExterior(x, y)->count(); } loadingListener->setProgressRange(refsToLoad); @@ -403,7 +460,7 @@ namespace MWWorld ++current; } - int refsToLoad = countRefs(*cell); + int refsToLoad = cell->count(); loadingListener->setProgressRange(refsToLoad); // Load cell. @@ -451,55 +508,10 @@ namespace MWWorld mCellChanged = false; } - int Scene::countRefs (const CellStore& cell) - { - return cell.mActivators.mList.size() - + cell.mPotions.mList.size() - + cell.mAppas.mList.size() - + cell.mArmors.mList.size() - + cell.mBooks.mList.size() - + cell.mClothes.mList.size() - + cell.mContainers.mList.size() - + cell.mDoors.mList.size() - + cell.mIngreds.mList.size() - + cell.mCreatureLists.mList.size() - + cell.mItemLists.mList.size() - + cell.mLights.mList.size() - + cell.mLockpicks.mList.size() - + cell.mMiscItems.mList.size() - + cell.mProbes.mList.size() - + cell.mRepairs.mList.size() - + cell.mStatics.mList.size() - + cell.mWeapons.mList.size() - + cell.mCreatures.mList.size() - + cell.mNpcs.mList.size(); - } - void Scene::insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener) { - // Loop through all references in the cell - insertCellRefList(mRendering, cell.mActivators, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mPotions, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mAppas, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mArmors, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mBooks, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mClothes, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mContainers, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mDoors, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mIngreds, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mItemLists, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mLights, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mLockpicks, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mMiscItems, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mProbes, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mRepairs, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mStatics, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mWeapons, cell, *mPhysics, rescale, loadingListener); - // Load NPCs and creatures _after_ everything else (important for adjustPosition to work correctly) - insertCellRefList(mRendering, cell.mCreatures, cell, *mPhysics, rescale, loadingListener); - insertCellRefList(mRendering, cell.mNpcs, cell, *mPhysics, rescale, loadingListener); - // Since this adds additional creatures, load afterwards, or they would be loaded twice - insertCellRefList(mRendering, cell.mCreatureLists, cell, *mPhysics, rescale, loadingListener); + InsertFunctor functor (cell, rescale, *loadingListener, *mPhysics, mRendering); + cell.forEach (functor); } void Scene::addObjectToScene (const Ptr& ptr) diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index af833f331..16d4877a9 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -63,8 +63,6 @@ namespace MWWorld void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener); - int countRefs (const CellStore& cell); - public: Scene (MWRender::RenderingManager& rendering, PhysicsSystem *physics); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index e258d8503..b51e224f8 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -48,27 +48,6 @@ using namespace Ogre; -namespace -{ - template - MWWorld::LiveCellRef *searchViaHandle (const std::string& handle, - MWWorld::CellRefList& refList) - { - typedef typename MWWorld::CellRefList::List::iterator iterator; - - for (iterator iter (refList.mList.begin()); iter!=refList.mList.end(); ++iter) - { - if (iter->mData.getCount() > 0 && iter->mData.getBaseNode()){ - if (iter->mData.getHandle()==handle) - { - return &*iter; - } - } - } - return 0; - } -} - namespace MWWorld { struct GameContentLoader : public ContentLoader @@ -103,52 +82,6 @@ namespace MWWorld LoadersContainer mLoaders; }; - Ptr World::getPtrViaHandle (const std::string& handle, CellStore& cell) - { - if (MWWorld::LiveCellRef *ref = - searchViaHandle (handle, cell.mActivators)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mPotions)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mAppas)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mArmors)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mBooks)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mClothes)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = - searchViaHandle (handle, cell.mContainers)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = - searchViaHandle (handle, cell.mCreatures)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mDoors)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = - searchViaHandle (handle, cell.mIngreds)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mLights)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mLockpicks)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mMiscItems)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mNpcs)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mProbes)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mRepairs)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mStatics)) - return Ptr (ref, &cell); - if (MWWorld::LiveCellRef *ref = searchViaHandle (handle, cell.mWeapons)) - return Ptr (ref, &cell); - return Ptr(); - } - - int World::getDaysPerMonth (int month) const { switch (month) @@ -579,7 +512,7 @@ namespace MWWorld iter!=mWorldScene->getActiveCells().end(); ++iter) { CellStore* cellstore = *iter; - Ptr ptr = getPtrViaHandle (handle, *cellstore); + Ptr ptr = cellstore->searchViaHandle (handle); if (!ptr.isEmpty()) return ptr; @@ -1505,7 +1438,7 @@ namespace MWWorld Ogre::Vector2 World::getNorthVector (CellStore* cell) { - MWWorld::CellRefList& statics = cell->mStatics; + MWWorld::CellRefList& statics = cell->get(); MWWorld::LiveCellRef* ref = statics.find("northmarker"); if (!ref) return Vector2(0, 1); @@ -1517,7 +1450,7 @@ namespace MWWorld void World::getDoorMarkers (CellStore* cell, std::vector& out) { - MWWorld::CellRefList& doors = cell->mDoors; + MWWorld::CellRefList& doors = cell->get(); CellRefList::List& refList = doors.mList; for (CellRefList::List::iterator it = refList.begin(); it != refList.end(); ++it) { @@ -1900,7 +1833,7 @@ namespace MWWorld const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells(); for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt) { - MWWorld::CellRefList& containers = (*cellIt)->mContainers; + MWWorld::CellRefList& containers = (*cellIt)->get(); CellRefList::List& refList = containers.mList; for (CellRefList::List::iterator container = refList.begin(); container != refList.end(); ++container) { @@ -1972,7 +1905,7 @@ namespace MWWorld if (0 == cellStore) { return false; } - const DoorList &doors = cellStore->mDoors.mList; + const DoorList &doors = cellStore->get().mList; for (DoorList::const_iterator it = doors.begin(); it != doors.end(); ++it) { if (!it->mRef.mTeleport) { continue; @@ -1994,7 +1927,7 @@ namespace MWWorld if (0 != source) { // Find door leading to our current teleport door // and use it destination to position inside cell. - const DoorList &doors = source->mDoors.mList; + const DoorList &doors = source->get().mList; for (DoorList::const_iterator jt = doors.begin(); jt != doors.end(); ++jt) { if (it->mRef.mTeleport && Misc::StringUtils::ciEqual(name, jt->mRef.mDestCell)) @@ -2402,7 +2335,7 @@ namespace MWWorld { if (cell->isExterior()) return false; - MWWorld::CellRefList& doors = cell->mDoors; + MWWorld::CellRefList& doors = cell->get(); CellRefList::List& refList = doors.mList; // Check if any door in the cell leads to an exterior directly From bfcd768078ea8d0d74ce8fdcafc04b2d48e13b52 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 23 Feb 2014 21:39:18 +0100 Subject: [PATCH 8/9] various bits of cleanup --- apps/openmw/mwworld/cellstore.cpp | 15 ++ apps/openmw/mwworld/cellstore.hpp | 273 +++++++++++++++--------------- components/esm/cellid.cpp | 13 +- components/esm/cellid.hpp | 3 + 4 files changed, 162 insertions(+), 142 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 8b0740d3b..f84b35b58 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -430,6 +430,11 @@ namespace MWWorld } } + bool CellStore::isExterior() const + { + return mCell->isExterior(); + } + Ptr CellStore::searchInContainer (const std::string& id) { if (Ptr ptr = searchInContainerList (mContainers, id)) @@ -637,4 +642,14 @@ namespace MWWorld } } } + + bool operator== (const CellStore& left, const CellStore& right) + { + return left.getCell()->getCellId()==right.getCell()->getCellId(); + } + + bool operator!= (const CellStore& left, const CellStore& right) + { + return !(left==right); + } } diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 5ff63c582..6c18d1ce1 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -1,7 +1,6 @@ #ifndef GAME_MWWORLD_CELLSTORE_H #define GAME_MWWORLD_CELLSTORE_H -#include #include #include @@ -18,161 +17,150 @@ namespace MWWorld { class Ptr; - /// \brief Mutable state of a cell - class CellStore - { - public: - - enum State - { - State_Unloaded, State_Preloaded, State_Loaded - }; - - private: - - const ESM::Cell *mCell; - State mState; - std::vector mIds; - float mWaterLevel; - - CellRefList mActivators; - CellRefList mPotions; - CellRefList mAppas; - CellRefList mArmors; - CellRefList mBooks; - CellRefList mClothes; - CellRefList mContainers; - CellRefList mCreatures; - CellRefList mDoors; - CellRefList mIngreds; - CellRefList mCreatureLists; - CellRefList mItemLists; - CellRefList mLights; - CellRefList mLockpicks; - CellRefList mMiscItems; - CellRefList mNpcs; - CellRefList mProbes; - CellRefList mRepairs; - CellRefList mStatics; - CellRefList mWeapons; - - public: - - CellStore (const ESM::Cell *cell_); - - const ESM::Cell *getCell() const; - - State getState() const; - - bool hasId (const std::string& id) const; - ///< May return true for deleted IDs when in preload state. Will return false, if cell is - /// unloaded. - - Ptr search (const std::string& id); - ///< Will return an empty Ptr if cell is not loaded. Does not check references in - /// containers. - - Ptr searchViaHandle (const std::string& handle); - ///< Will return an empty Ptr if cell is not loaded. - - float getWaterLevel() const; - - void setWaterLevel (float level); - - int count() const; - ///< Return total number of references, including deleted ones. - - - void load (const MWWorld::ESMStore &store, std::vector &esm); - - void preload (const MWWorld::ESMStore &store, std::vector &esm); - - /// Call functor (ref) for each reference. functor must return a bool. Returning - /// false will abort the iteration. - /// \return Iteration completed? - /// - /// \note Creatures and NPCs are handled last. - template - bool forEach (Functor& functor) + /// \brief Mutable state of a cell + class CellStore { - return - forEachImp (functor, mActivators) && - forEachImp (functor, mPotions) && - forEachImp (functor, mAppas) && - forEachImp (functor, mArmors) && - forEachImp (functor, mBooks) && - forEachImp (functor, mClothes) && - forEachImp (functor, mContainers) && - forEachImp (functor, mDoors) && - forEachImp (functor, mIngreds) && - forEachImp (functor, mItemLists) && - forEachImp (functor, mLights) && - forEachImp (functor, mLockpicks) && - forEachImp (functor, mMiscItems) && - forEachImp (functor, mProbes) && - forEachImp (functor, mRepairs) && - forEachImp (functor, mStatics) && - forEachImp (functor, mWeapons) && - forEachImp (functor, mCreatures) && - forEachImp (functor, mNpcs) && - forEachImp (functor, mCreatureLists); - } + public: - bool operator==(const CellStore &cell) { - return mCell->mName == cell.mCell->mName && - mCell->mData.mX == cell.mCell->mData.mX && - mCell->mData.mY == cell.mCell->mData.mY; - } + enum State + { + State_Unloaded, State_Preloaded, State_Loaded + }; - bool operator!=(const CellStore &cell) { - return !(*this == cell); - } + private: - bool isExterior() const { - return mCell->isExterior(); - } + const ESM::Cell *mCell; + State mState; + std::vector mIds; + float mWaterLevel; - Ptr searchInContainer (const std::string& id); + CellRefList mActivators; + CellRefList mPotions; + CellRefList mAppas; + CellRefList mArmors; + CellRefList mBooks; + CellRefList mClothes; + CellRefList mContainers; + CellRefList mCreatures; + CellRefList mDoors; + CellRefList mIngreds; + CellRefList mCreatureLists; + CellRefList mItemLists; + CellRefList mLights; + CellRefList mLockpicks; + CellRefList mMiscItems; + CellRefList mNpcs; + CellRefList mProbes; + CellRefList mRepairs; + CellRefList mStatics; + CellRefList mWeapons; - void loadState (const ESM::CellState& state); + public: - void saveState (ESM::CellState& state) const; + CellStore (const ESM::Cell *cell_); - void writeReferences (ESM::ESMWriter& writer) const; + const ESM::Cell *getCell() const; - void readReferences (ESM::ESMReader& reader, const std::map& contentFileMap); + State getState() const; - template - CellRefList& get() { - throw std::runtime_error ("Storage for this type not exist in cells"); - } + bool hasId (const std::string& id) const; + ///< May return true for deleted IDs when in preload state. Will return false, if cell is + /// unloaded. - private: + Ptr search (const std::string& id); + ///< Will return an empty Ptr if cell is not loaded. Does not check references in + /// containers. - template - bool forEachImp (Functor& functor, List& list) - { - for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end(); - ++iter) - { - if (!iter->mData.getCount()) - continue; - if (!functor (MWWorld::Ptr(&*iter, this))) - return false; - } - return true; - } + Ptr searchViaHandle (const std::string& handle); + ///< Will return an empty Ptr if cell is not loaded. - /// Run through references and store IDs - void listRefs(const MWWorld::ESMStore &store, std::vector &esm); + float getWaterLevel() const; - void loadRefs(const MWWorld::ESMStore &store, std::vector &esm); + void setWaterLevel (float level); - void loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store); - ///< Make case-adjustments to \a ref and insert it into the respective container. - /// - /// Invalid \a ref objects are silently dropped. - }; + int count() const; + ///< Return total number of references, including deleted ones. + + void load (const MWWorld::ESMStore &store, std::vector &esm); + ///< Load references from content file. + + void preload (const MWWorld::ESMStore &store, std::vector &esm); + ///< Build ID list from content file. + + /// Call functor (ref) for each reference. functor must return a bool. Returning + /// false will abort the iteration. + /// \return Iteration completed? + /// + /// \note Creatures and NPCs are handled last. + template + bool forEach (Functor& functor) + { + return + forEachImp (functor, mActivators) && + forEachImp (functor, mPotions) && + forEachImp (functor, mAppas) && + forEachImp (functor, mArmors) && + forEachImp (functor, mBooks) && + forEachImp (functor, mClothes) && + forEachImp (functor, mContainers) && + forEachImp (functor, mDoors) && + forEachImp (functor, mIngreds) && + forEachImp (functor, mItemLists) && + forEachImp (functor, mLights) && + forEachImp (functor, mLockpicks) && + forEachImp (functor, mMiscItems) && + forEachImp (functor, mProbes) && + forEachImp (functor, mRepairs) && + forEachImp (functor, mStatics) && + forEachImp (functor, mWeapons) && + forEachImp (functor, mCreatures) && + forEachImp (functor, mNpcs) && + forEachImp (functor, mCreatureLists); + } + + bool isExterior() const; + + Ptr searchInContainer (const std::string& id); + + void loadState (const ESM::CellState& state); + + void saveState (ESM::CellState& state) const; + + void writeReferences (ESM::ESMWriter& writer) const; + + void readReferences (ESM::ESMReader& reader, const std::map& contentFileMap); + + template + CellRefList& get() { + throw std::runtime_error ("Storage for this type not exist in cells"); + } + + private: + + template + bool forEachImp (Functor& functor, List& list) + { + for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end(); + ++iter) + { + if (!iter->mData.getCount()) + continue; + if (!functor (MWWorld::Ptr(&*iter, this))) + return false; + } + return true; + } + + /// Run through references and store IDs + void listRefs(const MWWorld::ESMStore &store, std::vector &esm); + + void loadRefs(const MWWorld::ESMStore &store, std::vector &esm); + + void loadRef (ESM::CellRef& ref, bool deleted, const ESMStore& store); + ///< Make case-adjustments to \a ref and insert it into the respective container. + /// + /// Invalid \a ref objects are silently dropped. + }; template<> inline CellRefList& CellStore::get() @@ -293,6 +281,9 @@ namespace MWWorld { return mWeapons; } + + bool operator== (const CellStore& left, const CellStore& right); + bool operator!= (const CellStore& left, const CellStore& right); } #endif diff --git a/components/esm/cellid.cpp b/components/esm/cellid.cpp index 5bc8b7aef..3c6e23ffd 100644 --- a/components/esm/cellid.cpp +++ b/components/esm/cellid.cpp @@ -23,4 +23,15 @@ void ESM::CellId::save (ESMWriter &esm) const if (mPaged) esm.writeHNT ("CIDX", mIndex, 8); -} \ No newline at end of file +} + +bool ESM::operator== (const CellId& left, const CellId& right) +{ + return left.mWorldspace==right.mWorldspace && left.mPaged==right.mPaged && + (!left.mPaged || (left.mIndex.mX==right.mIndex.mX && left.mIndex.mY==right.mIndex.mY)); +} + +bool ESM::operator!= (const CellId& left, const CellId& right) +{ + return !(left==right); +} diff --git a/components/esm/cellid.hpp b/components/esm/cellid.hpp index 54dbdae78..40bc552e0 100644 --- a/components/esm/cellid.hpp +++ b/components/esm/cellid.hpp @@ -23,6 +23,9 @@ namespace ESM void load (ESMReader &esm); void save (ESMWriter &esm) const; }; + + bool operator== (const CellId& left, const CellId& right); + bool operator!= (const CellId& left, const CellId& right); } #endif \ No newline at end of file From 9b18e0150708fc32875d13991723d4e8b05290c4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 24 Feb 2014 10:03:04 +0100 Subject: [PATCH 9/9] keep track of which cells have state that needs to be saved --- apps/openmw/mwworld/cells.cpp | 28 ++++++++++------------------ apps/openmw/mwworld/cells.hpp | 9 +++------ apps/openmw/mwworld/cellstore.cpp | 30 +++++++++++++++++++++++++++++- apps/openmw/mwworld/cellstore.hpp | 26 ++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 74df0f79d..acffe20f3 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -66,8 +66,11 @@ MWWorld::Ptr MWWorld::Cells::getPtrAndCache (const std::string& name, CellStore& return ptr; } -void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, const CellStore& cell) const +void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, CellStore& cell) const { + if (cell.getState()!=CellStore::State_Loaded) + cell.load (mStore, mReader); + ESM::CellState cellState; cell.saveState (cellState); @@ -79,17 +82,6 @@ void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, const CellStore& cell) c writer.endRecord (ESM::REC_CSTA); } -bool MWWorld::Cells::hasState (const CellStore& cellStore) const -{ - if (cellStore.getState()==CellStore::State_Loaded) - return true; - - if (cellStore.getCell()->mData.mFlags & ESM::Cell::Interior) - return cellStore.getCell()->mData.mFlags & ESM::Cell::HasWater; - else - return false; -} - MWWorld::Cells::Cells (const MWWorld::ESMStore& store, std::vector& reader) : mStore (store), mReader (reader), mIdCache (40, std::pair ("", (CellStore*)0)), /// \todo make cache size configurable @@ -274,12 +266,12 @@ int MWWorld::Cells::countSavedGameRecords() const for (std::map::const_iterator iter (mInteriors.begin()); iter!=mInteriors.end(); ++iter) - if (hasState (iter->second)) + if (iter->second.hasState()) ++count; for (std::map, CellStore>::const_iterator iter (mExteriors.begin()); iter!=mExteriors.end(); ++iter) - if (hasState (iter->second)) + if (iter->second.hasState()) ++count; return count; @@ -287,14 +279,14 @@ int MWWorld::Cells::countSavedGameRecords() const void MWWorld::Cells::write (ESM::ESMWriter& writer) const { - for (std::map, CellStore>::const_iterator iter (mExteriors.begin()); + for (std::map, CellStore>::iterator iter (mExteriors.begin()); iter!=mExteriors.end(); ++iter) - if (hasState (iter->second)) + if (iter->second.hasState()) writeCell (writer, iter->second); - for (std::map::const_iterator iter (mInteriors.begin()); + for (std::map::iterator iter (mInteriors.begin()); iter!=mInteriors.end(); ++iter) - if (hasState (iter->second)) + if (iter->second.hasState()) writeCell (writer, iter->second); } diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index 0df55b586..5209aa51a 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -24,8 +24,8 @@ namespace MWWorld { const MWWorld::ESMStore& mStore; std::vector& mReader; - std::map mInteriors; - std::map, CellStore> mExteriors; + mutable std::map mInteriors; + mutable std::map, CellStore> mExteriors; std::vector > mIdCache; std::size_t mIdCacheIndex; @@ -36,10 +36,7 @@ namespace MWWorld Ptr getPtrAndCache (const std::string& name, CellStore& cellStore); - void writeCell (ESM::ESMWriter& writer, const CellStore& cell) const; - - bool hasState (const CellStore& cellStore) const; - ///< Check if cell has state that needs to be included in a saved game file. + void writeCell (ESM::ESMWriter& writer, CellStore& cell) const; public: diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index f84b35b58..3f1ef8ab2 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -141,7 +141,7 @@ namespace MWWorld } CellStore::CellStore (const ESM::Cell *cell) - : mCell (cell), mState (State_Unloaded) + : mCell (cell), mState (State_Unloaded), mHasState (false) { mWaterLevel = cell->mWater; } @@ -156,6 +156,11 @@ namespace MWWorld return mState; } + bool CellStore::hasState() const + { + return mHasState; + } + bool CellStore::hasId (const std::string& id) const { if (mState==State_Unloaded) @@ -170,6 +175,10 @@ namespace MWWorld Ptr CellStore::search (const std::string& id) { + bool oldState = mHasState; + + mHasState = true; + if (LiveCellRef *ref = mActivators.find (id)) return Ptr (ref, this); @@ -230,11 +239,17 @@ namespace MWWorld if (LiveCellRef *ref = mWeapons.find (id)) return Ptr (ref, this); + mHasState = oldState; + return Ptr(); } Ptr CellStore::searchViaHandle (const std::string& handle) { + bool oldState = mHasState; + + mHasState = true; + if (LiveCellRef *ref = mActivators.searchViaHandle (handle)) return Ptr (ref, this); @@ -295,6 +310,8 @@ namespace MWWorld if (LiveCellRef *ref = mWeapons.searchViaHandle (handle)) return Ptr (ref, this); + mHasState = oldState; + return Ptr(); } @@ -306,6 +323,7 @@ namespace MWWorld void CellStore::setWaterLevel (float level) { mWaterLevel = level; + mHasState = true; } int CellStore::count() const @@ -437,6 +455,10 @@ namespace MWWorld Ptr CellStore::searchInContainer (const std::string& id) { + bool oldState = mHasState; + + mHasState = true; + if (Ptr ptr = searchInContainerList (mContainers, id)) return ptr; @@ -446,6 +468,8 @@ namespace MWWorld if (Ptr ptr = searchInContainerList (mNpcs, id)) return ptr; + mHasState = oldState; + return Ptr(); } @@ -486,6 +510,8 @@ namespace MWWorld void CellStore::loadState (const ESM::CellState& state) { + mHasState = true; + if (mCell->mData.mFlags & ESM::Cell::Interior && mCell->mData.mFlags & ESM::Cell::HasWater) mWaterLevel = state.mWaterLevel; @@ -529,6 +555,8 @@ namespace MWWorld void CellStore::readReferences (ESM::ESMReader& reader, const std::map& contentFileMap) { + mHasState = true; + while (reader.isNextSub ("OBJE")) { unsigned int id = 0; diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 6c18d1ce1..4b7c0011b 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -31,6 +31,7 @@ namespace MWWorld const ESM::Cell *mCell; State mState; + bool mHasState; std::vector mIds; float mWaterLevel; @@ -63,6 +64,9 @@ namespace MWWorld State getState() const; + bool hasState() const; + ///< Does this cell have state that needs to be stored in a saved game file? + bool hasId (const std::string& id) const; ///< May return true for deleted IDs when in preload state. Will return false, if cell is /// unloaded. @@ -95,6 +99,8 @@ namespace MWWorld template bool forEach (Functor& functor) { + mHasState = true; + return forEachImp (functor, mActivators) && forEachImp (functor, mPotions) && @@ -165,120 +171,140 @@ namespace MWWorld template<> inline CellRefList& CellStore::get() { + mHasState = true; return mActivators; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mPotions; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mAppas; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mArmors; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mBooks; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mClothes; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mContainers; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mCreatures; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mDoors; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mIngreds; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mCreatureLists; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mItemLists; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mLights; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mLockpicks; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mMiscItems; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mNpcs; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mProbes; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mRepairs; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mStatics; } template<> inline CellRefList& CellStore::get() { + mHasState = true; return mWeapons; }