mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 05:21:49 +00:00
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#ifndef VOXELS_VOXEL_HPP_
|
|
#define VOXELS_VOXEL_HPP_
|
|
|
|
#include "../typedefs.hpp"
|
|
|
|
inline constexpr int BLOCK_DIR_NORTH = 0x0;
|
|
inline constexpr int BLOCK_DIR_WEST = 0x1;
|
|
inline constexpr int BLOCK_DIR_SOUTH = 0x2;
|
|
inline constexpr int BLOCK_DIR_EAST = 0x3;
|
|
inline constexpr int BLOCK_DIR_UP = 0x4;
|
|
inline constexpr int BLOCK_DIR_DOWN = 0x5;
|
|
|
|
struct blockstate {
|
|
uint8_t rotation : 3;
|
|
uint8_t segment : 2; // planned to 0.22
|
|
uint8_t reserved : 3;
|
|
uint8_t userbits : 8;
|
|
};
|
|
static_assert (sizeof(blockstate) == 2);
|
|
|
|
inline constexpr blockstate_t blockstate2int(blockstate b) {
|
|
return static_cast<blockstate_t>(b.rotation) |
|
|
static_cast<blockstate_t>(b.segment) << 3 |
|
|
static_cast<blockstate_t>(b.reserved) << 5 |
|
|
static_cast<blockstate_t>(b.userbits) << 8;
|
|
}
|
|
|
|
inline constexpr blockstate int2blockstate(blockstate_t i) {
|
|
return {
|
|
static_cast<uint8_t>(i & 0b111),
|
|
static_cast<uint8_t>((i >> 3) & 0b11),
|
|
static_cast<uint8_t>((i >> 5) & 0b111),
|
|
static_cast<uint8_t>((i >> 8) & 0xFF)
|
|
};
|
|
}
|
|
|
|
struct voxel {
|
|
blockid_t id;
|
|
blockstate state;
|
|
};
|
|
static_assert(sizeof(voxel) == 4);
|
|
|
|
#endif // VOXELS_VOXEL_HPP_
|