From cfa27fd8eed42599195fdff6d7d0e25586e8f18c Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Sep 2025 16:00:57 +0500 Subject: Graft header-only math::AABB from qfengine --- game/shared/world/CMakeLists.txt | 3 +-- game/shared/world/chunk_aabb.cc | 54 ---------------------------------------- game/shared/world/chunk_aabb.hh | 25 +++---------------- 3 files changed, 4 insertions(+), 78 deletions(-) delete mode 100644 game/shared/world/chunk_aabb.cc (limited to 'game/shared/world') diff --git a/game/shared/world/CMakeLists.txt b/game/shared/world/CMakeLists.txt index 6b9c281..15d5b59 100644 --- a/game/shared/world/CMakeLists.txt +++ b/game/shared/world/CMakeLists.txt @@ -1,8 +1,7 @@ target_sources(shared PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/chunk_aabb.hh" "${CMAKE_CURRENT_LIST_DIR}/chunk.cc" "${CMAKE_CURRENT_LIST_DIR}/chunk.hh" - "${CMAKE_CURRENT_LIST_DIR}/chunk_aabb.cc" - "${CMAKE_CURRENT_LIST_DIR}/chunk_aabb.hh" "${CMAKE_CURRENT_LIST_DIR}/dimension.cc" "${CMAKE_CURRENT_LIST_DIR}/dimension.hh" "${CMAKE_CURRENT_LIST_DIR}/feature.cc" diff --git a/game/shared/world/chunk_aabb.cc b/game/shared/world/chunk_aabb.cc deleted file mode 100644 index 634b230..0000000 --- a/game/shared/world/chunk_aabb.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "shared/pch.hh" - -#include "shared/world/chunk_aabb.hh" - -void world::ChunkAABB::set_bounds(const chunk_pos& min, const chunk_pos& max) -{ - this->min = min; - this->max = max; -} - -void world::ChunkAABB::set_offset(const chunk_pos& base, const chunk_pos& size) -{ - this->min = base; - this->max = base + size; -} - -bool world::ChunkAABB::contains(const chunk_pos& point) const -{ - auto result = true; - result = result && (point.x >= min.x) && (point.x <= max.x); - result = result && (point.y >= min.y) && (point.y <= max.y); - result = result && (point.z >= min.z) && (point.z <= max.z); - return result; -} - -bool world::ChunkAABB::intersect(const ChunkAABB& other_box) const -{ - auto result = true; - result = result && (min.x < other_box.max.x) && (max.x > other_box.min.x); - result = result && (min.y < other_box.max.y) && (max.y > other_box.min.y); - result = result && (min.z < other_box.max.z) && (max.z > other_box.min.z); - return result; -} - -world::ChunkAABB world::ChunkAABB::combine_with(const ChunkAABB& other_box) const -{ - ChunkAABB result; - result.set_bounds(min, other_box.max); - return result; -} - -world::ChunkAABB world::ChunkAABB::multiply_with(const ChunkAABB& other_box) const -{ - ChunkAABB result; - result.set_bounds(other_box.min, max); - return result; -} - -world::ChunkAABB world::ChunkAABB::push(const chunk_pos& vector) const -{ - ChunkAABB result; - result.set_bounds(min + vector, max + vector); - return result; -} diff --git a/game/shared/world/chunk_aabb.hh b/game/shared/world/chunk_aabb.hh index a9e0205..3a2d26f 100644 --- a/game/shared/world/chunk_aabb.hh +++ b/game/shared/world/chunk_aabb.hh @@ -2,32 +2,13 @@ #define SHARED_CHUNK_AABB 1 #pragma once +#include "core/math/aabb.hh" + #include "shared/types.hh" namespace world { -class ChunkAABB final { -public: - ChunkAABB(void) = default; - virtual ~ChunkAABB(void) = default; - - void set_bounds(const chunk_pos& min, const chunk_pos& max); - void set_offset(const chunk_pos& base, const chunk_pos& size); - - const chunk_pos& get_min(void) const; - const chunk_pos& get_max(void) const; - - bool contains(const chunk_pos& point) const; - bool intersect(const ChunkAABB& other_box) const; - - ChunkAABB combine_with(const ChunkAABB& other_box) const; - ChunkAABB multiply_with(const ChunkAABB& other_box) const; - ChunkAABB push(const chunk_pos& vector) const; - -public: - chunk_pos min; - chunk_pos max; -}; +using ChunkAABB = math::AABB; } // namespace world #endif // SHARED_CHUNK_AABB -- cgit