rename ContentLUT to ContentReport
This commit is contained in:
parent
c1ef4dbe9f
commit
3f826a88d3
@ -1,4 +1,4 @@
|
||||
#include "ContentLUT.hpp"
|
||||
#include "ContentReport.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -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> ContentLUT::create(
|
||||
std::shared_ptr<ContentReport> ContentReport::create(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
const fs::path& filename,
|
||||
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 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);
|
||||
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> ContentLUT::create(
|
||||
template<class T, class U>
|
||||
static void build_issues(
|
||||
std::vector<ContentIssue>& issues,
|
||||
const ContentUnitLUT<T, U>& lut
|
||||
const ContentUnitLUT<T, U>& 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<ContentIssue>& ContentLUT::getIssues() const {
|
||||
const std::vector<ContentIssue>& ContentReport::getIssues() const {
|
||||
return issues;
|
||||
}
|
||||
|
||||
std::vector<ContentEntry> ContentLUT::getMissingContent() const {
|
||||
std::vector<ContentEntry> ContentReport::getMissingContent() const {
|
||||
std::vector<ContentEntry> entries;
|
||||
blocks.getMissingContent(entries);
|
||||
items.getMissingContent(entries);
|
||||
@ -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<blockid_t, Block> blocks;
|
||||
ContentUnitLUT<itemid_t, ItemDef> items;
|
||||
|
||||
std::vector<ContentIssue> issues;
|
||||
|
||||
ContentLUT(
|
||||
ContentReport(
|
||||
const ContentIndices* indices,
|
||||
size_t blocks,
|
||||
size_t items
|
||||
);
|
||||
|
||||
static std::shared_ptr<ContentLUT> create(
|
||||
static std::shared_ptr<ContentReport> create(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
const fs::path& filename,
|
||||
const Content* content
|
||||
@ -5,7 +5,7 @@
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#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>& worldFiles,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut
|
||||
std::shared_ptr<ContentReport> 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<Task> WorldConverter::startTask(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
const Content* content,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const std::shared_ptr<ContentReport>& report,
|
||||
const runnable& onDone,
|
||||
bool multithreading
|
||||
) {
|
||||
auto converter = std::make_shared<WorldConverter>(worldFiles, content, lut);
|
||||
auto converter = std::make_shared<WorldConverter>(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());
|
||||
}
|
||||
|
||||
|
||||
@ -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<WorldFiles> wfile;
|
||||
std::shared_ptr<ContentLUT> const lut;
|
||||
std::shared_ptr<ContentReport> const report;
|
||||
const Content* const content;
|
||||
std::queue<convert_task> tasks;
|
||||
runnable onComplete;
|
||||
@ -35,7 +35,7 @@ public:
|
||||
WorldConverter(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut
|
||||
std::shared_ptr<ContentReport> report
|
||||
);
|
||||
~WorldConverter();
|
||||
|
||||
@ -54,7 +54,7 @@ public:
|
||||
static std::shared_ptr<Task> startTask(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
const Content* content,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const std::shared_ptr<ContentReport>& report,
|
||||
const runnable& onDone,
|
||||
bool multithreading
|
||||
);
|
||||
|
||||
@ -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<dynamic::Map> 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");
|
||||
|
||||
@ -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<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) {
|
||||
this->id = id;
|
||||
|
||||
@ -4,10 +4,10 @@
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#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<Task> create_converter(
|
||||
Engine* engine,
|
||||
const std::shared_ptr<WorldFiles>& worldFiles,
|
||||
const Content* content,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const std::shared_ptr<ContentReport>& 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<Task> create_converter(
|
||||
void show_convert_request(
|
||||
Engine* engine,
|
||||
const Content* content,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const std::shared_ptr<ContentReport>& report,
|
||||
const std::shared_ptr<WorldFiles>& 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<ContentLUT>& lut
|
||||
Engine* engine, const std::shared_ptr<ContentReport>& 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<WorldFiles>(
|
||||
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<MenuScreen>(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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<dynamic::Map> 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;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#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<blockid_t>(data[i]) << 8) |
|
||||
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[CHUNK_VOL + i] = replacement & 0xFF;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include <utility>
|
||||
|
||||
#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<Level> World::load(
|
||||
return level;
|
||||
}
|
||||
|
||||
std::shared_ptr<ContentLUT> World::checkIndices(
|
||||
std::shared_ptr<ContentReport> World::checkIndices(
|
||||
const std::shared_ptr<WorldFiles>& 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;
|
||||
}
|
||||
|
||||
@ -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<ContentLUT> checkIndices(
|
||||
static std::shared_ptr<ContentReport> checkIndices(
|
||||
const std::shared_ptr<WorldFiles>& worldFiles, const Content* content
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user