mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Split ESM headers
This commit is contained in:
parent
a57c350c08
commit
01166b1f26
29 changed files with 172 additions and 118 deletions
|
@ -1,79 +1,18 @@
|
|||
#ifndef OPENMW_ESM_UTIL_H
|
||||
#define OPENMW_ESM_UTIL_H
|
||||
#ifndef OPENMW_COMPONENTS_ESM_UTIL_H
|
||||
#define OPENMW_COMPONENTS_ESM_UTIL_H
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <osg/Quat>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec2i>
|
||||
#include <osg/Vec3f>
|
||||
#include <osg/Vec2f>
|
||||
|
||||
#include <components/esm/refid.hpp>
|
||||
#include <components/esm3/loadcell.hpp>
|
||||
#include <components/misc/constants.hpp>
|
||||
#include "components/esm3/loadcell.hpp"
|
||||
#include "components/misc/constants.hpp"
|
||||
|
||||
#include "exteriorcelllocation.hpp"
|
||||
#include "refid.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
// format 0, savegames only
|
||||
|
||||
struct Quaternion
|
||||
{
|
||||
float mValues[4];
|
||||
|
||||
Quaternion() = default;
|
||||
|
||||
Quaternion(const osg::Quat& q)
|
||||
{
|
||||
mValues[0] = q.w();
|
||||
mValues[1] = q.x();
|
||||
mValues[2] = q.y();
|
||||
mValues[3] = q.z();
|
||||
}
|
||||
|
||||
operator osg::Quat() const { return osg::Quat(mValues[1], mValues[2], mValues[3], mValues[0]); }
|
||||
};
|
||||
|
||||
struct Vector3
|
||||
{
|
||||
float mValues[3];
|
||||
|
||||
Vector3() = default;
|
||||
|
||||
Vector3(const osg::Vec3f& v)
|
||||
{
|
||||
mValues[0] = v.x();
|
||||
mValues[1] = v.y();
|
||||
mValues[2] = v.z();
|
||||
}
|
||||
|
||||
operator osg::Vec3f() const { return osg::Vec3f(mValues[0], mValues[1], mValues[2]); }
|
||||
};
|
||||
|
||||
struct ExteriorCellLocation
|
||||
{
|
||||
int mX = 0;
|
||||
int mY = 0;
|
||||
ESM::RefId mWorldspace = ESM::Cell::sDefaultWorldspaceId;
|
||||
ExteriorCellLocation() = default;
|
||||
|
||||
ExteriorCellLocation(int x, int y, ESM::RefId worldspace)
|
||||
: mX(x)
|
||||
, mY(y)
|
||||
, mWorldspace(worldspace)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const ExteriorCellLocation& other) const
|
||||
{
|
||||
return mX == other.mX && mY == other.mY && mWorldspace == other.mWorldspace;
|
||||
}
|
||||
|
||||
bool operator<(const ExteriorCellLocation& other) const
|
||||
{
|
||||
return std::make_tuple(mX, mY, mWorldspace) < std::make_tuple(other.mX, other.mY, other.mWorldspace);
|
||||
}
|
||||
};
|
||||
|
||||
inline bool isEsm4Ext(ESM::RefId worldspaceId)
|
||||
{
|
||||
return worldspaceId != ESM::Cell::sDefaultWorldspaceId;
|
||||
|
@ -81,7 +20,6 @@ namespace ESM
|
|||
|
||||
inline int getCellSize(ESM::RefId worldspaceId)
|
||||
{
|
||||
|
||||
return isEsm4Ext(worldspaceId) ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits;
|
||||
}
|
||||
|
||||
|
@ -95,25 +33,8 @@ namespace ESM
|
|||
return { static_cast<int>(std::floor(x / cellSize)), static_cast<int>(std::floor(y / cellSize)), worldspaceId };
|
||||
}
|
||||
|
||||
osg::Vec2 indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre = false);
|
||||
///< Convert cell numbers to position.
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<ESM::ExteriorCellLocation>
|
||||
{
|
||||
std::size_t operator()(const ESM::ExteriorCellLocation& toHash) const
|
||||
{
|
||||
// Compute individual hash values for first,
|
||||
// second and third and combine them using XOR
|
||||
// and bit shifting:
|
||||
|
||||
return ((hash<int>()(toHash.mX) ^ (hash<int>()(toHash.mY) << 1)) >> 1)
|
||||
^ (hash<ESM::RefId>()(toHash.mWorldspace) << 1);
|
||||
}
|
||||
};
|
||||
// Convert exterior cell location to position.
|
||||
osg::Vec2f indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre = false);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue