add content issues (WIP)

This commit is contained in:
MihailRis 2024-09-02 09:31:53 +03:00
parent 3dda512468
commit c1ef4dbe9f
6 changed files with 78 additions and 30 deletions

View File

@ -24,15 +24,15 @@ namespace rigging {
class SkeletonConfig; class SkeletonConfig;
} }
constexpr const char* contenttype_name(contenttype type) { constexpr const char* contenttype_name(ContentType type) {
switch (type) { switch (type) {
case contenttype::none: case ContentType::NONE:
return "none"; return "none";
case contenttype::block: case ContentType::BLOCK:
return "block"; return "block";
case contenttype::item: case ContentType::ITEM:
return "item"; return "item";
case contenttype::entity: case ContentType::ENTITY:
return "entity"; return "entity";
default: default:
return "unknown"; return "unknown";
@ -40,13 +40,13 @@ constexpr const char* contenttype_name(contenttype type) {
} }
class namereuse_error : public std::runtime_error { class namereuse_error : public std::runtime_error {
contenttype type; ContentType type;
public: public:
namereuse_error(const std::string& msg, contenttype type) namereuse_error(const std::string& msg, ContentType type)
: std::runtime_error(msg), type(type) { : std::runtime_error(msg), type(type) {
} }
inline contenttype getType() const { inline ContentType getType() const {
return type; return type;
} }
}; };

View File

@ -12,8 +12,8 @@
template <class T> template <class T>
class ContentUnitBuilder { class ContentUnitBuilder {
std::unordered_map<std::string, contenttype>& allNames; std::unordered_map<std::string, ContentType>& allNames;
contenttype type; ContentType type;
void checkIdentifier(const std::string& id) { void checkIdentifier(const std::string& id) {
const auto& found = allNames.find(id); const auto& found = allNames.find(id);
@ -28,7 +28,7 @@ public:
std::vector<std::string> names; std::vector<std::string> names;
ContentUnitBuilder( ContentUnitBuilder(
std::unordered_map<std::string, contenttype>& allNames, contenttype type std::unordered_map<std::string, ContentType>& allNames, ContentType type
) )
: allNames(allNames), type(type) { : allNames(allNames), type(type) {
} }
@ -62,11 +62,11 @@ class ContentBuilder {
UptrsMap<std::string, BlockMaterial> blockMaterials; UptrsMap<std::string, BlockMaterial> blockMaterials;
UptrsMap<std::string, rigging::SkeletonConfig> skeletons; UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
UptrsMap<std::string, ContentPackRuntime> packs; UptrsMap<std::string, ContentPackRuntime> packs;
std::unordered_map<std::string, contenttype> allNames; std::unordered_map<std::string, ContentType> allNames;
public: public:
ContentUnitBuilder<Block> blocks {allNames, contenttype::block}; ContentUnitBuilder<Block> blocks {allNames, ContentType::BLOCK};
ContentUnitBuilder<ItemDef> items {allNames, contenttype::item}; ContentUnitBuilder<ItemDef> items {allNames, ContentType::ITEM};
ContentUnitBuilder<EntityDef> entities {allNames, contenttype::entity}; ContentUnitBuilder<EntityDef> entities {allNames, ContentType::ENTITY};
ResourceIndicesSet resourceIndices {}; ResourceIndicesSet resourceIndices {};
~ContentBuilder(); ~ContentBuilder();

View File

@ -12,11 +12,13 @@
#include "Content.hpp" #include "Content.hpp"
ContentLUT::ContentLUT( ContentLUT::ContentLUT(
const ContentIndices* indices, size_t blocksCount, size_t itemsCount const ContentIndices* indices,
size_t blocksCount,
size_t itemsCount
) )
: blocks(blocksCount, indices->blocks, BLOCK_VOID, contenttype::block), : blocks(blocksCount, indices->blocks, BLOCK_VOID, ContentType::BLOCK),
items(itemsCount, indices->items, ITEM_VOID, contenttype::item) { items(itemsCount, indices->items, ITEM_VOID, ContentType::ITEM)
} {}
template <class T> template <class T>
static constexpr size_t get_entries_count( static constexpr size_t get_entries_count(
@ -47,6 +49,7 @@ std::shared_ptr<ContentLUT> ContentLUT::create(
lut->blocks.setup(blocklist.get(), content->blocks); lut->blocks.setup(blocklist.get(), content->blocks);
lut->items.setup(itemlist.get(), content->items); lut->items.setup(itemlist.get(), content->items);
lut->buildIssues();
if (lut->hasContentReorder() || lut->hasMissingContent()) { if (lut->hasContentReorder() || lut->hasMissingContent()) {
return lut; return lut;
@ -55,8 +58,31 @@ std::shared_ptr<ContentLUT> ContentLUT::create(
} }
} }
std::vector<contententry> ContentLUT::getMissingContent() const { template<class T, class U>
std::vector<contententry> entries; static void build_issues(
std::vector<ContentIssue>& issues,
const ContentUnitLUT<T, U>& lut
) {
auto type = lut.getContentType();
if (lut.hasContentReorder()) {
issues.push_back(ContentIssue {ContentIssueType::REORDER, type});
}
if (lut.hasMissingContent()) {
issues.push_back(ContentIssue {ContentIssueType::MISSING, type});
}
}
void ContentLUT::buildIssues() {
build_issues(issues, blocks);
build_issues(issues, items);
}
const std::vector<ContentIssue>& ContentLUT::getIssues() const {
return issues;
}
std::vector<ContentEntry> ContentLUT::getMissingContent() const {
std::vector<ContentEntry> entries;
blocks.getMissingContent(entries); blocks.getMissingContent(entries);
items.getMissingContent(entries); items.getMissingContent(entries);
return entries; return entries;

View File

@ -12,8 +12,18 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
struct contententry { enum class ContentIssueType {
contenttype type; REORDER,
MISSING,
};
struct ContentIssue {
ContentIssueType issueType;
ContentType contentType;
};
struct ContentEntry {
ContentType type;
std::string name; std::string name;
}; };
@ -26,13 +36,13 @@ class ContentUnitLUT {
bool missingContent = false; bool missingContent = false;
bool reorderContent = false; bool reorderContent = false;
T missingValue; T missingValue;
contenttype type; ContentType type;
public: public:
ContentUnitLUT( ContentUnitLUT(
size_t count, size_t count,
const ContentUnitIndices<U>& unitIndices, const ContentUnitIndices<U>& unitIndices,
T missingValue, T missingValue,
contenttype type ContentType type
) )
: missingValue(missingValue), type(type) { : missingValue(missingValue), type(type) {
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
@ -57,11 +67,11 @@ public:
} }
} }
} }
void getMissingContent(std::vector<contententry>& entries) const { void getMissingContent(std::vector<ContentEntry>& entries) const {
for (size_t i = 0; i < count(); i++) { for (size_t i = 0; i < count(); i++) {
if (indices[i] == missingValue) { if (indices[i] == missingValue) {
auto& name = names[i]; auto& name = names[i];
entries.push_back(contententry {type, name}); entries.push_back(ContentEntry {type, name});
} }
} }
} }
@ -80,6 +90,9 @@ public:
reorderContent = true; reorderContent = true;
} }
} }
inline ContentType getContentType() const {
return type;
}
inline size_t count() const { inline size_t count() const {
return indices.size(); return indices.size();
} }
@ -99,7 +112,13 @@ public:
ContentUnitLUT<blockid_t, Block> blocks; ContentUnitLUT<blockid_t, Block> blocks;
ContentUnitLUT<itemid_t, ItemDef> items; ContentUnitLUT<itemid_t, ItemDef> items;
ContentLUT(const ContentIndices* indices, size_t blocks, size_t items); std::vector<ContentIssue> issues;
ContentLUT(
const ContentIndices* indices,
size_t blocks,
size_t items
);
static std::shared_ptr<ContentLUT> create( static std::shared_ptr<ContentLUT> create(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
@ -113,6 +132,8 @@ public:
inline bool hasMissingContent() const { inline bool hasMissingContent() const {
return blocks.hasMissingContent() || items.hasMissingContent(); return blocks.hasMissingContent() || items.hasMissingContent();
} }
void buildIssues();
std::vector<contententry> getMissingContent() const; const std::vector<ContentIssue>& getIssues() const;
std::vector<ContentEntry> getMissingContent() const;
}; };

View File

@ -5,7 +5,7 @@
class Content; class Content;
class ContentPackRuntime; class ContentPackRuntime;
enum class contenttype { none, block, item, entity }; enum class ContentType { NONE, BLOCK, ITEM, ENTITY };
enum class ResourceType : size_t { CAMERA, LAST = CAMERA }; enum class ResourceType : size_t { CAMERA, LAST = CAMERA };

View File

@ -109,6 +109,7 @@ static void write_indices(
void WorldFiles::writeIndices(const ContentIndices* indices) { void WorldFiles::writeIndices(const ContentIndices* indices) {
dynamic::Map root; dynamic::Map root;
root.put("region-version", REGION_FORMAT_VERSION);
write_indices(indices->blocks, root.putList("blocks")); write_indices(indices->blocks, root.putList("blocks"));
write_indices(indices->items, root.putList("items")); write_indices(indices->items, root.putList("items"));
write_indices(indices->entities, root.putList("entities")); write_indices(indices->entities, root.putList("entities"));