random cleanup
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 31 Dec 2021 04:06:16 +0000 (22:06 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 31 Dec 2021 04:06:16 +0000 (22:06 -0600)
src/main.onyx
src/player.onyx
src/vecmath.onyx
src/world.onyx

index 50fbcdc2bc1887825a519b44a2992d45422e1750..135d1e63cfe5c3f88c03b7a62e08dcc78ec7799a 100644 (file)
@@ -150,17 +150,11 @@ draw :: () {
     glLineWidth(2);
     chunk_highlight_block(~~selected_block.x, ~~selected_block.y, ~~selected_block.z);
 
-    #if false {
-        aabb_buffer := (cast(^AABB) alloc.from_stack(sizeof [128] AABB))[0 .. 128];
-        aabbs := world_get_aabbs(world, camera.position, 5, aabb_buffer);
-        for^ aabbs do chunk_highlight_block(it.x0, it.y0, it.z0);
-    }
+    ww, wh: i32;
+    glfwGetWindowSize(window, ^ww, ^wh);
+    font_print(font, ~~(ww / 2), ~~(wh / 2), ".");
 
     if debug_screen {
-        ww, wh: i32;
-        glfwGetWindowSize(window, ^ww, ^wh);
-        font_print(font, ~~(ww / 2), ~~(wh / 2), ".");
-
         font_print(font, 0, 32, "FPS: {}", game_fps);
         font_print(font, 0, 64, "Position: {}", camera.position);
         font_print(font, 0, 96, "Facing: {}", camera.y_rot * 180 / math.PI);
index e9d6ecb93e9d58c2187df446850f9a6b2b796a0c..3c634fb14f9055cb8b022fc2fedf020d6ab74230 100644 (file)
@@ -77,7 +77,8 @@ player_update :: (use player: ^Player, dt: f32) {
     }
 
     if is_button_just_down(GLFW_MOUSE_BUTTON_RIGHT) {
-        world_set_block(world, selected_block.x + dir.x, selected_block.y + dir.y, selected_block.z + dir.z, block_make(1,0,0,1));
+        target := selected_block + dir;
+        world_set_block(world, target.x, target.y, target.z, block_make(1,0,0,1));
     }
 }
 
index c57891d81ab3e982e8e2e0d063bbf26c8a9d2d1a..95abdf10e53c6bf301e37d3efb20e51dce5e9d75 100644 (file)
@@ -43,6 +43,10 @@ Vector3 :: struct [conv.Custom_Format.{format_vector3}] {
 #operator - macro (v1, v2: Vector3)    => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
 #operator * macro (v: Vector3, s: f32) => Vector3.{ v.x * s,     v.y * s,     v.z * s };
 
+#operator + macro (v1, v2: Vector3i)    => Vector3i.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
+#operator - macro (v1, v2: Vector3i)    => Vector3i.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
+#operator * macro (v: Vector3i, s: i32) => Vector3i.{ v.x * s,     v.y * s,     v.z * s };
+
 #local {
     conv :: package core.conv
 
index a852b1e27e8587863bbfb5568a556e1d3f23d09b..2a1bf35749e4cb5f5ad5ed199995f53d08fbc04d 100644 (file)
@@ -92,7 +92,7 @@ Ray :: struct {
 }
 
 @Relocate // to a utils file
-ray_cast :: (ray: Ray, max_distance: f32, ctx: $T, is_solid: (T, Vector3i) -> bool, out_block: ^Vector3i, out_dir: ^Vector3i) -> bool {
+ray_cast :: (ray: Ray, max_distance: f32, ctx: rawptr, is_solid: (rawptr, Vector3i) -> bool, out_block: ^Vector3i, out_dir: ^Vector3i) -> bool {
     pos := Vector3i.{ ~~math.floor(ray.origin.x), ~~math.floor(ray.origin.y), ~~math.floor(ray.origin.z) };
 
     dir := ray.direction;