summaryrefslogtreecommitdiff
path: root/src/World
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-08-14 03:40:10 +0200
committerMel <einebeere@gmail.com>2023-08-14 03:40:10 +0200
commit7562a79fa214245544cb379423314c3a0766a7f2 (patch)
tree0aaafd06c6026fabc82dbc3454487d009c9043e7 /src/World
parent5a1b126f1f6d55226c2b5068d0c17c428fd29ba8 (diff)
downloadmeowcraft-7562a79fa214245544cb379423314c3a0766a7f2.tar.zst
meowcraft-7562a79fa214245544cb379423314c3a0766a7f2.zip
Generate AABBs for terrain that collides with Player
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Chunk.cpp15
-rw-r--r--src/World/Chunk.hpp6
-rw-r--r--src/World/Generation/Decoration.cpp6
-rw-r--r--src/World/Generation/Decoration.hpp2
4 files changed, 16 insertions, 13 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index 8b204c0..6cb67bb 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -19,10 +19,6 @@ Chunk::BlockData& Chunk::at(Position::BlockLocal pos) {
return at(pos.x(), pos.y(), pos.z());
}
-Bool Chunk::is_empty(U32 x, U32 y, U32 z) const {
- return at(x, y, z).empty();
-}
-
ChunkIndex Chunk::index() const {
return m_index;
}
@@ -39,12 +35,19 @@ void Chunk::damage() {
m_damaged = true;
}
-Bool Chunk::is_valid_position(U32 x, U32 y, U32 z) {
- return x < Width && y < Height && z < Width;
+Bool Chunk::is_valid_position(Position::BlockLocal pos) {
+ return pos.x() < Width && pos.y() < Height && pos.z() < Width;
}
U64 Chunk::pos(U32 x, U32 y, U32 z) {
return x + Width * y + Width * Height * z;
}
+AABB Chunk::block_bounds(Position::BlockLocal pos) {
+ return {
+ {pos.x(), pos.y(), pos.z()},
+ {pos.x() + 1, pos.y() + 1, pos.z() + 1},
+ };
+}
+
}
diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp
index 0b00c97..ed3220d 100644
--- a/src/World/Chunk.hpp
+++ b/src/World/Chunk.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "../Common/Sizes.hpp"
+#include "../Math/AABB.hpp"
#include "ChunkDimensions.hpp"
#include "BiomeType.hpp"
#include "BlockType.hpp"
@@ -35,8 +36,6 @@ public:
const BlockData& at(Position::BlockLocal pos) const;
BlockData& at(Position::BlockLocal pos);
- Bool is_empty(U32 x, U32 y, U32 z) const;
-
struct Details {
Matrix<Width, Width> landmass_values{};
Matrix<Width, Width> hill_values{};
@@ -55,7 +54,8 @@ public:
Bool is_damaged() const;
void damage();
- static Bool is_valid_position(U32 x, U32 y, U32 z);
+ static Bool is_valid_position(Position::BlockLocal pos);
+ static AABB block_bounds(Position::BlockLocal pos);
private:
static U64 pos(U32 x, U32 y, U32 z);
diff --git a/src/World/Generation/Decoration.cpp b/src/World/Generation/Decoration.cpp
index 556b5e7..0623c05 100644
--- a/src/World/Generation/Decoration.cpp
+++ b/src/World/Generation/Decoration.cpp
@@ -4,11 +4,11 @@
namespace MC::World::Generation {
void Decorator::put_block(Chunk& chunk, Pos pos, BlockType block) {
- if (!Chunk::is_valid_position(pos.x(), pos.y(), pos.z())) {
+ if (!Chunk::is_valid_position(pos)) {
return;
}
- auto& place = chunk.at(pos.x(), pos.y(), pos.z());
+ auto& place = chunk.at(pos);
if (place.empty()) {
place = {block};
}
@@ -88,7 +88,7 @@ void TreeDecorator::draw_tree(Chunk& chunk, Pos pos) const {
}
}
-Bool TreeDecorator::is_valid_position(Vector<3, UInt> pos) {
+Bool TreeDecorator::is_valid_position(Pos pos) {
Int tree_radius = s_tree_radius;
return (Int)pos.x() - tree_radius >= 0
&& pos.x() + tree_radius <= Chunk::Width
diff --git a/src/World/Generation/Decoration.hpp b/src/World/Generation/Decoration.hpp
index 2f119ff..c157688 100644
--- a/src/World/Generation/Decoration.hpp
+++ b/src/World/Generation/Decoration.hpp
@@ -7,7 +7,7 @@ namespace MC::World::Generation {
class Decorator {
public:
- using Pos = Vector<3, UInt>;
+ using Pos = Position::BlockLocal;
virtual ~Decorator() = default;