1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch 'rm_redundant_virtual' into 'master'

Remove redundant virtual functions

See merge request OpenMW/openmw!1836
This commit is contained in:
psi29a 2022-05-08 16:51:38 +00:00
commit fad6a849a5
10 changed files with 127 additions and 125 deletions

View File

@ -53,8 +53,6 @@ namespace MWBase
///
/// \param bypass Skip new game mechanics.
virtual void endGame() = 0;
virtual void resumeGame() = 0;
virtual void deleteGame (const MWState::Character *character, const MWState::Slot *slot) = 0;

View File

@ -282,8 +282,6 @@ namespace MWBase
/// Warning: do not use MyGUI::InputManager::setKeyFocusWidget directly. Instead use this.
virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0;
virtual void loadUserFonts() = 0;
virtual Loading::Listener* getLoadingScreen() = 0;
/// Should the cursor be visible?

View File

@ -150,8 +150,6 @@ namespace MWBase
virtual bool toggleWorld() = 0;
virtual bool toggleBorders() = 0;
virtual void adjustSky() = 0;
virtual MWWorld::Player& getPlayer() = 0;
virtual MWWorld::Ptr getPlayerPtr() = 0;
virtual MWWorld::ConstPtr getPlayerConstPtr() const = 0;
@ -273,7 +271,7 @@ namespace MWBase
virtual float getDistanceToFacedObject() = 0;
virtual float getMaxActivationDistance() = 0;
virtual float getMaxActivationDistance() const = 0;
/// Returns a pointer to the object the provided object would hit (if within the
/// specified distance), and the point where the hit occurs. This will attempt to
@ -548,7 +546,7 @@ namespace MWBase
const osg::Vec3f& worldPos, const osg::Quat& orient, MWWorld::Ptr& bow, float speed, float attackStrength) = 0;
virtual void updateProjectilesCasters() = 0;
virtual void applyLoopingParticles(const MWWorld::Ptr& ptr) = 0;
virtual void applyLoopingParticles(const MWWorld::Ptr& ptr) const = 0;
virtual const std::vector<std::string>& getContentFiles() const = 0;
@ -623,7 +621,6 @@ namespace MWBase
virtual bool isPlayerInJail() const = 0;
virtual void rest(double hours) = 0;
virtual void rechargeItems(double duration, bool activeOnly) = 0;
virtual void setPlayerTraveling(bool traveling) = 0;
virtual bool isPlayerTraveling() const = 0;

View File

@ -142,7 +142,7 @@ namespace MWGui
void setStore (const MWWorld::ESMStore& store);
void initUI();
void loadUserFonts() override;
void loadUserFonts();
Loading::Listener* getLoadingScreen() override;

View File

@ -46,7 +46,7 @@ namespace MWState
///
/// \param bypass Skip new game mechanics.
void endGame() override;
void endGame();
void resumeGame() override;

View File

@ -0,0 +1,20 @@
#ifndef OPENMW_MWWORLD_CELLUTILS_H
#define OPENMW_MWWORLD_CELLUTILS_H
#include <components/misc/constants.hpp>
#include <components/esm3/cellid.hpp>
#include <cmath>
namespace MWWorld
{
inline ESM::CellId::CellIndex positionToIndex(float x, float y)
{
return {
static_cast<int>(std::floor(x / Constants::CellSizeInUnits)),
static_cast<int>(std::floor(y / Constants::CellSizeInUnits))
};
}
}
#endif

View File

