1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 13:23:53 +00:00
openmw/apps/opencs/model/world/infocollection.hpp
elsid e892c62b10
Fix loading, inserting and moving topic info records
Topic info records need to have specific order defined via mNext and mPrev
fields (next and previous records). When loading multiple files a record may be
inserted into middle of the topic but neighborhood records may not be aware of
it. Having the order it's possible to move the records within one topic.

Sort the record once after loading all content files but preserve the order for
all other operations. Use std::map to group info ids by topic to make sure the
topics order is stable. Keep order within a topic for info ids on loading new
records. Use this order later for sorting the records.
2023-03-13 21:57:38 +01:00

60 lines
1.4 KiB
C++

#ifndef CSM_WOLRD_INFOCOLLECTION_H
#define CSM_WOLRD_INFOCOLLECTION_H
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "collection.hpp"
#include "info.hpp"
namespace ESM
{
struct Dialogue;
class ESMReader;
template <class T>
class InfoOrder;
}
namespace CSMWorld
{
using InfosRecordPtrByTopic = std::unordered_map<ESM::RefId, std::vector<const Record<Info>*>>;
struct OrderedInfo
{
ESM::RefId mId;
ESM::RefId mNext;
ESM::RefId mPrev;
explicit OrderedInfo(const Info& info)
: mId(info.mOriginalId)
, mNext(info.mNext)
, mPrev(info.mPrev)
{
}
};
using InfoOrder = ESM::InfoOrder<OrderedInfo>;
using InfoOrderByTopic = std::map<ESM::RefId, ESM::InfoOrder<OrderedInfo>>;
class InfoCollection : public Collection<Info>
{
private:
void load(const Info& value, bool base);
public:
void load(ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue, InfoOrderByTopic& infoOrder);
void sort(const InfoOrderByTopic& infoOrders);
InfosRecordPtrByTopic getInfosByTopic() const;
int getAppendIndex(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None) const override;
bool reorderRows(int baseIndex, const std::vector<int>& newOrder) override;
};
}
#endif