SIMD noise (not used yet)
This commit is contained in:
41
src/Game.zig
41
src/Game.zig
@@ -616,6 +616,7 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
|
||||
const block_grass = blocks.getFilename("Grass.json").?;
|
||||
const block_dirt = blocks.getFilename("Dirt.json").?;
|
||||
const block_stone = blocks.getFilename("Stone.json").?;
|
||||
const block_bedrock = blocks.getFilename("Bedrock.json").?;
|
||||
|
||||
while (it.next()) |chunk_coords| {
|
||||
@@ -636,26 +637,30 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
var it2 = Interator3(usize).init(0, 0, 0, 15, 15, 0);
|
||||
while (it2.next()) |pos| {
|
||||
const x, const y, _ = pos;
|
||||
const fpos = Vector3.init(
|
||||
const fpos = Vector2.init(
|
||||
@floatFromInt(pos[0]),
|
||||
@floatFromInt(pos[1]),
|
||||
@floatFromInt(pos[2]),
|
||||
).add(origin);
|
||||
).add(origin.asVector2());
|
||||
|
||||
const noise = std.math.clamp(math.noise2(fpos.asVector2().divScalar(30)), -1, 1);
|
||||
const fheight = (0.5 * noise + 0.5) * 4 + 1;
|
||||
const iheight: u32 = @intFromFloat(@round(fheight));
|
||||
const iheight = worldHeightI(fpos);
|
||||
|
||||
chunk.blocks[0][y][x] = block_bedrock;
|
||||
var i: u32 = 0;
|
||||
var i: i32 = 0;
|
||||
while (i < iheight) : (i += 1) {
|
||||
const iz = i + 1;
|
||||
const block = if (i + 1 == iheight) block_grass else block_dirt;
|
||||
chunk.blocks[iz][y][x] = block;
|
||||
const block = if (i + 1 == iheight)
|
||||
block_grass
|
||||
else if (i + 4 >= iheight)
|
||||
block_dirt
|
||||
else
|
||||
block_stone;
|
||||
chunk.blocks[@intCast(iz)][y][x] = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const camera_position = Vector3.init(0, 0, @as(f32, @floatFromInt(worldHeightI(.zero))) + 0.5 + 1.62);
|
||||
|
||||
var chunk_it = chunks.iterator();
|
||||
while (chunk_it.next()) |entry| {
|
||||
const x, const y, const z = entry.key_ptr.*;
|
||||
@@ -713,6 +718,8 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
.materials = materials,
|
||||
.textures = textures,
|
||||
.chunks = chunks,
|
||||
|
||||
.camera_position = camera_position,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -989,3 +996,19 @@ fn recreateSwapchain(self: *Game) !void {
|
||||
self.engine.setObjectName(semaphore.*, "S Transfer[{d}]", .{i});
|
||||
}
|
||||
}
|
||||
|
||||
fn worldHeightF(pos: Vector2) f32 {
|
||||
const noise_hscale = 80;
|
||||
|
||||
const noise_zcenter = 8;
|
||||
const noise_zscale = 5;
|
||||
|
||||
const noise = math.noise2(pos.divScalar(noise_hscale));
|
||||
const height = noise_zscale * noise + noise_zcenter;
|
||||
return height;
|
||||
}
|
||||
|
||||
fn worldHeightI(pos: Vector2) i32 {
|
||||
const iheight = worldHeightF(pos);
|
||||
return @intFromFloat(@round(iheight));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user