Merge branch 'dev' into pathfinding
This commit is contained in:
@@ -35,13 +35,15 @@ Content::Content(
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
|
||||
ResourceIndicesSet resourceIndices,
|
||||
dv::value defaults
|
||||
dv::value defaults,
|
||||
std::unordered_map<std::string, int> tags
|
||||
)
|
||||
: indices(std::move(indices)),
|
||||
packs(std::move(packs)),
|
||||
blockMaterials(std::move(blockMaterials)),
|
||||
skeletons(std::move(skeletons)),
|
||||
defaults(std::move(defaults)),
|
||||
tags(std::move(tags)),
|
||||
blocks(std::move(blocks)),
|
||||
items(std::move(items)),
|
||||
entities(std::move(entities)),
|
||||
|
||||
+11
-1
@@ -176,6 +176,7 @@ class Content {
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
||||
dv::value defaults = nullptr;
|
||||
std::unordered_map<std::string, int> tags;
|
||||
public:
|
||||
ContentUnitDefs<Block> blocks;
|
||||
ContentUnitDefs<ItemDef> items;
|
||||
@@ -195,7 +196,8 @@ public:
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials,
|
||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons,
|
||||
ResourceIndicesSet resourceIndices,
|
||||
dv::value defaults
|
||||
dv::value defaults,
|
||||
std::unordered_map<std::string, int> tags
|
||||
);
|
||||
~Content();
|
||||
|
||||
@@ -211,6 +213,14 @@ public:
|
||||
return defaults;
|
||||
}
|
||||
|
||||
int getTagIndex(const std::string& tag) const {
|
||||
const auto& found = tags.find(tag);
|
||||
if (found == tags.end()) {
|
||||
return -1;
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
const rigging::SkeletonConfig* getSkeleton(const std::string& id) const;
|
||||
const rigging::SkeletonConfig& requireSkeleton(const std::string& id) const;
|
||||
const BlockMaterial* findBlockMaterial(const std::string& id) const;
|
||||
|
||||
@@ -28,6 +28,9 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
// Generating runtime info
|
||||
def.rt.id = blockDefsIndices.size();
|
||||
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
||||
for (const auto& tag : def.tags) {
|
||||
def.rt.tags.insert(tags.add(tag));
|
||||
}
|
||||
|
||||
if (def.variants) {
|
||||
for (auto& variant : def.variants->variants) {
|
||||
@@ -58,7 +61,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
}
|
||||
|
||||
blockDefsIndices.push_back(&def);
|
||||
groups->insert(def.defaults.drawGroup); // FIXME
|
||||
groups->insert(def.defaults.drawGroup); // FIXME: variants
|
||||
}
|
||||
|
||||
std::vector<ItemDef*> itemDefsIndices;
|
||||
@@ -93,7 +96,8 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
std::move(blockMaterials),
|
||||
std::move(skeletons),
|
||||
std::move(resourceIndices),
|
||||
std::move(defaults)
|
||||
std::move(defaults),
|
||||
std::move(tags.map)
|
||||
);
|
||||
|
||||
// Now, it's time to resolve foreign keys
|
||||
|
||||
@@ -62,6 +62,27 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct TagsIndices {
|
||||
int nextIndex = 1;
|
||||
std::unordered_map<std::string, int> map;
|
||||
|
||||
int add(const std::string& tag) {
|
||||
const auto& found = map.find(tag);
|
||||
if (found != map.end()) {
|
||||
return found->second;
|
||||
}
|
||||
return map[tag] = nextIndex++;
|
||||
}
|
||||
|
||||
int indexOf(const std::string& tag) {
|
||||
const auto& found = map.find(tag);
|
||||
if (found == map.end()) {
|
||||
return -1;
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
};
|
||||
|
||||
class ContentBuilder {
|
||||
UptrsMap<std::string, BlockMaterial> blockMaterials;
|
||||
UptrsMap<std::string, rigging::SkeletonConfig> skeletons;
|
||||
@@ -74,6 +95,7 @@ public:
|
||||
ContentUnitBuilder<GeneratorDef> generators {allNames, ContentType::GENERATOR};
|
||||
ResourceIndicesSet resourceIndices {};
|
||||
dv::value defaults = nullptr;
|
||||
TagsIndices tags {};
|
||||
|
||||
~ContentBuilder();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#define VC_ENABLE_REFLECTION
|
||||
#include "ContentUnitLoader.hpp"
|
||||
#include "ContentLoadingCommons.hpp"
|
||||
|
||||
#include "../ContentBuilder.hpp"
|
||||
#include "coders/json.hpp"
|
||||
@@ -87,20 +88,8 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||
Block& def, const std::string& name, const io::path& file
|
||||
) {
|
||||
auto root = io::read_json(file);
|
||||
if (def.properties == nullptr) {
|
||||
def.properties = dv::object();
|
||||
def.properties["name"] = name;
|
||||
}
|
||||
for (auto& [key, value] : root.asObject()) {
|
||||
auto pos = key.rfind('@');
|
||||
if (pos == std::string::npos) {
|
||||
def.properties[key] = value;
|
||||
continue;
|
||||
}
|
||||
auto field = key.substr(0, pos);
|
||||
auto suffix = key.substr(pos + 1);
|
||||
process_method(def.properties, suffix, field, value);
|
||||
}
|
||||
process_properties(def, name, root);
|
||||
process_tags(def, root);
|
||||
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "data/dv.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
template <typename T>
|
||||
inline void process_properties(T& def, const std::string& name, const dv::value& root) {
|
||||
if (def.properties == nullptr) {
|
||||
def.properties = dv::object();
|
||||
def.properties["name"] = name;
|
||||
}
|
||||
for (auto& [key, value] : root.asObject()) {
|
||||
auto pos = key.rfind('@');
|
||||
if (pos == std::string::npos) {
|
||||
def.properties[key] = value;
|
||||
continue;
|
||||
}
|
||||
auto field = key.substr(0, pos);
|
||||
auto suffix = key.substr(pos + 1);
|
||||
process_method(def.properties, suffix, field, value);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void process_tags(T& def, const dv::value& root) {
|
||||
if (!root.has("tags")) {
|
||||
return;
|
||||
}
|
||||
const auto& tags = root["tags"];
|
||||
for (const auto& tagValue : tags) {
|
||||
if (!tagValue.isString()) {
|
||||
continue;
|
||||
}
|
||||
def.tags.push_back(tagValue.asString());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#define VC_ENABLE_REFLECTION
|
||||
#include "ContentUnitLoader.hpp"
|
||||
#include "ContentLoadingCommons.hpp"
|
||||
|
||||
#include "../ContentBuilder.hpp"
|
||||
#include "coders/json.hpp"
|
||||
@@ -12,11 +13,13 @@
|
||||
|
||||
static debug::Logger logger("item-content-loader");
|
||||
|
||||
|
||||
template<> void ContentUnitLoader<ItemDef>::loadUnit(
|
||||
ItemDef& def, const std::string& name, const io::path& file
|
||||
) {
|
||||
auto root = io::read_json(file);
|
||||
def.properties = root;
|
||||
process_properties(def, name, root);
|
||||
process_tags(def, root);
|
||||
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
|
||||
Reference in New Issue
Block a user