From: Brendan Hansen Date: Mon, 17 Jan 2022 00:31:07 +0000 (-0600) Subject: bugfixes; random colors in worldgen X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=f30954faf7a98802570fe546c090cf2b7bdb3391;p=voxel-shooter.git bugfixes; random colors in worldgen --- diff --git a/src/chunk.onyx b/src/chunk.onyx index ef3b5ef..aeaa5e0 100644 --- a/src/chunk.onyx +++ b/src/chunk.onyx @@ -156,12 +156,10 @@ chunk_build_mesh :: (use chunk: ^Chunk) { if chunk_get(chunk, nx, ny, nz) != Block_Empty do continue; color := block; - if i != 4 { - color = cast(Block) (0xb000 | (0xffff0fff & cast(u32) color)); - } - if i == 5 { - color = cast(Block) (0x9000 | (0xffff0fff & cast(u32) color)); - } + l := ~~((cast(u32) color & 0xf000) >> 12) / 16.0f; + if i != 4 do l *= 0.75; + if i == 5 do l *= 0.75; + color = cast(Block) (((cast(u32) (l * 16.0f)) << 12) | (0xffff0fff & cast(u32) color)); indicies := cast([] u32) block_indicies[i]; tex_indicies := cast([] u32) block_texture_indicies[i]; diff --git a/src/main.onyx b/src/main.onyx index 73fcb8a..719204c 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -165,6 +165,7 @@ draw :: () { font_print(font, 0, 96, "Facing: {}", camera.y_rot * 180 / math.PI); font_print(font, 0, 128, "Looking at: {}", selected_block); font_print(font, 0, 160, "Chunk: {}", player_chunk); + font_print(font, 0, 192, "Chunks loading: {}", world.chunks_to_load.count); } glfwSwapBuffers(window); diff --git a/src/world.onyx b/src/world.onyx index 4c691b9..afcc0fa 100644 --- a/src/world.onyx +++ b/src/world.onyx @@ -141,7 +141,6 @@ world_move_center :: (use world: ^World, new_center: Vector3i) { sl := world.chunk_dist * 2 + 1; current_chunks := memory.copy_slice(world.chunks); - memory.alloc_slice(^world.chunks, sl * sl * sl); memory.fill_slice(world.chunks, null); center_chunk = new_center; @@ -152,9 +151,10 @@ world_move_center :: (use world: ^World, new_center: Vector3i) { } } - for x: (center_chunk.x-world.chunk_dist) .. center_chunk.x+world.chunk_dist+1 - do for y: (center_chunk.y-world.chunk_dist) .. center_chunk.y+world.chunk_dist+1 - do for z: (center_chunk.z-world.chunk_dist) .. center_chunk.z+world.chunk_dist+1 { + array.clear(^chunks_to_load); + for x: center_chunk.x-world.chunk_dist .. center_chunk.x+world.chunk_dist+1 + do for y: center_chunk.y-world.chunk_dist .. center_chunk.y+world.chunk_dist+1 + do for z: center_chunk.z-world.chunk_dist .. center_chunk.z+world.chunk_dist+1 { if world_get_chunk(world, x, y, z) == null do world.chunks_to_load << .{x, y, z}; } diff --git a/src/worldgen.onyx b/src/worldgen.onyx index e3a3e59..1df745a 100644 --- a/src/worldgen.onyx +++ b/src/worldgen.onyx @@ -11,12 +11,14 @@ generate_chunk :: (world: ^World, chunk: ^Chunk) { pz := cast(f64) t.z / 24; n := perlin.noise(px, ~~(10 * seed), pz); + l := perlin.noise(px, ~~(10 * seed + 6), pz); + l = (math.clamp(math.abs(l), 0.2, 0.5) - 0.2) / 0.6 + 0.5; h := cast(i32) (n * 32 + 18); h = math.max(h, 14); if n < -0.9 do h += ~~((n + 0.9) * 4); h -= chunk.coord.y * Chunk_Size; - if h >= 0 { chunk_set(chunk, cx, h, cz, block_make(0.2, 1, 0.2, 1)); h -= 1; } + if h >= 0 { chunk_set(chunk, cx, h, cz, block_make(0.2, 1, 0.2, ~~l)); h -= 1; } for cy: 2 .. h+1 do chunk_set(chunk, cx, cy, cz, block_make(0.3, 0.3, 0.1, 1, .{texture_enabled=false})); for cy: 0 .. math.min(h, 2)+1 do chunk_set(chunk, cx, cy, cz, block_make(0.2, 0.2, 0.2, 0.5, .{texture_enabled=false})); }