1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00
OpenMW/apps/openmw/mwworld/livecellref.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.1 KiB
C++
Raw Normal View History

#include "livecellref.hpp"
#include <sstream>
2018-08-14 23:05:43 +04:00
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadscpt.hpp>
#include <components/esm3/objectstate.hpp>
2014-03-22 16:39:24 +01:00
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
2014-03-22 16:39:24 +01:00
#include "class.hpp"
2014-03-22 16:39:24 +01:00
#include "esmstore.hpp"
#include "ptr.hpp"
MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM::CellRef& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
{
}
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)
{
mRef = MWWorld::CellRef(state.mRef);
mData = RefData(state, mData.isDeletedByContentFile());
Ptr ptr(this);
if (state.mHasLocals)
2014-03-22 16:39:24 +01:00
{
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
const ESM::RefId& scriptId = mClass->getScript(ptr);
// Make sure we still have a script. It could have been coming from a content file that is no longer active.
if (!scriptId.empty())
{
if (const ESM::Script* script
2023-04-20 21:07:53 +02:00
= MWBase::Environment::get().getESMStore()->get<ESM::Script>().search(scriptId))
{
try
{
mData.setLocals(*script);
mData.getLocals().read(state.mLocals, scriptId);
}
catch (const std::exception& exception)
{
Log(Debug::Error) << "Error: failed to load state for local script " << scriptId
2018-08-14 23:05:43 +04:00
<< " because an exception has been thrown: " << exception.what();
}
}
}
2014-03-22 16:39:24 +01:00
}
mClass->readAdditionalState(ptr, state);
if (!mRef.getSoul().empty()
2023-04-20 21:07:53 +02:00
&& !MWBase::Environment::get().getESMStore()->get<ESM::Creature>().search(mRef.getSoul()))
{
2018-08-14 23:05:43 +04:00
Log(Debug::Warning) << "Soul '" << mRef.getSoul() << "' not found, removing the soul from soul gem";
mRef.setSoul(ESM::RefId());
}
MWBase::Environment::get().getLuaManager()->loadLocalScripts(ptr, state.mLuaScripts);
}
void MWWorld::LiveCellRefBase::saveImp(ESM::ObjectState& state) const
{
mRef.writeState(state);
ConstPtr ptr(this);
mData.write(state, mClass->getScript(ptr));
MWBase::Environment::get().getLuaManager()->saveLocalScripts(
Ptr(const_cast<LiveCellRefBase*>(this)), state.mLuaScripts);
mClass->writeAdditionalState(ptr, state);
}
bool MWWorld::LiveCellRefBase::checkStateImp(const ESM::ObjectState& state)
{
return true;
}
unsigned int MWWorld::LiveCellRefBase::getType() const
{
return mClass->getType();
}
namespace MWWorld
{
std::string makeDynamicCastErrorMessage(const LiveCellRefBase* value, std::string_view recordType)
{
std::stringstream message;
message << "Bad LiveCellRef cast to " << recordType << " from ";
if (value != nullptr)
message << value->getTypeDescription();
else
message << "an empty object";
return message.str();
}
}