From 3f826a88d31dce8831939b577ad9e7b73526ef28 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 2 Sep 2024 09:40:00 +0300 Subject: [PATCH] rename ContentLUT to ContentReport --- .../{ContentLUT.cpp => ContentReport.cpp} | 33 +++++++++---------- .../{ContentLUT.hpp => ContentReport.hpp} | 9 +++-- src/files/WorldConverter.cpp | 16 ++++----- src/files/WorldConverter.hpp | 8 ++--- src/items/Inventory.cpp | 6 ++-- src/items/Inventory.hpp | 4 +-- src/logic/EngineController.cpp | 28 ++++++++-------- src/objects/Player.cpp | 8 ++--- src/objects/Player.hpp | 4 +-- src/voxels/Chunk.cpp | 6 ++-- src/voxels/Chunk.hpp | 4 +-- src/world/World.cpp | 6 ++-- src/world/World.hpp | 4 +-- 13 files changed, 67 insertions(+), 69 deletions(-) rename src/content/{ContentLUT.cpp => ContentReport.cpp} (67%) rename src/content/{ContentLUT.hpp => ContentReport.hpp} (91%) diff --git a/src/content/ContentLUT.cpp b/src/content/ContentReport.cpp similarity index 67% rename from src/content/ContentLUT.cpp rename to src/content/ContentReport.cpp index 80c0699c..54b4098d 100644 --- a/src/content/ContentLUT.cpp +++ b/src/content/ContentReport.cpp @@ -1,4 +1,4 @@ -#include "ContentLUT.hpp" +#include "ContentReport.hpp" #include @@ -11,7 +11,7 @@ #include "files/WorldFiles.hpp" #include "Content.hpp" -ContentLUT::ContentLUT( +ContentReport::ContentReport( const ContentIndices* indices, size_t blocksCount, size_t itemsCount @@ -27,7 +27,7 @@ static constexpr size_t get_entries_count( return list ? std::max(list->size(), indices.count()) : indices.count(); } -std::shared_ptr ContentLUT::create( +std::shared_ptr ContentReport::create( const std::shared_ptr& worldFiles, const fs::path& filename, const Content* content @@ -45,14 +45,13 @@ std::shared_ptr ContentLUT::create( size_t blocks_c = get_entries_count(indices->blocks, blocklist); size_t items_c = get_entries_count(indices->items, itemlist); - auto lut = std::make_shared(indices, blocks_c, items_c); + auto report = std::make_shared(indices, blocks_c, items_c); + report->blocks.setup(blocklist.get(), content->blocks); + report->items.setup(itemlist.get(), content->items); + report->buildIssues(); - lut->blocks.setup(blocklist.get(), content->blocks); - lut->items.setup(itemlist.get(), content->items); - lut->buildIssues(); - - if (lut->hasContentReorder() || lut->hasMissingContent()) { - return lut; + if (report->hasContentReorder() || report->hasMissingContent()) { + return report; } else { return nullptr; } @@ -61,27 +60,27 @@ std::shared_ptr ContentLUT::create( template static void build_issues( std::vector& issues, - const ContentUnitLUT& lut + const ContentUnitLUT& report ) { - auto type = lut.getContentType(); - if (lut.hasContentReorder()) { + auto type = report.getContentType(); + if (report.hasContentReorder()) { issues.push_back(ContentIssue {ContentIssueType::REORDER, type}); } - if (lut.hasMissingContent()) { + if (report.hasMissingContent()) { issues.push_back(ContentIssue {ContentIssueType::MISSING, type}); } } -void ContentLUT::buildIssues() { +void ContentReport::buildIssues() { build_issues(issues, blocks); build_issues(issues, items); } -const std::vector& ContentLUT::getIssues() const { +const std::vector& ContentReport::getIssues() const { return issues; } -std::vector ContentLUT::getMissingContent() const { +std::vector ContentReport::getMissingContent() const { std::vector entries; blocks.getMissingContent(entries); items.getMissingContent(entries); diff --git a/src/content/ContentLUT.hpp b/src/content/ContentReport.hpp similarity index 91% rename from src/content/ContentLUT.hpp rename to src/content/ContentReport.hpp index 20259114..d4c1a056 100644 --- a/src/content/ContentLUT.hpp +++ b/src/content/ContentReport.hpp @@ -104,23 +104,22 @@ public: } }; -/// @brief Content indices lookup table or report -/// used to convert world with different indices +/// @brief Content incapatibility report used to convert world. /// Building with indices.json -class ContentLUT { +class ContentReport { public: ContentUnitLUT blocks; ContentUnitLUT items; std::vector issues; - ContentLUT( + ContentReport( const ContentIndices* indices, size_t blocks, size_t items ); - static std::shared_ptr create( + static std::shared_ptr create( const std::shared_ptr& worldFiles, const fs::path& filename, const Content* content diff --git a/src/files/WorldConverter.cpp b/src/files/WorldConverter.cpp index 8e23e432..c94708dd 100644 --- a/src/files/WorldConverter.cpp +++ b/src/files/WorldConverter.cpp @@ -5,7 +5,7 @@ #include #include -#include "content/ContentLUT.hpp" +#include "content/ContentReport.hpp" #include "data/dynamic.hpp" #include "debug/Logger.hpp" #include "files/files.hpp" @@ -34,10 +34,10 @@ public: WorldConverter::WorldConverter( const std::shared_ptr& worldFiles, const Content* content, - std::shared_ptr lut + std::shared_ptr report ) : wfile(worldFiles), - lut(std::move(lut)), + report(std::move(report)), content(content) { fs::path regionsFolder = wfile->getRegions().getRegionsFolder(REGION_LAYER_VOXELS); @@ -58,11 +58,11 @@ WorldConverter::~WorldConverter() { std::shared_ptr WorldConverter::startTask( const std::shared_ptr& worldFiles, const Content* content, - const std::shared_ptr& lut, + const std::shared_ptr& report, const runnable& onDone, bool multithreading ) { - auto converter = std::make_shared(worldFiles, content, lut); + auto converter = std::make_shared(worldFiles, content, report); if (!multithreading) { converter->setOnComplete([=]() { converter->write(); @@ -98,8 +98,8 @@ void WorldConverter::convertRegion(const fs::path& file) const { } logger.info() << "converting region " << name; wfile->getRegions().processRegionVoxels(x, z, [=](ubyte* data) { - if (lut) { - Chunk::convert(data, lut.get()); + if (report) { + Chunk::convert(data, report.get()); } return true; }); @@ -108,7 +108,7 @@ void WorldConverter::convertRegion(const fs::path& file) const { void WorldConverter::convertPlayer(const fs::path& file) const { logger.info() << "converting player " << file.u8string(); auto map = files::read_json(file); - Player::convert(map.get(), lut.get()); + Player::convert(map.get(), report.get()); files::write_json(file, map.get()); } diff --git a/src/files/WorldConverter.hpp b/src/files/WorldConverter.hpp index c16151e8..3b14942a 100644 --- a/src/files/WorldConverter.hpp +++ b/src/files/WorldConverter.hpp @@ -11,7 +11,7 @@ namespace fs = std::filesystem; class Content; -class ContentLUT; +class ContentReport; class WorldFiles; enum class convert_task_type { region, player }; @@ -23,7 +23,7 @@ struct convert_task { class WorldConverter : public Task { std::shared_ptr wfile; - std::shared_ptr const lut; + std::shared_ptr const report; const Content* const content; std::queue tasks; runnable onComplete; @@ -35,7 +35,7 @@ public: WorldConverter( const std::shared_ptr& worldFiles, const Content* content, - std::shared_ptr lut + std::shared_ptr report ); ~WorldConverter(); @@ -54,7 +54,7 @@ public: static std::shared_ptr startTask( const std::shared_ptr& worldFiles, const Content* content, - const std::shared_ptr& lut, + const std::shared_ptr& report, const runnable& onDone, bool multithreading ); diff --git a/src/items/Inventory.cpp b/src/items/Inventory.cpp index 34f20bba..c2bc16ed 100644 --- a/src/items/Inventory.cpp +++ b/src/items/Inventory.cpp @@ -1,6 +1,6 @@ #include "Inventory.hpp" -#include "content/ContentLUT.hpp" +#include "content/ContentReport.hpp" #include "data/dynamic.hpp" Inventory::Inventory(int64_t id, size_t size) : id(id), slots(size) { @@ -81,12 +81,12 @@ std::unique_ptr Inventory::serialize() const { return map; } -void Inventory::convert(dynamic::Map* data, const ContentLUT* lut) { +void Inventory::convert(dynamic::Map* data, const ContentReport* report) { auto slotsarr = data->list("slots"); for (size_t i = 0; i < slotsarr->size(); i++) { auto item = slotsarr->map(i); itemid_t id = item->get("id", ITEM_EMPTY); - itemid_t replacement = lut->items.getId(id); + itemid_t replacement = report->items.getId(id); item->put("id", replacement); if (replacement == 0 && item->has("count")) { item->remove("count"); diff --git a/src/items/Inventory.hpp b/src/items/Inventory.hpp index a557d2c0..260ec08c 100644 --- a/src/items/Inventory.hpp +++ b/src/items/Inventory.hpp @@ -11,7 +11,7 @@ namespace dynamic { class Map; } -class ContentLUT; +class ContentReport; class ContentIndices; class Inventory : public Serializable { @@ -42,7 +42,7 @@ public: /* serializing inventory */ std::unique_ptr serialize() const override; - static void convert(dynamic::Map* data, const ContentLUT* lut); + static void convert(dynamic::Map* data, const ContentReport* report); inline void setId(int64_t id) { this->id = id; diff --git a/src/logic/EngineController.cpp b/src/logic/EngineController.cpp index 7e0d59c3..91e77220 100644 --- a/src/logic/EngineController.cpp +++ b/src/logic/EngineController.cpp @@ -4,10 +4,10 @@ #include #include -#include "coders/commons.hpp" -#include "content/ContentLUT.hpp" -#include "debug/Logger.hpp" #include "engine.hpp" +#include "coders/commons.hpp" +#include "debug/Logger.hpp" +#include "content/ContentReport.hpp" #include "files/WorldConverter.hpp" #include "files/WorldFiles.hpp" #include "frontend/locale.hpp" @@ -46,13 +46,13 @@ std::shared_ptr create_converter( Engine* engine, const std::shared_ptr& worldFiles, const Content* content, - const std::shared_ptr& lut, + const std::shared_ptr& report, const runnable& postRunnable ) { return WorldConverter::startTask( worldFiles, content, - lut, + report, [=]() { auto menu = engine->getGUI()->getMenu(); menu->reset(); @@ -66,7 +66,7 @@ std::shared_ptr create_converter( void show_convert_request( Engine* engine, const Content* content, - const std::shared_ptr& lut, + const std::shared_ptr& report, const std::shared_ptr& worldFiles, const runnable& postRunnable ) { @@ -75,7 +75,7 @@ void show_convert_request( langs::get(L"world.convert-request"), [=]() { auto converter = - create_converter(engine, worldFiles, content, lut, postRunnable); + create_converter(engine, worldFiles, content, report, postRunnable); menus::show_process_panel( engine, converter, L"Converting world..." ); @@ -86,12 +86,12 @@ void show_convert_request( } static void show_content_missing( - Engine* engine, const std::shared_ptr& lut + Engine* engine, const std::shared_ptr& report ) { using namespace dynamic; auto root = create_map(); auto& contentEntries = root->putList("content"); - for (auto& entry : lut->getMissingContent()) { + for (auto& entry : report->getMissingContent()) { std::string contentName = contenttype_name(entry.type); auto& contentEntry = contentEntries.putMap(); contentEntry.put("type", contentName); @@ -135,10 +135,10 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) { auto* content = engine->getContent(); auto worldFiles = std::make_shared( folder, engine->getSettings().debug); - if (auto lut = World::checkIndices(worldFiles, content)) { - if (lut->hasMissingContent()) { + if (auto report = World::checkIndices(worldFiles, content)) { + if (report->hasMissingContent()) { engine->setScreen(std::make_shared(engine)); - show_content_missing(engine, lut); + show_content_missing(engine, report); } else { if (confirmConvert) { menus::show_process_panel( @@ -147,13 +147,13 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) { engine, worldFiles, content, - lut, + report, [=]() { openWorld(name, false); } ), L"Converting world..." ); } else { - show_convert_request(engine, content, lut, std::move(worldFiles), [=]() { + show_convert_request(engine, content, report, std::move(worldFiles), [=]() { openWorld(name, false); }); } diff --git a/src/objects/Player.cpp b/src/objects/Player.cpp index 74fad257..3c145473 100644 --- a/src/objects/Player.cpp +++ b/src/objects/Player.cpp @@ -4,7 +4,7 @@ #include #include -#include "content/ContentLUT.hpp" +#include "content/ContentReport.hpp" #include "items/Inventory.hpp" #include "Entities.hpp" #include "rigging.hpp" @@ -329,19 +329,19 @@ void Player::deserialize(dynamic::Map* src) { } } -void Player::convert(dynamic::Map* data, const ContentLUT* lut) { +void Player::convert(dynamic::Map* data, const ContentReport* report) { auto players = data->list("players"); if (players) { for (uint i = 0; i < players->size(); i++) { auto playerData = players->map(i); if (auto inventory = playerData->map("inventory")) { - Inventory::convert(inventory.get(), lut); + Inventory::convert(inventory.get(), report); } } } else { if (auto inventory = data->map("inventory")) { - Inventory::convert(inventory.get(), lut); + Inventory::convert(inventory.get(), report); } } } diff --git a/src/objects/Player.hpp b/src/objects/Player.hpp index 94ce3096..49c18fac 100644 --- a/src/objects/Player.hpp +++ b/src/objects/Player.hpp @@ -12,7 +12,7 @@ class Camera; class Inventory; -class ContentLUT; +class ContentReport; class Level; struct Hitbox; struct EngineSettings; @@ -106,7 +106,7 @@ public: std::unique_ptr serialize() const override; void deserialize(dynamic::Map* src) override; - static void convert(dynamic::Map* data, const ContentLUT* lut); + static void convert(dynamic::Map* data, const ContentReport* report); inline int getId() const { return objectUID; diff --git a/src/voxels/Chunk.cpp b/src/voxels/Chunk.cpp index 78932659..c77532da 100644 --- a/src/voxels/Chunk.cpp +++ b/src/voxels/Chunk.cpp @@ -2,7 +2,7 @@ #include -#include "content/ContentLUT.hpp" +#include "content/ContentReport.hpp" #include "items/Inventory.hpp" #include "lighting/Lightmap.hpp" #include "voxel.hpp" @@ -123,13 +123,13 @@ bool Chunk::decode(const ubyte* data) { return true; } -void Chunk::convert(ubyte* data, const ContentLUT* lut) { +void Chunk::convert(ubyte* data, const ContentReport* report) { for (uint i = 0; i < CHUNK_VOL; i++) { // see encode method to understand what the hell is going on here blockid_t id = ((static_cast(data[i]) << 8) | static_cast(data[CHUNK_VOL + i])); - blockid_t replacement = lut->blocks.getId(id); + blockid_t replacement = report->blocks.getId(id); data[i] = replacement >> 8; data[CHUNK_VOL + i] = replacement & 0xFF; } diff --git a/src/voxels/Chunk.hpp b/src/voxels/Chunk.hpp index 14ead964..d9a25186 100644 --- a/src/voxels/Chunk.hpp +++ b/src/voxels/Chunk.hpp @@ -12,7 +12,7 @@ inline constexpr int CHUNK_DATA_LEN = CHUNK_VOL * 4; class Lightmap; -class ContentLUT; +class ContentReport; class Inventory; namespace dynamic { @@ -71,5 +71,5 @@ public: /// @return true if all is fine bool decode(const ubyte* data); - static void convert(ubyte* data, const ContentLUT* lut); + static void convert(ubyte* data, const ContentReport* report); }; diff --git a/src/world/World.cpp b/src/world/World.cpp index f8358960..c3e9e07c 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -5,7 +5,7 @@ #include #include "content/Content.hpp" -#include "content/ContentLUT.hpp" +#include "content/ContentReport.hpp" #include "debug/Logger.hpp" #include "files/WorldFiles.hpp" #include "items/Inventories.hpp" @@ -154,12 +154,12 @@ std::unique_ptr World::load( return level; } -std::shared_ptr World::checkIndices( +std::shared_ptr World::checkIndices( const std::shared_ptr& worldFiles, const Content* content ) { fs::path indicesFile = worldFiles->getIndicesFile(); if (fs::is_regular_file(indicesFile)) { - return ContentLUT::create(worldFiles, indicesFile, content); + return ContentReport::create(worldFiles, indicesFile, content); } return nullptr; } diff --git a/src/world/World.hpp b/src/world/World.hpp index f5443b2a..b166ee1f 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -14,7 +14,7 @@ class Content; class WorldFiles; class Level; -class ContentLUT; +class ContentReport; struct EngineSettings; namespace fs = std::filesystem; @@ -85,7 +85,7 @@ public: /// @param directory world directory /// @param content current Content instance /// @return ContentLUT if world convert required else nullptr - static std::shared_ptr checkIndices( + static std::shared_ptr checkIndices( const std::shared_ptr& worldFiles, const Content* content );