diff options
| author | Mel <einebeere@gmail.com> | 2023-08-06 04:27:07 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-08-06 04:27:07 +0200 |
| commit | 5a1b126f1f6d55226c2b5068d0c17c428fd29ba8 (patch) | |
| tree | 3acc0240cd8dedd0764eeae6df04e134b04584c8 /src/World | |
| parent | e6f5f9e03f673db796f1babb308609ca2576db2f (diff) | |
| download | meowcraft-5a1b126f1f6d55226c2b5068d0c17c428fd29ba8.tar.zst meowcraft-5a1b126f1f6d55226c2b5068d0c17c428fd29ba8.zip | |
Create separate Player entity and add bad collision system
Diffstat (limited to 'src/World')
| -rw-r--r-- | src/World/ChunkIndex.hpp | 4 | ||||
| -rw-r--r-- | src/World/Clouds.cpp | 2 | ||||
| -rw-r--r-- | src/World/Position.hpp | 4 | ||||
| -rw-r--r-- | src/World/World.cpp | 6 | ||||
| -rw-r--r-- | src/World/World.hpp | 2 |
5 files changed, 13 insertions, 5 deletions
diff --git a/src/World/ChunkIndex.hpp b/src/World/ChunkIndex.hpp index 70de99f..2e4fa67 100644 --- a/src/World/ChunkIndex.hpp +++ b/src/World/ChunkIndex.hpp @@ -22,8 +22,8 @@ struct ChunkIndex { } static ChunkIndex from_position(Position::BlockWorld pos) { - I32 chunk_x = std::round(pos.x() / ChunkDimensions::Width); - I32 chunk_y = std::round(pos.z() / ChunkDimensions::Width); + I32 chunk_x = std::floor((Real)pos.x() / ChunkDimensions::Width); + I32 chunk_y = std::floor((Real)pos.z() / ChunkDimensions::Width); return {chunk_x, chunk_y}; } diff --git a/src/World/Clouds.cpp b/src/World/Clouds.cpp index 2567985..b30c0ce 100644 --- a/src/World/Clouds.cpp +++ b/src/World/Clouds.cpp @@ -103,7 +103,7 @@ GFX::Mesh Clouds::create_mesh(const CloudMatrix& cloud_matrix) { if (!neighbors[2]) faces |= FaceSet::Front; if (!neighbors[3]) faces |= FaceSet::Back; - auto aabb = Math::AABB{{x, 0, y}, {x + 1, 1, y + 1}}; + auto aabb = AABB{{x, 0, y}, {x + 1, 1, y + 1}}; auto box = GFX::Util::Primitives::box(aabb, (FaceSet::Value)faces); builder.primitive(box); } diff --git a/src/World/Position.hpp b/src/World/Position.hpp index bc874c0..91ec306 100644 --- a/src/World/Position.hpp +++ b/src/World/Position.hpp @@ -53,7 +53,7 @@ public: BlockLocal to_local() const { using namespace MC::World::ChunkDimensions; - return {Math::mod(x(), Width), y(), Math::mod(z(), Width)}; + return {Math::mod(x(), Width), std::clamp<I64>(y(), 0, Height), Math::mod(z(), Width)}; } }; @@ -73,7 +73,7 @@ public: MC_POSITION_MAKE_DEFAULT_CONSTRUCTORS(World, Real) BlockWorld round_to_block() const { - auto rounded = map([](auto x) { return std::round(x); }); + auto rounded = map([](auto x) { return std::floor(x); }); return {rounded.x(), rounded.y(), rounded.z()}; } }; diff --git a/src/World/World.cpp b/src/World/World.cpp index 089c498..ce15ae8 100644 --- a/src/World/World.cpp +++ b/src/World/World.cpp @@ -41,6 +41,12 @@ std::vector<ChunkRegistry::Data*> World::get_visible_chunks(Position::World posi return chunks; } +Chunk::BlockData World::block_at(Position::BlockWorld pos) { + auto& data = m_registry.find(pos); + if (data.chunk.has_value()) return data.chunk->at(pos.to_local()); + return {}; +} + std::vector<ChunkIndex> World::get_visible_chunk_indices(const Position::World position) const { ChunkIndex center = ChunkIndex::from_position(position.round_to_block()); diff --git a/src/World/World.hpp b/src/World/World.hpp index e3b08f5..3bf05f8 100644 --- a/src/World/World.hpp +++ b/src/World/World.hpp @@ -13,6 +13,8 @@ class World { public: std::vector<ChunkRegistry::Data*> get_visible_chunks(Position::World position); + Chunk::BlockData block_at(Position::BlockWorld pos); + Real get_average_chunk_time() const; private: std::vector<ChunkIndex> get_visible_chunk_indices(Position::World position) const; |
