Questions about Crafti code #20
Replies: 8 comments 47 replies
-
It makes you wonder what this is for: typedef uint8_t BLOCK_SIDE_BITFIELD;
constexpr BLOCK_SIDE_BITFIELD BLOCK_FRONT_BIT = 1;
constexpr BLOCK_SIDE_BITFIELD BLOCK_BACK_BIT = 2;
constexpr BLOCK_SIDE_BITFIELD BLOCK_LEFT_BIT = 4;
constexpr BLOCK_SIDE_BITFIELD BLOCK_RIGHT_BIT = 8;
constexpr BLOCK_SIDE_BITFIELD BLOCK_TOP_BIT = 16;
constexpr BLOCK_SIDE_BITFIELD BLOCK_BOTTOM_BIT = 32;
constexpr BLOCK_SIDE_BITFIELD blockSideToBit(const BLOCK_SIDE side)
{
return 1 << side;
} |
Beta Was this translation helpful? Give feedback.
-
That code seems to convert BLOCK_SIDE to "bits" So block_side: enum BLOCK_SIDE{
BLOCK_FRONT=0,
BLOCK_BACK=1,
BLOCK_LEFT=2,
BLOCK_RIGHT=3,
BLOCK_TOP=4,
BLOCK_BOTTOM=5
}; And seems to shift 1 by the value of that so... constexpr BLOCK_SIDE_BITFIELD BLOCK_FRONT_BIT = 1;
constexpr BLOCK_SIDE_BITFIELD BLOCK_BACK_BIT = 2;
constexpr BLOCK_SIDE_BITFIELD BLOCK_LEFT_BIT = 4;
constexpr BLOCK_SIDE_BITFIELD BLOCK_RIGHT_BIT = 8;
constexpr BLOCK_SIDE_BITFIELD BLOCK_TOP_BIT = 16;
constexpr BLOCK_SIDE_BITFIELD BLOCK_BOTTOM_BIT = 32; |
Beta Was this translation helpful? Give feedback.
-
But this doesn't seem to match up with what you said earlier @m-doescode as the bit values take more than 3 bits... |
Beta Was this translation helpful? Give feedback.
-
I might actually be wrong in that the first 8 bits are used for the type. Because according to this code the first 8 leftmost bits are used for the data, then I assume the latter 8 bits are used for type. constexpr uint8_t getBLOCKDATA(BLOCK_WDATA bd) { return (bd >> 8) & 0x7F; } |
Beta Was this translation helpful? Give feedback.
-
We need a system for this Are "first bits" left to rigt? Or are "first bits" right to left? |
Beta Was this translation helpful? Give feedback.
-
What I have so far is that the regular blocks are basically just standard 8-bit integers where the leftmost 8 bits seem to be for data getBlockData seems to give the last 8 bits |
Beta Was this translation helpful? Give feedback.
-
Do you know what the purpose of constexpr uint8_t getBLOCKDATA(BLOCK_WDATA bd) { return (bd >> 8) & 0x7F; } ? |
Beta Was this translation helpful? Give feedback.
-
Slight problem [nvm, solved, see last reply] While the 16 bit bitmap seems to work fine with special blocks, how exactly do normal blocks handle data? (blocks of BLOCK type (uint8_t)) as they are only 8 bit, and do not appear to carry data, however, when selecting arenderer in map[BLOCK_AIR] = null_renderer;
map[BLOCK_BOOKSHELF] = oriented_renderer;
map[BLOCK_CAKE] = std::make_shared<CakeRenderer>();
map[BLOCK_CRAFTING_TABLE] = oriented_renderer;
map[BLOCK_DIRT] = color_renderer;
map[BLOCK_DOOR] = std::make_shared<DoorRenderer>();
map[BLOCK_FURNACE] = oriented_renderer;
map[BLOCK_GLASS] = std::make_shared<GlassRenderer>();
map[BLOCK_GRASS] = color_renderer;
map[BLOCK_LEAVES] = std::make_shared<LeavesRenderer>();
map[BLOCK_TNT] = std::make_shared<TNTRenderer>();
map[BLOCK_PLANKS_NORMAL] = color_renderer;
map[BLOCK_PUMPKIN] = oriented_renderer;
map[BLOCK_REDSTONE_LAMP] = std::make_shared<LampRenderer>();
map[BLOCK_REDSTONE_SWITCH] = std::make_shared<SwitchRenderer>();
map[BLOCK_REDSTONE_WIRE] = std::make_shared<WireRenderer>();
map[BLOCK_REDSTONE_TORCH] = std::make_shared<RedstoneTorchRenderer>();
map[BLOCK_PRESSURE_PLATE] = std::make_shared<PressurePlateRenderer>();
map[BLOCK_SAND] = color_renderer;
map[BLOCK_STONE] = color_renderer;
map[BLOCK_TORCH] = std::make_shared<TorchRenderer>();
map[BLOCK_WATER] = std::make_shared<FluidRenderer>(13, 12, "Water");
map[BLOCK_LAVA] = std::make_shared<FluidRenderer>(13, 14, "Lava");
map[BLOCK_WHEAT] = std::make_shared<WheatRenderer>();
map[BLOCK_WOOD] = color_renderer;
map[BLOCK_WOOL] = std::make_shared<WoolRenderer>(); You can see that oriented blocks exist, and in the function that renders them: void OrientedBlockRenderer::geometryNormalBlock(const BLOCK_WDATA block, const int local_x, const int local_y, const int local_z, const BLOCK_SIDE side, Chunk &c)
{
BLOCK_SIDE map[BLOCK_SIDE_LAST + 1];
BLOCK type = getBLOCK(block);
switch(static_cast<BLOCK_SIDE>(getBLOCKDATA(block)))
{
default:
case BLOCK_FRONT:
map[BLOCK_TOP] = BLOCK_TOP;
map[BLOCK_BOTTOM] = BLOCK_BOTTOM;
map[BLOCK_LEFT] = BLOCK_LEFT;
map[BLOCK_RIGHT] = BLOCK_RIGHT;
map[BLOCK_BACK] = BLOCK_BACK;
map[BLOCK_FRONT] = BLOCK_FRONT;
break;
case BLOCK_BACK:
map[BLOCK_TOP] = BLOCK_TOP;
map[BLOCK_BOTTOM] = BLOCK_BOTTOM;
map[BLOCK_LEFT] = BLOCK_RIGHT;
map[BLOCK_RIGHT] = BLOCK_LEFT;
map[BLOCK_BACK] = BLOCK_FRONT;
map[BLOCK_FRONT] = BLOCK_BACK;
break;
case BLOCK_LEFT:
map[BLOCK_TOP] = BLOCK_TOP;
map[BLOCK_BOTTOM] = BLOCK_BOTTOM;
map[BLOCK_LEFT] = BLOCK_FRONT;
map[BLOCK_RIGHT] = BLOCK_BACK;
map[BLOCK_BACK] = BLOCK_LEFT;
map[BLOCK_FRONT] = BLOCK_RIGHT;
break;
case BLOCK_RIGHT:
map[BLOCK_TOP] = BLOCK_TOP;
map[BLOCK_BOTTOM] = BLOCK_BOTTOM;
map[BLOCK_LEFT] = BLOCK_BACK;
map[BLOCK_RIGHT] = BLOCK_FRONT;
map[BLOCK_BACK] = BLOCK_RIGHT;
map[BLOCK_FRONT] = BLOCK_LEFT;
break;
}
BlockRenderer::renderNormalBlockSide(local_x, local_y, local_z, side, block_textures[type][map[side]].current, c);
} The oriented block renderer uses block data directly (no 3 bit bitmap stuff) to determine orientation of a regular block |
Beta Was this translation helpful? Give feedback.
-
We can see doorrenderer using the block side data:
This seems to indicate that it is first three bits?
(as in the bits with values1,2 and 4)
BLOCK_SIDE side = static_cast<BLOCK_SIDE>(getBLOCKDATA(block) & BLOCK_SIDE_BITS);
Since BLOCK_SIDE_BITS is 0b111 it seems to be this way
Beta Was this translation helpful? Give feedback.
All reactions