BlockMaterial struct + minor refactor and docs
This commit is contained in:
parent
f8e02e1b3b
commit
8658a170bc
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -43,11 +43,8 @@ struct CoordSystem {
|
||||
|
||||
void transform(AABB& aabb) const;
|
||||
|
||||
static bool isVectorHasNegatives(glm::ivec3 vec) {
|
||||
if (vec.x < 0 || vec.y < 0 || vec.z < 0) {
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
inline bool isVectorHasNegatives(glm::ivec3 vec) {
|
||||
return (vec.x < 0 || vec.y < 0 || vec.z < 0);
|
||||
}
|
||||
};
|
||||
|
||||
@ -56,56 +53,99 @@ struct BlockRotProfile {
|
||||
std::string name;
|
||||
CoordSystem variants[MAX_COUNT];
|
||||
|
||||
/* Wood logs, pillars, pipes */
|
||||
/// @brief Wood logs, pillars, pipes
|
||||
static const BlockRotProfile PIPE;
|
||||
/* Doors, signs and other panes */
|
||||
/// @brief Doors, signs and other panes
|
||||
static const BlockRotProfile PANE;
|
||||
};
|
||||
|
||||
enum class BlockModel {
|
||||
none, // invisible
|
||||
block, // default shape
|
||||
xsprite, // X-shape (grass)
|
||||
aabb, // box shaped as block hitbox
|
||||
/// @brief invisible
|
||||
none,
|
||||
/// @brief default cube shape
|
||||
block,
|
||||
/// @brief X-shape (grass)
|
||||
xsprite,
|
||||
/// @brief box shape sized as block hitbox
|
||||
aabb,
|
||||
/// @brief custom model defined in json
|
||||
custom
|
||||
};
|
||||
|
||||
using BoxModel = AABB;
|
||||
|
||||
|
||||
/// @brief Common kit of block properties applied to groups of blocks
|
||||
struct BlockMaterial {
|
||||
std::string name;
|
||||
std::string stepsSound;
|
||||
std::string placeSound;
|
||||
std::string breakSound;
|
||||
};
|
||||
|
||||
/// @brief Block properties definition
|
||||
class Block {
|
||||
public:
|
||||
/// @brief Block string id (with prefix included)
|
||||
std::string const name;
|
||||
// 0 1 2 3 4 5
|
||||
/// @brief Textures set applied to block sides
|
||||
std::string textureFaces[6]; // -x,x, -y,y, -z,z
|
||||
|
||||
std::vector<std::string> modelTextures = {};
|
||||
std::vector<BoxModel> modelBoxes = {};
|
||||
std::vector<glm::vec3> modelExtraPoints = {}; //initially made for tetragons
|
||||
std::vector<UVRegion> modelUVs = {}; // boxes' tex-UVs also there
|
||||
|
||||
/// @brief Light emission R, G, B, S (sky lights: sun, moon, radioactive clouds)
|
||||
uint8_t emission[4] {0, 0, 0, 0};
|
||||
/// @brief Influences visible block sides for transparent blocks
|
||||
uint8_t drawGroup = 0;
|
||||
/// @brief Block model type
|
||||
BlockModel model = BlockModel::block;
|
||||
/// @brief Does the block passing lights into itself
|
||||
bool lightPassing = false;
|
||||
/// @brief Does the block passing top-down sky lights into itself
|
||||
bool skyLightPassing = false;
|
||||
/// @brief Is the block a physical obstacle
|
||||
bool obstacle = true;
|
||||
/// @brief Can the block be selected
|
||||
bool selectable = true;
|
||||
/// @brief Can the block be replaced with other.
|
||||
/// Examples of replaceable blocks: air, flower, water
|
||||
bool replaceable = false;
|
||||
/// @brief Can player destroy the block
|
||||
bool breakable = true;
|
||||
/// @brief Can the block be oriented different ways
|
||||
bool rotatable = false;
|
||||
/// @brief Can the block exist without physical support be a solid block below
|
||||
bool grounded = false;
|
||||
/// @brief Turns off block item generation
|
||||
bool hidden = false;
|
||||
/// @brief Set of block physical hitboxes
|
||||
std::vector<AABB> hitboxes;
|
||||
/// @brief Set of available block rotations (coord-systems)
|
||||
BlockRotProfile rotations;
|
||||
/// @brief Item will be picked on MMB click on the block
|
||||
std::string pickingItem = name+BLOCK_ITEM_SUFFIX;
|
||||
std::string scriptName = name.substr(name.find(':')+1);
|
||||
/// @brief Block script name in blocks/ without extension
|
||||
std::string scriptName = name.substr(name.find(':')+1);
|
||||
/// @brief Default block layout will be used by hud.open_block(...)
|
||||
std::string uiLayout = name;
|
||||
/// @brief Block inventory size. 0 - no inventory
|
||||
uint inventorySize = 0;
|
||||
|
||||
struct {
|
||||
/// @brief block runtime integer id
|
||||
blockid_t id;
|
||||
/// @brief is the block completely opaque for render and raycast
|
||||
bool solid = true;
|
||||
/// @brief does the block emit any lights
|
||||
bool emissive = false;
|
||||
/// @brief set of hitboxes sets with all coord-systems precalculated
|
||||
std::vector<AABB> hitboxes[BlockRotProfile::MAX_COUNT];
|
||||
/// @brief set of block callbacks flags
|
||||
block_funcs_set funcsset {};
|
||||
/// @brief picking item integer id
|
||||
itemid_t pickingItem = 0;
|
||||
} rt;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user