bugfixes; random colors in worldgen
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 17 Jan 2022 00:31:07 +0000 (18:31 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 17 Jan 2022 00:31:07 +0000 (18:31 -0600)
src/chunk.onyx
src/main.onyx
src/world.onyx
src/worldgen.onyx

index ef3b5ef359371cf6974f6f4c37e6d482228c6ff6..aeaa5e0e7d87a9fc6b9ab3dac8d5be170e22e7f4 100644 (file)
@@ -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];
index 73fcb8a06cbc62427607a1764040fe936a8768cc..719204c63ddfea59ad8b5d46e4ddc049d8e9d2a8 100644 (file)
@@ -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);
index 4c691b94beb156e6beb740c8abf4b4e4107cf989..afcc0fa950ed22b8e6507edab2e854b79056fcc1 100644 (file)
@@ -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};
     }
 
index e3a3e59c796307042f5445321a38e6a357f6f937..1df745a189130a6b0fbfae92786bce37649cf227 100644 (file)
@@ -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}));
     }