add advanced entities.raycast overload

This commit is contained in:
MihailRis 2026-07-15 22:21:18 +03:00
parent 66c99adab9
commit f29f3b1bba
10 changed files with 235 additions and 128 deletions

View file

@ -223,8 +223,7 @@ static inline voxel* raycast_blocks(
glm::vec3& end,
glm::ivec3& norm,
glm::ivec3& iend,
std::set<blockid_t> filter,
bool includeNonSelectable
const RaycastSettings& settings
) {
const auto& blocks = chunks.getContentIndices().blocks;
float px = start.x;
@ -259,16 +258,20 @@ static inline voxel* raycast_blocks(
float tzMax = (tzDelta < infinity) ? tzDelta * zdist : infinity;
int steppedIndex = -1;
bool includeNonSelectable = settings.includeNonSelectable;
while (t <= maxDist) {
voxel* voxel = get(chunks, ix, iy, iz);
if (voxel == nullptr) {
return nullptr;
}
auto filter = settings.filter;
const auto& def = blocks.require(voxel->id);
if (voxel->id != BLOCK_AIR && (def.selectable || includeNonSelectable) &&
(filter.empty() || filter.find(def.rt.id) == filter.end())) {
if (voxel->id != BLOCK_AIR
&& (def.selectable || includeNonSelectable)
&& (filter == nullptr || filter->empty() ||
filter->find(def.rt.id) == filter->end())) {
end.x = px + t * dx;
end.y = py + t * dy;
end.z = pz + t * dz;
@ -365,10 +368,9 @@ voxel* blocks_agent::raycast(
glm::vec3& end,
glm::ivec3& norm,
glm::ivec3& iend,
std::set<blockid_t> filter,
bool includeNonSelectable
const RaycastSettings& settings
) {
return raycast_blocks(chunks, start, dir, maxDist, end, norm, iend, filter, includeNonSelectable);
return raycast_blocks(chunks, start, dir, maxDist, end, norm, iend, settings);
}
voxel* blocks_agent::raycast(
@ -379,10 +381,9 @@ voxel* blocks_agent::raycast(
glm::vec3& end,
glm::ivec3& norm,
glm::ivec3& iend,
std::set<blockid_t> filter,
bool includeNonSelectable
const RaycastSettings& settings
) {
return raycast_blocks(chunks, start, dir, maxDist, end, norm, iend, filter, includeNonSelectable);
return raycast_blocks(chunks, start, dir, maxDist, end, norm, iend, settings);
}
// reduce nesting on next modification