summaryrefslogtreecommitdiffhomepage
path: root/src/world.hpp
blob: 0d28429e72bf58fe1d437159f397fa1a8c4798ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include "src/chunk.hpp"
#include "compat/assert.hpp"

namespace floormat {

struct chunk_coords final {
    std::int16_t x = 0, y = 0;
};

struct global_coords final {
    std::int32_t x = 0, y = 0;
    constexpr chunk_coords chunk() const noexcept;
    constexpr chunk_coords local() const noexcept;
};

constexpr chunk_coords global_coords::chunk() const noexcept {
    constexpr std::uint32_t mask = 0xffff0000u;
    const auto x_ = (std::int16_t)(std::uint16_t)((std::uint32_t)x & mask >> 24),
               y_ = (std::int16_t)(std::uint16_t)((std::uint32_t)y & mask >> 24);
    return {x_, y_};
}

constexpr chunk_coords global_coords::local() const noexcept {
    const auto x_ = (std::uint8_t)x, y_ = (std::uint8_t)y;
    return {x_, y_};
}

} // namespace floormat