Remove LightState from openmw save format to streamline inventory loading

This commit is contained in:
scrawl 2015-01-19 10:34:49 +01:00
parent ad398f0c65
commit 235683e449
11 changed files with 44 additions and 109 deletions

View file

@ -2,7 +2,7 @@
#include "light.hpp"
#include <components/esm/loadligh.hpp>
#include <components/esm/lightstate.hpp>
#include <components/esm/objectstate.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
@ -285,21 +285,17 @@ namespace MWClass
void Light::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
const
{
const ESM::LightState& state2 = dynamic_cast<const ESM::LightState&> (state);
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)
const
{
ESM::LightState& state2 = dynamic_cast<ESM::LightState&> (state);
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

View file

@ -7,7 +7,6 @@
#include <components/esm/cellid.hpp>
#include <components/esm/esmwriter.hpp>
#include <components/esm/objectstate.hpp>
#include <components/esm/lightstate.hpp>
#include <components/esm/containerstate.hpp>
#include <components/esm/npcstate.hpp>
#include <components/esm/creaturestate.hpp>
@ -624,7 +623,7 @@ namespace MWWorld
writeReferenceCollection<ESM::ObjectState> (writer, mIngreds);
writeReferenceCollection<ESM::CreatureLevListState> (writer, mCreatureLists);
writeReferenceCollection<ESM::ObjectState> (writer, mItemLists);
writeReferenceCollection<ESM::LightState> (writer, mLights);
writeReferenceCollection<ESM::ObjectState> (writer, mLights);
writeReferenceCollection<ESM::ObjectState> (writer, mLockpicks);
writeReferenceCollection<ESM::ObjectState> (writer, mMiscItems);
writeReferenceCollection<ESM::NpcState> (writer, mNpcs);
@ -708,7 +707,7 @@ namespace MWWorld
case ESM::REC_LIGH:
readReferenceCollection<ESM::LightState> (reader, mLights, contentFileMap);
readReferenceCollection<ESM::ObjectState> (reader, mLights, contentFileMap);
break;
case ESM::REC_LOCK:

View file

@ -87,7 +87,7 @@ void MWWorld::ContainerStore::storeState (const LiveCellRef<T>& ref, ESM::Object
template<typename T>
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());
iter!=collection.mList.end(); ++iter)
@ -97,7 +97,7 @@ void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
ESM::ObjectState state;
storeState (*iter, state);
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 (repairs, state.mItems);
storeStates (weapons, state.mItems, true);
state.mLights.clear();
storeStates (lights, state.mItems, true);
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)
{
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)
{
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_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_REPA: getState (repairs, iter->first); break;
case ESM::REC_WEAP: setSlot (getState (weapons, iter->first), slot); break;
case ESM::REC_LIGH: setSlot (getState (lights, iter->first), slot); break;
default:
std::cerr << "invalid item type in inventory state" << std::endl;
std::cerr << "invalid item type in inventory state, refid " << state.mRef.mRefID << 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;
}

View file

@ -86,7 +86,7 @@ namespace MWWorld
template<typename T>
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;
virtual int getSlot (const MWWorld::LiveCellRefBase& ref) const;

View file

@ -61,7 +61,7 @@ add_component_dir (esm
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
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
aisequence magiceffects util custommarkerstate
)

View file

@ -14,9 +14,10 @@ namespace
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)
esm.writeHNT ("SLOT", slot);
@ -29,27 +30,15 @@ void ESM::InventoryState::load (ESMReader &esm)
{
while (esm.isNextSub ("IOBJ"))
{
unsigned int id = 0;
esm.getHT (id);
int unused; // no longer used
esm.getHT(unused);
if (id==ESM::REC_LIGH)
{
LightState state;
int slot;
read (esm, state, slot);
if (state.mCount == 0)
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)));
}
ObjectState state;
int slot;
read (esm, state, slot);
if (state.mCount == 0)
continue;
mItems.push_back (std::make_pair (state, slot));
}
while (esm.isNextSub("LEVM"))
@ -78,12 +67,8 @@ void ESM::InventoryState::load (ESMReader &esm)
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)
write (esm, iter->first, iter->second.first, iter->second.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::vector<std::pair<ObjectState, int> >::const_iterator iter (mItems.begin()); iter!=mItems.end(); ++iter)
write (esm, iter->first, iter->second);
for (std::map<std::string, int>::const_iterator it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it)
{

View file

@ -4,7 +4,6 @@
#include <map>
#include "objectstate.hpp"
#include "lightstate.hpp"
namespace ESM
{
@ -16,11 +15,7 @@ namespace ESM
/// \brief State for inventories and containers
struct InventoryState
{
// anything but lights (type, slot)
std::vector<std::pair<ObjectState, std::pair<unsigned int, int> > > mItems;
// lights (slot)
std::vector<std::pair<LightState, int> > mLights;
std::vector<std::pair<ObjectState, int> > mItems;
std::map<std::string, int> mLevelledItemMap;

View file

@ -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);
}

View file

@ -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

View file

@ -23,6 +23,10 @@ void ESM::ObjectState::load (ESMReader &esm)
esm.getHNOT (mPosition, "POS_", 24);
esm.getHNOT (mLocalRotation, "LROT", 12);
// used for lights only
mTime = 0;
esm.getHNOT (mTime, "LTIM");
}
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 ("LROT", mLocalRotation, 12);
}
if (mTime)
esm.writeHNT ("LTIM", mTime);
}
void ESM::ObjectState::blank()
@ -60,6 +67,7 @@ void ESM::ObjectState::blank()
mPosition.rot[i] = 0;
mLocalRotation[i] = 0;
}
mTime = 0;
}
ESM::ObjectState::~ObjectState() {}

View file

@ -26,6 +26,8 @@ namespace ESM
ESM::Position mPosition;
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 save (ESMWriter &esm, bool inInventory = false) const;