diff --git a/apps/essimporter/importproj.h b/apps/essimporter/importproj.h index a2e03b5ba3..04c7b4003e 100644 --- a/apps/essimporter/importproj.h +++ b/apps/essimporter/importproj.h @@ -2,7 +2,8 @@ #define OPENMW_ESSIMPORT_IMPORTPROJ_H #include -#include +#include + #include #include diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 380c0ace9f..9e6df46340 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -1,5 +1,6 @@ #include "aiescort.hpp" +#include #include #include #include diff --git a/apps/openmw/mwphysics/mtphysics.hpp b/apps/openmw/mwphysics/mtphysics.hpp index 57f3711096..579211b489 100644 --- a/apps/openmw/mwphysics/mtphysics.hpp +++ b/apps/openmw/mwphysics/mtphysics.hpp @@ -3,7 +3,9 @@ #include #include +#include #include +#include #include #include #include diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index 9cc55fecc6..876f8e8164 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -16,8 +15,6 @@ #include #include -#include - #include "../mwworld/ptr.hpp" #include "collisiontype.hpp" diff --git a/apps/openmw/mwrender/landmanager.hpp b/apps/openmw/mwrender/landmanager.hpp index 7166c4b111..1b82f32ce9 100644 --- a/apps/openmw/mwrender/landmanager.hpp +++ b/apps/openmw/mwrender/landmanager.hpp @@ -3,7 +3,7 @@ #include -#include +#include #include #include diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 3a8318a7a3..d913eb0915 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -11,6 +11,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/statemanager.hpp" #include "../mwbase/windowmanager.hpp" @@ -123,7 +125,7 @@ namespace MWScript MWBase::World* world = MWBase::Environment::get().getWorld(); MWWorld::Ptr playerPtr = world->getPlayerPtr(); - osg::Vec2 posFromIndex + const osg::Vec2f posFromIndex = ESM::indexToPosition(ESM::ExteriorCellLocation(x, y, ESM::Cell::sDefaultWorldspaceId), true); pos.pos[0] = posFromIndex.x(); pos.pos[1] = posFromIndex.y(); diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 614fbbe26f..7144147843 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -4,6 +4,8 @@ #include +#include + #include #include diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 5b2ad010ea..3ced01d28f 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -624,7 +624,7 @@ void MWState::StateManager::loadGame(const Character* character, const std::file Log(Debug::Warning) << "Player character's cell no longer exists, changing to the default cell"; ESM::ExteriorCellLocation cellIndex(0, 0, ESM::Cell::sDefaultWorldspaceId); MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex); - osg::Vec2 posFromIndex = ESM::indexToPosition(cellIndex, false); + const osg::Vec2f posFromIndex = ESM::indexToPosition(cellIndex, false); ESM::Position pos; pos.pos[0] = posFromIndex.x(); pos.pos[1] = posFromIndex.y(); diff --git a/apps/openmw/mwworld/cell.hpp b/apps/openmw/mwworld/cell.hpp index 1fa088eac4..eab5024e12 100644 --- a/apps/openmw/mwworld/cell.hpp +++ b/apps/openmw/mwworld/cell.hpp @@ -4,8 +4,8 @@ #include #include +#include #include -#include namespace ESM { diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index d6715c5ad2..4daa85a450 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -15,6 +15,9 @@ #include #include +#include +#include + #include #include #include diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index b373bf416e..169e4bfd21 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -542,7 +542,7 @@ namespace MWWorld = mCurrentCell ? mCurrentCell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; if (currentGridCenter) { - osg::Vec2 center = ESM::indexToPosition( + const osg::Vec2f center = ESM::indexToPosition( ESM::ExteriorCellLocation(currentGridCenter->x(), currentGridCenter->y(), worldspace), true); float distance = std::max(std::abs(center.x() - pos.x()), std::abs(center.y() - pos.y())); float cellSize = ESM::getCellSize(worldspace); @@ -1171,7 +1171,7 @@ namespace MWWorld && dx != -halfGridSizePlusOne) continue; // only care about the outer (not yet loaded) part of the grid ESM::ExteriorCellLocation cellIndex(cellX + dx, cellY + dy, extWorldspace); - osg::Vec2 thisCellCenter = ESM::indexToPosition(cellIndex, true); + const osg::Vec2f thisCellCenter = ESM::indexToPosition(cellIndex, true); float dist = std::max( std::abs(thisCellCenter.x() - playerPos.x()), std::abs(thisCellCenter.y() - playerPos.y())); diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 96050bad32..91feff8746 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -10,10 +10,9 @@ #include #include #include -#include #include -#include +#include #include namespace osg diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 24731055ad..a4464d70ad 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2784,7 +2784,7 @@ namespace MWWorld int x = ext->getGridX(); int y = ext->getGridY(); - osg::Vec2 posFromIndex = indexToPosition(ESM::ExteriorCellLocation(x, y, ext->getWorldSpace()), true); + const osg::Vec2f posFromIndex = indexToPosition(ESM::ExteriorCellLocation(x, y, ext->getWorldSpace()), true); pos.pos[0] = posFromIndex.x(); pos.pos[1] = posFromIndex.y(); diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index 324ff48023..c7b18671d3 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include "cellstore.hpp" diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 0926f738af..a0695b9a5b 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -169,6 +169,9 @@ add_component_dir(esm attr common defs esmcommon records util luascripts format indexrefid serializerefid esm3exteriorcellrefid + quaternion + vector3 + exteriorcelllocation ) add_component_dir(fx pass technique lexer lexer_types parse_constants widgets stateupdater) @@ -186,6 +189,7 @@ add_component_dir (esm3 weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate debugprofile aisequence magiceffects custommarkerstate stolenitems transport animationstate controlsstate mappings readerscache infoorder timestamp formatversion landrecorddata selectiongroup dialoguecondition + refnum ) add_component_dir (esmterrain diff --git a/components/esm/exteriorcelllocation.hpp b/components/esm/exteriorcelllocation.hpp new file mode 100644 index 0000000000..3b98bb7b03 --- /dev/null +++ b/components/esm/exteriorcelllocation.hpp @@ -0,0 +1,53 @@ +#ifndef OPENMW_COMPONENTS_ESM_EXTERIORCELLLOCATION_H +#define OPENMW_COMPONENTS_ESM_EXTERIORCELLLOCATION_H + +#include "refid.hpp" + +#include + +#include + +namespace ESM +{ + 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) + { + } + + friend bool operator==(const ExteriorCellLocation& lhs, const ExteriorCellLocation& rhs) = default; + + friend inline bool operator<(const ExteriorCellLocation& lhs, const ExteriorCellLocation& rhs) + { + return std::make_tuple(lhs.mX, lhs.mY, lhs.mWorldspace) < std::make_tuple(rhs.mX, rhs.mY, rhs.mWorldspace); + } + }; +} + +namespace std +{ + template <> + struct hash + { + 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()(toHash.mX) ^ (hash()(toHash.mY) << 1)) >> 1) + ^ (hash()(toHash.mWorldspace) << 1); + } + }; +} + +#endif diff --git a/components/esm/quaternion.hpp b/components/esm/quaternion.hpp new file mode 100644 index 0000000000..0f2f94a4e6 --- /dev/null +++ b/components/esm/quaternion.hpp @@ -0,0 +1,29 @@ +#ifndef OPENMW_COMPONENTS_ESM_QUATERNION_H +#define OPENMW_COMPONENTS_ESM_QUATERNION_H + +#include + +namespace ESM +{ + // format 0, savegames only + struct Quaternion + { + float mValues[4]; + + Quaternion() = default; + + Quaternion(const osg::Quat& q) + : mValues{ + static_cast(q.w()), + static_cast(q.x()), + static_cast(q.y()), + static_cast(q.z()), + } + { + } + + operator osg::Quat() const { return osg::Quat(mValues[1], mValues[2], mValues[3], mValues[0]); } + }; +} + +#endif diff --git a/components/esm/util.cpp b/components/esm/util.cpp index 0dc38d59aa..9a7faa6917 100644 --- a/components/esm/util.cpp +++ b/components/esm/util.cpp @@ -1,8 +1,9 @@ #include "util.hpp" + #include #include -osg::Vec2 ESM::indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre) +osg::Vec2f ESM::indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre) { const int cellSize = ESM::getCellSize(cellIndex.mWorldspace); @@ -14,7 +15,8 @@ osg::Vec2 ESM::indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool x += cellSize / 2; y += cellSize / 2; } - return osg::Vec2(x, y); + + return osg::Vec2f(x, y); } int ESM::getLandSize(ESM::RefId worldspaceId) diff --git a/components/esm/util.hpp b/components/esm/util.hpp index d7ebcf8f6f..ae756baf6a 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -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 -#include -#include -#include -#include +#include -#include -#include -#include +#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(std::floor(x / cellSize)), static_cast(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 - { - 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()(toHash.mX) ^ (hash()(toHash.mY) << 1)) >> 1) - ^ (hash()(toHash.mWorldspace) << 1); - } - }; + // Convert exterior cell location to position. + osg::Vec2f indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre = false); } #endif diff --git a/components/esm/vector3.hpp b/components/esm/vector3.hpp new file mode 100644 index 0000000000..dd0262b78d --- /dev/null +++ b/components/esm/vector3.hpp @@ -0,0 +1,24 @@ +#ifndef OPENMW_COMPONENTS_ESM_VECTOR3_H +#define OPENMW_COMPONENTS_ESM_VECTOR3_H + +#include + +namespace ESM +{ + // format 0, savegames only + struct Vector3 + { + float mValues[3]; + + Vector3() = default; + + Vector3(const osg::Vec3f& v) + : mValues{ v.x(), v.y(), v.z() } + { + } + + operator osg::Vec3f() const { return osg::Vec3f(mValues[0], mValues[1], mValues[2]); } + }; +} + +#endif diff --git a/components/esm3/aisequence.hpp b/components/esm3/aisequence.hpp index d6d6259f6b..729a914544 100644 --- a/components/esm3/aisequence.hpp +++ b/components/esm3/aisequence.hpp @@ -6,8 +6,8 @@ #include #include -#include "components/esm/refid.hpp" -#include "components/esm/util.hpp" +#include +#include namespace ESM { diff --git a/components/esm3/cellref.hpp b/components/esm3/cellref.hpp index 5079095889..8b23cc5c34 100644 --- a/components/esm3/cellref.hpp +++ b/components/esm3/cellref.hpp @@ -8,13 +8,13 @@ #include #include +#include "refnum.hpp" + namespace ESM { class ESMWriter; class ESMReader; - using RefNum = ESM::FormId; - /* Cell reference. This represents ONE object (of many) inside the cell. The cell references are not loaded as part of the normal loading process, but are rather loaded later on demand when we are diff --git a/components/esm3/projectilestate.hpp b/components/esm3/projectilestate.hpp index cab550b114..c89d55c0e5 100644 --- a/components/esm3/projectilestate.hpp +++ b/components/esm3/projectilestate.hpp @@ -1,18 +1,19 @@ #ifndef OPENMW_ESM_PROJECTILESTATE_H #define OPENMW_ESM_PROJECTILESTATE_H -#include - #include #include -#include "effectlist.hpp" - +#include "components/esm/quaternion.hpp" #include "components/esm/refid.hpp" -#include "components/esm/util.hpp" +#include "components/esm/vector3.hpp" + +#include "refnum.hpp" namespace ESM { + class ESMReader; + class ESMWriter; // format 0, savegames only diff --git a/components/esm3/refnum.hpp b/components/esm3/refnum.hpp new file mode 100644 index 0000000000..6e21d6893e --- /dev/null +++ b/components/esm3/refnum.hpp @@ -0,0 +1,11 @@ +#ifndef OPENMW_COMPONENTS_ESM3_REFNUM_H +#define OPENMW_COMPONENTS_ESM3_REFNUM_H + +#include + +namespace ESM +{ + using RefNum = ESM::FormId; +} + +#endif diff --git a/components/esm4/loadcell.hpp b/components/esm4/loadcell.hpp index 58d1f0da43..7b874b4179 100644 --- a/components/esm4/loadcell.hpp +++ b/components/esm4/loadcell.hpp @@ -32,8 +32,8 @@ #include #include +#include #include -#include #include #include diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index a00cca0904..bb44d836de 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/components/esmterrain/storage.hpp b/components/esmterrain/storage.hpp index 4858dfd544..5ebd0a9d37 100644 --- a/components/esmterrain/storage.hpp +++ b/components/esmterrain/storage.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include namespace ESM4 diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index bdf9f56790..63b55abb21 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -7,6 +7,7 @@ #include +#include #include #include #include diff --git a/components/terrain/storage.hpp b/components/terrain/storage.hpp index 7a99478929..b1007c13e6 100644 --- a/components/terrain/storage.hpp +++ b/components/terrain/storage.hpp @@ -8,8 +8,8 @@ #include #include +#include #include -#include #include "defs.hpp"