2012-10-01 19:17:04 +04:00
|
|
|
#include "esmstore.hpp"
|
|
|
|
|
2021-04-06 23:59:58 +02:00
|
|
|
#include <algorithm>
|
2021-09-26 15:21:46 +02:00
|
|
|
#include <fstream>
|
2022-09-03 11:08:23 +02:00
|
|
|
#include <tuple>
|
2010-05-17 17:35:42 +02:00
|
|
|
|
2018-08-14 23:05:43 +04:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm/records.hpp>
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/esmreader.hpp>
|
|
|
|
#include <components/esm3/esmwriter.hpp>
|
2022-06-01 22:53:18 +02:00
|
|
|
#include <components/esm3/readerscache.hpp>
|
2021-09-26 15:21:46 +02:00
|
|
|
#include <components/loadinglistener/loadinglistener.hpp>
|
|
|
|
#include <components/lua/configuration.hpp>
|
2021-04-06 23:59:58 +02:00
|
|
|
#include <components/misc/algorithm.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
|
2022-12-30 11:28:19 +01:00
|
|
|
#include <components/esm4/common.hpp>
|
2022-12-28 20:48:25 +01:00
|
|
|
#include <components/esm4/loadcell.hpp>
|
2023-02-06 20:22:17 +01:00
|
|
|
#include <components/esm4/loadligh.hpp>
|
2022-12-28 20:48:25 +01:00
|
|
|
#include <components/esm4/loadrefr.hpp>
|
|
|
|
#include <components/esm4/loadstat.hpp>
|
|
|
|
#include <components/esm4/reader.hpp>
|
2022-12-30 11:28:19 +01:00
|
|
|
#include <components/esm4/readerutils.hpp>
|
2022-06-03 18:59:08 +02:00
|
|
|
#include <components/esmloader/load.hpp>
|
2015-01-25 01:53:20 +01:00
|
|
|
|
2020-07-28 08:33:28 +02:00
|
|
|
#include "../mwmechanics/spelllist.hpp"
|
|
|
|
|
2020-07-26 11:07:18 +02:00
|
|
|
namespace
|
|
|
|
{
|
2021-04-06 23:59:58 +02:00
|
|
|
struct Ref
|
|
|
|
{
|
|
|
|
ESM::RefNum mRefNum;
|
|
|
|
std::size_t mRefID;
|
|
|
|
|
|
|
|
Ref(ESM::RefNum refNum, std::size_t refID)
|
|
|
|
: mRefNum(refNum)
|
|
|
|
, mRefID(refID)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr std::size_t deletedRefID = std::numeric_limits<std::size_t>::max();
|
|
|
|
|
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
|
|
|
void readRefs(const ESM::Cell& cell, std::vector<Ref>& refs, std::vector<ESM::RefId>& refIDs,
|
|
|
|
std::set<ESM::RefId>& keyIDs, ESM::ReadersCache& readers)
|
2020-07-26 11:07:18 +02:00
|
|
|
{
|
2021-11-02 13:46:41 +00:00
|
|
|
// TODO: we have many similar copies of this code.
|
2020-07-26 11:07:18 +02:00
|
|
|
for (size_t i = 0; i < cell.mContextList.size(); i++)
|
|
|
|
{
|
2022-06-01 22:53:18 +02:00
|
|
|
const std::size_t index = static_cast<std::size_t>(cell.mContextList[i].index);
|
|
|
|
const ESM::ReadersCache::BusyItem reader = readers.get(index);
|
|
|
|
cell.restore(*reader, i);
|
2020-07-26 11:07:18 +02:00
|
|
|
ESM::CellRef ref;
|
|
|
|
bool deleted = false;
|
2022-06-01 22:53:18 +02:00
|
|
|
while (cell.getNextRef(*reader, ref, deleted))
|
2020-07-26 11:07:18 +02:00
|
|
|
{
|
|
|
|
if (deleted)
|
2021-04-06 23:59:58 +02:00
|
|
|
refs.emplace_back(ref.mRefNum, deletedRefID);
|
2020-07-26 11:07:18 +02:00
|
|
|
else if (std::find(cell.mMovedRefs.begin(), cell.mMovedRefs.end(), ref.mRefNum)
|
|
|
|
== cell.mMovedRefs.end())
|
|
|
|
{
|
2022-09-30 12:16:45 +02:00
|
|
|
if (!ref.mKey.empty())
|
|
|
|
keyIDs.insert(std::move(ref.mKey));
|
2021-04-06 23:59:58 +02:00
|
|
|
refs.emplace_back(ref.mRefNum, refIDs.size());
|
|
|
|
refIDs.push_back(std::move(ref.mRefID));
|
2020-07-26 11:07:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-06 23:59:58 +02:00
|
|
|
for (const auto& [value, deleted] : cell.mLeasedRefs)
|
2020-07-26 11:07:18 +02:00
|
|
|
{
|
|
|
|
if (deleted)
|
2021-04-06 23:59:58 +02:00
|
|
|
refs.emplace_back(value.mRefNum, deletedRefID);
|
2020-07-26 11:07:18 +02:00
|
|
|
else
|
|
|
|
{
|
2022-09-30 12:16:45 +02:00
|
|
|
if (!value.mKey.empty())
|
|
|
|
keyIDs.insert(std::move(value.mKey));
|
2021-04-06 23:59:58 +02:00
|
|
|
refs.emplace_back(value.mRefNum, refIDs.size());
|
|
|
|
refIDs.push_back(value.mRefID);
|
2020-07-26 11:07:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-23 21:07:57 +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& getDefaultClass(const MWWorld::Store<ESM::Class>& classes)
|
2021-03-23 21:07:57 +01:00
|
|
|
{
|
|
|
|
auto it = classes.begin();
|
|
|
|
if (it != classes.end())
|
2022-06-06 10:59:26 +02:00
|
|
|
return it->mId;
|
|
|
|
throw std::runtime_error("List of NPC classes is empty!");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ESM::NPC> getNPCsToReplace(const MWWorld::Store<ESM::Faction>& factions,
|
2022-10-18 09:26:55 +02:00
|
|
|
const MWWorld::Store<ESM::Class>& classes, const std::unordered_map<ESM::RefId, ESM::NPC>& npcs)
|
2022-06-06 10:59:26 +02:00
|
|
|
{
|
|
|
|
// Cache first class from store - we will use it if current class is not found
|
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& defaultCls = getDefaultClass(classes);
|
2021-03-23 21:07:57 +01:00
|
|
|
|
|
|
|
// Validate NPCs for non-existing class and faction.
|
|
|
|
// We will replace invalid entries by fixed ones
|
|
|
|
std::vector<ESM::NPC> npcsToReplace;
|
|
|
|
|
2021-05-15 19:50:01 +02:00
|
|
|
for (const auto& npcIter : npcs)
|
2021-03-23 21:07:57 +01:00
|
|
|
{
|
2021-04-17 10:53:47 +04:00
|
|
|
ESM::NPC npc = npcIter.second;
|
2021-03-23 21:07:57 +01:00
|
|
|
bool changed = false;
|
|
|
|
|
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& npcFaction = npc.mFaction;
|
2021-03-23 21:07:57 +01:00
|
|
|
if (!npcFaction.empty())
|
|
|
|
{
|
|
|
|
const ESM::Faction* fact = factions.search(npcFaction);
|
|
|
|
if (!fact)
|
|
|
|
{
|
|
|
|
Log(Debug::Verbose) << "NPC '" << npc.mId << "' (" << npc.mName << ") has nonexistent faction '"
|
|
|
|
<< npc.mFaction << "', ignoring it.";
|
2023-02-17 19:20:29 +01:00
|
|
|
npc.mFaction = ESM::RefId();
|
2021-03-23 21:07:57 +01:00
|
|
|
npc.mNpdt.mRank = 0;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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& npcClass = npc.mClass;
|
2022-06-06 10:59:26 +02:00
|
|
|
const ESM::Class* cls = classes.search(npcClass);
|
|
|
|
if (!cls)
|
2021-03-23 21:07:57 +01:00
|
|
|
{
|
2022-06-06 10:59:26 +02:00
|
|
|
Log(Debug::Verbose) << "NPC '" << npc.mId << "' (" << npc.mName << ") has nonexistent class '"
|
|
|
|
<< npc.mClass << "', using '" << defaultCls << "' class as replacement.";
|
|
|
|
npc.mClass = defaultCls;
|
|
|
|
changed = true;
|
2021-03-23 21:07:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
npcsToReplace.push_back(npc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return npcsToReplace;
|
|
|
|
}
|
2021-07-12 20:51:13 +02:00
|
|
|
|
|
|
|
// Custom enchanted items can reference scripts that no longer exist, this doesn't necessarily mean the base item no
|
|
|
|
// longer exists however. So instead of removing the item altogether, we're only removing the script.
|
2021-10-30 17:27:57 +00:00
|
|
|
template <class MapT>
|
|
|
|
void removeMissingScripts(const MWWorld::Store<ESM::Script>& scripts, MapT& items)
|
2021-07-12 20:51:13 +02:00
|
|
|
{
|
|
|
|
for (auto& [id, item] : items)
|
|
|
|
{
|
|
|
|
if (!item.mScript.empty() && !scripts.search(item.mScript))
|
|
|
|
{
|
2023-02-17 19:20:29 +01:00
|
|
|
item.mScript = ESM::RefId();
|
2021-07-12 20:51:13 +02:00
|
|
|
Log(Debug::Verbose) << "Item '" << id << "' (" << item.mName << ") has nonexistent script '"
|
|
|
|
<< item.mScript << "', ignoring it.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-26 11:07:18 +02:00
|
|
|
}
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
namespace MWWorld
|
2010-05-17 17:35:42 +02: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
|
|
|
using IDMap = std::unordered_map<ESM::RefId, int>;
|
2022-07-20 19:28:06 +02:00
|
|
|
|
2022-07-03 11:47:46 +02:00
|
|
|
struct ESMStoreImp
|
|
|
|
{
|
2022-09-05 18:38:59 +02:00
|
|
|
ESMStore::StoreTuple mStores;
|
2022-07-03 18:11:20 +02:00
|
|
|
|
2022-09-02 23:46:37 +02:00
|
|
|
std::map<ESM::RecNameInts, DynamicStore*> mRecNameToStore;
|
2022-07-03 18:11:20 +02:00
|
|
|
|
2022-07-20 19:28:06 +02:00
|
|
|
// Lookup of all IDs. Makes looking up references faster. Just
|
|
|
|
// maps the id name to the record type.
|
|
|
|
IDMap mIds;
|
|
|
|
IDMap mStaticIds;
|
|
|
|
|
2022-09-03 11:08:23 +02:00
|
|
|
template <typename T>
|
2022-09-06 23:30:51 +02:00
|
|
|
static void assignStoreToIndex(ESMStore& stores, Store<T>& store)
|
2022-07-03 18:11:20 +02:00
|
|
|
{
|
2022-09-03 16:36:53 +02:00
|
|
|
const std::size_t storeIndex = ESMStore::getTypeIndex<T>();
|
2022-09-03 13:32:44 +02:00
|
|
|
if (stores.mStores.size() <= storeIndex)
|
|
|
|
stores.mStores.resize(storeIndex + 1);
|
2022-07-19 17:58:21 +02:00
|
|
|
|
2022-09-03 11:08:23 +02:00
|
|
|
assert(&store == &std::get<Store<T>>(stores.mStoreImp->mStores));
|
|
|
|
|
|
|
|
stores.mStores[storeIndex] = &store;
|
2022-09-06 23:10:58 +02:00
|
|
|
if constexpr (std::is_convertible_v<Store<T>*, DynamicStore*>)
|
2022-07-23 16:41:42 +02:00
|
|
|
{
|
2022-09-03 11:08:23 +02:00
|
|
|
stores.mDynamicStores.push_back(&store);
|
2022-09-02 23:36:41 +02:00
|
|
|
constexpr ESM::RecNameInts recName = T::sRecordId;
|
2022-07-24 12:37:27 +02:00
|
|
|
if constexpr (recName != ESM::REC_INTERNAL_PLAYER)
|
|
|
|
{
|
2022-09-03 11:08:23 +02:00
|
|
|
stores.mStoreImp->mRecNameToStore[recName] = &store;
|
2022-07-24 12:37:27 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-03 11:08:23 +02:00
|
|
|
}
|
2022-12-28 20:48:25 +01:00
|
|
|
|
|
|
|
template <typename T>
|
2023-01-02 19:20:03 +01:00
|
|
|
static bool typedReadRecordESM4(ESM4::Reader& reader, Store<T>& store)
|
2022-12-28 20:48:25 +01:00
|
|
|
{
|
|
|
|
auto recordType = static_cast<ESM4::RecordTypes>(reader.hdr().record.typeId);
|
|
|
|
|
|
|
|
ESM::RecNameInts esm4RecName = static_cast<ESM::RecNameInts>(ESM::esm4Recname(recordType));
|
2022-12-30 11:28:19 +01:00
|
|
|
if constexpr (std::is_convertible_v<Store<T>*, DynamicStore*> && HasRecordId<T>::value)
|
2022-12-28 20:48:25 +01:00
|
|
|
{
|
|
|
|
if constexpr (ESM::isESM4Rec(T::sRecordId))
|
|
|
|
{
|
|
|
|
if (T::sRecordId == esm4RecName)
|
|
|
|
{
|
|
|
|
reader.getRecordData();
|
|
|
|
T value;
|
|
|
|
value.load(reader);
|
|
|
|
store.insertStatic(value);
|
2023-01-02 19:20:03 +01:00
|
|
|
return true;
|
2022-12-28 20:48:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-02 19:20:03 +01:00
|
|
|
return false;
|
2022-12-28 20:48:25 +01:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:28:19 +01:00
|
|
|
static bool readRecord(ESM4::Reader& reader, ESMStore& store)
|
2022-12-28 20:48:25 +01:00
|
|
|
{
|
2023-01-23 23:51:45 +01:00
|
|
|
return std::apply(
|
|
|
|
[&reader](auto&... x) { return (typedReadRecordESM4(reader, x) || ...); }, store.mStoreImp->mStores);
|
2022-12-28 20:48:25 +01:00
|
|
|
}
|
2022-07-03 11:47:46 +02: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
|
|
|
int ESMStore::find(const ESM::RefId& id) const
|
2022-07-20 19:28:06 +02:00
|
|
|
{
|
|
|
|
IDMap::const_iterator it = mStoreImp->mIds.find(id);
|
|
|
|
if (it == mStoreImp->mIds.end())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
int ESMStore::findStatic(const ESM::RefId& id) const
|
2022-07-20 19:28:06 +02:00
|
|
|
{
|
|
|
|
IDMap::const_iterator it = mStoreImp->mStaticIds.find(id);
|
|
|
|
if (it == mStoreImp->mStaticIds.end())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2022-07-03 11:47:46 +02:00
|
|
|
ESMStore::ESMStore()
|
|
|
|
{
|
2022-09-03 20:04:31 +02:00
|
|
|
mStoreImp = std::make_unique<ESMStoreImp>();
|
2022-09-06 14:27:53 +02:00
|
|
|
std::apply([this](auto&... x) { (ESMStoreImp::assignStoreToIndex(*this, x), ...); }, mStoreImp->mStores);
|
2022-07-03 11:47:46 +02:00
|
|
|
mDynamicCount = 0;
|
2022-07-03 18:11:20 +02:00
|
|
|
getWritable<ESM::Pathgrid>().setCells(getWritable<ESM::Cell>());
|
2022-07-03 11:47:46 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 23:10:58 +02:00
|
|
|
ESMStore::~ESMStore() = default;
|
2022-07-03 11:47:46 +02:00
|
|
|
|
2022-07-03 14:40:37 +02:00
|
|
|
void ESMStore::clearDynamic()
|
|
|
|
{
|
2022-09-03 11:08:23 +02:00
|
|
|
for (const auto& store : mDynamicStores)
|
2022-07-19 17:58:21 +02:00
|
|
|
store->clearDynamic();
|
2022-07-03 14:40:37 +02:00
|
|
|
|
|
|
|
movePlayerRecord();
|
|
|
|
}
|
|
|
|
|
2012-11-05 18:09:14 +04:00
|
|
|
static bool isCacheableRecord(int id)
|
|
|
|
{
|
2022-09-03 19:25:15 +02:00
|
|
|
switch (id)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-09-03 19:25:15 +02:00
|
|
|
case ESM::REC_ACTI:
|
|
|
|
case ESM::REC_ALCH:
|
|
|
|
case ESM::REC_APPA:
|
|
|
|
case ESM::REC_ARMO:
|
|
|
|
case ESM::REC_BOOK:
|
|
|
|
case ESM::REC_CLOT:
|
|
|
|
case ESM::REC_CONT:
|
|
|
|
case ESM::REC_CREA:
|
|
|
|
case ESM::REC_DOOR:
|
|
|
|
case ESM::REC_INGR:
|
|
|
|
case ESM::REC_LEVC:
|
|
|
|
case ESM::REC_LEVI:
|
|
|
|
case ESM::REC_LIGH:
|
|
|
|
case ESM::REC_LOCK:
|
|
|
|
case ESM::REC_MISC:
|
|
|
|
case ESM::REC_NPC_:
|
|
|
|
case ESM::REC_PROB:
|
|
|
|
case ESM::REC_REPA:
|
|
|
|
case ESM::REC_STAT:
|
|
|
|
case ESM::REC_WEAP:
|
|
|
|
case ESM::REC_BODY:
|
2023-01-23 23:51:45 +01:00
|
|
|
case ESM::REC_STAT4:
|
2023-02-06 20:22:17 +01:00
|
|
|
case ESM::REC_LIGH4:
|
2022-09-03 19:25:15 +02:00
|
|
|
return true;
|
|
|
|
break;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-11-05 18:09:14 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-16 16:28:39 +02:00
|
|
|
void ESMStore::load(ESM::ESMReader& esm, Loading::Listener* listener, ESM::Dialogue*& dialogue)
|
2010-05-17 17:35:42 +02:00
|
|
|
{
|
2022-06-03 18:59:08 +02:00
|
|
|
if (listener != nullptr)
|
|
|
|
listener->setProgressRange(::EsmLoader::fileProgress);
|
2013-08-27 15:48:13 +02:00
|
|
|
|
2015-11-27 21:40:36 +01:00
|
|
|
// Land texture loading needs to use a separate internal store for each plugin.
|
2021-11-03 08:02:06 +00:00
|
|
|
// We set the number of plugins here so we can properly verify if valid plugin
|
|
|
|
// indices are being passed to the LandTexture Store retrieval methods.
|
2022-07-03 18:11:20 +02:00
|
|
|
getWritable<ESM::LandTexture>().resize(esm.getIndex() + 1);
|
2012-11-25 17:19:29 +01:00
|
|
|
|
2010-08-06 15:19:39 +02:00
|
|
|
// Loop through all records
|
|
|
|
while (esm.hasMoreRecs())
|
2022-04-16 16:28:39 +02:00
|
|
|
{
|
2012-10-01 19:17:04 +04:00
|
|
|
ESM::NAME n = esm.getRecName();
|
2010-08-06 15:19:39 +02:00
|
|
|
esm.getRecHeader();
|
2022-04-16 16:28:39 +02:00
|
|
|
if (esm.getRecordFlags() & ESM::FLAG_Ignored)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-04-16 16:28:39 +02:00
|
|
|
esm.skipRecord();
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-17 17:35:42 +02:00
|
|
|
|
2010-08-06 15:19:39 +02:00
|
|
|
// Look up the record type.
|
2022-07-20 19:04:31 +02:00
|
|
|
ESM::RecNameInts recName = static_cast<ESM::RecNameInts>(n.toInt());
|
2022-09-02 23:39:38 +02:00
|
|
|
const auto& it = mStoreImp->mRecNameToStore.find(recName);
|
2012-11-05 18:09:14 +04:00
|
|
|
|
2022-09-02 23:39:38 +02:00
|
|
|
if (it == mStoreImp->mRecNameToStore.end())
|
2022-07-20 19:04:31 +02:00
|
|
|
{
|
|
|
|
if (recName == ESM::REC_INFO)
|
2014-05-31 00:36:37 +02:00
|
|
|
{
|
|
|
|
if (dialogue)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2014-05-31 00:36:37 +02:00
|
|
|
dialogue->readInfo(esm, esm.getIndex() != 0);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-14 23:05:43 +04:00
|
|
|
Log(Debug::Error) << "Error: info record without dialog";
|
2014-09-13 20:48:24 +02:00
|
|
|
esm.skipRecord();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2014-05-31 00:36:37 +02:00
|
|
|
}
|
|
|
|
else if (n.toInt() == ESM::REC_MGEF)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-07-03 18:11:20 +02:00
|
|
|
getWritable<ESM::MagicEffect>().load(esm);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-10-17 02:52:22 +02:00
|
|
|
else if (n.toInt() == ESM::REC_SKIL)
|
2014-05-31 00:36:37 +02:00
|
|
|
{
|
2018-08-14 23:05:43 +04:00
|
|
|
getWritable<ESM::Skill>().load(esm);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2018-08-14 23:05:43 +04:00
|
|
|
else if (n.toInt() == ESM::REC_FILT || n.toInt() == ESM::REC_DBGP)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2018-08-14 23:05:43 +04:00
|
|
|
// ignore project file only records
|
2010-08-06 15:19:39 +02:00
|
|
|
esm.skipRecord();
|
|
|
|
}
|
2021-09-26 15:21:46 +02:00
|
|
|
else if (n.toInt() == ESM::REC_LUAL)
|
|
|
|
{
|
|
|
|
ESM::LuaScriptsCfg cfg;
|
|
|
|
cfg.load(esm);
|
2022-05-20 21:47:13 +02:00
|
|
|
cfg.adjustRefNums(esm);
|
2021-09-26 15:21:46 +02:00
|
|
|
mLuaContent.push_back(std::move(cfg));
|
|
|
|
}
|
2014-09-13 20:48:24 +02:00
|
|
|
else
|
|
|
|
{
|
2021-06-10 12:55:18 +02:00
|
|
|
throw std::runtime_error("Unknown record: " + n.toString());
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-08-06 15:19:39 +02:00
|
|
|
}
|
2012-11-05 18:09:14 +04:00
|
|
|
else
|
2015-07-08 21:26:20 +03:00
|
|
|
{
|
2022-07-20 19:04:31 +02:00
|
|
|
RecordId id = it->second->load(esm);
|
2015-07-12 15:20:22 +03:00
|
|
|
if (id.mIsDeleted)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-07-20 19:04:31 +02:00
|
|
|
it->second->eraseStatic(id.mId);
|
2015-07-08 21:26:20 +03:00
|
|
|
continue;
|
2014-06-07 19:21:37 +02:00
|
|
|
}
|
|
|
|
|
2021-10-17 02:52:22 +02:00
|
|
|
if (n.toInt() == ESM::REC_DIAL)
|
|
|
|
{
|
2022-07-03 18:11:20 +02:00
|
|
|
dialogue = const_cast<ESM::Dialogue*>(getWritable<ESM::Dialogue>().find(id.mId));
|
2012-11-05 18:09:14 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 11:39:47 +04:00
|
|
|
dialogue = nullptr;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-11-05 18:09:14 +04:00
|
|
|
}
|
2022-06-03 18:59:08 +02:00
|
|
|
if (listener != nullptr)
|
|
|
|
listener->setProgress(::EsmLoader::fileProgress * esm.getFileOffset() / esm.getFileSize());
|
2010-08-06 15:19:39 +02:00
|
|
|
}
|
2010-05-17 17:35:42 +02:00
|
|
|
}
|
2012-10-01 19:17:04 +04:00
|
|
|
|
2023-01-04 12:20:02 +01:00
|
|
|
void ESMStore::loadESM4(ESM4::Reader& reader)
|
2022-12-28 20:48:25 +01:00
|
|
|
{
|
2022-12-30 11:28:19 +01:00
|
|
|
auto visitorRec = [this](ESM4::Reader& reader) { return ESMStoreImp::readRecord(reader, *this); };
|
|
|
|
ESM4::ReaderUtils::readAll(reader, visitorRec, [](ESM4::Reader&) {});
|
2022-12-28 20:48:25 +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
|
|
|
void ESMStore::setIdType(const ESM::RefId& id, ESM::RecNameInts type)
|
2022-09-06 14:19:55 +02:00
|
|
|
{
|
2022-09-07 18:45:15 +02:00
|
|
|
mStoreImp->mIds[id] = type;
|
2022-09-06 14:19:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-26 15:21:46 +02:00
|
|
|
ESM::LuaScriptsCfg ESMStore::getLuaScriptsCfg() const
|
|
|
|
{
|
2022-06-19 13:28:33 +02:00
|
|
|
ESM::LuaScriptsCfg cfg;
|
|
|
|
for (const LuaContent& c : mLuaContent)
|
2021-09-26 15:21:46 +02:00
|
|
|
{
|
|
|
|
if (std::holds_alternative<std::filesystem::path>(c))
|
|
|
|
{
|
|
|
|
// *.omwscripts are intentionally reloaded every time when `getLuaScriptsCfg` is called.
|
|
|
|
// It is important for the `reloadlua` console command.
|
2022-09-22 21:26:05 +03:00
|
|
|
try
|
|
|
|
{
|
2022-06-19 13:28:33 +02:00
|
|
|
auto file = std::ifstream(std::get<std::filesystem::path>(c));
|
2021-09-26 15:21:46 +02:00
|
|
|
std::string fileContent(std::istreambuf_iterator<char>(file), {});
|
|
|
|
LuaUtil::parseOMWScripts(cfg, fileContent);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-09-26 15:21:46 +02:00
|
|
|
catch (std::exception& e)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-09-26 15:21:46 +02:00
|
|
|
Log(Debug::Error) << e.what();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-26 15:21:46 +02:00
|
|
|
const ESM::LuaScriptsCfg& addition = std::get<ESM::LuaScriptsCfg>(c);
|
|
|
|
cfg.mScripts.insert(cfg.mScripts.end(), addition.mScripts.begin(), addition.mScripts.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
2022-06-01 22:53:18 +02:00
|
|
|
void ESMStore::setUp()
|
2012-11-05 18:09:14 +04:00
|
|
|
{
|
2022-07-20 19:28:06 +02:00
|
|
|
mStoreImp->mIds.clear();
|
2015-12-11 16:59:13 +01:00
|
|
|
|
2015-12-11 15:55:45 +01:00
|
|
|
std::map<ESM::RecNameInts, DynamicStore*>::iterator storeIt = mStoreImp->mRecNameToStore.begin();
|
|
|
|
for (; storeIt != mStoreImp->mRecNameToStore.end(); ++storeIt)
|
|
|
|
{
|
2022-07-20 19:04:31 +02:00
|
|
|
storeIt->second->setUp();
|
2015-12-11 15:55:45 +01:00
|
|
|
|
|
|
|
if (isCacheableRecord(storeIt->first))
|
2022-09-22 21:26:05 +03: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
|
|
|
std::vector<ESM::RefId> identifiers;
|
2022-07-20 19:04:31 +02:00
|
|
|
storeIt->second->listIdentifier(identifiers);
|
2022-09-22 21:26:05 +03: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
|
|
|
for (auto& record : identifiers)
|
|
|
|
mStoreImp->mIds[record] = storeIt->first;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2015-12-11 15:55:45 +01:00
|
|
|
}
|
2019-06-13 13:37:00 +00:00
|
|
|
|
2022-07-20 19:28:06 +02:00
|
|
|
if (mStoreImp->mStaticIds.empty())
|
|
|
|
for (const auto& [k, v] : mStoreImp->mIds)
|
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
|
|
|
mStoreImp->mStaticIds.emplace(k, v);
|
2019-06-13 13:37:00 +00:00
|
|
|
|
2022-07-03 18:11:20 +02:00
|
|
|
getWritable<ESM::Skill>().setUp();
|
|
|
|
getWritable<ESM::MagicEffect>().setUp();
|
2022-09-22 21:26:05 +03:00
|
|
|
;
|
2022-07-03 18:11:20 +02:00
|
|
|
getWritable<ESM::Attribute>().setUp();
|
|
|
|
getWritable<ESM::Dialogue>().setUp();
|
2020-07-26 11:07:18 +02:00
|
|
|
}
|
|
|
|
|
2022-06-01 22:53:18 +02:00
|
|
|
void ESMStore::validateRecords(ESM::ReadersCache& readers)
|
2021-04-06 23:59:58 +02:00
|
|
|
{
|
|
|
|
validate();
|
2022-09-30 12:16:45 +02:00
|
|
|
countAllCellRefsAndMarkKeys(readers);
|
2018-06-09 20:47:17 +04:00
|
|
|
}
|
|
|
|
|
2022-09-30 12:16:45 +02:00
|
|
|
void ESMStore::countAllCellRefsAndMarkKeys(ESM::ReadersCache& readers)
|
2018-06-09 20:47:17 +04:00
|
|
|
{
|
2022-07-19 17:58:21 +02:00
|
|
|
// TODO: We currently need to read entire files here again.
|
|
|
|
// We should consider consolidating or deferring this reading.
|
|
|
|
if (!mRefCount.empty())
|
|
|
|
return;
|
|
|
|
std::vector<Ref> refs;
|
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
|
|
|
std::set<ESM::RefId> keyIDs;
|
|
|
|
std::vector<ESM::RefId> refIDs;
|
2022-09-30 12:16:45 +02:00
|
|
|
Store<ESM::Cell> Cells = get<ESM::Cell>();
|
2022-07-19 17:58:21 +02:00
|
|
|
for (auto it = Cells.intBegin(); it != Cells.intEnd(); ++it)
|
2022-09-30 12:16:45 +02:00
|
|
|
readRefs(*it, refs, refIDs, keyIDs, readers);
|
2022-07-03 18:11:20 +02:00
|
|
|
for (auto it = Cells.extBegin(); it != Cells.extEnd(); ++it)
|
2022-09-30 12:16:45 +02:00
|
|
|
readRefs(*it, refs, refIDs, keyIDs, readers);
|
2022-07-19 17:58:21 +02:00
|
|
|
const auto lessByRefNum = [](const Ref& l, const Ref& r) { return l.mRefNum < r.mRefNum; };
|
|
|
|
std::stable_sort(refs.begin(), refs.end(), lessByRefNum);
|
2021-04-06 23:59:58 +02:00
|
|
|
const auto equalByRefNum = [](const Ref& l, const Ref& r) { return l.mRefNum == r.mRefNum; };
|
|
|
|
const auto incrementRefCount = [&](const Ref& value) {
|
|
|
|
if (value.mRefID != deletedRefID)
|
2022-09-22 21:26:05 +03: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
|
|
|
ESM::RefId& refId = refIDs[value.mRefID];
|
2021-04-06 23:59:58 +02:00
|
|
|
++mRefCount[std::move(refId)];
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
};
|
2022-07-19 17:58:21 +02:00
|
|
|
Misc::forEachUnique(refs.rbegin(), refs.rend(), equalByRefNum, incrementRefCount);
|
2022-09-30 12:16:45 +02:00
|
|
|
auto& store = getWritable<ESM::Miscellaneous>().mStatic;
|
2022-10-14 00:41:59 +02:00
|
|
|
for (const auto& id : keyIDs)
|
2022-09-30 12:16:45 +02:00
|
|
|
{
|
|
|
|
auto it = store.find(id);
|
|
|
|
if (it != store.end())
|
|
|
|
it->second.mData.mFlags |= ESM::Miscellaneous::Key;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2018-06-09 20:47:17 +04: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
|
|
|
int ESMStore::getRefCount(const ESM::RefId& id) const
|
2018-06-09 20:47:17 +04: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
|
|
|
auto it = mRefCount.find(id);
|
2020-07-26 11:07:18 +02:00
|
|
|
if (it == mRefCount.end())
|
|
|
|
return 0;
|
2022-07-19 17:58:21 +02:00
|
|
|
return it->second;
|
2018-06-09 20:47:17 +04:00
|
|
|
}
|
2019-03-31 18:54:12 +03:00
|
|
|
|
|
|
|
void ESMStore::validate()
|
|
|
|
{
|
2022-07-19 17:58:21 +02:00
|
|
|
auto& npcs = getWritable<ESM::NPC>();
|
2019-03-31 18:54:12 +03:00
|
|
|
std::vector<ESM::NPC> npcsToReplace
|
|
|
|
= getNPCsToReplace(getWritable<ESM::Faction>(), getWritable<ESM::Class>(), npcs.mStatic);
|
|
|
|
|
2019-05-31 11:23:58 +03:00
|
|
|
for (const ESM::NPC& npc : npcsToReplace)
|
2019-03-31 18:54:12 +03:00
|
|
|
{
|
2022-07-03 18:11:20 +02:00
|
|
|
npcs.eraseStatic(npc.mId);
|
2019-10-17 23:45:27 +03:00
|
|
|
npcs.insertStatic(npc);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 23:45:27 +03:00
|
|
|
// Validate spell effects for invalid arguments
|
|
|
|
std::vector<ESM::Spell> spellsToReplace;
|
2019-05-31 11:23:58 +03:00
|
|
|
auto& spells = getWritable<ESM::Spell>();
|
|
|
|
for (ESM::Spell spell : spells)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
if (spell.mEffects.mList.empty())
|
2019-03-31 18:54:12 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bool changed = false;
|
|
|
|
auto iter = spell.mEffects.mList.begin();
|
|
|
|
while (iter != spell.mEffects.mList.end())
|
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
const ESM::MagicEffect* mgef = getWritable<ESM::MagicEffect>().search(iter->mEffectID);
|
|
|
|
if (!mgef)
|
2019-03-31 18:54:12 +03:00
|
|
|
{
|
2019-10-17 23:45:27 +03:00
|
|
|
Log(Debug::Verbose) << "Spell '" << spell.mId << "' has an invalid effect (index "
|
|
|
|
<< iter->mEffectID << ") present. Dropping the effect.";
|
|
|
|
iter = spell.mEffects.mList.erase(iter);
|
2019-03-31 18:54:12 +03:00
|
|
|
changed = true;
|
|
|
|
continue;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2019-03-31 18:54:12 +03:00
|
|
|
if (mgef->mData.mFlags & ESM::MagicEffect::TargetSkill)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
if (iter->mAttribute != -1)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
iter->mAttribute = -1;
|
|
|
|
Log(Debug::Verbose)
|
|
|
|
<< ESM::MagicEffect::effectIdToString(iter->mEffectID) << " effect of spell '" << spell.mId
|
2019-10-17 23:45:27 +03:00
|
|
|
<< "' has an attribute argument present. Dropping the argument.";
|
2019-03-31 18:54:12 +03:00
|
|
|
changed = true;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2019-03-31 18:54:12 +03:00
|
|
|
else if (mgef->mData.mFlags & ESM::MagicEffect::TargetAttribute)
|
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
if (iter->mSkill != -1)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
iter->mSkill = -1;
|
|
|
|
Log(Debug::Verbose)
|
|
|
|
<< ESM::MagicEffect::effectIdToString(iter->mEffectID) << " effect of spell '" << spell.mId
|
2019-10-17 23:45:27 +03:00
|
|
|
<< "' has a skill argument present. Dropping the argument.";
|
2019-03-31 18:54:12 +03:00
|
|
|
changed = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 11:23:58 +03:00
|
|
|
else if (iter->mSkill != -1 || iter->mAttribute != -1)
|
2019-03-31 18:54:12 +03:00
|
|
|
{
|
2019-05-31 11:23:58 +03:00
|
|
|
iter->mSkill = -1;
|
|
|
|
iter->mAttribute = -1;
|
|
|
|
Log(Debug::Verbose) << ESM::MagicEffect::effectIdToString(iter->mEffectID) << " effect of spell '"
|
2019-10-17 23:45:27 +03:00
|
|
|
<< spell.mId << "' has argument(s) present. Dropping the argument(s).";
|
2019-03-31 18:54:12 +03:00
|
|
|
changed = true;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2019-05-31 11:23:58 +03:00
|
|
|
++iter;
|
2019-03-31 18:54:12 +03:00
|
|
|
}
|
2019-05-31 11:23:58 +03:00
|
|
|
|
2019-03-31 18:54:12 +03:00
|
|
|
if (changed)
|
2019-05-31 11:23:58 +03:00
|
|
|
spellsToReplace.emplace_back(spell);
|
2019-03-31 18:54:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const ESM::Spell& spell : spellsToReplace)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2019-03-31 18:54:12 +03:00
|
|
|
spells.eraseStatic(spell.mId);
|
|
|
|
spells.insertStatic(spell);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2019-03-31 18:54:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ESMStore::movePlayerRecord()
|
|
|
|
{
|
2022-09-06 23:10:58 +02:00
|
|
|
auto& npcs = getWritable<ESM::NPC>();
|
2022-10-18 09:26:55 +02:00
|
|
|
auto player = npcs.find(ESM::RefId::stringRefId("Player"));
|
2022-09-06 23:10:58 +02:00
|
|
|
npcs.insert(*player);
|
2019-03-31 18:54:12 +03:00
|
|
|
}
|
2022-07-03 11:47:46 +02:00
|
|
|
|
2021-03-23 21:07:57 +01:00
|
|
|
void ESMStore::validateDynamic()
|
|
|
|
{
|
2022-07-19 17:58:21 +02:00
|
|
|
auto& npcs = getWritable<ESM::NPC>();
|
2022-07-03 18:11:20 +02:00
|
|
|
auto& scripts = getWritable<ESM::Script>();
|
|
|
|
|
2022-07-19 17:58:21 +02:00
|
|
|
std::vector<ESM::NPC> npcsToReplace
|
|
|
|
= getNPCsToReplace(getWritable<ESM::Faction>(), getWritable<ESM::Class>(), npcs.mDynamic);
|
2021-03-23 21:07:57 +01:00
|
|
|
|
|
|
|
for (const ESM::NPC& npc : npcsToReplace)
|
2022-07-19 17:58:21 +02:00
|
|
|
npcs.insert(npc);
|
2021-07-12 20:51:13 +02:00
|
|
|
|
2022-07-03 18:11:20 +02:00
|
|
|
removeMissingScripts(scripts, getWritable<ESM::Armor>().mDynamic);
|
|
|
|
removeMissingScripts(scripts, getWritable<ESM::Book>().mDynamic);
|
|
|
|
removeMissingScripts(scripts, getWritable<ESM::Clothing>().mDynamic);
|
|
|
|
removeMissingScripts(scripts, getWritable<ESM::Weapon>().mDynamic);
|
2021-07-12 20:51:13 +02:00
|
|
|
|
2022-07-03 18:11:20 +02:00
|
|
|
removeMissingObjects(getWritable<ESM::CreatureLevList>());
|
|
|
|
removeMissingObjects(getWritable<ESM::ItemLevList>());
|
2021-07-12 20:51:13 +02:00
|
|
|
}
|
|
|
|
|
2023-01-23 23:51:45 +01:00
|
|
|
// Leveled lists can be modified by scripts. This removes items that no longer exist (presumably because the
|
|
|
|
// plugin was removed) from modified lists
|
2021-07-12 20:51:13 +02:00
|
|
|
template <class T>
|
|
|
|
void ESMStore::removeMissingObjects(Store<T>& store)
|
|
|
|
{
|
2021-07-13 21:18:24 +02:00
|
|
|
for (auto& entry : store.mDynamic)
|
2021-07-12 20:51:13 +02:00
|
|
|
{
|
|
|
|
auto first = std::remove_if(entry.second.mList.begin(), entry.second.mList.end(), [&](const auto& item) {
|
|
|
|
if (!find(item.mId))
|
|
|
|
{
|
2021-07-13 21:18:24 +02:00
|
|
|
Log(Debug::Verbose) << "Leveled list '" << entry.first << "' has nonexistent object '" << item.mId
|
|
|
|
<< "', ignoring it.";
|
2021-07-12 20:51:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2021-07-13 21:18:24 +02:00
|
|
|
entry.second.mList.erase(first, entry.second.mList.end());
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-07-12 20:51:13 +02:00
|
|
|
}
|
2021-03-23 21:07:57 +01:00
|
|
|
|
2013-12-07 13:17:28 +01:00
|
|
|
int ESMStore::countSavedGameRecords() const
|
|
|
|
{
|
2014-05-11 00:32:22 +02:00
|
|
|
return 1 // DYNA (dynamic name counter)
|
2022-07-03 18:11:20 +02:00
|
|
|
+ get<ESM::Potion>().getDynamicSize() + get<ESM::Armor>().getDynamicSize()
|
|
|
|
+ get<ESM::Book>().getDynamicSize() + get<ESM::Class>().getDynamicSize()
|
|
|
|
+ get<ESM::Clothing>().getDynamicSize() + get<ESM::Enchantment>().getDynamicSize()
|
|
|
|
+ get<ESM::NPC>().getDynamicSize() + get<ESM::Spell>().getDynamicSize()
|
|
|
|
+ get<ESM::Weapon>().getDynamicSize() + get<ESM::CreatureLevList>().getDynamicSize()
|
|
|
|
+ get<ESM::ItemLevList>().getDynamicSize() + get<ESM::Creature>().getDynamicSize()
|
|
|
|
+ get<ESM::Container>().getDynamicSize();
|
2013-12-07 13:17:28 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 11:29:57 +02:00
|
|
|
void ESMStore::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
|
2013-12-07 13:17:28 +01:00
|
|
|
{
|
2014-05-11 00:32:22 +02:00
|
|
|
writer.startRecord(ESM::REC_DYNA);
|
|
|
|
writer.startSubRecord("COUN");
|
|
|
|
writer.writeT(mDynamicCount);
|
|
|
|
writer.endRecord("COUN");
|
|
|
|
writer.endRecord(ESM::REC_DYNA);
|
|
|
|
|
2022-07-03 18:11:20 +02:00
|
|
|
get<ESM::Potion>().write(writer, progress);
|
|
|
|
get<ESM::Armor>().write(writer, progress);
|
|
|
|
get<ESM::Book>().write(writer, progress);
|
|
|
|
get<ESM::Class>().write(writer, progress);
|
|
|
|
get<ESM::Clothing>().write(writer, progress);
|
|
|
|
get<ESM::Enchantment>().write(writer, progress);
|
|
|
|
get<ESM::NPC>().write(writer, progress);
|
|
|
|
get<ESM::Spell>().write(writer, progress);
|
|
|
|
get<ESM::Weapon>().write(writer, progress);
|
|
|
|
get<ESM::CreatureLevList>().write(writer, progress);
|
|
|
|
get<ESM::ItemLevList>().write(writer, progress);
|
|
|
|
get<ESM::Creature>().write(writer, progress);
|
|
|
|
get<ESM::Container>().write(writer, progress);
|
2013-12-07 13:17:28 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 19:04:31 +02:00
|
|
|
bool ESMStore::readRecord(ESM::ESMReader& reader, uint32_t type_id)
|
2013-12-07 13:17:28 +01:00
|
|
|
{
|
2022-07-20 19:04:31 +02:00
|
|
|
ESM::RecNameInts type = (ESM::RecNameInts)type_id;
|
2013-12-07 13:17:28 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ESM::REC_ALCH:
|
|
|
|
case ESM::REC_ARMO:
|
|
|
|
case ESM::REC_BOOK:
|
|
|
|
case ESM::REC_CLAS:
|
|
|
|
case ESM::REC_CLOT:
|
|
|
|
case ESM::REC_ENCH:
|
|
|
|
case ESM::REC_SPEL:
|
|
|
|
case ESM::REC_WEAP:
|
2014-12-17 01:05:32 +01:00
|
|
|
case ESM::REC_LEVI:
|
|
|
|
case ESM::REC_LEVC:
|
2022-09-02 23:39:38 +02:00
|
|
|
mStoreImp->mRecNameToStore[type]->read(reader);
|
2021-03-22 22:29:10 +01:00
|
|
|
return true;
|
|
|
|
case ESM::REC_NPC_:
|
2020-06-02 21:59:37 +02:00
|
|
|
case ESM::REC_CREA:
|
2020-10-29 13:55:24 +01:00
|
|
|
case ESM::REC_CONT:
|
2022-09-02 23:39:38 +02:00
|
|
|
mStoreImp->mRecNameToStore[type]->read(reader, true);
|
2013-12-07 13:17:28 +01:00
|
|
|
return true;
|
|
|
|
|
2014-05-11 00:32:22 +02:00
|
|
|
case ESM::REC_DYNA:
|
|
|
|
reader.getSubNameIs("COUN");
|
|
|
|
reader.getHT(mDynamicCount);
|
|
|
|
return true;
|
|
|
|
|
2013-12-07 13:17:28 +01:00
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 21:59:37 +02:00
|
|
|
void ESMStore::checkPlayer()
|
|
|
|
{
|
|
|
|
setUp();
|
|
|
|
|
2022-10-18 09:26:55 +02:00
|
|
|
const ESM::NPC* player = get<ESM::NPC>().find(ESM::RefId::stringRefId("Player"));
|
2020-06-02 21:59:37 +02:00
|
|
|
|
2022-07-03 18:11:20 +02:00
|
|
|
if (!get<ESM::Race>().find(player->mRace) || !get<ESM::Class>().find(player->mClass))
|
2020-06-02 21:59:37 +02:00
|
|
|
throw std::runtime_error("Invalid player record (race or class unavailable");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
std::pair<std::shared_ptr<MWMechanics::SpellList>, bool> ESMStore::getSpellList(const ESM::RefId& id) const
|
2020-07-28 08:33:28 +02:00
|
|
|
{
|
|
|
|
auto result = mSpellListCache.find(id);
|
|
|
|
std::shared_ptr<MWMechanics::SpellList> ptr;
|
|
|
|
if (result != mSpellListCache.end())
|
|
|
|
ptr = result->second.lock();
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
int type = find(id);
|
|
|
|
ptr = std::make_shared<MWMechanics::SpellList>(id, type);
|
|
|
|
if (result != mSpellListCache.end())
|
|
|
|
result->second = ptr;
|
|
|
|
else
|
|
|
|
mSpellListCache.insert({ id, ptr });
|
|
|
|
return { ptr, false };
|
|
|
|
}
|
|
|
|
return { ptr, true };
|
|
|
|
}
|
2022-07-03 11:47:46 +02:00
|
|
|
|
|
|
|
template <>
|
|
|
|
const ESM::Cell* ESMStore::insert<ESM::Cell>(const ESM::Cell& cell)
|
|
|
|
{
|
2022-07-03 18:11:20 +02:00
|
|
|
return getWritable<ESM::Cell>().insert(cell);
|
2022-07-03 11:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
const ESM::NPC* ESMStore::insert<ESM::NPC>(const ESM::NPC& npc)
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2022-07-19 17:58:21 +02:00
|
|
|
auto& npcs = getWritable<ESM::NPC>();
|
2022-10-18 09:26:55 +02:00
|
|
|
if (npc.mId == "Player")
|
2022-07-03 11:47:46 +02:00
|
|
|
{
|
2022-07-19 17:58:21 +02:00
|
|
|
return npcs.insert(npc);
|
2022-07-03 11:47:46 +02: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 id = ESM::RefId::stringRefId("$dynamic" + std::to_string(mDynamicCount++));
|
2022-09-05 18:04:10 +02:00
|
|
|
if (npcs.search(id) != nullptr)
|
2022-07-03 11:47:46 +02: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 std::string msg = "Try to override existing record '" + id.getRefIdString() + "'";
|
2022-07-03 11:47:46 +02:00
|
|
|
throw std::runtime_error(msg);
|
|
|
|
}
|
|
|
|
ESM::NPC record = npc;
|
|
|
|
|
|
|
|
record.mId = id;
|
|
|
|
|
2022-07-19 17:58:21 +02:00
|
|
|
ESM::NPC* ptr = npcs.insert(record);
|
2022-07-20 19:28:06 +02:00
|
|
|
mStoreImp->mIds[ptr->mId] = ESM::REC_NPC_;
|
2022-07-03 11:47:46 +02:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
} // end namespace
|