mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 06:29:56 +00:00
Use proper cell size for ESM4 cells in CoordinateConverter
This commit is contained in:
parent
a8ed567177
commit
5abbc56bf2
9 changed files with 44 additions and 24 deletions
|
@ -371,7 +371,8 @@ namespace MWMechanics
|
||||||
&& !actor.getClass().isPureWaterCreature(actor))
|
&& !actor.getClass().isPureWaterCreature(actor))
|
||||||
{
|
{
|
||||||
ESM::Pathgrid::PointList points;
|
ESM::Pathgrid::PointList points;
|
||||||
Misc::CoordinateConverter coords(*storage.mCell->getCell());
|
const Misc::CoordinateConverter coords
|
||||||
|
= Misc::makeCoordinateConverter(*storage.mCell->getCell());
|
||||||
|
|
||||||
osg::Vec3f localPos = actor.getRefData().getPosition().asVec3();
|
osg::Vec3f localPos = actor.getRefData().getPosition().asVec3();
|
||||||
coords.toLocal(localPos);
|
coords.toLocal(localPos);
|
||||||
|
|
|
@ -421,7 +421,7 @@ bool MWMechanics::AiPackage::isNearInactiveCell(osg::Vec3f position)
|
||||||
if (playerCell->isExterior())
|
if (playerCell->isExterior())
|
||||||
{
|
{
|
||||||
// get actor's distance from origin of center cell
|
// get actor's distance from origin of center cell
|
||||||
Misc::CoordinateConverter(*playerCell).toLocal(position);
|
Misc::makeCoordinateConverter(*playerCell).toLocal(position);
|
||||||
|
|
||||||
// currently assumes 3 x 3 grid for exterior cells, with player at center cell.
|
// currently assumes 3 x 3 grid for exterior cells, with player at center cell.
|
||||||
// AI shuts down actors before they reach edges of 3 x 3 grid.
|
// AI shuts down actors before they reach edges of 3 x 3 grid.
|
||||||
|
|
|
@ -730,7 +730,7 @@ namespace MWMechanics
|
||||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||||
int index = Misc::Rng::rollDice(storage.mAllowedNodes.size(), prng);
|
int index = Misc::Rng::rollDice(storage.mAllowedNodes.size(), prng);
|
||||||
ESM::Pathgrid::Point worldDest = storage.mAllowedNodes[index];
|
ESM::Pathgrid::Point worldDest = storage.mAllowedNodes[index];
|
||||||
auto converter = Misc::CoordinateConverter(*actor.getCell()->getCell());
|
const Misc::CoordinateConverter converter = Misc::makeCoordinateConverter(*actor.getCell()->getCell());
|
||||||
ESM::Pathgrid::Point dest = converter.toLocalPoint(worldDest);
|
ESM::Pathgrid::Point dest = converter.toLocalPoint(worldDest);
|
||||||
|
|
||||||
bool isPathGridOccupied = MWBase::Environment::get().getMechanicsManager()->isAnyActorInRange(
|
bool isPathGridOccupied = MWBase::Environment::get().getMechanicsManager()->isAnyActorInRange(
|
||||||
|
@ -835,7 +835,7 @@ namespace MWMechanics
|
||||||
if (mDistance && storage.mCanWanderAlongPathGrid && !actor.getClass().isPureWaterCreature(actor))
|
if (mDistance && storage.mCanWanderAlongPathGrid && !actor.getClass().isPureWaterCreature(actor))
|
||||||
{
|
{
|
||||||
// get NPC's position in local (i.e. cell) coordinates
|
// get NPC's position in local (i.e. cell) coordinates
|
||||||
auto converter = Misc::CoordinateConverter(*cellStore->getCell());
|
const Misc::CoordinateConverter converter = Misc::makeCoordinateConverter(*cellStore->getCell());
|
||||||
const osg::Vec3f npcPos = converter.toLocalVec3(mInitialActorPosition);
|
const osg::Vec3f npcPos = converter.toLocalVec3(mInitialActorPosition);
|
||||||
|
|
||||||
// Find closest pathgrid point
|
// Find closest pathgrid point
|
||||||
|
|
|
@ -189,7 +189,7 @@ namespace MWMechanics
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// NOTE: getClosestPoint expects local coordinates
|
// NOTE: getClosestPoint expects local coordinates
|
||||||
Misc::CoordinateConverter converter(*mCell->getCell());
|
const Misc::CoordinateConverter converter = Misc::makeCoordinateConverter(*mCell->getCell());
|
||||||
|
|
||||||
// NOTE: It is possible that getClosestPoint returns a pathgrind point index
|
// NOTE: It is possible that getClosestPoint returns a pathgrind point index
|
||||||
// that is unreachable in some situations. e.g. actor is standing
|
// that is unreachable in some situations. e.g. actor is standing
|
||||||
|
|
|
@ -116,7 +116,7 @@ namespace MWRender
|
||||||
return;
|
return;
|
||||||
|
|
||||||
osg::Vec3f cellPathGridPos(0, 0, 0);
|
osg::Vec3f cellPathGridPos(0, 0, 0);
|
||||||
Misc::CoordinateConverter(*store->getCell()).toWorld(cellPathGridPos);
|
Misc::makeCoordinateConverter(*store->getCell()).toWorld(cellPathGridPos);
|
||||||
|
|
||||||
osg::ref_ptr<osg::PositionAttitudeTransform> cellPathGrid = new osg::PositionAttitudeTransform;
|
osg::ref_ptr<osg::PositionAttitudeTransform> cellPathGrid = new osg::PositionAttitudeTransform;
|
||||||
cellPathGrid->setPosition(cellPathGridPos);
|
cellPathGrid->setPosition(cellPathGridPos);
|
||||||
|
|
|
@ -133,7 +133,7 @@ namespace DetourNavigator
|
||||||
|
|
||||||
void NavigatorImpl::addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid)
|
void NavigatorImpl::addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid)
|
||||||
{
|
{
|
||||||
Misc::CoordinateConverter converter(&cell);
|
const Misc::CoordinateConverter converter = Misc::makeCoordinateConverter(cell);
|
||||||
for (const auto& edge : pathgrid.mEdges)
|
for (const auto& edge : pathgrid.mEdges)
|
||||||
{
|
{
|
||||||
const auto src = Misc::Convert::makeOsgVec3f(converter.toWorldPoint(pathgrid.mPoints[edge.mV0]));
|
const auto src = Misc::Convert::makeOsgVec3f(converter.toWorldPoint(pathgrid.mPoints[edge.mV0]));
|
||||||
|
|
|
@ -5,11 +5,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "cellref.hpp"
|
|
||||||
#include "components/esm/defs.hpp"
|
#include "components/esm/defs.hpp"
|
||||||
#include "components/esm/esmcommon.hpp"
|
#include "components/esm/esmcommon.hpp"
|
||||||
#include "components/esm/refid.hpp"
|
#include "components/esm/refid.hpp"
|
||||||
|
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
|
#include "cellref.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
class ESMStore;
|
class ESMStore;
|
||||||
|
@ -70,6 +73,8 @@ namespace ESM
|
||||||
|
|
||||||
constexpr static RecNameInts sRecordId = REC_CELL;
|
constexpr static RecNameInts sRecordId = REC_CELL;
|
||||||
|
|
||||||
|
static constexpr int sSize = Constants::CellSizeInUnits;
|
||||||
|
|
||||||
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
|
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
|
||||||
static std::string_view getRecordType() { return "Cell"; }
|
static std::string_view getRecordType() { return "Cell"; }
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <components/esm/refid.hpp>
|
#include <components/esm/refid.hpp>
|
||||||
#include <components/esm/util.hpp>
|
#include <components/esm/util.hpp>
|
||||||
#include <components/esm4/reader.hpp>
|
#include <components/esm4/reader.hpp>
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
#include "lighting.hpp"
|
#include "lighting.hpp"
|
||||||
|
|
||||||
|
@ -62,6 +63,8 @@ namespace ESM4
|
||||||
// The cells need to be organised under world spaces.
|
// The cells need to be organised under world spaces.
|
||||||
struct Cell
|
struct Cell
|
||||||
{
|
{
|
||||||
|
static constexpr int sSize = Constants::ESM4CellSizeInUnits;
|
||||||
|
|
||||||
ESM::RefId mId; // from the header
|
ESM::RefId mId; // from the header
|
||||||
std::uint32_t mFlags = 0; // from the header, see enum type RecordFlag for details
|
std::uint32_t mFlags = 0; // from the header, see enum type RecordFlag for details
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
#include <components/esm/esmbridge.hpp>
|
#include <components/esm/esmbridge.hpp>
|
||||||
#include <components/esm3/loadcell.hpp>
|
#include <components/esm3/loadcell.hpp>
|
||||||
#include <components/esm3/loadland.hpp>
|
|
||||||
#include <components/esm3/loadpgrd.hpp>
|
#include <components/esm3/loadpgrd.hpp>
|
||||||
#include <components/esm4/loadcell.hpp>
|
#include <components/esm4/loadcell.hpp>
|
||||||
|
#include <components/misc/constants.hpp>
|
||||||
|
|
||||||
namespace Misc
|
namespace Misc
|
||||||
{
|
{
|
||||||
|
@ -13,21 +13,9 @@ namespace Misc
|
||||||
class CoordinateConverter
|
class CoordinateConverter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CoordinateConverter(bool exterior, int cellX, int cellY)
|
explicit CoordinateConverter(int cellX, int cellY)
|
||||||
: mCellX(exterior ? cellX * ESM::Land::REAL_SIZE : 0)
|
: mCellX(cellX)
|
||||||
, mCellY(exterior ? cellY * ESM::Land::REAL_SIZE : 0)
|
, mCellY(cellY)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit CoordinateConverter(const ESM::CellVariant& cell)
|
|
||||||
: CoordinateConverter(cell.isEsm4() ? cell.getEsm4().isExterior() : cell.getEsm3().isExterior(),
|
|
||||||
cell.isEsm4() ? cell.getEsm4().getGridX() : cell.getEsm3().getGridX(),
|
|
||||||
cell.isEsm4() ? cell.getEsm4().getGridY() : cell.getEsm3().getGridY())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit CoordinateConverter(const ESM::Cell* cell)
|
|
||||||
: CoordinateConverter(cell->isExterior(), cell->getGridX(), cell->getGridY())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +69,29 @@ namespace Misc
|
||||||
int mCellX;
|
int mCellX;
|
||||||
int mCellY;
|
int mCellY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
CoordinateConverter makeCoordinateConverterImpl(const T& cell)
|
||||||
|
{
|
||||||
|
if (cell.isExterior())
|
||||||
|
return CoordinateConverter(cell.sSize * cell.getGridX(), cell.sSize * cell.getGridY());
|
||||||
|
return CoordinateConverter(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CoordinateConverter makeCoordinateConverter(const ESM::Cell& cell)
|
||||||
|
{
|
||||||
|
return makeCoordinateConverterImpl(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CoordinateConverter makeCoordinateConverter(const ESM4::Cell& cell)
|
||||||
|
{
|
||||||
|
return makeCoordinateConverterImpl(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CoordinateConverter makeCoordinateConverter(const ESM::CellVariant& cell)
|
||||||
|
{
|
||||||
|
return visit([](const auto& v) { return makeCoordinateConverterImpl(v); }, cell);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue