format blocks_agent.hpp

This commit is contained in:
MihailRis 2026-03-02 01:13:45 +03:00
parent dc27bd1430
commit 6bdbf5b40e

View file

@ -2,23 +2,23 @@
/// blocks_agent is set of templates but not a class to minimize OOP overhead.
#include "voxel.hpp"
#include "Block.hpp"
#include "Chunk.hpp"
#include "Chunks.hpp"
#include "VoxelsVolume.hpp"
#include "GlobalChunks.hpp"
#include "constants.hpp"
#include "typedefs.hpp"
#include "content/Content.hpp"
#include "GlobalChunks.hpp"
#include "maths/voxmaths.hpp"
#include "typedefs.hpp"
#include "voxel.hpp"
#include "VoxelsVolume.hpp"
#include <algorithm>
#include <set>
#include <algorithm>
#include <stdint.h>
#include <stdexcept>
#include <glm/glm.hpp>
#include <set>
#include <stdexcept>
#include <stdint.h>
struct AABB;
@ -96,7 +96,6 @@ inline const Block& get_block_def(const Storage& chunks, blockid_t 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
@ -104,8 +103,10 @@ inline const Block& get_block_def(const Storage& chunks, blockid_t id) {
/// @param y position Y
/// @param z position Z
/// @return true if block exists and solid
template<class Storage>
inline bool is_solid_at(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
template <class Storage>
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)) {
return get_block_def(chunks, vox->id).rt.solid;
}
@ -119,8 +120,10 @@ inline bool is_solid_at(const Storage& chunks, int32_t x, int32_t y, int32_t z)
/// @param y position Y
/// @param z position Z
/// @return true if block exists and replaceable
template<class Storage>
inline bool is_replaceable_at(const Storage& chunks, int32_t x, int32_t y, int32_t z) {
template <class Storage>
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)) {
return get_block_def(chunks, vox->id).replaceable;
}
@ -456,12 +459,18 @@ voxel* raycast(
bool includeNonSelectable
);
void get_voxels(const Chunks& chunks, VoxelsVolume* volume, bool backlight=false);
void get_voxels(
const Chunks& chunks, VoxelsVolume* volume, bool backlight = false
);
void get_voxels(const GlobalChunks& chunks, VoxelsVolume* volume, bool backlight=false);
void get_voxels(
const GlobalChunks& chunks, VoxelsVolume* volume, bool backlight = false
);
template <class Storage>
inline const AABB* is_obstacle_at(const Storage& chunks, float x, float y, float z) {
inline const AABB* is_obstacle_at(
const Storage& chunks, float x, float y, float z
) {
int ix = std::floor(x);
int iy = std::floor(y);
int iz = std::floor(z);
@ -510,41 +519,47 @@ inline bool check_grounding(
) {
const auto& vec = get_ground_direction(def, rotationIndex);
if (def.rt.extended) {
const auto& rotation = def.rotations.variants[rotationIndex];
if (def.groundingBehaviour == GroundingBehaviour::PARTIAL) {
for (int sz = 0; sz < def.size.z; sz++) {
for (int sx = 0; sx < def.size.x; sx++) {
auto pos = origin;
pos += rotation.axes[0] * sx;
pos += rotation.axes[2] * sz;
if (blocks_agent::is_solid_at(chunks, pos.x + vec.x, pos.y + vec.y, pos.z + vec.z)) {
return true;
}
}
}
return false;
}
else if (def.groundingBehaviour == GroundingBehaviour::COMPLETE) {
for (int sz = 0; sz < def.size.z; sz++) {
for (int sx = 0; sx < def.size.x; sx++) {
auto pos = origin;
pos += rotation.axes[0] * sx;
pos += rotation.axes[2] * sz;
if (!blocks_agent::is_solid_at(chunks, pos.x + vec.x, pos.y + vec.y, pos.z + vec.z)) {
return false;
}
}
}
return true;
}
else if (def.groundingBehaviour == GroundingBehaviour::ORIGIN) {
return blocks_agent::is_solid_at(chunks, origin.x + vec.x, origin.y + vec.y, origin.z + vec.z);
}
if (!def.rt.extended) {
return blocks_agent::is_solid_at(
chunks, origin.x + vec.x, origin.y + vec.y, origin.z + vec.z
);
}
return blocks_agent::is_solid_at(chunks, origin.x + vec.x, origin.y + vec.y, origin.z + vec.z);
const auto& rotation = def.rotations.variants[rotationIndex];
if (def.groundingBehaviour == GroundingBehaviour::PARTIAL) {
for (int sz = 0; sz < def.size.z; sz++) {
for (int sx = 0; sx < def.size.x; sx++) {
auto pos = origin;
pos += rotation.axes[0] * sx;
pos += rotation.axes[2] * sz;
if (blocks_agent::is_solid_at(
chunks, pos.x + vec.x, pos.y + vec.y, pos.z + vec.z
)) {
return true;
}
}
}
return false;
} else if (def.groundingBehaviour == GroundingBehaviour::COMPLETE) {
for (int sz = 0; sz < def.size.z; sz++) {
for (int sx = 0; sx < def.size.x; sx++) {
auto pos = origin;
pos += rotation.axes[0] * sx;
pos += rotation.axes[2] * sz;
if (!blocks_agent::is_solid_at(
chunks, pos.x + vec.x, pos.y + vec.y, pos.z + vec.z
)) {
return false;
}
}
}
return true;
} else {
return blocks_agent::is_solid_at(
chunks, origin.x + vec.x, origin.y + vec.y, origin.z + vec.z
);
}
}
} // blocks_agent