add docs to some blocks_agent functions
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/// blocks_agent is set of templates but not a class to minimize OOP overhead.
|
||||||
|
|
||||||
#include "voxel.hpp"
|
#include "voxel.hpp"
|
||||||
#include "Block.hpp"
|
#include "Block.hpp"
|
||||||
#include "Chunk.hpp"
|
#include "Chunk.hpp"
|
||||||
@@ -11,18 +13,31 @@
|
|||||||
#include "maths/voxmaths.hpp"
|
#include "maths/voxmaths.hpp"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
/// Using templates to minimize OOP overhead
|
|
||||||
|
|
||||||
namespace blocks_agent {
|
namespace blocks_agent {
|
||||||
|
|
||||||
|
/// @brief Get specified chunk.
|
||||||
|
/// @tparam Storage
|
||||||
|
/// @param chunks
|
||||||
|
/// @param cx chunk grid position X
|
||||||
|
/// @param cz chunk grid position Z
|
||||||
|
/// @return chunk or nullptr if does not exists
|
||||||
template<class Storage>
|
template<class Storage>
|
||||||
inline Chunk* get_chunk(const Storage& chunks, int cx, int cz) {
|
inline Chunk* get_chunk(const Storage& chunks, int cx, int cz) {
|
||||||
return chunks.getChunk(cx, cz);
|
return chunks.getChunk(cx, cz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get voxel at specified position.
|
||||||
|
/// Returns nullptr if voxel does not exists.
|
||||||
|
/// @tparam Storage chunks storage class
|
||||||
|
/// @param chunks chunks storage
|
||||||
|
/// @param x position X
|
||||||
|
/// @param y position Y
|
||||||
|
/// @param z position Z
|
||||||
|
/// @return voxel pointer or nullptr
|
||||||
template<class Storage>
|
template<class Storage>
|
||||||
inline voxel* get(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
inline voxel* get(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
||||||
if (y < 0 || y >= CHUNK_H) {
|
if (y < 0 || y >= CHUNK_H) {
|
||||||
@@ -39,6 +54,14 @@ inline voxel* get(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
|||||||
return &chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx];
|
return &chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Get voxel at specified position.
|
||||||
|
/// @throws std::runtime_error if voxel does not exists
|
||||||
|
/// @tparam Storage chunks storage class
|
||||||
|
/// @param chunks chunks storage
|
||||||
|
/// @param x position X
|
||||||
|
/// @param y position Y
|
||||||
|
/// @param z position Z
|
||||||
|
/// @return voxel reference
|
||||||
template<class Storage>
|
template<class Storage>
|
||||||
inline voxel& require(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
inline voxel& require(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
||||||
auto vox = get(chunks, x, y, z);
|
auto vox = get(chunks, x, y, z);
|
||||||
@@ -53,6 +76,14 @@ inline const Block& get_block_def(const Storage& chunks, blockid_t id) {
|
|||||||
return chunks.getContentIndices().blocks.require(id);
|
return chunks.getContentIndices().blocks.require(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Check if block at specified position is solid.
|
||||||
|
/// @tparam Storage chunks storage class
|
||||||
|
/// @param chunks chunks storage
|
||||||
|
/// @param x position X
|
||||||
|
/// @param y position Y
|
||||||
|
/// @param z position Z
|
||||||
|
/// @return true if block exists and solid
|
||||||
template<class Storage>
|
template<class Storage>
|
||||||
inline bool is_solid_at(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
inline bool is_solid_at(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
||||||
if (auto vox = get(chunks, x, y, z)) {
|
if (auto vox = get(chunks, x, y, z)) {
|
||||||
@@ -61,6 +92,13 @@ inline bool is_solid_at(const Storage& chunks, int32_t x, int32_t y, int32_t z)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Check if block at specified position is replaceable.
|
||||||
|
/// @tparam Storage chunks storage class
|
||||||
|
/// @param chunks chunks storage
|
||||||
|
/// @param x position X
|
||||||
|
/// @param y position Y
|
||||||
|
/// @param z position Z
|
||||||
|
/// @return true if block exists and replaceable
|
||||||
template<class Storage>
|
template<class Storage>
|
||||||
inline bool is_replaceable_at(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
inline bool is_replaceable_at(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
|
||||||
if (auto vox = get(chunks, x, y, z)) {
|
if (auto vox = get(chunks, x, y, z)) {
|
||||||
@@ -87,6 +125,14 @@ void set(
|
|||||||
blockstate state
|
blockstate state
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// @brief Erase extended block segments
|
||||||
|
/// @tparam Storage chunks storage class
|
||||||
|
/// @param chunks chunks storage
|
||||||
|
/// @param def origin block definition
|
||||||
|
/// @param state origin block state
|
||||||
|
/// @param x origin position X
|
||||||
|
/// @param y origin position Y
|
||||||
|
/// @param z origin position Z
|
||||||
template<class Storage>
|
template<class Storage>
|
||||||
inline void erase_segments(
|
inline void erase_segments(
|
||||||
Storage& chunks, const Block& def, blockstate state, int x, int y, int z
|
Storage& chunks, const Block& def, blockstate state, int x, int y, int z
|
||||||
@@ -108,10 +154,23 @@ inline void erase_segments(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr uint8_t segment_to_int(int sx, int sy, int sz) {
|
/// @brief Convert segment offset to segment bits
|
||||||
|
/// @param sx segment offset X
|
||||||
|
/// @param sy segment offset Y
|
||||||
|
/// @param sz segment offset Z
|
||||||
|
/// @return segment bits
|
||||||
|
static constexpr inline uint8_t segment_to_int(int sx, int sy, int sz) {
|
||||||
return ((sx > 0) | ((sy > 0) << 1) | ((sz > 0) << 2));
|
return ((sx > 0) | ((sy > 0) << 1) | ((sz > 0) << 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Restore invalid extended block segments
|
||||||
|
/// @tparam Storage chunks storage class
|
||||||
|
/// @param chunks chunks storage
|
||||||
|
/// @param def origin block definition
|
||||||
|
/// @param state origin block state
|
||||||
|
/// @param x origin position X
|
||||||
|
/// @param y origin position Y
|
||||||
|
/// @param z origin position Z
|
||||||
template <class Storage>
|
template <class Storage>
|
||||||
inline void repair_segments(
|
inline void repair_segments(
|
||||||
Storage& chunks, const Block& def, blockstate state, int x, int y, int z
|
Storage& chunks, const Block& def, blockstate state, int x, int y, int z
|
||||||
|
|||||||
Reference in New Issue
Block a user