mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 11:45:35 +00:00
Static references are created as refcells, nothing displayed yet.
This commit is contained in:
parent
c896a2ca48
commit
3515c8e61a
10 changed files with 108 additions and 20 deletions
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
#include <components/esm/esm3esm4bridge.hpp>
|
||||||
#include <components/esm3/cellref.hpp>
|
#include <components/esm3/cellref.hpp>
|
||||||
|
#include <components/esm4/loadrefr.hpp>
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
|
@ -20,9 +22,19 @@ namespace MWWorld
|
||||||
CellRef(const ESM::CellRef& ref)
|
CellRef(const ESM::CellRef& ref)
|
||||||
: mCellRef(ref)
|
: mCellRef(ref)
|
||||||
{
|
{
|
||||||
|
mIsEsm4 = false;
|
||||||
mChanged = false;
|
mChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CellRef(const ESM4::Reference& ref)
|
||||||
|
: mCellRef4(ref)
|
||||||
|
{
|
||||||
|
mRefrPos = { { mCellRef4.mPlacement.pos.x, mCellRef4.mPlacement.pos.y, mCellRef4.mPlacement.pos.z },
|
||||||
|
{ mCellRef4.mPlacement.rot.x, mCellRef4.mPlacement.rot.y, mCellRef4.mPlacement.rot.z } };
|
||||||
|
mChanged = false;
|
||||||
|
mIsEsm4 = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Note: Currently unused for items in containers
|
// Note: Currently unused for items in containers
|
||||||
const ESM::RefNum& getRefNum() const { return mCellRef.mRefNum; }
|
const ESM::RefNum& getRefNum() const { return mCellRef.mRefNum; }
|
||||||
|
|
||||||
|
@ -50,12 +62,24 @@ namespace MWWorld
|
||||||
const std::string& getDestCell() const { return mCellRef.mDestCell; }
|
const std::string& getDestCell() const { return mCellRef.mDestCell; }
|
||||||
|
|
||||||
// Scale applied to mesh
|
// Scale applied to mesh
|
||||||
float getScale() const { return mCellRef.mScale; }
|
float getScale() const
|
||||||
|
{
|
||||||
|
if (mIsEsm4)
|
||||||
|
return mCellRef4.mScale;
|
||||||
|
else
|
||||||
|
return mCellRef.mScale;
|
||||||
|
}
|
||||||
void setScale(float scale);
|
void setScale(float scale);
|
||||||
|
|
||||||
// The *original* position and rotation as it was given in the Construction Set.
|
// The *original* position and rotation as it was given in the Construction Set.
|
||||||
// Current position and rotation of the object is stored in RefData.
|
// Current position and rotation of the object is stored in RefData.
|
||||||
const ESM::Position& getPosition() const { return mCellRef.mPos; }
|
const ESM::Position& getPosition() const
|
||||||
|
{
|
||||||
|
if (mIsEsm4)
|
||||||
|
return mRefrPos;
|
||||||
|
else
|
||||||
|
return mCellRef.mPos;
|
||||||
|
}
|
||||||
void setPosition(const ESM::Position& position);
|
void setPosition(const ESM::Position& position);
|
||||||
|
|
||||||
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
|
||||||
|
@ -124,6 +148,9 @@ namespace MWWorld
|
||||||
private:
|
private:
|
||||||
bool mChanged;
|
bool mChanged;
|
||||||
ESM::CellRef mCellRef;
|
ESM::CellRef mCellRef;
|
||||||
|
ESM4::Reference mCellRef4;
|
||||||
|
ESM::Position mRefrPos;
|
||||||
|
bool mIsEsm4;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ namespace MWWorld
|
||||||
/// all methods are known.
|
/// all methods are known.
|
||||||
void load(ESM::CellRef& ref, bool deleted, const MWWorld::ESMStore& esmStore);
|
void load(ESM::CellRef& ref, bool deleted, const MWWorld::ESMStore& esmStore);
|
||||||
|
|
||||||
|
void load(const ESM4::Reference& ref, bool deleted, const MWWorld::ESMStore& esmStore);
|
||||||
|
|
||||||
LiveRef& insert(const LiveRef& item)
|
LiveRef& insert(const LiveRef& item)
|
||||||
{
|
{
|
||||||
mList.push_back(item);
|
mList.push_back(item);
|
||||||
|
|
|
@ -371,6 +371,37 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
void CellRefList<X>::load(const ESM4::Reference& ref, bool deleted, const MWWorld::ESMStore& esmStore)
|
||||||
|
{
|
||||||
|
|
||||||
|
if constexpr (!ESM::isESM4Rec(X::sRecordId))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const MWWorld::Store<X>& store = esmStore.get<X>();
|
||||||
|
|
||||||
|
if (const X* ptr = store.search(ref.mBaseObj))
|
||||||
|
{
|
||||||
|
// typename std::list<LiveRef>::iterator iter = std::find(mList.begin(), mList.end(), ref.);
|
||||||
|
|
||||||
|
LiveRef liveCellRef(ref, ptr);
|
||||||
|
|
||||||
|
if (deleted)
|
||||||
|
liveCellRef.mData.setDeletedByContentFile(true);
|
||||||
|
|
||||||
|
/*if (iter != mList.end())
|
||||||
|
*iter = liveCellRef;
|
||||||
|
else
|
||||||
|
*/
|
||||||
|
mList.push_back(liveCellRef);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log(Debug::Warning) << "Warning: could not resolve cell reference '" << ref.mId << "'"
|
||||||
|
<< " (dropping reference)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename X>
|
template <typename X>
|
||||||
bool operator==(const LiveCellRef<X>& ref, int pRefnum)
|
bool operator==(const LiveCellRef<X>& ref, int pRefnum)
|
||||||
{
|
{
|
||||||
|
@ -863,16 +894,6 @@ namespace MWWorld
|
||||||
return Ptr();
|
return Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static void loadRefESM4(
|
|
||||||
const MWWorld::ESMStore& store, const ESM4::Reference& ref, MWWorld::CellRefList<T>& storeIn, bool deleted)
|
|
||||||
{
|
|
||||||
if constexpr (ESM::isESM4Rec(T::sRecordId))
|
|
||||||
{
|
|
||||||
// storeIn.load(ref, deleted, store);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CellStore::loadRef(const ESM4::Reference& ref, bool deleted)
|
void CellStore::loadRef(const ESM4::Reference& ref, bool deleted)
|
||||||
{
|
{
|
||||||
const MWWorld::ESMStore& store = mStore;
|
const MWWorld::ESMStore& store = mStore;
|
||||||
|
@ -881,7 +902,7 @@ namespace MWWorld
|
||||||
|
|
||||||
Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType](auto& x) {
|
Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType](auto& x) {
|
||||||
recNameSwitcher(
|
recNameSwitcher(
|
||||||
x, foundType, [&ref, &deleted, &store](auto& storeIn) { loadRefESM4(store, ref, storeIn, deleted); });
|
x, foundType, [&ref, &deleted, &store](auto& storeIn) { storeIn.load(ref, deleted, store); });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,8 +210,8 @@ namespace MWWorld
|
||||||
|
|
||||||
static bool readRecord(ESM4::Reader& reader, ESMStore& store)
|
static bool readRecord(ESM4::Reader& reader, ESMStore& store)
|
||||||
{
|
{
|
||||||
return std::apply([&reader](auto&... x) { return (ESMStoreImp::typedReadRecordESM4(reader, x) || ...); },
|
return std::apply(
|
||||||
store.mStoreImp->mStores);
|
[&reader](auto&... x) { return (typedReadRecordESM4(reader, x) || ...); }, store.mStoreImp->mStores);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -278,6 +278,7 @@ namespace MWWorld
|
||||||
case ESM::REC_STAT:
|
case ESM::REC_STAT:
|
||||||
case ESM::REC_WEAP:
|
case ESM::REC_WEAP:
|
||||||
case ESM::REC_BODY:
|
case ESM::REC_BODY:
|
||||||
|
case ESM::REC_STAT4:
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -595,8 +596,8 @@ namespace MWWorld
|
||||||
removeMissingObjects(getWritable<ESM::ItemLevList>());
|
removeMissingObjects(getWritable<ESM::ItemLevList>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leveled lists can be modified by scripts. This removes items that no longer exist (presumably because the plugin
|
// Leveled lists can be modified by scripts. This removes items that no longer exist (presumably because the
|
||||||
// was removed) from modified lists
|
// plugin was removed) from modified lists
|
||||||
template <class T>
|
template <class T>
|
||||||
void ESMStore::removeMissingObjects(Store<T>& store)
|
void ESMStore::removeMissingObjects(Store<T>& store)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,13 @@ MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM::CellRef&
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::Reference& cref)
|
||||||
|
: mClass(&Class::get(type))
|
||||||
|
, mRef(cref)
|
||||||
|
, mData(cref)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state)
|
void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state)
|
||||||
{
|
{
|
||||||
mRef = state.mRef;
|
mRef = state.mRef;
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace MWWorld
|
||||||
RefData mData;
|
RefData mData;
|
||||||
|
|
||||||
LiveCellRefBase(unsigned int type, const ESM::CellRef& cref = ESM::CellRef());
|
LiveCellRefBase(unsigned int type, const ESM::CellRef& cref = ESM::CellRef());
|
||||||
|
LiveCellRefBase(unsigned int type, const ESM4::Reference& cref);
|
||||||
/* Need this for the class to be recognized as polymorphic */
|
/* Need this for the class to be recognized as polymorphic */
|
||||||
virtual ~LiveCellRefBase() {}
|
virtual ~LiveCellRefBase() {}
|
||||||
|
|
||||||
|
@ -115,6 +116,12 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveCellRef(const ESM4::Reference& cref, const X* b = nullptr)
|
||||||
|
: LiveCellRefBase(X::sRecordId, cref)
|
||||||
|
, mBase(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
LiveCellRef(const X* b = nullptr)
|
LiveCellRef(const X* b = nullptr)
|
||||||
: LiveCellRefBase(X::sRecordId)
|
: LiveCellRefBase(X::sRecordId)
|
||||||
, mBase(b)
|
, mBase(b)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "manualref.hpp"
|
#include "manualref.hpp"
|
||||||
#include <components/esm/records.hpp>
|
#include <components/esm/records.hpp>
|
||||||
|
#include <components/esm4/loadstat.hpp>
|
||||||
|
|
||||||
#include "esmstore.hpp"
|
#include "esmstore.hpp"
|
||||||
|
|
||||||
|
@ -89,7 +90,9 @@ MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId&
|
||||||
case ESM::REC_BODY:
|
case ESM::REC_BODY:
|
||||||
create(store.get<ESM::BodyPart>(), name, mRef, mPtr);
|
create(store.get<ESM::BodyPart>(), name, mRef, mPtr);
|
||||||
break;
|
break;
|
||||||
|
case ESM::REC_STAT4:
|
||||||
|
create(store.get<ESM4::Static>(), name, mRef, mPtr);
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
throw std::logic_error("failed to create manual cell ref for " + name.getRefIdString() + " (unknown ID)");
|
throw std::logic_error("failed to create manual cell ref for " + name.getRefIdString() + " (unknown ID)");
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,20 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefData::RefData(const ESM4::Reference& cellRef)
|
||||||
|
: mBaseNode(nullptr)
|
||||||
|
, mDeletedByContentFile(false)
|
||||||
|
, mEnabled(true)
|
||||||
|
, mPhysicsPostponed(false)
|
||||||
|
, mCount(1)
|
||||||
|
, mPosition{ { cellRef.mPlacement.pos.x, cellRef.mPlacement.pos.y, cellRef.mPlacement.pos.z },
|
||||||
|
{ cellRef.mPlacement.rot.x, cellRef.mPlacement.rot.y, cellRef.mPlacement.rot.z } }
|
||||||
|
, mCustomData(nullptr)
|
||||||
|
, mChanged(false)
|
||||||
|
, mFlags(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
RefData::RefData(const ESM::ObjectState& objectState, bool deletedByContentFile)
|
RefData::RefData(const ESM::ObjectState& objectState, bool deletedByContentFile)
|
||||||
: mBaseNode(nullptr)
|
: mBaseNode(nullptr)
|
||||||
, mDeletedByContentFile(deletedByContentFile)
|
, mDeletedByContentFile(deletedByContentFile)
|
||||||
|
|
|
@ -25,6 +25,11 @@ namespace ESM
|
||||||
struct ObjectState;
|
struct ObjectState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace ESM4
|
||||||
|
{
|
||||||
|
struct Reference;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
{
|
{
|
||||||
class LocalScripts;
|
class LocalScripts;
|
||||||
|
@ -76,6 +81,7 @@ namespace MWWorld
|
||||||
/// be altered without affecting the original data. This makes it possible
|
/// be altered without affecting the original data. This makes it possible
|
||||||
/// to reset the position as the original data is still held in the CellRef
|
/// to reset the position as the original data is still held in the CellRef
|
||||||
RefData(const ESM::CellRef& cellRef);
|
RefData(const ESM::CellRef& cellRef);
|
||||||
|
RefData(const ESM4::Reference& cellRef);
|
||||||
|
|
||||||
RefData(const ESM::ObjectState& objectState, bool deletedByContentFile);
|
RefData(const ESM::ObjectState& objectState, bool deletedByContentFile);
|
||||||
///< Ignores local variables and custom data (not enough context available here to
|
///< Ignores local variables and custom data (not enough context available here to
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef COMPONENTS_ESM_CELLCOMMON
|
#ifndef COMPONENTS_ESM_ESMBRIDGE
|
||||||
#define COMPONENTS_ESM_CELLCOMMON
|
#define COMPONENTS_ESM_ESMBRIDGE
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
Loading…
Reference in a new issue