Vectorized noise (but was it a bottleneck?)
This commit is contained in:
49
src/Game.zig
49
src/Game.zig
@@ -21,8 +21,10 @@ const Interator2 = math.Interator2;
|
||||
const Matrix4x4 = math.Matrix4x4;
|
||||
const Quaternion = math.Quaternion;
|
||||
const Vector2 = math.Vector2;
|
||||
const Vector2x8 = math.Vector2x8;
|
||||
const Vector3 = math.Vector3;
|
||||
const Vector4 = math.Vector4;
|
||||
const ps = math.ps;
|
||||
|
||||
const PointLight = extern struct {
|
||||
positionWS: [3]f32,
|
||||
@@ -628,27 +630,36 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
);
|
||||
const chunk = chunks.getPtr(chunk_coords3).?;
|
||||
|
||||
var it2 = Interator2(usize).init(0, 0, 15, 15);
|
||||
while (it2.next()) |pos| {
|
||||
const x, const y = pos;
|
||||
const fpos = Vector2.init(
|
||||
@floatFromInt(pos[0]),
|
||||
@floatFromInt(pos[1]),
|
||||
).add(origin.asVector2());
|
||||
var y: usize = 0;
|
||||
while (y < 16) : (y += 1) {
|
||||
const fpos0 = Vector2x8.initScalars(
|
||||
.{ 0, 1, 2, 3, 4, 5, 6, 7 },
|
||||
@splat(@floatFromInt(y)),
|
||||
).add(.initVector(origin.asVector2()));
|
||||
const fpos1 = Vector2x8.initScalars(
|
||||
.{ 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
@splat(@floatFromInt(y)),
|
||||
).add(.initVector(origin.asVector2()));
|
||||
|
||||
const iheight = worldgen.heightI(world_seed, fpos);
|
||||
const iheight0 = worldgen.heightIv(world_seed, fpos0);
|
||||
const iheight1 = worldgen.heightIv(world_seed, fpos1);
|
||||
|
||||
chunk.blocks[0][y][x] = block_bedrock;
|
||||
var i: i32 = 0;
|
||||
while (i < iheight) : (i += 1) {
|
||||
const iz = i + 1;
|
||||
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 iheightv: [16]i32 = @as([8]i32, iheight0) ++ @as([8]i32, iheight1);
|
||||
var x: usize = 0;
|
||||
while (x < 16) : (x += 1) {
|
||||
chunk.blocks[0][y][x] = block_bedrock;
|
||||
const iheight = iheightv[x];
|
||||
var i: i32 = 0;
|
||||
while (i < iheight) : (i += 1) {
|
||||
const iz = i + 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user