forked from mirror/openmw-tes3mp
Remove LightState from openmw save format to streamline inventory loading
This commit is contained in:
parent
ad398f0c65
commit
235683e449
11 changed files with 44 additions and 109 deletions
|
@ -2,7 +2,7 @@
|
||||||
#include "light.hpp"
|
#include "light.hpp"
|
||||||
|
|
||||||
#include <components/esm/loadligh.hpp>
|
#include <components/esm/loadligh.hpp>
|
||||||
#include <components/esm/lightstate.hpp>
|
#include <components/esm/objectstate.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
@ -285,21 +285,17 @@ namespace MWClass
|
||||||
void Light::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
void Light::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
const ESM::LightState& state2 = dynamic_cast<const ESM::LightState&> (state);
|
|
||||||
|
|
||||||
ensureCustomData (ptr);
|
ensureCustomData (ptr);
|
||||||
|
|
||||||
dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime = state2.mTime;
|
dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime = state.mTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Light::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
void Light::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
ESM::LightState& state2 = dynamic_cast<ESM::LightState&> (state);
|
|
||||||
|
|
||||||
ensureCustomData (ptr);
|
ensureCustomData (ptr);
|
||||||
|
|
||||||
state2.mTime = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
state.mTime = dynamic_cast<LightCustomData&> (*ptr.getRefData().getCustomData()).mTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Light::getSound(const MWWorld::Ptr& ptr) const
|
std::string Light::getSound(const MWWorld::Ptr& ptr) const
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <components/esm/cellid.hpp>
|
#include <components/esm/cellid.hpp>
|
||||||
#include <components/esm/esmwriter.hpp>
|
#include <components/esm/esmwriter.hpp>
|
||||||
#include <components/esm/objectstate.hpp>
|
#include <components/esm/objectstate.hpp>
|
||||||
#include <components/esm/lightstate.hpp>
|
|
||||||
#include <components/esm/containerstate.hpp>
|
#include <components/esm/containerstate.hpp>
|
||||||
#include <components/esm/npcstate.hpp>
|
#include <components/esm/npcstate.hpp>
|
||||||
#include <components/esm/creaturestate.hpp>
|
#include <components/esm/creaturestate.hpp>
|
||||||
|
@ -624,7 +623,7 @@ namespace MWWorld
|
||||||
writeReferenceCollection<ESM::ObjectState> (writer, mIngreds);
|
writeReferenceCollection<ESM::ObjectState> (writer, mIngreds);
|
||||||
writeReferenceCollection<ESM::CreatureLevListState> (writer, mCreatureLists);
|
writeReferenceCollection<ESM::CreatureLevListState> (writer, mCreatureLists);
|
||||||
writeReferenceCollection<ESM::ObjectState> (writer, mItemLists);
|
writeReferenceCollection<ESM::ObjectState> (writer, mItemLists);
|
||||||
writeReferenceCollection<ESM::LightState> (writer, mLights);
|
writeReferenceCollection<ESM::ObjectState> (writer, mLights);
|
||||||
writeReferenceCollection<ESM::ObjectState> (writer, mLockpicks);
|
writeReferenceCollection<ESM::ObjectState> (writer, mLockpicks);
|
||||||
writeReferenceCollection<ESM::ObjectState> (writer, mMiscItems);
|
writeReferenceCollection<ESM::ObjectState> (writer, mMiscItems);
|
||||||
writeReferenceCollection<ESM::NpcState> (writer, mNpcs);
|
writeReferenceCollection<ESM::NpcState> (writer, mNpcs);
|
||||||
|
@ -708,7 +707,7 @@ namespace MWWorld
|
||||||
|
|
||||||
case ESM::REC_LIGH:
|
case ESM::REC_LIGH:
|
||||||
|
|
||||||
readReferenceCollection<ESM::LightState> (reader, mLights, contentFileMap);
|
readReferenceCollection<ESM::ObjectState> (reader, mLights, contentFileMap);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESM::REC_LOCK:
|
case ESM::REC_LOCK:
|
||||||
|
|
|
@ -87,7 +87,7 @@ void MWWorld::ContainerStore::storeState (const LiveCellRef<T>& ref, ESM::Object
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
|
void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
|
||||||
std::vector<std::pair<ESM::ObjectState, std::pair<unsigned int, int> > >& states, bool equipable) const
|
std::vector<std::pair<ESM::ObjectState, int> >& states, bool equipable) const
|
||||||
{
|
{
|
||||||
for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin());
|
for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin());
|
||||||
iter!=collection.mList.end(); ++iter)
|
iter!=collection.mList.end(); ++iter)
|
||||||
|
@ -97,7 +97,7 @@ void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
|
||||||
ESM::ObjectState state;
|
ESM::ObjectState state;
|
||||||
storeState (*iter, state);
|
storeState (*iter, state);
|
||||||
int slot = equipable ? getSlot (*iter) : -1;
|
int slot = equipable ? getSlot (*iter) : -1;
|
||||||
states.push_back (std::make_pair (state, std::make_pair (T::sRecordId, slot)));
|
states.push_back (std::make_pair (state, slot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,30 +656,25 @@ void MWWorld::ContainerStore::writeState (ESM::InventoryState& state) const
|
||||||
storeStates (probes, state.mItems, true);
|
storeStates (probes, state.mItems, true);
|
||||||
storeStates (repairs, state.mItems);
|
storeStates (repairs, state.mItems);
|
||||||
storeStates (weapons, state.mItems, true);
|
storeStates (weapons, state.mItems, true);
|
||||||
|
storeStates (lights, state.mItems, true);
|
||||||
state.mLights.clear();
|
|
||||||
|
|
||||||
state.mLevelledItemMap = mLevelledItemMap;
|
state.mLevelledItemMap = mLevelledItemMap;
|
||||||
|
|
||||||
for (MWWorld::CellRefList<ESM::Light>::List::const_iterator iter (lights.mList.begin());
|
|
||||||
iter!=lights.mList.end(); ++iter)
|
|
||||||
{
|
|
||||||
ESM::LightState objectState;
|
|
||||||
storeState (*iter, objectState);
|
|
||||||
state.mLights.push_back (std::make_pair (objectState, getSlot (*iter)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWWorld::ContainerStore::readState (const ESM::InventoryState& state)
|
void MWWorld::ContainerStore::readState (const ESM::InventoryState& state)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
for (std::vector<std::pair<ESM::ObjectState, std::pair<unsigned int, int> > >::const_iterator
|
for (std::vector<std::pair<ESM::ObjectState, int> >::const_iterator
|
||||||
iter (state.mItems.begin()); iter!=state.mItems.end(); ++iter)
|
iter (state.mItems.begin()); iter!=state.mItems.end(); ++iter)
|
||||||
{
|
{
|
||||||
int slot = iter->second.second;
|
int slot = iter->second;
|
||||||
|
|
||||||
switch (iter->second.first)
|
const ESM::ObjectState& state = iter->first;
|
||||||
|
|
||||||
|
int type = MWBase::Environment::get().getWorld()->getStore().find(state.mRef.mRefID);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
{
|
{
|
||||||
case ESM::REC_ALCH: getState (potions, iter->first); break;
|
case ESM::REC_ALCH: getState (potions, iter->first); break;
|
||||||
case ESM::REC_APPA: getState (appas, iter->first); break;
|
case ESM::REC_APPA: getState (appas, iter->first); break;
|
||||||
|
@ -692,19 +687,14 @@ void MWWorld::ContainerStore::readState (const ESM::InventoryState& state)
|
||||||
case ESM::REC_PROB: setSlot (getState (probes, iter->first), slot); break;
|
case ESM::REC_PROB: setSlot (getState (probes, iter->first), slot); break;
|
||||||
case ESM::REC_REPA: getState (repairs, iter->first); break;
|
case ESM::REC_REPA: getState (repairs, iter->first); break;
|
||||||
case ESM::REC_WEAP: setSlot (getState (weapons, iter->first), slot); break;
|
case ESM::REC_WEAP: setSlot (getState (weapons, iter->first), slot); break;
|
||||||
|
case ESM::REC_LIGH: setSlot (getState (lights, iter->first), slot); break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
std::cerr << "invalid item type in inventory state, refid " << state.mRef.mRefID << std::endl;
|
||||||
std::cerr << "invalid item type in inventory state" << std::endl;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<std::pair<ESM::LightState, int> >::const_iterator iter (state.mLights.begin());
|
|
||||||
iter!=state.mLights.end(); ++iter)
|
|
||||||
{
|
|
||||||
int slot = iter->second;
|
|
||||||
setSlot (getState (lights, iter->first), slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
mLevelledItemMap = state.mLevelledItemMap;
|
mLevelledItemMap = state.mLevelledItemMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace MWWorld
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void storeStates (const CellRefList<T>& collection,
|
void storeStates (const CellRefList<T>& collection,
|
||||||
std::vector<std::pair<ESM::ObjectState, std::pair<unsigned int, int> > >& states,
|
std::vector<std::pair<ESM::ObjectState, int> >& states,
|
||||||
bool equipable = false) const;
|
bool equipable = false) const;
|
||||||
|
|
||||||
virtual int getSlot (const MWWorld::LiveCellRefBase& ref) const;
|
virtual int getSlot (const MWWorld::LiveCellRefBase& ref) const;
|
||||||
|
|
|
@ -61,7 +61,7 @@ add_component_dir (esm
|
||||||
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
|
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
|
||||||
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
|
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
|
||||||
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
|
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
|
||||||
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap lightstate inventorystate containerstate npcstate creaturestate dialoguestate statstate
|
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap inventorystate containerstate npcstate creaturestate dialoguestate statstate
|
||||||
npcstats creaturestats weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate debugprofile
|
npcstats creaturestats weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate debugprofile
|
||||||
aisequence magiceffects util custommarkerstate
|
aisequence magiceffects util custommarkerstate
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,9 +14,10 @@ namespace
|
||||||
state.load (esm);
|
state.load (esm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write (ESM::ESMWriter &esm, const ESM::ObjectState& state, unsigned int type, int slot)
|
void write (ESM::ESMWriter &esm, const ESM::ObjectState& state, int slot)
|
||||||
{
|
{
|
||||||
esm.writeHNT ("IOBJ", type);
|
int unused = 0;
|
||||||
|
esm.writeHNT ("IOBJ", unused);
|
||||||
|
|
||||||
if (slot!=-1)
|
if (slot!=-1)
|
||||||
esm.writeHNT ("SLOT", slot);
|
esm.writeHNT ("SLOT", slot);
|
||||||
|
@ -29,27 +30,15 @@ void ESM::InventoryState::load (ESMReader &esm)
|
||||||
{
|
{
|
||||||
while (esm.isNextSub ("IOBJ"))
|
while (esm.isNextSub ("IOBJ"))
|
||||||
{
|
{
|
||||||
unsigned int id = 0;
|
int unused; // no longer used
|
||||||
esm.getHT (id);
|
esm.getHT(unused);
|
||||||
|
|
||||||
if (id==ESM::REC_LIGH)
|
ObjectState state;
|
||||||
{
|
int slot;
|
||||||
LightState state;
|
read (esm, state, slot);
|
||||||
int slot;
|
if (state.mCount == 0)
|
||||||
read (esm, state, slot);
|
continue;
|
||||||
if (state.mCount == 0)
|
mItems.push_back (std::make_pair (state, slot));
|
||||||
continue;
|
|
||||||
mLights.push_back (std::make_pair (state, slot));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ObjectState state;
|
|
||||||
int slot;
|
|
||||||
read (esm, state, slot);
|
|
||||||
if (state.mCount == 0)
|
|
||||||
continue;
|
|
||||||
mItems.push_back (std::make_pair (state, std::make_pair (id, slot)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (esm.isNextSub("LEVM"))
|
while (esm.isNextSub("LEVM"))
|
||||||
|
@ -78,12 +67,8 @@ void ESM::InventoryState::load (ESMReader &esm)
|
||||||
|
|
||||||
void ESM::InventoryState::save (ESMWriter &esm) const
|
void ESM::InventoryState::save (ESMWriter &esm) const
|
||||||
{
|
{
|
||||||
for (std::vector<std::pair<ObjectState, std::pair<unsigned int, int> > >::const_iterator iter (mItems.begin()); iter!=mItems.end(); ++iter)
|
for (std::vector<std::pair<ObjectState, int> >::const_iterator iter (mItems.begin()); iter!=mItems.end(); ++iter)
|
||||||
write (esm, iter->first, iter->second.first, iter->second.second);
|
write (esm, iter->first, iter->second);
|
||||||
|
|
||||||
for (std::vector<std::pair<LightState, int> >::const_iterator iter (mLights.begin());
|
|
||||||
iter!=mLights.end(); ++iter)
|
|
||||||
write (esm, iter->first, ESM::REC_LIGH, iter->second);
|
|
||||||
|
|
||||||
for (std::map<std::string, int>::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
for (std::map<std::string, int>::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "objectstate.hpp"
|
#include "objectstate.hpp"
|
||||||
#include "lightstate.hpp"
|
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
|
@ -16,11 +15,7 @@ namespace ESM
|
||||||
/// \brief State for inventories and containers
|
/// \brief State for inventories and containers
|
||||||
struct InventoryState
|
struct InventoryState
|
||||||
{
|
{
|
||||||
// anything but lights (type, slot)
|
std::vector<std::pair<ObjectState, int> > mItems;
|
||||||
std::vector<std::pair<ObjectState, std::pair<unsigned int, int> > > mItems;
|
|
||||||
|
|
||||||
// lights (slot)
|
|
||||||
std::vector<std::pair<LightState, int> > mLights;
|
|
||||||
|
|
||||||
std::map<std::string, int> mLevelledItemMap;
|
std::map<std::string, int> mLevelledItemMap;
|
||||||
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
|
|
||||||
#include "lightstate.hpp"
|
|
||||||
|
|
||||||
#include "esmreader.hpp"
|
|
||||||
#include "esmwriter.hpp"
|
|
||||||
|
|
||||||
void ESM::LightState::load (ESMReader &esm)
|
|
||||||
{
|
|
||||||
ObjectState::load (esm);
|
|
||||||
|
|
||||||
mTime = 0;
|
|
||||||
esm.getHNOT (mTime, "LTIM");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ESM::LightState::save (ESMWriter &esm, bool inInventory) const
|
|
||||||
{
|
|
||||||
ObjectState::save (esm, inInventory);
|
|
||||||
|
|
||||||
if (mTime)
|
|
||||||
esm.writeHNT ("LTIM", mTime);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef OPENMW_ESM_LIGHTSTATE_H
|
|
||||||
#define OPENMW_ESM_LIGHTSTATE_H
|
|
||||||
|
|
||||||
#include "objectstate.hpp"
|
|
||||||
|
|
||||||
namespace ESM
|
|
||||||
{
|
|
||||||
// format 0, saved games only
|
|
||||||
|
|
||||||
struct LightState : public ObjectState
|
|
||||||
{
|
|
||||||
float mTime;
|
|
||||||
|
|
||||||
virtual void load (ESMReader &esm);
|
|
||||||
virtual void save (ESMWriter &esm, bool inInventory = false) const;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -23,6 +23,10 @@ void ESM::ObjectState::load (ESMReader &esm)
|
||||||
esm.getHNOT (mPosition, "POS_", 24);
|
esm.getHNOT (mPosition, "POS_", 24);
|
||||||
|
|
||||||
esm.getHNOT (mLocalRotation, "LROT", 12);
|
esm.getHNOT (mLocalRotation, "LROT", 12);
|
||||||
|
|
||||||
|
// used for lights only
|
||||||
|
mTime = 0;
|
||||||
|
esm.getHNOT (mTime, "LTIM");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESM::ObjectState::save (ESMWriter &esm, bool inInventory) const
|
void ESM::ObjectState::save (ESMWriter &esm, bool inInventory) const
|
||||||
|
@ -46,6 +50,9 @@ void ESM::ObjectState::save (ESMWriter &esm, bool inInventory) const
|
||||||
esm.writeHNT ("POS_", mPosition, 24);
|
esm.writeHNT ("POS_", mPosition, 24);
|
||||||
esm.writeHNT ("LROT", mLocalRotation, 12);
|
esm.writeHNT ("LROT", mLocalRotation, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mTime)
|
||||||
|
esm.writeHNT ("LTIM", mTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESM::ObjectState::blank()
|
void ESM::ObjectState::blank()
|
||||||
|
@ -60,6 +67,7 @@ void ESM::ObjectState::blank()
|
||||||
mPosition.rot[i] = 0;
|
mPosition.rot[i] = 0;
|
||||||
mLocalRotation[i] = 0;
|
mLocalRotation[i] = 0;
|
||||||
}
|
}
|
||||||
|
mTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::ObjectState::~ObjectState() {}
|
ESM::ObjectState::~ObjectState() {}
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace ESM
|
||||||
ESM::Position mPosition;
|
ESM::Position mPosition;
|
||||||
float mLocalRotation[3];
|
float mLocalRotation[3];
|
||||||
|
|
||||||
|
float mTime; // Used for lights only. Overhead should not be so awful, besides CellRef isn't OO either
|
||||||
|
|
||||||
virtual void load (ESMReader &esm);
|
virtual void load (ESMReader &esm);
|
||||||
virtual void save (ESMWriter &esm, bool inInventory = false) const;
|
virtual void save (ESMWriter &esm, bool inInventory = false) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue