mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Merge branch 'position_to_index' into 'master'
Use free function instead of virtual MWBase::World::positionToIndex (#5336) See merge request OpenMW/openmw!1922
This commit is contained in:
commit
9d232a72d3
@ -319,9 +319,6 @@ namespace MWBase
|
||||
const = 0;
|
||||
///< Convert cell numbers to position.
|
||||
|
||||
virtual void positionToIndex (float x, float y, int &cellX, int &cellY) const = 0;
|
||||
///< Convert position to cell numbers
|
||||
|
||||
virtual void queueMovement(const MWWorld::Ptr &ptr, const osg::Vec3f &velocity) = 0;
|
||||
///< Queues movement for \a ptr (in local space), to be applied in the next call to
|
||||
/// doPhysics.
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
#include "../mwworld/actiontrap.hpp"
|
||||
#include "../mwworld/customdata.hpp"
|
||||
#include "../mwworld/cellutils.hpp"
|
||||
|
||||
#include "../mwgui/tooltips.hpp"
|
||||
|
||||
@ -303,10 +304,10 @@ namespace MWClass
|
||||
if (dest.empty())
|
||||
{
|
||||
// door leads to exterior, use cell name (if any), otherwise translated region name
|
||||
int x,y;
|
||||
auto world = MWBase::Environment::get().getWorld();
|
||||
world->positionToIndex (door.mRef.getDoorDest().pos[0], door.mRef.getDoorDest().pos[1], x, y);
|
||||
const ESM::Cell* cell = world->getStore().get<ESM::Cell>().search(x,y);
|
||||
const osg::Vec2i index = MWWorld::positionToCellIndex(door.mRef.getDoorDest().pos[0],
|
||||
door.mRef.getDoorDest().pos[1]);
|
||||
const ESM::Cell* cell = world->getStore().get<ESM::Cell>().search(index.x(), index.y());
|
||||
dest = world->getCellName(cell);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
#include "../mwworld/cellutils.hpp"
|
||||
|
||||
#include "../mwrender/globalmap.hpp"
|
||||
#include "../mwrender/localmap.hpp"
|
||||
@ -277,22 +278,22 @@ namespace MWGui
|
||||
|
||||
MyGUI::IntPoint LocalMapBase::getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const
|
||||
{
|
||||
int cellX, cellY;
|
||||
osg::Vec2i cellIndex;
|
||||
// normalized cell coordinates
|
||||
float nX,nY;
|
||||
|
||||
if (!mInterior)
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(worldX, worldY, cellX, cellY);
|
||||
nX = (worldX - cellSize * cellX) / cellSize;
|
||||
cellIndex = MWWorld::positionToCellIndex(worldX, worldY);
|
||||
nX = (worldX - cellSize * cellIndex.x()) / cellSize;
|
||||
// Image space is -Y up, cells are Y up
|
||||
nY = 1 - (worldY - cellSize * cellY) / cellSize;
|
||||
nY = 1 - (worldY - cellSize * cellIndex.y()) / cellSize;
|
||||
}
|
||||
else
|
||||
mLocalMapRender->worldToInteriorMapPosition({ worldX, worldY }, nX, nY, cellX, cellY);
|
||||
mLocalMapRender->worldToInteriorMapPosition({ worldX, worldY }, nX, nY, cellIndex.x(), cellIndex.y());
|
||||
|
||||
markerPos.cellX = cellX;
|
||||
markerPos.cellY = cellY;
|
||||
markerPos.cellX = cellIndex.x();
|
||||
markerPos.cellY = cellIndex.y();
|
||||
markerPos.nX = nX;
|
||||
markerPos.nY = nY;
|
||||
return getPosition(markerPos.cellX, markerPos.cellY, markerPos.nX, markerPos.nY);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/actionteleport.hpp"
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
#include "../mwworld/cellutils.hpp"
|
||||
|
||||
|
||||
namespace MWGui
|
||||
@ -119,12 +120,10 @@ namespace MWGui
|
||||
{
|
||||
std::string cellname = transport[i].mCellName;
|
||||
bool interior = true;
|
||||
int x,y;
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(transport[i].mPos.pos[0],
|
||||
transport[i].mPos.pos[1],x,y);
|
||||
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]);
|
||||
if (cellname == "")
|
||||
{
|
||||
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(x,y);
|
||||
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y());
|
||||
cellname = MWBase::Environment::get().getWorld()->getCellName(cell);
|
||||
interior = false;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/timestamp.hpp"
|
||||
#include "../mwworld/cellutils.hpp"
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
@ -128,9 +129,8 @@ namespace MWLua
|
||||
bool exterior = name.empty() || world->getExterior(name);
|
||||
if (exterior)
|
||||
{
|
||||
int cellX, cellY;
|
||||
world->positionToIndex(position.x(), position.y(), cellX, cellY);
|
||||
return world->getExterior(cellX, cellY);
|
||||
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(position.x(), position.y());
|
||||
return world->getExterior(cellIndex.x(), cellIndex.y());
|
||||
}
|
||||
else
|
||||
return world->getInterior(name);
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/cellutils.hpp"
|
||||
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
|
||||
@ -411,9 +412,8 @@ namespace MWScript
|
||||
if(!isPlayer)
|
||||
return;
|
||||
}
|
||||
int cx,cy;
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
||||
store = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
||||
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
|
||||
store = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y());
|
||||
}
|
||||
if(store)
|
||||
{
|
||||
@ -460,15 +460,14 @@ namespace MWScript
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true);
|
||||
}
|
||||
int cx,cy;
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
||||
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
|
||||
|
||||
// another morrowind oddity: player will be moved to the exterior cell at this location,
|
||||
// non-player actors will move within the cell they are in.
|
||||
MWWorld::Ptr base = ptr;
|
||||
if (ptr == MWMechanics::getPlayer())
|
||||
{
|
||||
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
||||
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y());
|
||||
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, cell, osg::Vec3(x, y, z));
|
||||
}
|
||||
else
|
||||
@ -517,9 +516,8 @@ namespace MWScript
|
||||
catch(std::exception&)
|
||||
{
|
||||
const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID);
|
||||
int cx,cy;
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
||||
store = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
||||
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
|
||||
store = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y());
|
||||
if(!cell)
|
||||
{
|
||||
runtime.getContext().report ("unknown cell (" + cellID + ")");
|
||||
@ -569,9 +567,8 @@ namespace MWScript
|
||||
MWWorld::CellStore* store = nullptr;
|
||||
if (player.getCell()->isExterior())
|
||||
{
|
||||
int cx,cy;
|
||||
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
||||
store = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
||||
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
|
||||
store = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y());
|
||||
}
|
||||
else
|
||||
store = player.getCell();
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/cellutils.hpp"
|
||||
|
||||
#include "player.hpp"
|
||||
|
||||
@ -52,11 +53,8 @@ namespace MWWorld
|
||||
actor.getClass().getCreatureStats(actor).getAiSequence().stopCombat();
|
||||
else if (mCellName.empty())
|
||||
{
|
||||
int cellX;
|
||||
int cellY;
|
||||
world->positionToIndex(mPosition.pos[0],mPosition.pos[1],cellX,cellY);
|
||||
world->moveObject(actor,world->getExterior(cellX,cellY),
|
||||
mPosition.asVec3(), true, true);
|
||||
const osg::Vec2i index = positionToCellIndex(mPosition.pos[0], mPosition.pos[1]);
|
||||
world->moveObject(actor, world->getExterior(index.x(), index.y()), mPosition.asVec3(), true, true);
|
||||
}
|
||||
else
|
||||
world->moveObject(actor,world->getInterior(mCellName),mPosition.asVec3(), true, true);
|
||||
|
@ -2,13 +2,14 @@
|
||||
#define OPENMW_MWWORLD_CELLUTILS_H
|
||||
|
||||
#include <components/misc/constants.hpp>
|
||||
#include <components/esm3/cellid.hpp>
|
||||
|
||||
#include <osg/Vec2i>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
inline ESM::CellId::CellIndex positionToIndex(float x, float y)
|
||||
inline osg::Vec2i positionToCellIndex(float x, float y)
|
||||
{
|
||||
return {
|
||||
static_cast<int>(std::floor(x / Constants::CellSizeInUnits)),
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "cellstore.hpp"
|
||||
#include "cellpreloader.hpp"
|
||||
#include "worldimp.hpp"
|
||||
#include "cellutils.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -504,9 +505,7 @@ namespace MWWorld
|
||||
if (distance <= maxDistance)
|
||||
return *currentGridCenter;
|
||||
}
|
||||
osg::Vec2i newCenter;
|
||||
mWorld.positionToIndex(pos.x(), pos.y(), newCenter.x(), newCenter.y());
|
||||
return newCenter;
|
||||
return positionToCellIndex(pos.x(), pos.y());
|
||||
}
|
||||
|
||||
void Scene::playerMoved(const osg::Vec3f &pos)
|
||||
@ -867,17 +866,14 @@ namespace MWWorld
|
||||
|
||||
void Scene::changeToExteriorCell (const ESM::Position& position, bool adjustPlayerPos, bool changeEvent)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
mWorld.positionToIndex (position.pos[0], position.pos[1], x, y);
|
||||
const osg::Vec2i cellIndex = positionToCellIndex(position.pos[0], position.pos[1]);
|
||||
|
||||
if (changeEvent)
|
||||
MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
|
||||
|
||||
changeCellGrid(position.asVec3(), x, y, changeEvent);
|
||||
changeCellGrid(position.asVec3(), cellIndex.x(), cellIndex.y(), changeEvent);
|
||||
|
||||
CellStore* current = mWorld.getExterior(x, y);
|
||||
CellStore* current = mWorld.getExterior(cellIndex.x(), cellIndex.y());
|
||||
changePlayerCell(current, position, adjustPlayerPos);
|
||||
|
||||
if (changeEvent)
|
||||
@ -1078,9 +1074,8 @@ namespace MWWorld
|
||||
else
|
||||
{
|
||||
osg::Vec3f pos = door.getCellRef().getDoorDest().asVec3();
|
||||
int x,y;
|
||||
mWorld.positionToIndex (pos.x(), pos.y(), x, y);
|
||||
preloadCell(mWorld.getExterior(x,y), true);
|
||||
const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y());
|
||||
preloadCell(mWorld.getExterior(cellIndex.x(), cellIndex.y()), true);
|
||||
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
|
||||
}
|
||||
}
|
||||
@ -1216,9 +1211,8 @@ namespace MWWorld
|
||||
else
|
||||
{
|
||||
osg::Vec3f pos = dest.mPos.asVec3();
|
||||
int x,y;
|
||||
mWorld.positionToIndex( pos.x(), pos.y(), x, y);
|
||||
preloadCell(mWorld.getExterior(x,y), true);
|
||||
const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y());
|
||||
preloadCell(mWorld.getExterior(cellIndex.x(), cellIndex.y()), true);
|
||||
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
|
||||
}
|
||||
}
|
||||
|
@ -1279,10 +1279,10 @@ namespace MWWorld
|
||||
|
||||
MWWorld::Ptr World::moveObject(const Ptr& ptr, const osg::Vec3f& position, bool movePhysics, bool moveToActive)
|
||||
{
|
||||
const auto index = MWWorld::positionToIndex(position.x(), position.y());
|
||||
const osg::Vec2i index = positionToCellIndex(position.x(), position.y());
|
||||
|
||||
CellStore* cell = ptr.getCell();
|
||||
CellStore* newCell = getExterior(index.mX, index.mY);
|
||||
CellStore* newCell = getExterior(index.x(), index.y());
|
||||
bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() && mWorldScene->isCellActive(*newCell);
|
||||
|
||||
if (cell->isExterior() || (moveToActive && isCellActive && ptr.getClass().isActor()))
|
||||
@ -1518,13 +1518,6 @@ namespace MWWorld
|
||||
}
|
||||
}
|
||||
|
||||
void World::positionToIndex (float x, float y, int &cellX, int &cellY) const
|
||||
{
|
||||
const auto index = MWWorld::positionToIndex(x, y);
|
||||
cellX = index.mX;
|
||||
cellY = index.mY;
|
||||
}
|
||||
|
||||
void World::queueMovement(const Ptr &ptr, const osg::Vec3f &velocity)
|
||||
{
|
||||
mPhysics->queueObjectMovement(ptr, velocity);
|
||||
@ -2112,7 +2105,9 @@ namespace MWWorld
|
||||
else
|
||||
{
|
||||
cellid.mPaged = true;
|
||||
cellid.mIndex = MWWorld::positionToIndex(ref.mRef.getDoorDest().pos[0], ref.mRef.getDoorDest().pos[1]);
|
||||
const osg::Vec2i index = positionToCellIndex(ref.mRef.getDoorDest().pos[0], ref.mRef.getDoorDest().pos[1]);
|
||||
cellid.mIndex.mX = index.x();
|
||||
cellid.mIndex.mY = index.y();
|
||||
}
|
||||
newMarker.dest = cellid;
|
||||
|
||||
@ -2214,8 +2209,8 @@ namespace MWWorld
|
||||
throw std::runtime_error("copyObjectToCell(): cannot copy object to null cell");
|
||||
if (cell->isExterior())
|
||||
{
|
||||
const auto index = MWWorld::positionToIndex(pos.pos[0], pos.pos[1]);
|
||||
cell = mCells.getExterior(index.mX, index.mY);
|
||||
const osg::Vec2i index = positionToCellIndex(pos.pos[0], pos.pos[1]);
|
||||
cell = mCells.getExterior(index.x(), index.y());
|
||||
}
|
||||
|
||||
MWWorld::Ptr dropped =
|
||||
@ -2823,8 +2818,8 @@ namespace MWWorld
|
||||
if (door->getDestCell().empty())
|
||||
{
|
||||
ESM::Position doorDest = door->getDoorDest();
|
||||
const auto index = MWWorld::positionToIndex(doorDest.pos[0], doorDest.pos[1]);
|
||||
source = getExterior(index.mX, index.mY);
|
||||
const osg::Vec2i index = positionToCellIndex(doorDest.pos[0], doorDest.pos[1]);
|
||||
source = getExterior(index.x(), index.y());
|
||||
}
|
||||
// door to interior
|
||||
else
|
||||
|
@ -407,9 +407,6 @@ namespace MWWorld
|
||||
const override;
|
||||
///< Convert cell numbers to position.
|
||||
|
||||
void positionToIndex (float x, float y, int &cellX, int &cellY) const override;
|
||||
///< Convert position to cell numbers
|
||||
|
||||
void queueMovement(const Ptr &ptr, const osg::Vec3f &velocity) override;
|
||||
///< Queues movement for \a ptr (in local space), to be applied in the next call to
|
||||
/// doPhysics.
|
||||
|
Loading…
x
Reference in New Issue
Block a user