Skip to content

Commit

Permalink
[octree] Change uint8_t to std::uint8_t, 1U to 1u
Browse files Browse the repository at this point in the history
  • Loading branch information
movabo committed May 7, 2021
1 parent 9dba059 commit af65a79
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/vulkan-renderer/world/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void Cube::rotate<3>(const RotationAxis::Type &axis) {

Cube::Cube(const float size, const glm::vec3 &position) : m_size(size), m_position(position) {}

Cube::Cube(std::weak_ptr<Cube> parent, uint8_t index, const float size, const glm::vec3 &position)
Cube::Cube(std::weak_ptr<Cube> parent, const std::uint8_t index, const float size, const glm::vec3 &position)
: Cube(size, position) {
m_parent = std::move(parent);
m_index = index;
Expand Down Expand Up @@ -256,7 +256,7 @@ void Cube::set_type(const Type new_type) {
break;
case Type::OCTANT:
const float half_size = m_size / 2;
uint8_t index = 0;
std::uint8_t index = 0;
auto create_cube = [&](const glm::vec3 &offset) {
return std::make_shared<Cube>(weak_from_this(), index++, half_size, m_position + offset);
};
Expand Down Expand Up @@ -424,21 +424,21 @@ std::vector<PolygonCache> Cube::polygons(const bool update_invalid) const {
collect(*this);
return polygons;
}
std::optional<std::shared_ptr<Cube>> Cube::neighbor(NeighborAxis axis, NeighborDirection direction) {
std::optional<std::shared_ptr<Cube>> Cube::neighbor(const NeighborAxis axis, const NeighborDirection direction) {
assert(!is_root());

// Each axis only requires information and manipulation of one (relevant) bit to find the neighbor.
const auto relevant_bit_index = static_cast<uint8_t>(axis); // bit index of the axis we are working on
const auto relevant_bit_index = static_cast<std::uint8_t>(axis); // bit index of the axis we are working on

std::function<bool(const uint8_t)> get_bit = [&relevant_bit_index](const uint8_t bit_index) {
return (bit_index >> relevant_bit_index) & 1U;
std::function<bool(const std::uint8_t)> get_bit = [&relevant_bit_index](const std::uint8_t bit_index) {
return (bit_index >> relevant_bit_index) & 1u;
};
std::function<uint8_t(const uint8_t)> toggle_bit = [&relevant_bit_index](const uint8_t bit_index) {
return bit_index ^ (1U << relevant_bit_index);
std::function<std::uint8_t(const std::uint8_t)> toggle_bit = [&relevant_bit_index](const std::uint8_t bit_index) {
return bit_index ^ (1u << relevant_bit_index);
};

auto parent = m_parent.lock();
const uint8_t index = m_index.value();
const std::uint8_t index = m_index.value();
const bool this_bit = get_bit(index);

// The relevant bit denotes whether `m_parent` and `this` share a face on the upper side of the relevant axis.
Expand All @@ -455,12 +455,12 @@ std::optional<std::shared_ptr<Cube>> Cube::neighbor(NeighborAxis axis, NeighborD

// Keep the history of indices because we just need to mirror indices (i.e. toggle the relevant bit)
// to find the desired neighboring cube.
std::stack<uint8_t> history;
std::stack<std::uint8_t> history;
history.push(index);

// Find the first cube where the bit (of `get_bit`) is different to `this_bit`.
// That cubes parent is the first mutual parent of the desired neighbor and `this`.
uint8_t p_index = parent->m_index.value();
std::uint8_t p_index = parent->m_index.value();
history.push(p_index);
while (get_bit(p_index) == this_bit) {
parent = parent->m_parent.lock();
Expand Down

0 comments on commit af65a79

Please sign in to comment.