Eliminate opposing walls
This commit is contained in:
61
src/Game.zig
61
src/Game.zig
@@ -15,7 +15,7 @@ const Engine = @import("engine/Engine.zig");
|
||||
const GenericBuffer = @import("engine/GenericBuffer.zig").GenericBuffer;
|
||||
const StagingBuffer = @import("engine/StagingBuffer.zig");
|
||||
const Swapchain = @import("engine/Swapchain.zig");
|
||||
const Iterator3 = math.Iterator3;
|
||||
const Interator3 = math.Interator3;
|
||||
const Matrix4x4 = math.Matrix4x4;
|
||||
const Quaternion = math.Quaternion;
|
||||
const Vector2 = math.Vector2;
|
||||
@@ -117,7 +117,7 @@ index_buffer: IndexBuffer,
|
||||
|
||||
global_uniforms: GlobalUniformsBuffer,
|
||||
global_uniforms_staging_buffer: StagingBuffer,
|
||||
global_uniforms_transfer_command_buffer: CommandBuffer(.graphics, .persistent),
|
||||
global_uniforms_transfer_command_buffer: CommandBuffer(.transfer, .persistent),
|
||||
global_uniforms_transfer_semaphores: []vk.Semaphore,
|
||||
point_lights: PointLightBuffer,
|
||||
directional_lights: DirectionalLightBuffer,
|
||||
@@ -126,7 +126,7 @@ sampler: vk.Sampler,
|
||||
blocks: Blocks,
|
||||
materials: Materials,
|
||||
textures: Textures,
|
||||
chunks: std.ArrayList(Chunk),
|
||||
chunks: std.AutoHashMapUnmanaged([3]i16, Chunk),
|
||||
|
||||
camera_position: Vector3 = .init(0, 0, 1.62),
|
||||
camera_pitch: f32 = 0,
|
||||
@@ -142,7 +142,7 @@ input_down: bool = false,
|
||||
const max_textures = 1024;
|
||||
const max_point_lights = 1024;
|
||||
const max_directional_lights = 4;
|
||||
const max_objects = 1024;
|
||||
const chunk_descriptor_pool = 512;
|
||||
|
||||
const camera_near_plane = 0.1;
|
||||
const camera_vertical_fov_deg = 80.0;
|
||||
@@ -318,7 +318,7 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
});
|
||||
errdefer global_uniforms_staging_buffer.deinit(engine);
|
||||
|
||||
var global_uniforms_transfer_command_buffer: CommandBuffer(.graphics, .persistent) = try .init(engine);
|
||||
var global_uniforms_transfer_command_buffer: CommandBuffer(.transfer, .persistent) = try .init(engine);
|
||||
errdefer global_uniforms_transfer_command_buffer.deinit(engine);
|
||||
|
||||
try global_uniforms_transfer_command_buffer.beginCommandBuffer(.{});
|
||||
@@ -491,7 +491,7 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
engine.setObjectName(pipeline, "P", .{});
|
||||
|
||||
const descriptor_pool = try engine.createDescriptorPool(.{
|
||||
.max_sets = 1 + 256,
|
||||
.max_sets = 1 + chunk_descriptor_pool,
|
||||
.pool_sizes = &.{
|
||||
.{
|
||||
.type = .sampler,
|
||||
@@ -507,7 +507,7 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
},
|
||||
.{
|
||||
.type = .storage_buffer,
|
||||
.descriptor_count = 3 + 256,
|
||||
.descriptor_count = 3 + chunk_descriptor_pool,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -603,33 +603,51 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
},
|
||||
});
|
||||
|
||||
var chunks: std.ArrayList(Chunk) = .empty;
|
||||
var chunks: std.AutoHashMapUnmanaged([3]i16, Chunk) = .empty;
|
||||
errdefer {
|
||||
for (chunks.items) |*chunk| {
|
||||
var it = chunks.valueIterator();
|
||||
while (it.next()) |chunk| {
|
||||
chunk.deinit(engine, descriptor_pool);
|
||||
}
|
||||
chunks.deinit(allocator);
|
||||
}
|
||||
|
||||
var it: Iterator3 = .init(.init(-64, -64, 0), .init(64, 64, 0), .init(16, 16, 16));
|
||||
while (it.next()) |origin| {
|
||||
var it = Interator3(i16).init(-10, -10, 0, 9, 9, 0);
|
||||
while (it.next()) |chunk_coords| {
|
||||
const origin = Vector3.init(
|
||||
@floatFromInt(chunk_coords[0]),
|
||||
@floatFromInt(chunk_coords[1]),
|
||||
@floatFromInt(chunk_coords[2]),
|
||||
).mulScalar(16);
|
||||
|
||||
try chunks.ensureUnusedCapacity(allocator, 1);
|
||||
chunks.appendAssumeCapacity(try Chunk.init(engine, .{
|
||||
chunks.putAssumeCapacityNoClobber(chunk_coords, try Chunk.init(engine, .{
|
||||
.origin = origin,
|
||||
.descriptor_pool = descriptor_pool,
|
||||
.per_batch_descriptor_set_layout = per_batch_descriptor_set_layout,
|
||||
}));
|
||||
const chunk = chunks.getPtr(chunk_coords).?;
|
||||
|
||||
const chunk = &chunks.items[chunks.items.len - 1];
|
||||
|
||||
var it2 = Iterator3.init(.init(0, 0, 0), .init(1, 1, 0), .{ .vector = @splat(1.0 / 16.0) });
|
||||
while (it2.next()) |fpos| {
|
||||
const x, const y, const z = fpos.asArrayNorm(u4);
|
||||
var it2 = Interator3(usize).init(0, 0, 0, 15, 15, 0);
|
||||
while (it2.next()) |pos| {
|
||||
const x, const y, const z = pos;
|
||||
const block: Blocks.Id = @enumFromInt(engine.random.intRangeLessThan(u12, 1, @intCast(blocks.blocks.items.len)));
|
||||
chunk.blocks[z][y][x] = block;
|
||||
}
|
||||
}
|
||||
|
||||
try chunk.refresh(engine, &blocks, allocator);
|
||||
var chunk_it = chunks.iterator();
|
||||
while (chunk_it.next()) |entry| {
|
||||
const x, const y, const z = entry.key_ptr.*;
|
||||
const chunk = entry.value_ptr;
|
||||
try chunk.refresh(engine, &blocks, .{
|
||||
.positive_x = chunks.getPtr(.{ x + 1, y, z }),
|
||||
.negative_x = chunks.getPtr(.{ x - 1, y, z }),
|
||||
.positive_y = chunks.getPtr(.{ x, y + 1, z }),
|
||||
.negative_y = chunks.getPtr(.{ x, y - 1, z }),
|
||||
.positive_z = chunks.getPtr(.{ x, y, z + 1 }),
|
||||
.negative_z = chunks.getPtr(.{ x, y, z - 1 }),
|
||||
}, allocator);
|
||||
}
|
||||
|
||||
const point_lights_data: []const PointLight = &.{};
|
||||
@@ -683,7 +701,9 @@ pub fn deinit(self: *Game) void {
|
||||
|
||||
self.vertex_buffer.deinit(self.engine);
|
||||
self.index_buffer.deinit(self.engine);
|
||||
for (self.chunks.items) |*chunk| {
|
||||
|
||||
var it = self.chunks.valueIterator();
|
||||
while (it.next()) |chunk| {
|
||||
chunk.deinit(self.engine, self.descriptor_pool);
|
||||
}
|
||||
self.chunks.deinit(self.allocator);
|
||||
@@ -916,7 +936,8 @@ fn render(self: *Game) !void {
|
||||
command_buffer.bindIndexBuffer(self.index_buffer.buffer, 0, .uint16);
|
||||
command_buffer.bindDescriptorSet(.graphics, self.pipeline_layout, 0, self.global_descriptor_set, null);
|
||||
|
||||
for (self.chunks.items) |chunk| {
|
||||
var it = self.chunks.valueIterator();
|
||||
while (it.next()) |chunk| {
|
||||
chunk.draw(self.pipeline_layout, command_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user