aboutsummaryrefslogtreecommitdiff
path: root/src/server/movement.cc
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
commite4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch)
treeed58c3c246e3af1af337697695d780aa31f6ad9a /src/server/movement.cc
parent1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff)
Update to most recent version (old initial commit)
Diffstat (limited to 'src/server/movement.cc')
-rw-r--r--src/server/movement.cc87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/server/movement.cc b/src/server/movement.cc
deleted file mode 100644
index 42b17f1..0000000
--- a/src/server/movement.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-#include "server/movement.hh"
-
-// Gets blocks from chunks, returning nullopt if it doesn't exist.
-static std::optional<shared::world::block>
-get_block(const shared::math::coords& pos, server::resources::chunk_map& chunks,
- const glm::ivec3& block_pos) noexcept {
-
- const auto find_it = chunks.find(pos);
- if (find_it == std::end(chunks)) {
- return std::nullopt;
- }
- auto& chunk_data = find_it->second;
- if (!chunk_data->has_initialised()) {
- return std::nullopt;
- }
-
- return chunk_data->get_chunk().get_block(block_pos);
-}
-
-static std::optional<std::vector<shared::movement::blockinfo>>
-make_blockinfos(server::client& client,
- server::resources::chunk_map& chunks) noexcept {
-
- std::vector<shared::movement::blockinfo> blockinfos;
-
- constexpr int width = shared::movement::move_width;
- constexpr int height = shared::movement::move_height;
- for (int x = -width; x <= width; ++x) {
- for (int y = -height; y <= height; ++y) {
- for (int z = -width; z <= width; ++z) {
-
- const glm::ivec3 rel_pos =
- glm::ivec3{x, y, z} +
- glm::ivec3{client.get_player().local_pos};
-
- if (rel_pos.y < 0 ||
- rel_pos.y >= shared::world::chunk::HEIGHT) {
- continue;
- }
-
- const shared::math::coords norm_chunk_pos =
- shared::world::chunk::get_normalised_chunk(
- client.get_player().chunk_pos, rel_pos.x, rel_pos.z);
- const glm::ivec3 norm_pos =
- shared::world::chunk::get_normalised_coords(rel_pos);
-
- const auto block = get_block(norm_chunk_pos, chunks, norm_pos);
-
- if (!block.has_value()) {
- return std::nullopt;
- }
-
- const glm::vec3 pos =
- glm::vec3{rel_pos} - client.get_player().local_pos;
-
- const shared::movement::aabb aabb = {
- .min = glm::vec3{0.0f, 0.0f, 0.0f} + pos,
- .max = glm::vec3{1.0f, 1.0f, 1.0f} + pos};
- blockinfos.push_back(
- shared::movement::blockinfo{.block = *block,
- .aabb = aabb,
- .chunk_pos = norm_chunk_pos,
- .pos = norm_pos});
- }
- }
- }
-
- return blockinfos;
-}
-
-void server::movement::move(server::client& client,
- server::resources::chunk_map& chunks) noexcept {
-
- if (!client.has_initialised()) {
- return;
- }
-
- const auto blockinfos = make_blockinfos(client, chunks);
-
- if (!blockinfos.has_value()) {
- return;
- }
-
- const float deltatime = 1.0f / static_cast<float>(server::state.tickrate);
-
- shared::movement::move(client.get_player(), *blockinfos, deltatime);
-}