rename ContentLUT to ContentReport

This commit is contained in:
MihailRis
2024-09-02 09:40:00 +03:00
parent c1ef4dbe9f
commit 3f826a88d3
13 changed files with 67 additions and 69 deletions
@@ -1,4 +1,4 @@
#include "ContentLUT.hpp" #include "ContentReport.hpp"
#include <memory> #include <memory>
@@ -11,7 +11,7 @@
#include "files/WorldFiles.hpp" #include "files/WorldFiles.hpp"
#include "Content.hpp" #include "Content.hpp"
ContentLUT::ContentLUT( ContentReport::ContentReport(
const ContentIndices* indices, const ContentIndices* indices,
size_t blocksCount, size_t blocksCount,
size_t itemsCount size_t itemsCount
@@ -27,7 +27,7 @@ static constexpr size_t get_entries_count(
return list ? std::max(list->size(), indices.count()) : indices.count(); return list ? std::max(list->size(), indices.count()) : indices.count();
} }
std::shared_ptr<ContentLUT> ContentLUT::create( std::shared_ptr<ContentReport> ContentReport::create(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const fs::path& filename, const fs::path& filename,
const Content* content const Content* content
@@ -45,14 +45,13 @@ std::shared_ptr<ContentLUT> ContentLUT::create(
size_t blocks_c = get_entries_count(indices->blocks, blocklist); size_t blocks_c = get_entries_count(indices->blocks, blocklist);
size_t items_c = get_entries_count(indices->items, itemlist); size_t items_c = get_entries_count(indices->items, itemlist);
auto lut = std::make_shared<ContentLUT>(indices, blocks_c, items_c); auto report = std::make_shared<ContentReport>(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); if (report->hasContentReorder() || report->hasMissingContent()) {
lut->items.setup(itemlist.get(), content->items); return report;
lut->buildIssues();
if (lut->hasContentReorder() || lut->hasMissingContent()) {
return lut;
} else { } else {
return nullptr; return nullptr;
} }
@@ -61,27 +60,27 @@ std::shared_ptr<ContentLUT> ContentLUT::create(
template<class T, class U> template<class T, class U>
static void build_issues( static void build_issues(
std::vector<ContentIssue>& issues, std::vector<ContentIssue>& issues,
const ContentUnitLUT<T, U>& lut const ContentUnitLUT<T, U>& report
) { ) {
auto type = lut.getContentType(); auto type = report.getContentType();
if (lut.hasContentReorder()) { if (report.hasContentReorder()) {
issues.push_back(ContentIssue {ContentIssueType::REORDER, type}); issues.push_back(ContentIssue {ContentIssueType::REORDER, type});
} }
if (lut.hasMissingContent()) { if (report.hasMissingContent()) {
issues.push_back(ContentIssue {ContentIssueType::MISSING, type}); issues.push_back(ContentIssue {ContentIssueType::MISSING, type});
} }
} }
void ContentLUT::buildIssues() { void ContentReport::buildIssues() {
build_issues(issues, blocks); build_issues(issues, blocks);
build_issues(issues, items); build_issues(issues, items);
} }
const std::vector<ContentIssue>& ContentLUT::getIssues() const { const std::vector<ContentIssue>& ContentReport::getIssues() const {
return issues; return issues;
} }
std::vector<ContentEntry> ContentLUT::getMissingContent() const { std::vector<ContentEntry> ContentReport::getMissingContent() const {
std::vector<ContentEntry> entries; std::vector<ContentEntry> entries;
blocks.getMissingContent(entries); blocks.getMissingContent(entries);
items.getMissingContent(entries); items.getMissingContent(entries);
@@ -104,23 +104,22 @@ public:
} }
}; };
/// @brief Content indices lookup table or report /// @brief Content incapatibility report used to convert world.
/// used to convert world with different indices
/// Building with indices.json /// Building with indices.json
class ContentLUT { class ContentReport {
public: public:
ContentUnitLUT<blockid_t, Block> blocks; ContentUnitLUT<blockid_t, Block> blocks;
ContentUnitLUT<itemid_t, ItemDef> items; ContentUnitLUT<itemid_t, ItemDef> items;
std::vector<ContentIssue> issues; std::vector<ContentIssue> issues;
ContentLUT( ContentReport(
const ContentIndices* indices, const ContentIndices* indices,
size_t blocks, size_t blocks,
size_t items size_t items
); );
static std::shared_ptr<ContentLUT> create( static std::shared_ptr<ContentReport> create(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const fs::path& filename, const fs::path& filename,
const Content* content const Content* content
+8 -8
View File
@@ -5,7 +5,7 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include "content/ContentLUT.hpp" #include "content/ContentReport.hpp"
#include "data/dynamic.hpp" #include "data/dynamic.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "files/files.hpp" #include "files/files.hpp"
@@ -34,10 +34,10 @@ public:
WorldConverter::WorldConverter( WorldConverter::WorldConverter(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const Content* content, const Content* content,
std::shared_ptr<ContentLUT> lut std::shared_ptr<ContentReport> report
) )
: wfile(worldFiles), : wfile(worldFiles),
lut(std::move(lut)), report(std::move(report)),
content(content) { content(content) {
fs::path regionsFolder = fs::path regionsFolder =
wfile->getRegions().getRegionsFolder(REGION_LAYER_VOXELS); wfile->getRegions().getRegionsFolder(REGION_LAYER_VOXELS);
@@ -58,11 +58,11 @@ WorldConverter::~WorldConverter() {
std::shared_ptr<Task> WorldConverter::startTask( std::shared_ptr<Task> WorldConverter::startTask(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const Content* content, const Content* content,
const std::shared_ptr<ContentLUT>& lut, const std::shared_ptr<ContentReport>& report,
const runnable& onDone, const runnable& onDone,
bool multithreading bool multithreading
) { ) {
auto converter = std::make_shared<WorldConverter>(worldFiles, content, lut); auto converter = std::make_shared<WorldConverter>(worldFiles, content, report);
if (!multithreading) { if (!multithreading) {
converter->setOnComplete([=]() { converter->setOnComplete([=]() {
converter->write(); converter->write();
@@ -98,8 +98,8 @@ void WorldConverter::convertRegion(const fs::path& file) const {
} }
logger.info() << "converting region " << name; logger.info() << "converting region " << name;
wfile->getRegions().processRegionVoxels(x, z, [=](ubyte* data) { wfile->getRegions().processRegionVoxels(x, z, [=](ubyte* data) {
if (lut) { if (report) {
Chunk::convert(data, lut.get()); Chunk::convert(data, report.get());
} }
return true; return true;
}); });
@@ -108,7 +108,7 @@ void WorldConverter::convertRegion(const fs::path& file) const {
void WorldConverter::convertPlayer(const fs::path& file) const { void WorldConverter::convertPlayer(const fs::path& file) const {
logger.info() << "converting player " << file.u8string(); logger.info() << "converting player " << file.u8string();
auto map = files::read_json(file); auto map = files::read_json(file);
Player::convert(map.get(), lut.get()); Player::convert(map.get(), report.get());
files::write_json(file, map.get()); files::write_json(file, map.get());
} }
+4 -4
View File
@@ -11,7 +11,7 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
class Content; class Content;
class ContentLUT; class ContentReport;
class WorldFiles; class WorldFiles;
enum class convert_task_type { region, player }; enum class convert_task_type { region, player };
@@ -23,7 +23,7 @@ struct convert_task {
class WorldConverter : public Task { class WorldConverter : public Task {
std::shared_ptr<WorldFiles> wfile; std::shared_ptr<WorldFiles> wfile;
std::shared_ptr<ContentLUT> const lut; std::shared_ptr<ContentReport> const report;
const Content* const content; const Content* const content;
std::queue<convert_task> tasks; std::queue<convert_task> tasks;
runnable onComplete; runnable onComplete;
@@ -35,7 +35,7 @@ public:
WorldConverter( WorldConverter(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const Content* content, const Content* content,
std::shared_ptr<ContentLUT> lut std::shared_ptr<ContentReport> report
); );
~WorldConverter(); ~WorldConverter();
@@ -54,7 +54,7 @@ public:
static std::shared_ptr<Task> startTask( static std::shared_ptr<Task> startTask(
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const Content* content, const Content* content,
const std::shared_ptr<ContentLUT>& lut, const std::shared_ptr<ContentReport>& report,
const runnable& onDone, const runnable& onDone,
bool multithreading bool multithreading
); );
+3 -3
View File
@@ -1,6 +1,6 @@
#include "Inventory.hpp" #include "Inventory.hpp"
#include "content/ContentLUT.hpp" #include "content/ContentReport.hpp"
#include "data/dynamic.hpp" #include "data/dynamic.hpp"
Inventory::Inventory(int64_t id, size_t size) : id(id), slots(size) { Inventory::Inventory(int64_t id, size_t size) : id(id), slots(size) {
@@ -81,12 +81,12 @@ std::unique_ptr<dynamic::Map> Inventory::serialize() const {
return map; 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"); auto slotsarr = data->list("slots");
for (size_t i = 0; i < slotsarr->size(); i++) { for (size_t i = 0; i < slotsarr->size(); i++) {
auto item = slotsarr->map(i); auto item = slotsarr->map(i);
itemid_t id = item->get("id", ITEM_EMPTY); 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); item->put("id", replacement);
if (replacement == 0 && item->has("count")) { if (replacement == 0 && item->has("count")) {
item->remove("count"); item->remove("count");
+2 -2
View File
@@ -11,7 +11,7 @@ namespace dynamic {
class Map; class Map;
} }
class ContentLUT; class ContentReport;
class ContentIndices; class ContentIndices;
class Inventory : public Serializable { class Inventory : public Serializable {
@@ -42,7 +42,7 @@ public:
/* serializing inventory */ /* serializing inventory */
std::unique_ptr<dynamic::Map> serialize() const override; std::unique_ptr<dynamic::Map> 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) { inline void setId(int64_t id) {
this->id = id; this->id = id;
+14 -14
View File
@@ -4,10 +4,10 @@
#include <filesystem> #include <filesystem>
#include <memory> #include <memory>
#include "coders/commons.hpp"
#include "content/ContentLUT.hpp"
#include "debug/Logger.hpp"
#include "engine.hpp" #include "engine.hpp"
#include "coders/commons.hpp"
#include "debug/Logger.hpp"
#include "content/ContentReport.hpp"
#include "files/WorldConverter.hpp" #include "files/WorldConverter.hpp"
#include "files/WorldFiles.hpp" #include "files/WorldFiles.hpp"
#include "frontend/locale.hpp" #include "frontend/locale.hpp"
@@ -46,13 +46,13 @@ std::shared_ptr<Task> create_converter(
Engine* engine, Engine* engine,
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const Content* content, const Content* content,
const std::shared_ptr<ContentLUT>& lut, const std::shared_ptr<ContentReport>& report,
const runnable& postRunnable const runnable& postRunnable
) { ) {
return WorldConverter::startTask( return WorldConverter::startTask(
worldFiles, worldFiles,
content, content,
lut, report,
[=]() { [=]() {
auto menu = engine->getGUI()->getMenu(); auto menu = engine->getGUI()->getMenu();
menu->reset(); menu->reset();
@@ -66,7 +66,7 @@ std::shared_ptr<Task> create_converter(
void show_convert_request( void show_convert_request(
Engine* engine, Engine* engine,
const Content* content, const Content* content,
const std::shared_ptr<ContentLUT>& lut, const std::shared_ptr<ContentReport>& report,
const std::shared_ptr<WorldFiles>& worldFiles, const std::shared_ptr<WorldFiles>& worldFiles,
const runnable& postRunnable const runnable& postRunnable
) { ) {
@@ -75,7 +75,7 @@ void show_convert_request(
langs::get(L"world.convert-request"), langs::get(L"world.convert-request"),
[=]() { [=]() {
auto converter = auto converter =
create_converter(engine, worldFiles, content, lut, postRunnable); create_converter(engine, worldFiles, content, report, postRunnable);
menus::show_process_panel( menus::show_process_panel(
engine, converter, L"Converting world..." engine, converter, L"Converting world..."
); );
@@ -86,12 +86,12 @@ void show_convert_request(
} }
static void show_content_missing( static void show_content_missing(
Engine* engine, const std::shared_ptr<ContentLUT>& lut Engine* engine, const std::shared_ptr<ContentReport>& report
) { ) {
using namespace dynamic; using namespace dynamic;
auto root = create_map(); auto root = create_map();
auto& contentEntries = root->putList("content"); auto& contentEntries = root->putList("content");
for (auto& entry : lut->getMissingContent()) { for (auto& entry : report->getMissingContent()) {
std::string contentName = contenttype_name(entry.type); std::string contentName = contenttype_name(entry.type);
auto& contentEntry = contentEntries.putMap(); auto& contentEntry = contentEntries.putMap();
contentEntry.put("type", contentName); contentEntry.put("type", contentName);
@@ -135,10 +135,10 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) {
auto* content = engine->getContent(); auto* content = engine->getContent();
auto worldFiles = std::make_shared<WorldFiles>( auto worldFiles = std::make_shared<WorldFiles>(
folder, engine->getSettings().debug); folder, engine->getSettings().debug);
if (auto lut = World::checkIndices(worldFiles, content)) { if (auto report = World::checkIndices(worldFiles, content)) {
if (lut->hasMissingContent()) { if (report->hasMissingContent()) {
engine->setScreen(std::make_shared<MenuScreen>(engine)); engine->setScreen(std::make_shared<MenuScreen>(engine));
show_content_missing(engine, lut); show_content_missing(engine, report);
} else { } else {
if (confirmConvert) { if (confirmConvert) {
menus::show_process_panel( menus::show_process_panel(
@@ -147,13 +147,13 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) {
engine, engine,
worldFiles, worldFiles,
content, content,
lut, report,
[=]() { openWorld(name, false); } [=]() { openWorld(name, false); }
), ),
L"Converting world..." L"Converting world..."
); );
} else { } else {
show_convert_request(engine, content, lut, std::move(worldFiles), [=]() { show_convert_request(engine, content, report, std::move(worldFiles), [=]() {
openWorld(name, false); openWorld(name, false);
}); });
} }
+4 -4
View File
@@ -4,7 +4,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <utility> #include <utility>
#include "content/ContentLUT.hpp" #include "content/ContentReport.hpp"
#include "items/Inventory.hpp" #include "items/Inventory.hpp"
#include "Entities.hpp" #include "Entities.hpp"
#include "rigging.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"); auto players = data->list("players");
if (players) { if (players) {
for (uint i = 0; i < players->size(); i++) { for (uint i = 0; i < players->size(); i++) {
auto playerData = players->map(i); auto playerData = players->map(i);
if (auto inventory = playerData->map("inventory")) { if (auto inventory = playerData->map("inventory")) {
Inventory::convert(inventory.get(), lut); Inventory::convert(inventory.get(), report);
} }
} }
} else { } else {
if (auto inventory = data->map("inventory")) { if (auto inventory = data->map("inventory")) {
Inventory::convert(inventory.get(), lut); Inventory::convert(inventory.get(), report);
} }
} }
} }
+2 -2
View File
@@ -12,7 +12,7 @@
class Camera; class Camera;
class Inventory; class Inventory;
class ContentLUT; class ContentReport;
class Level; class Level;
struct Hitbox; struct Hitbox;
struct EngineSettings; struct EngineSettings;
@@ -106,7 +106,7 @@ public:
std::unique_ptr<dynamic::Map> serialize() const override; std::unique_ptr<dynamic::Map> serialize() const override;
void deserialize(dynamic::Map* src) 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 { inline int getId() const {
return objectUID; return objectUID;
+3 -3
View File
@@ -2,7 +2,7 @@
#include <utility> #include <utility>
#include "content/ContentLUT.hpp" #include "content/ContentReport.hpp"
#include "items/Inventory.hpp" #include "items/Inventory.hpp"
#include "lighting/Lightmap.hpp" #include "lighting/Lightmap.hpp"
#include "voxel.hpp" #include "voxel.hpp"
@@ -123,13 +123,13 @@ bool Chunk::decode(const ubyte* data) {
return true; 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++) { for (uint i = 0; i < CHUNK_VOL; i++) {
// see encode method to understand what the hell is going on here // see encode method to understand what the hell is going on here
blockid_t id = blockid_t id =
((static_cast<blockid_t>(data[i]) << 8) | ((static_cast<blockid_t>(data[i]) << 8) |
static_cast<blockid_t>(data[CHUNK_VOL + i])); static_cast<blockid_t>(data[CHUNK_VOL + i]));
blockid_t replacement = lut->blocks.getId(id); blockid_t replacement = report->blocks.getId(id);
data[i] = replacement >> 8; data[i] = replacement >> 8;
data[CHUNK_VOL + i] = replacement & 0xFF; data[CHUNK_VOL + i] = replacement & 0xFF;
} }
+2 -2
View File
@@ -12,7 +12,7 @@
inline constexpr int CHUNK_DATA_LEN = CHUNK_VOL * 4; inline constexpr int CHUNK_DATA_LEN = CHUNK_VOL * 4;
class Lightmap; class Lightmap;
class ContentLUT; class ContentReport;
class Inventory; class Inventory;
namespace dynamic { namespace dynamic {
@@ -71,5 +71,5 @@ public:
/// @return true if all is fine /// @return true if all is fine
bool decode(const ubyte* data); bool decode(const ubyte* data);
static void convert(ubyte* data, const ContentLUT* lut); static void convert(ubyte* data, const ContentReport* report);
}; };
+3 -3
View File
@@ -5,7 +5,7 @@
#include <utility> #include <utility>
#include "content/Content.hpp" #include "content/Content.hpp"
#include "content/ContentLUT.hpp" #include "content/ContentReport.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "files/WorldFiles.hpp" #include "files/WorldFiles.hpp"
#include "items/Inventories.hpp" #include "items/Inventories.hpp"
@@ -154,12 +154,12 @@ std::unique_ptr<Level> World::load(
return level; return level;
} }
std::shared_ptr<ContentLUT> World::checkIndices( std::shared_ptr<ContentReport> World::checkIndices(
const std::shared_ptr<WorldFiles>& worldFiles, const Content* content const std::shared_ptr<WorldFiles>& worldFiles, const Content* content
) { ) {
fs::path indicesFile = worldFiles->getIndicesFile(); fs::path indicesFile = worldFiles->getIndicesFile();
if (fs::is_regular_file(indicesFile)) { if (fs::is_regular_file(indicesFile)) {
return ContentLUT::create(worldFiles, indicesFile, content); return ContentReport::create(worldFiles, indicesFile, content);
} }
return nullptr; return nullptr;
} }
+2 -2
View File
@@ -14,7 +14,7 @@
class Content; class Content;
class WorldFiles; class WorldFiles;
class Level; class Level;
class ContentLUT; class ContentReport;
struct EngineSettings; struct EngineSettings;
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -85,7 +85,7 @@ public:
/// @param directory world directory /// @param directory world directory
/// @param content current Content instance /// @param content current Content instance
/// @return ContentLUT if world convert required else nullptr /// @return ContentLUT if world convert required else nullptr
static std::shared_ptr<ContentLUT> checkIndices( static std::shared_ptr<ContentReport> checkIndices(
const std::shared_ptr<WorldFiles>& worldFiles, const Content* content const std::shared_ptr<WorldFiles>& worldFiles, const Content* content
); );