@ -40,6 +40,7 @@
#include "cellvisitors.hpp"
#include "cellstore.hpp"
#include "cellpreloader.hpp"
#include "worldimp.hpp"
namespace
{
@ -97,7 +98,7 @@ namespace
return model;
}
void addObject(const MWWorld::Ptr& ptr, MWPhysics::PhysicsSystem& physics,
void addObject(const MWWorld::Ptr& ptr, const MWWorld::World& world, MWPhysics::PhysicsSystem& physics,
MWRender::RenderingManager& rendering, std::set<ESM::RefNum>& pagedRefs)
{
if (ptr.getRefData().getBaseNode() || physics.getActor(ptr))
@ -123,7 +124,7 @@ namespace
rendering.addWaterRippleEmitter(ptr);
// Restore effect particles
MWBase::Environment::get().getWorld()->applyLoopingParticles(ptr);
world.applyLoopingParticles(ptr);
if (!model.empty())
ptr.getClass().insertObject(ptr, model, rotation, physics);
@ -131,7 +132,8 @@ namespace
MWBase::Environment::get().getLuaManager()->objectAddedToScene(ptr);
}
void addObject(const MWWorld::Ptr& ptr, const MWPhysics::PhysicsSystem& physics, DetourNavigator::Navigator& navigator)
void addObject(const MWWorld::Ptr& ptr, const MWWorld::World& world, const MWPhysics::PhysicsSystem& physics,
DetourNavigator::Navigator& navigator)
{
if (const auto object = physics.getObject(ptr))
{
@ -145,7 +147,7 @@ namespace
const auto center = (aabbMax + aabbMin) * 0.5f;
const auto distanceFromDoor = MWBase::Environment::get().getWorld()->getMaxActivationDistance() * 0.5f;
const auto distanceFromDoor = world.getMaxActivationDistance() * 0.5f;
const auto toPoint = aabbMax.x() - aabbMin.x() < aabbMax.y() - aabbMin.y()
? btVector3(distanceFromDoor, 0, 0)
: btVector3(0, distanceFromDoor, 0);
@ -183,7 +185,7 @@ namespace
}
else if (physics.getActor(ptr))
{
navigator.addAgent(MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(ptr));
navigator.addAgent(world.getPathfindingHalfExtents(ptr));
}
}
@ -295,7 +297,7 @@ namespace MWWorld
mPhysics->updateScale(ptr);
}
void Scene::update (float duration, bool paused)
void Scene::update(float duration)
{
if (mChangeCellGridRequest.has_value())
{
@ -306,8 +308,6 @@ namespace MWWorld
mPreloader->updateCache(mRendering.getReferenceTime());
preloadCells(duration);
mRendering.update (duration, paused);
}
void Scene::unloadCell(CellStore* cell)
@ -320,7 +320,6 @@ namespace MWWorld
ListAndResetObjectsVisitor visitor;
cell->forEach(visitor);
const auto world = MWBase::Environment::get().getWorld();
for (const auto& ptr : visitor.mObjects)
{
if (const auto object = mPhysics->getObject(ptr))
@ -331,7 +330,7 @@ namespace MWWorld
}
else if (mPhysics->getActor(ptr))
{
mNavigator.removeAgent(world->getPathfindingHalfExtents(ptr));
mNavigator.removeAgent(mWorld.getPathfindingHalfExtents(ptr));
mRendering.removeActorPath(ptr);
mPhysics->remove(ptr);
}
@ -352,17 +351,17 @@ namespace MWWorld
if (cell->getCell()->hasWater())
mNavigator.removeWater(osg::Vec2i(cellX, cellY));
if (const auto pathgrid = world->getStore().get<ESM::Pathgrid>().search(*cell->getCell()))
if (const auto pathgrid = mWorld.getStore().get<ESM::Pathgrid>().search(*cell->getCell()))
mNavigator.removePathgrid(*pathgrid);
mNavigator.update(world->getPlayerPtr().getRefData().getPosition().asVec3());
mNavigator.update(mWorld.getPlayerPtr().getRefData().getPosition().asVec3());
MWBase::Environment::get().getMechanicsManager()->drop (cell);
mRendering.removeCell(cell);
MWBase::Environment::get().getWindowManager()->removeCell(cell);
MWBase::Environment::get().getWorld()->getLocalScripts().clearCell (cell);
mWorld.getLocalScripts().clearCell (cell);
MWBase::Environment::get().getSoundManager()->stopSound (cell);
mActiveCells.erase(cell);
@ -377,8 +376,6 @@ namespace MWWorld
Log(Debug::Info) << "Loading cell " << cell->getCell()->getDescription();
const auto world = MWBase::Environment::get().getWorld();
const int cellX = cell->getCell()->getGridX();
const int cellY = cell->getCell()->getGridY();
@ -425,12 +422,12 @@ namespace MWWorld
}
}
if (const auto pathgrid = world->getStore().get<ESM::Pathgrid>().search(*cell->getCell()))
if (const auto pathgrid = mWorld.getStore().get<ESM::Pathgrid>().search(*cell->getCell()))
mNavigator.addPathgrid(*cell->getCell(), *pathgrid);
// register local scripts
// do this before insertCell, to make sure we don't add scripts from levelled creature spawning twice
MWBase::Environment::get().getWorld()->getLocalScripts().addCell (cell);
mWorld.getLocalScripts().addCell (cell);
if (respawn)
cell->respawn();
@ -461,7 +458,7 @@ namespace MWWorld
else
mPhysics->disableWater();
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const auto player = mWorld.getPlayerPtr();
// The player is loaded before the scene and by default it is grounded, with the scene fully loaded, we validate and correct this.
if (player.mCell == cell) // Only run once, during initial cell load.
@ -500,14 +497,14 @@ namespace MWWorld
if (currentGridCenter)
{
float centerX, centerY;
MWBase::Environment::get().getWorld()->indexToPosition(currentGridCenter->x(), currentGridCenter->y(), centerX, centerY, true);
mWorld.indexToPosition(currentGridCenter->x(), currentGridCenter->y(), centerX, centerY, true);
float distance = std::max(std::abs(centerX-pos.x()), std::abs(centerY-pos.y()));
const float maxDistance = Constants::CellSizeInUnits / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold
if (distance <= maxDistance)
return *currentGridCenter;
}
osg::Vec2i newCenter;
MWBase::Environment::get().getWorld()->positionToIndex(pos.x(), pos.y(), newCenter.x(), newCenter.y());
mWorld.positionToIndex(pos.x(), pos.y(), newCenter.x(), newCenter.y());
return newCenter;
}
@ -561,7 +558,7 @@ namespace MWWorld
mRendering.getPagedRefnums(newGrid, mPagedRefs);
std::size_t refsToLoad = 0;
const auto cellsToLoad = [&playerCellX,&playerCellY,&refsToLoad](CellStoreCollection& collection, int range) -> std::vector<std::pair<int,int>>
const auto cellsToLoad = [&] (CellStoreCollection& collection, int range) -> std::vector<std::pair<int,int>>
{
std::vector<std::pair<int, int>> cellsPositionsToLoad;
for (int x = playerCellX - range; x <= playerCellX + range; ++x)
@ -570,7 +567,7 @@ namespace MWWorld
{
if (!isCellInCollection(x, y, collection))
{
refsToLoad += MWBase::Environment::get().getWorld()->getExterior(x, y)->count();
refsToLoad += mWorld.getExterior(x, y)->count();
cellsPositionsToLoad.emplace_back(x, y);
}
}
@ -626,12 +623,12 @@ namespace MWWorld
{
if (!isCellInCollection(x, y, mActiveCells))
{
CellStore *cell = MWBase::Environment::get().getWorld()->getExterior(x, y);
CellStore *cell = mWorld.getExterior(x, y);
loadCell(cell, loadingListener, changeEvent, pos);
}
}
CellStore* current = MWBase::Environment::get().getWorld()->getExterior(playerCellX, playerCellY);
CellStore* current = mWorld.getExterior(playerCellX, playerCellY);
MWBase::Environment::get().getWindowManager()->changeCell(current);
if (changeEvent)
@ -647,7 +644,7 @@ namespace MWWorld
mRendering.getResourceSystem()->setExpiryDelay(1.f);
const MWWorld::Store<ESM::Cell> &cells = MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>();
const MWWorld::Store<ESM::Cell> &cells = mWorld.getStore().get<ESM::Cell>();
Loading::Listener* loadingListener = MWBase::Environment::get().getWindowManager()->getLoadingScreen();
Loading::ScopedLoad load(loadingListener);
@ -659,7 +656,7 @@ namespace MWWorld
{
loadingListener->setLabel("Testing exterior cells ("+std::to_string(i)+"/"+std::to_string(cells.getExtSize())+")...");
CellStore *cell = MWBase::Environment::get().getWorld()->getExterior(it->mData.mX, it->mData.mY);
CellStore *cell = mWorld.getExterior(it->mData.mX, it->mData.mY);
loadCell(cell, nullptr, false, osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits);
auto iter = mActiveCells.begin();
@ -692,7 +689,7 @@ namespace MWWorld
mRendering.getResourceSystem()->setExpiryDelay(1.f);
const MWWorld::Store<ESM::Cell> &cells = MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>();
const MWWorld::Store<ESM::Cell> &cells = mWorld.getStore().get<ESM::Cell>();
Loading::Listener* loadingListener = MWBase::Environment::get().getWindowManager()->getLoadingScreen();
Loading::ScopedLoad load(loadingListener);
@ -704,9 +701,9 @@ namespace MWWorld
{
loadingListener->setLabel("Testing interior cells ("+std::to_string(i)+"/"+std::to_string(cells.getIntSize())+")...");
CellStore *cell = MWBase::Environment::get().getWorld()->getInterior(it->mName);
CellStore *cell = mWorld.getInterior(it->mName);
ESM::Position position;
MWBase::Environment::get().getWorld()->findInteriorPosition(it->mName, position);
mWorld.findInteriorPosition(it->mName, position);
loadCell(cell, nullptr, false, position.asVec3());
auto iter = mActiveCells.begin();
@ -739,16 +736,16 @@ namespace MWWorld
mRendering.enableTerrain(cell->isExterior());
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr old = world->getPlayerPtr();
world->getPlayer().setCell(cell);
MWWorld::Ptr old = mWorld.getPlayerPtr();
mWorld.getPlayer().setCell(cell);
MWWorld::Ptr player = world->getPlayerPtr();
MWWorld::Ptr player = mWorld.getPlayerPtr();
mRendering.updatePlayerPtr(player);
if (adjustPlayerPos) {
world->moveObject(player, pos.asVec3());
world->rotateObject(player, pos.asRotationVec3());
if (adjustPlayerPos)
{
mWorld.moveObject(player, pos.asVec3());
mWorld.rotateObject(player, pos.asRotationVec3());
player.getClass().adjustPosition(player, true);
}
@ -758,14 +755,15 @@ namespace MWWorld
mPhysics->updatePtr(old, player);
world->adjustSky();
mWorld.adjustSky();
mLastPlayerPos = player.getRefData().getPosition().asVec3();
}
Scene::Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics,
Scene::Scene(MWWorld::World& world, MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics,
DetourNavigator::Navigator& navigator)
: mCurrentCell (nullptr), mCellChanged (false), mPhysics(physics), mRendering(rendering), mNavigator(navigator)
: mCurrentCell (nullptr), mCellChanged (false)
, mWorld(world), mPhysics(physics), mRendering(rendering), mNavigator(navigator)
, mCellLoadingThreshold(1024.f)
, mPreloadDistance(Settings::Manager::getInt("preload distance", "Cells"))
, mPreloadEnabled(Settings::Manager::getBool("preload enabled", "Cells"))
@ -806,7 +804,7 @@ namespace MWWorld
void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent)
{
CellStore *cell = MWBase::Environment::get().getWorld()->getInterior(cellName);
CellStore *cell = mWorld.getInterior(cellName);
bool useFading = (mCurrentCell != nullptr);
if (useFading)
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
@ -818,12 +816,11 @@ namespace MWWorld
if(mCurrentCell != nullptr && *mCurrentCell == *cell)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
world->moveObject(world->getPlayerPtr(), position.asVec3());
world->rotateObject(world->getPlayerPtr(), position.asRotationVec3());
mWorld.moveObject(mWorld.getPlayerPtr(), position.asVec3());
mWorld.rotateObject(mWorld.getPlayerPtr(), position.asRotationVec3());
if (adjustPlayerPos)
world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true);
mWorld.getPlayerPtr().getClass().adjustPosition(mWorld.getPlayerPtr(), true);
MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
return;
}
@ -852,7 +849,7 @@ namespace MWWorld
mRendering.configureFog(mCurrentCell->getCell());
// Sky system
MWBase::Environment::get().getWorld()->adjustSky();
mWorld.adjustSky();
if (changeEvent)
mCellChanged = true;
@ -870,14 +867,14 @@ namespace MWWorld
int x = 0;
int y = 0;
MWBase::Environment::get().getWorld()->positionToIndex (position.pos[0], position.pos[1], x, y);
mWorld.positionToIndex (position.pos[0], position.pos[1], x, y);
if (changeEvent)
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
changeCellGrid(position.asVec3(), x, y, changeEvent);
CellStore* current = MWBase::Environment::get().getWorld()->getExterior(x, y);
CellStore* current = mWorld.getExterior(x, y);
changePlayerCell(current, position, adjustPlayerPos);
if (changeEvent)
@ -898,20 +895,20 @@ namespace MWWorld
{
InsertVisitor insertVisitor(cell, loadingListener);
cell.forEach (insertVisitor);
insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, *mPhysics, mRendering, mPagedRefs); });
insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, *mPhysics, mNavigator); });
insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, mWorld, *mPhysics, mRendering, mPagedRefs); });
insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, mWorld, *mPhysics, mNavigator); });
}
void Scene::addObjectToScene (const Ptr& ptr)
{
try
{
addObject(ptr, *mPhysics, mRendering, mPagedRefs);
addObject(ptr, *mPhysics, mNavigator);
MWBase::Environment::get().getWorld()->scaleObject(ptr, ptr.getCellRef().getScale());
addObject(ptr, mWorld, *mPhysics, mRendering, mPagedRefs);
addObject(ptr, mWorld, *mPhysics, mNavigator);
mWorld.scaleObject(ptr, ptr.getCellRef().getScale());
if (mCurrentCell != nullptr)
{
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const auto player = mWorld.getPlayerPtr();
mNavigator.update(player.getRefData().getPosition().asVec3());
}
}
@ -931,13 +928,13 @@ namespace MWWorld
mNavigator.removeObject(DetourNavigator::ObjectId(object));
if (mCurrentCell != nullptr)
{
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const auto player = mWorld.getPlayerPtr();
mNavigator.update(player.getRefData().getPosition().asVec3());
}
}
else if (mPhysics->getActor(ptr))
{
mNavigator.removeAgent(MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(ptr));
mNavigator.removeAgent(mWorld.getPathfindingHalfExtents(ptr));
}
mPhysics->remove(ptr);
mRendering.removeObject (ptr);
@ -1022,7 +1019,7 @@ namespace MWWorld
if (dt<=1e-06) return;
std::vector<PositionCellGrid> exteriorPositions;
const MWWorld::ConstPtr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const MWWorld::ConstPtr player = mWorld.getPlayerPtr();
osg::Vec3f playerPos = player.getRefData().getPosition().asVec3();
osg::Vec3f moved = playerPos - mLastPlayerPos;
osg::Vec3f predictedPos = playerPos + moved / dt * mPredictionTime;
@ -1072,13 +1069,13 @@ namespace MWWorld
try
{
if (!door.getCellRef().getDestCell().empty())
preloadCell(MWBase::Environment::get().getWorld()->getInterior(door.getCellRef().getDestCell()));
preloadCell(mWorld.getInterior(door.getCellRef().getDestCell()));
else
{
osg::Vec3f pos = door.getCellRef().getDoorDest().asVec3();
int x,y;
MWBase::Environment::get().getWorld()->positionToIndex (pos.x(), pos.y(), x, y);
preloadCell(MWBase::Environment::get().getWorld()->getExterior(x,y), true);
mWorld.positionToIndex (pos.x(), pos.y(), x, y);
preloadCell(mWorld.getExterior(x,y), true);
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
}
}
@ -1092,7 +1089,7 @@ namespace MWWorld
void Scene::preloadExteriorGrid(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos)
{
if (!MWBase::Environment::get().getWorld()->isCellExterior())
if (!mWorld.isCellExterior())
return;
int halfGridSizePlusOne = mHalfGridSize + 1;
@ -1102,7 +1099,7 @@ namespace MWWorld
cellX = mCurrentGridCenter.x(); cellY = mCurrentGridCenter.y();
float centerX, centerY;
MWBase::Environment::get().getWorld()->indexToPosition(cellX, cellY, centerX, centerY, true);
mWorld.indexToPosition(cellX, cellY, centerX, centerY, true);
for (int dx = -halfGridSizePlusOne; dx <= halfGridSizePlusOne; ++dx)
{
@ -1112,14 +1109,14 @@ namespace MWWorld
continue; // only care about the outer (not yet loaded) part of the grid
float thisCellCenterX, thisCellCenterY;
MWBase::Environment::get().getWorld()->indexToPosition(cellX+dx, cellY+dy, thisCellCenterX, thisCellCenterY, true);
mWorld.indexToPosition(cellX+dx, cellY+dy, thisCellCenterX, thisCellCenterY, true);
float dist = std::max(std::abs(thisCellCenterX - playerPos.x()), std::abs(thisCellCenterY - playerPos.y()));
dist = std::min(dist,std::max(std::abs(thisCellCenterX - predictedPos.x()), std::abs(thisCellCenterY - predictedPos.y())));
float loadDist = Constants::CellSizeInUnits / 2 + Constants::CellSizeInUnits - mCellLoadingThreshold + mPreloadDistance;
if (dist < loadDist)
preloadCell(MWBase::Environment::get().getWorld()->getExterior(cellX+dx, cellY+dy));
preloadCell(mWorld.getExterior(cellX+dx, cellY+dy));
}
}
}
@ -1135,7 +1132,7 @@ namespace MWWorld
{
for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy)
{
mPreloader->preload(MWBase::Environment::get().getWorld()->getExterior(x+dx, y+dy), mRendering.getReferenceTime());
mPreloader->preload(mWorld.getExterior(x+dx, y+dy), mRendering.getReferenceTime());
if (++numpreloaded >= mPreloader->getMaxCacheSize())
break;
}
@ -1198,7 +1195,7 @@ namespace MWWorld
void Scene::preloadFastTravelDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& /*predictedPos*/, std::vector<PositionCellGrid>& exteriorPositions) // ignore predictedPos here since opening dialogue with travel service takes extra time
{
const MWWorld::ConstPtr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const MWWorld::ConstPtr player = mWorld.getPlayerPtr();
ListFastTravelDestinationsVisitor listVisitor(mPreloadDistance, player.getRefData().getPosition().asVec3());
for (MWWorld::CellStore* cellStore : mActiveCells)
@ -1210,13 +1207,13 @@ namespace MWWorld
for (ESM::Transport::Dest& dest : listVisitor.mList)
{
if (!dest.mCellName.empty())
preloadCell(MWBase::Environment::get().getWorld()->getInterior(dest.mCellName));
preloadCell(mWorld.getInterior(dest.mCellName));
else
{
osg::Vec3f pos = dest.mPos.asVec3();
int x,y;
MWBase::Environment::get().getWorld()->positionToIndex( pos.x(), pos.y(), x, y);
preloadCell(MWBase::Environment::get().getWorld()->getExterior(x,y), true);
mWorld.positionToIndex( pos.x(), pos.y(), x, y);
preloadCell(mWorld.getExterior(x,y), true);
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
}
}

View File

@ -62,6 +62,7 @@ namespace MWWorld
class Player;
class CellStore;
class CellPreloader;
class World;
enum class RotationOrder
{
@ -85,6 +86,7 @@ namespace MWWorld
CellStore* mCurrentCell; // the cell the player is in
CellStoreCollection mActiveCells;
bool mCellChanged;
MWWorld::World& mWorld;
MWPhysics::PhysicsSystem *mPhysics;
MWRender::RenderingManager& mRendering;
DetourNavigator::Navigator& mNavigator;
@ -131,7 +133,7 @@ namespace MWWorld
public:
Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics,
Scene(MWWorld::World& world, MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics,
DetourNavigator::Navigator& navigator);
~Scene();
@ -164,7 +166,7 @@ namespace MWWorld
void markCellAsUnchanged();
void update (float duration, bool paused);
void update(float duration);
void addObjectToScene (const Ptr& ptr);
///< Add an object that already exists in the world model to the scene.

View File

@ -78,6 +78,7 @@
#include "contentloader.hpp"
#include "esmloader.hpp"
#include "cellutils.hpp"
namespace MWWorld
{
@ -200,7 +201,7 @@ namespace MWWorld
mWeatherManager.reset(new MWWorld::WeatherManager(*mRendering, mStore));
mWorldScene.reset(new Scene(*mRendering.get(), mPhysics.get(), *mNavigator));
mWorldScene.reset(new Scene(*this, *mRendering.get(), mPhysics.get(), *mNavigator));
}
void World::fillGlobalVariables()
@ -1034,7 +1035,7 @@ namespace MWWorld
return mWorldScene->markCellAsUnchanged();
}
float World::getMaxActivationDistance ()
float World::getMaxActivationDistance() const
{
if (mActivationDistanceOverride >= 0)
return static_cast<float>(mActivationDistanceOverride);
@ -1276,11 +1277,10 @@ namespace MWWorld
MWWorld::Ptr World::moveObject(const Ptr& ptr, const osg::Vec3f& position, bool movePhysics, bool moveToActive)
{
int cellX, cellY;
positionToIndex(position.x(), position.y(), cellX, cellY);
const auto index = MWWorld::positionToIndex(position.x(), position.y());
CellStore* cell = ptr.getCell();
CellStore* newCell = getExterior(cellX, cellY);
CellStore* newCell = getExterior(index.mX, index.mY);
bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() && mWorldScene->isCellActive(*newCell);
if (cell->isExterior() || (moveToActive && isCellActive && ptr.getClass().isActor()))
@ -1518,8 +1518,9 @@ namespace MWWorld
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
{
cellX = static_cast<int>(std::floor(x / Constants::CellSizeInUnits));
cellY = static_cast<int>(std::floor(y / Constants::CellSizeInUnits));
const auto index = MWWorld::positionToIndex(x, y);
cellX = index.mX;
cellY = index.mY;
}
void World::queueMovement(const Ptr &ptr, const osg::Vec3f &velocity)
@ -1849,7 +1850,9 @@ namespace MWWorld
mPhysics->debugDraw();
mWorldScene->update (duration, paused);
mWorldScene->update(duration);
mRendering->update(duration, paused);
updateSoundListener();
@ -2072,11 +2075,6 @@ namespace MWWorld
struct GetDoorMarkerVisitor
{
GetDoorMarkerVisitor(std::vector<World::DoorMarker>& out)
: mOut(out)
{
}
std::vector<World::DoorMarker>& mOut;
bool operator()(const MWWorld::Ptr& ptr)
@ -2102,11 +2100,7 @@ namespace MWWorld
else
{
cellid.mPaged = true;
MWBase::Environment::get().getWorld()->positionToIndex(
ref.mRef.getDoorDest().pos[0],
ref.mRef.getDoorDest().pos[1],
cellid.mIndex.mX,
cellid.mIndex.mY);
cellid.mIndex = MWWorld::positionToIndex(ref.mRef.getDoorDest().pos[0], ref.mRef.getDoorDest().pos[1]);
}
newMarker.dest = cellid;
@ -2122,7 +2116,7 @@ namespace MWWorld
void World::getDoorMarkers (CellStore* cell, std::vector<World::DoorMarker>& out)
{
GetDoorMarkerVisitor visitor(out);
GetDoorMarkerVisitor visitor {out};
cell->forEachType<ESM::Door>(visitor);
}
@ -2208,9 +2202,8 @@ namespace MWWorld
throw std::runtime_error("copyObjectToCell(): cannot copy object to null cell");
if (cell->isExterior())
{
int cellX, cellY;
positionToIndex(pos.pos[0], pos.pos[1], cellX, cellY);
cell = mCells.getExterior(cellX, cellY);
const auto index = MWWorld::positionToIndex(pos.pos[0], pos.pos[1]);
cell = mCells.getExterior(index.mX, index.mY);
}
MWWorld::Ptr dropped =
@ -2817,10 +2810,9 @@ namespace MWWorld
// door to exterior
if (door->getDestCell().empty())
{
int x, y;
ESM::Position doorDest = door->getDoorDest();
positionToIndex(doorDest.pos[0], doorDest.pos[1], x, y);
source = getExterior(x, y);
const auto index = MWWorld::positionToIndex(doorDest.pos[0], doorDest.pos[1]);
source = getExterior(index.mX, index.mY);
}
// door to interior
else
@ -3152,7 +3144,7 @@ namespace MWWorld
const osg::Vec3f sourcePos = worldPos + orient * osg::Vec3f(0,-1,0) * 64.f;
// Early out if the launch position is underwater
bool underwater = MWBase::Environment::get().getWorld()->isUnderwater(MWMechanics::getPlayer().getCell(), worldPos);
bool underwater = isUnderwater(MWMechanics::getPlayer().getCell(), worldPos);
if (underwater)
{
MWMechanics::projectileHit(actor, Ptr(), bow, projectile, worldPos, attackStrength);
@ -3183,7 +3175,7 @@ namespace MWWorld
mProjectileManager->updateCasters();
}
void World::applyLoopingParticles(const MWWorld::Ptr& ptr)
void World::applyLoopingParticles(const MWWorld::Ptr& ptr) const
{
const MWWorld::Class &cls = ptr.getClass();
if (cls.isActor())
@ -3413,15 +3405,12 @@ namespace MWWorld
struct AddDetectedReferenceVisitor
{
AddDetectedReferenceVisitor(std::vector<Ptr>& out, const Ptr& detector, World::DetectionType type, float squaredDist)
: mOut(out), mDetector(detector), mSquaredDist(squaredDist), mType(type)
{
}
std::vector<Ptr>& mOut;
Ptr mDetector;
float mSquaredDist;
World::DetectionType mType;
const MWWorld::ESMStore& mStore;
bool operator() (const MWWorld::Ptr& ptr)
{
if ((ptr.getRefData().getPosition().asVec3() - mDetector.getRefData().getPosition().asVec3()).length2() >= mSquaredDist)
@ -3437,14 +3426,13 @@ namespace MWWorld
// but ignore containers without resolved content
if (isContainer && ptr.getRefData().getCustomData() == nullptr)
{
const auto& store = MWBase::Environment::get().getWorld()->getStore();
for(const auto& containerItem : ptr.get<ESM::Container>()->mBase->mInventory.mList)
{
if(containerItem.mCount)
{
try
{
ManualRef ref(store, containerItem.mItem, containerItem.mCount);
ManualRef ref(mStore, containerItem.mItem, containerItem.mCount);
if(needToAdd(ref.getPtr(), mDetector))
{
mOut.push_back(ptr);
@ -3519,7 +3507,7 @@ namespace MWWorld
dist = feetToGameUnits(dist);
AddDetectedReferenceVisitor visitor (out, ptr, type, dist*dist);
AddDetectedReferenceVisitor visitor {out, ptr, dist * dist, type, mStore};
for (CellStore* cellStore : mWorldScene->getActiveCells())
{
@ -3699,10 +3687,9 @@ namespace MWWorld
static int iNumberCreatures = mStore.get<ESM::GameSetting>().find("iNumberCreatures")->mValue.getInteger();
int numCreatures = 1 + Misc::Rng::rollDice(iNumberCreatures); // [1, iNumberCreatures]
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
for (int i=0; i<numCreatures; ++i)
{
std::string selectedCreature = MWMechanics::getLevelledItem(list, true, prng);
std::string selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng);
if (selectedCreature.empty())
continue;
@ -3831,6 +3818,8 @@ namespace MWWorld
struct ResetActorsVisitor
{
World& mWorld;
bool operator() (const Ptr& ptr)
{
if (ptr.getClass().isActor() && ptr.getCellRef().hasContentFile())
@ -3839,18 +3828,19 @@ namespace MWWorld
return true;
const ESM::Position& origPos = ptr.getCellRef().getPosition();
MWBase::Environment::get().getWorld()->moveObject(ptr, origPos.asVec3());
MWBase::Environment::get().getWorld()->rotateObject(ptr, origPos.asRotationVec3());
mWorld.moveObject(ptr, origPos.asVec3());
mWorld.rotateObject(ptr, origPos.asRotationVec3());
ptr.getClass().adjustPosition(ptr, true);
}
return true;
}
};
void World::resetActors()
{
for (CellStore* cellstore : mWorldScene->getActiveCells())
{
ResetActorsVisitor visitor;
ResetActorsVisitor visitor {*this};
cellstore->forEach(visitor);
}
}

View File

@ -232,7 +232,7 @@ namespace MWWorld
bool toggleWorld() override;
bool toggleBorders() override;
void adjustSky() override;
void adjustSky();
Player& getPlayer() override;
MWWorld::Ptr getPlayerPtr() override;
@ -396,7 +396,7 @@ namespace MWWorld
///< Place an object in a safe place next to \a referenceObject. \a direction and \a distance specify the wanted placement
/// relative to \a referenceObject (but the object may be placed somewhere else if the wanted location is obstructed).
float getMaxActivationDistance() override;
float getMaxActivationDistance() const override;
void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)
const override;
@ -587,7 +587,7 @@ namespace MWWorld
///< check if the player is allowed to rest
void rest(double hours) override;
void rechargeItems(double duration, bool activeOnly) override;
void rechargeItems(double duration, bool activeOnly);
/// \todo Probably shouldn't be here
MWRender::Animation* getAnimation(const MWWorld::Ptr &ptr) override;
@ -643,7 +643,7 @@ namespace MWWorld
const osg::Vec3f& worldPos, const osg::Quat& orient, MWWorld::Ptr& bow, float speed, float attackStrength) override;
void updateProjectilesCasters() override;
void applyLoopingParticles(const MWWorld::Ptr& ptr) override;
void applyLoopingParticles(const MWWorld::Ptr& ptr) const override;
const std::vector<std::string>& getContentFiles() const override;
void breakInvisibility (const MWWorld::Ptr& actor) override;