BlockMaterial struct + minor refactor and docs

This commit is contained in:
MihailRis
2024-03-07 10:55:19 +03:00
parent f8e02e1b3b
commit 8658a170bc
4 changed files with 86 additions and 43 deletions
+18 -19
View File
@@ -10,8 +10,7 @@
#include "ContentPack.h"
#include "../logic/scripting/scripting.h"
ContentBuilder::~ContentBuilder() {
}
ContentBuilder::~ContentBuilder() {}
void ContentBuilder::add(Block* def) {
checkIdentifier(def->name);
@@ -127,25 +126,25 @@ Content* ContentBuilder::build() {
ContentIndices::ContentIndices(
std::vector<Block*> blockDefs,
std::vector<ItemDef*> itemDefs)
: blockDefs(blockDefs),
itemDefs(itemDefs) {
}
std::vector<ItemDef*> itemDefs
) : blockDefs(blockDefs),
itemDefs(itemDefs)
{}
Content::Content(ContentIndices* indices,
std::unique_ptr<DrawGroups> drawGroups,
std::unordered_map<std::string, Block*> blockDefs,
std::unordered_map<std::string, ItemDef*> itemDefs,
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs)
: blockDefs(blockDefs),
itemDefs(itemDefs),
indices(indices),
packs(std::move(packs)),
drawGroups(std::move(drawGroups)) {
}
Content::Content(
ContentIndices* indices,
std::unique_ptr<DrawGroups> drawGroups,
std::unordered_map<std::string, Block*> blockDefs,
std::unordered_map<std::string, ItemDef*> itemDefs,
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs
) : blockDefs(blockDefs),
itemDefs(itemDefs),
indices(indices),
packs(std::move(packs)),
drawGroups(std::move(drawGroups))
{}
Content::~Content() {
}
Content::~Content() {}
Block* Content::findBlock(std::string id) const {
auto found = blockDefs.find(id);
+12 -8
View File
@@ -65,13 +65,15 @@ public:
Content* build();
};
/* Runtime defs cache: indices */
/// @brief Runtime defs cache: indices
class ContentIndices {
std::vector<Block*> blockDefs;
std::vector<ItemDef*> itemDefs;
public:
ContentIndices(std::vector<Block*> blockDefs,
std::vector<ItemDef*> itemDefs);
ContentIndices(
std::vector<Block*> blockDefs,
std::vector<ItemDef*> itemDefs
);
inline Block* getBlockDef(blockid_t id) const {
if (id >= blockDefs.size())
@@ -112,11 +114,13 @@ class Content {
public:
std::unique_ptr<DrawGroups> const drawGroups;
Content(ContentIndices* indices,
std::unique_ptr<DrawGroups> drawGroups,
std::unordered_map<std::string, Block*> blockDefs,
std::unordered_map<std::string, ItemDef*> itemDefs,
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs);
Content(
ContentIndices* indices,
std::unique_ptr<DrawGroups> drawGroups,
std::unordered_map<std::string, Block*> blockDefs,
std::unordered_map<std::string, ItemDef*> itemDefs,
std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>> packs
);
~Content();
inline ContentIndices* getIndices() const {
+3 -3
View File
@@ -19,9 +19,9 @@ struct contententry {
// TODO: make it unified for all types of content
/* Content indices lookup table or report
used to convert world with different indices
Building with indices.json */
/// @brief Content indices lookup table or report
/// used to convert world with different indices
/// Building with indices.json
class ContentLUT {
std::vector<blockid_t> blocks;
std::vector<std::string> blockNames;