Change the way how faces are handled (they are now stored in the chunk they are facing towards, instead of the chunk where the actual block is in).

This commit is contained in:
IntegratedQuantum 2022-10-01 11:41:23 +02:00
parent e8e1fb401c
commit 219957681d
3 changed files with 12 additions and 12 deletions

View File

@ -47,12 +47,12 @@ const vec3[6] normals = vec3[6](
vec3(0, 0, -1) vec3(0, 0, -1)
); );
const vec3[6] positionOffset = vec3[6]( const vec3[6] positionOffset = vec3[6](
vec3(0, 0, 0),
vec3(0, 1, 0), vec3(0, 1, 0),
vec3(0, 0, 0), vec3(0, 0, 0),
vec3(1, 0, 0), vec3(1, 0, 0),
vec3(0, 0, 0), vec3(0, 0, 0),
vec3(0, 0, 1), vec3(0, 0, 1)
vec3(0, 0, 0)
); );
const ivec3[6] textureX = ivec3[6]( const ivec3[6] textureX = ivec3[6](
ivec3(1, 0, 0), ivec3(1, 0, 0),

View File

@ -643,7 +643,7 @@ pub const meshing = struct {
var isVisible = neighborBlock.typ == 0; // TODO: Transparency var isVisible = neighborBlock.typ == 0; // TODO: Transparency
if(isVisible) { if(isVisible) {
const normal: u32 = i; const normal: u32 = i;
const position: u32 = @as(u32, x) | @as(u32, y)<<5 | @as(u32, z)<<10; const position: u32 = @intCast(u32, x2) | @intCast(u32, y2)<<5 | @intCast(u32, z2)<<10;
const textureNormal = blocks.meshes.textureIndices(block)[i] | normal<<24; const textureNormal = blocks.meshes.textureIndices(block)[i] | normal<<24;
try self.faces.append(position); try self.faces.append(position);
try self.faces.append(textureNormal); try self.faces.append(textureNormal);
@ -700,21 +700,21 @@ pub const meshing = struct {
var otherX = @intCast(u8, x+%Neighbors.relX[neighbor] & chunkMask); var otherX = @intCast(u8, x+%Neighbors.relX[neighbor] & chunkMask);
var otherY = @intCast(u8, y+%Neighbors.relY[neighbor] & chunkMask); var otherY = @intCast(u8, y+%Neighbors.relY[neighbor] & chunkMask);
var otherZ = @intCast(u8, z+%Neighbors.relZ[neighbor] & chunkMask); var otherZ = @intCast(u8, z+%Neighbors.relZ[neighbor] & chunkMask);
var block = self.chunk.?.blocks[getIndex(x, y, z)]; var block = (&self.chunk.?.blocks)[getIndex(x, y, z)]; // a little hack that increases speed 100×. TODO: check if this is *that* compiler bug.
var otherBlock = neighborMesh.chunk.?.blocks[getIndex(otherX, otherY, otherZ)]; var otherBlock = (&neighborMesh.chunk.?.blocks)[getIndex(otherX, otherY, otherZ)]; // a little hack that increases speed 100×. TODO: check if this is *that* compiler bug.
if(otherBlock.typ == 0 and block.typ != 0) { // TODO: Transparency if(otherBlock.typ == 0 and block.typ != 0) { // TODO: Transparency
const normal: u32 = neighbor; const normal: u32 = neighbor;
const position: u32 = @as(u32, x) | @as(u32, y)<<5 | @as(u32, z)<<10; const position: u32 = @as(u32, otherX) | @as(u32, otherY)<<5 | @as(u32, otherZ)<<10;
const textureNormal = blocks.meshes.textureIndices(block)[neighbor] | normal<<24; const textureNormal = blocks.meshes.textureIndices(block)[neighbor] | normal<<24;
try self.faces.append(position); try additionalNeighborFaces.append(position);
try self.faces.append(textureNormal); try additionalNeighborFaces.append(textureNormal);
} }
if(block.typ == 0 and otherBlock.typ != 0) { // TODO: Transparency if(block.typ == 0 and otherBlock.typ != 0) { // TODO: Transparency
const normal: u32 = neighbor ^ 1; const normal: u32 = neighbor ^ 1;
const position: u32 = @as(u32, otherX) | @as(u32, otherY)<<5 | @as(u32, otherZ)<<10; const position: u32 = @as(u32, x) | @as(u32, y)<<5 | @as(u32, z)<<10;
const textureNormal = blocks.meshes.textureIndices(otherBlock)[neighbor] | normal<<24; const textureNormal = blocks.meshes.textureIndices(otherBlock)[neighbor] | normal<<24;
try additionalNeighborFaces.append(position); try self.faces.append(position);
try additionalNeighborFaces.append(textureNormal); try self.faces.append(textureNormal);
} }
} }
} }

View File

@ -691,7 +691,7 @@ pub const Protocols = blk: {
const _inflatedData = try utils.Compression.inflate(main.threadAllocator, data[16..]); const _inflatedData = try utils.Compression.inflate(main.threadAllocator, data[16..]);
data = _inflatedData; data = _inflatedData;
defer main.threadAllocator.free(_inflatedData); defer main.threadAllocator.free(_inflatedData);
if(pos.voxelSize == 1) { if(pos.voxelSize != 0) {
var ch = try renderer.RenderStructure.allocator.create(chunk.Chunk); var ch = try renderer.RenderStructure.allocator.create(chunk.Chunk);
ch.init(pos); ch.init(pos);
for(ch.blocks) |*block| { for(ch.blocks) |*block| {