mirror of https://github.com/OpenMW/openmw.git
Merge branch 'load-ESM4-Cell' into 'master'
Can load and coc into an interrior oblivion cell See merge request OpenMW/openmw!26477220-lua-add-a-general-purpose-lexical-parser
commit
4032c447e9
@ -0,0 +1,61 @@
|
||||
#include "cell.hpp"
|
||||
|
||||
#include <components/esm3/loadcell.hpp>
|
||||
#include <components/esm4/loadcell.hpp>
|
||||
#include <components/misc/algorithm.hpp>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
Cell::Cell(const ESM4::Cell& cell)
|
||||
: ESM::CellVariant(cell)
|
||||
, mIsExterior(!(cell.mCellFlags & ESM4::CELL_Interior))
|
||||
, mIsQuasiExterior(cell.mCellFlags & ESM4::CELL_QuasiExt)
|
||||
, mHasWater(cell.mCellFlags & ESM4::CELL_HasWater)
|
||||
, mNoSleep(false) // No such notion in ESM4
|
||||
, mGridPos(cell.mX, cell.mY)
|
||||
, mDisplayname(cell.mFullName)
|
||||
, mNameID(cell.mEditorId)
|
||||
, mRegion(ESM::RefId::sEmpty) // Unimplemented for now
|
||||
, mCellId{
|
||||
.mWorldspace{ Misc::StringUtils::lowerCase(cell.mEditorId) },
|
||||
.mIndex{ cell.getGridX(), cell.getGridY() },
|
||||
.mPaged = isExterior(),}
|
||||
,mMood{
|
||||
.mAmbiantColor = cell.mLighting.ambient,
|
||||
.mDirectionalColor = cell.mLighting.directional,
|
||||
.mFogColor = cell.mLighting.fogColor,
|
||||
.mFogDensity = cell.mLighting.fogPower,}
|
||||
,mWaterHeight(cell.mWaterHeight)
|
||||
{
|
||||
}
|
||||
|
||||
Cell::Cell(const ESM::Cell& cell)
|
||||
: ESM::CellVariant(cell)
|
||||
, mIsExterior(!(cell.mData.mFlags & ESM::Cell::Interior))
|
||||
, mIsQuasiExterior(cell.mData.mFlags & ESM::Cell::QuasiEx)
|
||||
, mHasWater(cell.mData.mFlags & ESM::Cell::HasWater)
|
||||
, mNoSleep(cell.mData.mFlags & ESM::Cell::NoSleep)
|
||||
, mGridPos(cell.getGridX(), cell.getGridY())
|
||||
, mDisplayname(cell.mName)
|
||||
, mNameID(cell.mName)
|
||||
, mRegion(ESM::RefId::sEmpty) // Unimplemented for now
|
||||
, mCellId(cell.getCellId())
|
||||
, mMood{
|
||||
.mAmbiantColor = cell.mAmbi.mAmbient,
|
||||
.mDirectionalColor = cell.mAmbi.mSunlight,
|
||||
.mFogColor = cell.mAmbi.mFog,
|
||||
.mFogDensity = cell.mAmbi.mFogDensity,
|
||||
}
|
||||
,mWaterHeight(cell.mWater)
|
||||
{
|
||||
}
|
||||
|
||||
std::string Cell::getDescription() const
|
||||
{
|
||||
return ESM::visit(ESM::VisitOverload{
|
||||
[&](const ESM::Cell& cell) { return cell.getDescription(); },
|
||||
[&](const ESM4::Cell& cell) { return cell.mEditorId; },
|
||||
},
|
||||
*this);
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
#ifndef OPENW_MWORLD_CELL
|
||||
#define OPENW_MWORLD_CELL
|
||||
|
||||
#include <osg/Vec2i>
|
||||
|
||||
#include <components/esm/esmbridge.hpp>
|
||||
#include <components/esm/refid.hpp>
|
||||
#include <components/esm3/cellid.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct Cell;
|
||||
struct CellId;
|
||||
}
|
||||
|
||||
namespace ESM4
|
||||
{
|
||||
struct Cell;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class CellStore;
|
||||
|
||||
class Cell : public ESM::CellVariant
|
||||
{
|
||||
struct MoodData
|
||||
{
|
||||
uint32_t mAmbiantColor;
|
||||
uint32_t mDirectionalColor;
|
||||
uint32_t mFogColor;
|
||||
float mFogDensity;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit Cell(const ESM4::Cell& cell);
|
||||
explicit Cell(const ESM::Cell& cell);
|
||||
|
||||
int getGridX() const { return mGridPos.x(); }
|
||||
int getGridY() const { return mGridPos.y(); }
|
||||
bool isExterior() const { return mIsExterior; }
|
||||
bool isQuasiExterior() const { return mIsQuasiExterior; }
|
||||
bool hasWater() const { return mHasWater; }
|
||||
bool noSleep() const { return mNoSleep; }
|
||||
const ESM::CellId& getCellId() const { return mCellId; }
|
||||
const ESM::RefId& getRegion() const { return mRegion; }
|
||||
std::string_view getNameId() const { return mNameID; }
|
||||
std::string_view getDisplayName() const { return mDisplayname; }
|
||||
std::string getDescription() const;
|
||||
const MoodData& getMood() const { return mMood; }
|
||||
float getWaterHeight() const { return mWaterHeight; }
|
||||
|
||||
private:
|
||||
bool mIsExterior;
|
||||
bool mIsQuasiExterior;
|
||||
bool mHasWater;
|
||||
bool mNoSleep;
|
||||
|
||||
osg::Vec2i mGridPos;
|
||||
std::string mDisplayname; // How the game displays it
|
||||
std::string mNameID; // The name that will be used by the script and console commands
|
||||
ESM::RefId mRegion;
|
||||
ESM::CellId mCellId;
|
||||
MoodData mMood;
|
||||
|
||||
float mWaterHeight;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
#include <components/esm/esmbridge.hpp>
|
||||
#include <components/esm3/loadcell.hpp>
|
||||
#include <components/esm4/loadcell.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
const ESM4::Cell& CellVariant::getEsm4() const
|
||||
{
|
||||
auto cell4 = std::get<const ESM4::Cell*>(mVariant);
|
||||
return *cell4;
|
||||
}
|
||||
|
||||
const ESM::Cell& CellVariant::getEsm3() const
|
||||
{
|
||||
auto cell = std::get<const ESM::Cell*>(mVariant);
|
||||
return *cell;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
#ifndef COMPONENTS_ESM_ESMBRIDGE
|
||||
#define COMPONENTS_ESM_ESMBRIDGE
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
|
||||
#include <components/esm3/cellref.hpp>
|
||||
#include <components/esm4/loadrefr.hpp>
|
||||
|
||||
namespace ESM4
|
||||
{
|
||||
struct Cell;
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct Cell;
|
||||
struct CellId;
|
||||
struct RefId;
|
||||
|
||||
class CellVariant
|
||||
{
|
||||
protected:
|
||||
std::variant<const ESM4::Cell*, const ESM::Cell*> mVariant;
|
||||
|
||||
public:
|
||||
explicit CellVariant(const ESM4::Cell& cell)
|
||||
: mVariant(&cell)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CellVariant(const ESM::Cell& cell)
|
||||
: mVariant(&cell)
|
||||
{
|
||||
}
|
||||
|
||||
bool isEsm4() const { return std::holds_alternative<const ESM4::Cell*>(mVariant); }
|
||||
const ESM4::Cell& getEsm4() const;
|
||||
const ESM::Cell& getEsm3() const;
|
||||
|
||||
template <class F, class... T>
|
||||
friend auto visit(F&& f, T&&... v);
|
||||
};
|
||||
|
||||
struct ReferenceVariant
|
||||
{
|
||||
std::variant<ESM::CellRef, ESM4::Reference> mVariant;
|
||||
|
||||
explicit ReferenceVariant(const ESM4::Reference& ref)
|
||||
: mVariant(ref)
|
||||
{
|
||||
}
|
||||
|
||||
explicit ReferenceVariant(const ESM::CellRef& ref)
|
||||
: mVariant(ref)
|
||||
{
|
||||
}
|
||||
|
||||
bool isESM4() const { return std::holds_alternative<ESM4::Reference>(mVariant); }
|
||||
|
||||
const ESM::CellRef& getEsm3() const { return std::get<ESM::CellRef>(mVariant); }
|
||||
const ESM4::Reference& getEsm4() const { return std::get<ESM4::Reference>(mVariant); }
|
||||
|
||||
ESM::CellRef& getEsm3() { return std::get<ESM::CellRef>(mVariant); }
|
||||
ESM4::Reference& getEsm4() { return std::get<ESM4::Reference>(mVariant); }
|
||||
};
|
||||
|
||||
template <class F, class... T>
|
||||
auto visit(F&& f, T&&... v)
|
||||
{
|
||||
return std::visit([&](auto*... ptr) { return std::forward<F>(f)(*ptr...); }, std::forward<T>(v).mVariant...);
|
||||
}
|
||||
|
||||
template <class... Ts>
|
||||
struct VisitOverload : Ts...
|
||||
{
|
||||
using Ts::operator()...;
|
||||
};
|
||||
|
||||
template <class... Ts>
|
||||
VisitOverload(Ts...) -> VisitOverload<Ts...>;
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue