From c1ef4dbe9f998dd58176846b4e117af651ae989d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 2 Sep 2024 09:31:53 +0300 Subject: [PATCH] add content issues (WIP) --- src/content/Content.hpp | 16 +++++++------- src/content/ContentBuilder.hpp | 14 ++++++------- src/content/ContentLUT.cpp | 38 ++++++++++++++++++++++++++++------ src/content/ContentLUT.hpp | 37 ++++++++++++++++++++++++++------- src/content/content_fwd.hpp | 2 +- src/files/WorldFiles.cpp | 1 + 6 files changed, 78 insertions(+), 30 deletions(-) diff --git a/src/content/Content.hpp b/src/content/Content.hpp index 1931c262..e2275612 100644 --- a/src/content/Content.hpp +++ b/src/content/Content.hpp @@ -24,15 +24,15 @@ namespace rigging { class SkeletonConfig; } -constexpr const char* contenttype_name(contenttype type) { +constexpr const char* contenttype_name(ContentType type) { switch (type) { - case contenttype::none: + case ContentType::NONE: return "none"; - case contenttype::block: + case ContentType::BLOCK: return "block"; - case contenttype::item: + case ContentType::ITEM: return "item"; - case contenttype::entity: + case ContentType::ENTITY: return "entity"; default: return "unknown"; @@ -40,13 +40,13 @@ constexpr const char* contenttype_name(contenttype type) { } class namereuse_error : public std::runtime_error { - contenttype type; + ContentType type; public: - namereuse_error(const std::string& msg, contenttype type) + namereuse_error(const std::string& msg, ContentType type) : std::runtime_error(msg), type(type) { } - inline contenttype getType() const { + inline ContentType getType() const { return type; } }; diff --git a/src/content/ContentBuilder.hpp b/src/content/ContentBuilder.hpp index d3e8f536..7961d1bf 100644 --- a/src/content/ContentBuilder.hpp +++ b/src/content/ContentBuilder.hpp @@ -12,8 +12,8 @@ template class ContentUnitBuilder { - std::unordered_map& allNames; - contenttype type; + std::unordered_map& allNames; + ContentType type; void checkIdentifier(const std::string& id) { const auto& found = allNames.find(id); @@ -28,7 +28,7 @@ public: std::vector names; ContentUnitBuilder( - std::unordered_map& allNames, contenttype type + std::unordered_map& allNames, ContentType type ) : allNames(allNames), type(type) { } @@ -62,11 +62,11 @@ class ContentBuilder { UptrsMap blockMaterials; UptrsMap skeletons; UptrsMap packs; - std::unordered_map allNames; + std::unordered_map allNames; public: - ContentUnitBuilder blocks {allNames, contenttype::block}; - ContentUnitBuilder items {allNames, contenttype::item}; - ContentUnitBuilder entities {allNames, contenttype::entity}; + ContentUnitBuilder blocks {allNames, ContentType::BLOCK}; + ContentUnitBuilder items {allNames, ContentType::ITEM}; + ContentUnitBuilder entities {allNames, ContentType::ENTITY}; ResourceIndicesSet resourceIndices {}; ~ContentBuilder(); diff --git a/src/content/ContentLUT.cpp b/src/content/ContentLUT.cpp index 8e670152..80c0699c 100644 --- a/src/content/ContentLUT.cpp +++ b/src/content/ContentLUT.cpp @@ -12,11 +12,13 @@ #include "Content.hpp" 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), - items(itemsCount, indices->items, ITEM_VOID, contenttype::item) { -} + : blocks(blocksCount, indices->blocks, BLOCK_VOID, ContentType::BLOCK), + items(itemsCount, indices->items, ITEM_VOID, ContentType::ITEM) +{} template static constexpr size_t get_entries_count( @@ -47,6 +49,7 @@ std::shared_ptr ContentLUT::create( lut->blocks.setup(blocklist.get(), content->blocks); lut->items.setup(itemlist.get(), content->items); + lut->buildIssues(); if (lut->hasContentReorder() || lut->hasMissingContent()) { return lut; @@ -55,8 +58,31 @@ std::shared_ptr ContentLUT::create( } } -std::vector ContentLUT::getMissingContent() const { - std::vector entries; +template +static void build_issues( + std::vector& issues, + const ContentUnitLUT& 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& ContentLUT::getIssues() const { + return issues; +} + +std::vector ContentLUT::getMissingContent() const { + std::vector entries; blocks.getMissingContent(entries); items.getMissingContent(entries); return entries; diff --git a/src/content/ContentLUT.hpp b/src/content/ContentLUT.hpp index f0b92c07..20259114 100644 --- a/src/content/ContentLUT.hpp +++ b/src/content/ContentLUT.hpp @@ -12,8 +12,18 @@ namespace fs = std::filesystem; -struct contententry { - contenttype type; +enum class ContentIssueType { + REORDER, + MISSING, +}; + +struct ContentIssue { + ContentIssueType issueType; + ContentType contentType; +}; + +struct ContentEntry { + ContentType type; std::string name; }; @@ -26,13 +36,13 @@ class ContentUnitLUT { bool missingContent = false; bool reorderContent = false; T missingValue; - contenttype type; + ContentType type; public: ContentUnitLUT( size_t count, const ContentUnitIndices& unitIndices, T missingValue, - contenttype type + ContentType type ) : missingValue(missingValue), type(type) { for (size_t i = 0; i < count; i++) { @@ -57,11 +67,11 @@ public: } } } - void getMissingContent(std::vector& entries) const { + void getMissingContent(std::vector& entries) const { for (size_t i = 0; i < count(); i++) { if (indices[i] == missingValue) { auto& name = names[i]; - entries.push_back(contententry {type, name}); + entries.push_back(ContentEntry {type, name}); } } } @@ -80,6 +90,9 @@ public: reorderContent = true; } } + inline ContentType getContentType() const { + return type; + } inline size_t count() const { return indices.size(); } @@ -99,7 +112,13 @@ public: ContentUnitLUT blocks; ContentUnitLUT items; - ContentLUT(const ContentIndices* indices, size_t blocks, size_t items); + std::vector issues; + + ContentLUT( + const ContentIndices* indices, + size_t blocks, + size_t items + ); static std::shared_ptr create( const std::shared_ptr& worldFiles, @@ -113,6 +132,8 @@ public: inline bool hasMissingContent() const { return blocks.hasMissingContent() || items.hasMissingContent(); } + void buildIssues(); - std::vector getMissingContent() const; + const std::vector& getIssues() const; + std::vector getMissingContent() const; }; diff --git a/src/content/content_fwd.hpp b/src/content/content_fwd.hpp index 719fbfca..b1618593 100644 --- a/src/content/content_fwd.hpp +++ b/src/content/content_fwd.hpp @@ -5,7 +5,7 @@ class Content; class ContentPackRuntime; -enum class contenttype { none, block, item, entity }; +enum class ContentType { NONE, BLOCK, ITEM, ENTITY }; enum class ResourceType : size_t { CAMERA, LAST = CAMERA }; diff --git a/src/files/WorldFiles.cpp b/src/files/WorldFiles.cpp index 33ebaf37..01b9cb77 100644 --- a/src/files/WorldFiles.cpp +++ b/src/files/WorldFiles.cpp @@ -109,6 +109,7 @@ static void write_indices( void WorldFiles::writeIndices(const ContentIndices* indices) { dynamic::Map root; + root.put("region-version", REGION_FORMAT_VERSION); write_indices(indices->blocks, root.putList("blocks")); write_indices(indices->items, root.putList("items")); write_indices(indices->entities, root.putList("entities"));