diff --git a/src/content/Content.cpp b/src/content/Content.cpp index 99db7f5c..db574e17 100644 --- a/src/content/Content.cpp +++ b/src/content/Content.cpp @@ -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 blockDefs, - std::vector itemDefs) - : blockDefs(blockDefs), - itemDefs(itemDefs) { -} + std::vector itemDefs +) : blockDefs(blockDefs), + itemDefs(itemDefs) +{} -Content::Content(ContentIndices* indices, - std::unique_ptr drawGroups, - std::unordered_map blockDefs, - std::unordered_map itemDefs, - std::unordered_map> packs) - : blockDefs(blockDefs), - itemDefs(itemDefs), - indices(indices), - packs(std::move(packs)), - drawGroups(std::move(drawGroups)) { -} +Content::Content( + ContentIndices* indices, + std::unique_ptr drawGroups, + std::unordered_map blockDefs, + std::unordered_map itemDefs, + std::unordered_map> 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); diff --git a/src/content/Content.h b/src/content/Content.h index 01921b9b..9f201fa9 100644 --- a/src/content/Content.h +++ b/src/content/Content.h @@ -65,13 +65,15 @@ public: Content* build(); }; -/* Runtime defs cache: indices */ +/// @brief Runtime defs cache: indices class ContentIndices { std::vector blockDefs; std::vector itemDefs; public: - ContentIndices(std::vector blockDefs, - std::vector itemDefs); + ContentIndices( + std::vector blockDefs, + std::vector itemDefs + ); inline Block* getBlockDef(blockid_t id) const { if (id >= blockDefs.size()) @@ -112,11 +114,13 @@ class Content { public: std::unique_ptr const drawGroups; - Content(ContentIndices* indices, - std::unique_ptr drawGroups, - std::unordered_map blockDefs, - std::unordered_map itemDefs, - std::unordered_map> packs); + Content( + ContentIndices* indices, + std::unique_ptr drawGroups, + std::unordered_map blockDefs, + std::unordered_map itemDefs, + std::unordered_map> packs + ); ~Content(); inline ContentIndices* getIndices() const { diff --git a/src/content/ContentLUT.h b/src/content/ContentLUT.h index 6219c696..8b3f5886 100644 --- a/src/content/ContentLUT.h +++ b/src/content/ContentLUT.h @@ -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 blocks; std::vector blockNames; diff --git a/src/voxels/Block.h b/src/voxels/Block.h index d0403261..8d941d00 100644 --- a/src/voxels/Block.h +++ b/src/voxels/Block.h @@ -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 modelTextures = {}; std::vector modelBoxes = {}; std::vector modelExtraPoints = {}; //initially made for tetragons std::vector 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 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 hitboxes[BlockRotProfile::MAX_COUNT]; + /// @brief set of block callbacks flags block_funcs_set funcsset {}; + /// @brief picking item integer id itemid_t pickingItem = 0; } rt;