macros were slowing things down
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 23 Sep 2022 14:05:27 +0000 (09:05 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 23 Sep 2022 14:05:27 +0000 (09:05 -0500)
.vscode/launch.json [new file with mode: 0644]
.vscode/tasks.json
run_tree/run.sh
src/entity/components/collision_mask.onyx
src/utils/vecmath.onyx

diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644 (file)
index 0000000..ca18c20
--- /dev/null
@@ -0,0 +1,21 @@
+{
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "onyx",
+            "request": "attach",
+            "name": "Attach",
+            "socketPath": "/tmp/ovm-debug.0000",
+            "stopOnEntry": true
+        },
+        {
+            "type": "onyx",
+            "request": "launch",
+            "name": "Launch",
+            "wasmFile": "game.wasm",
+            "workingDir": "${workspaceFolder}/run_tree",
+            "stopOnEntry": true,
+            "preLaunchTask": "Build debug game"
+        }
+    ]
+}
index cd529eb28afdea4c25c10f771d8ddf81c05ad448..092c93baf11de749d1384384cf321fb1696fcf86 100644 (file)
@@ -9,12 +9,39 @@
             "options": {
                 "cwd": "${workspaceFolder}/run_tree",
                 "shell": {
-                    "executable": "/bin/sh"
+                    "executable": "/bin/sh",
+                    "args": ["-c"]
                 }
             },
             "problemMatcher": "$onyx",
             "command": "./run.sh",
-            // "args": ["build"],
+            "args": ["build"],
+            "presentation": {
+                "echo": true,
+                "reveal": "silent",
+                "focus": false,
+                "panel": "shared",
+                "showReuseMessage": false,
+                "clear": true,
+            },
+            "group": {
+                "kind": "build",
+                "isDefault": true
+            }
+        },
+        {
+            "label": "Build debug game",
+            "type": "shell",
+            "options": {
+                "cwd": "${workspaceFolder}/run_tree",
+                "shell": {
+                    "executable": "/bin/sh",
+                    "args": ["-c"]
+                }
+            },
+            "problemMatcher": "$onyx",
+            "command": "./run.sh",
+            "args": ["build", "--debug"],
             "presentation": {
                 "echo": true,
                 "reveal": "silent",
@@ -34,7 +61,8 @@
             "options": {
                 "cwd": "${workspaceFolder}/run_tree",
                 "shell": {
-                    "executable": "/bin/sh"
+                    "executable": "/bin/sh",
+                    "args": ["-c"]
                 }
             },
             "problemMatcher": "$onyx",
index d7d7b85d31c99cf416c2affabeada9c8b2d76d83..e9050d4926598b0e02213f3056374355a9790d5c 100755 (executable)
@@ -2,6 +2,7 @@ dest=game.wasm
 
 case "$1" in
     build) shift; onyx -V -I ../src build -o $dest $@ ;;
+    check) shift; onyx check -V -I ../src build  $@ ;;
     run)   onyx-run $dest ;;
     debug) onyx-run --debug $dest ;;
     *)     onyx run -V -I ../src build $@ ;;
index e42b1c2966ea9c9a40b2dc5bf306925ecde02e4a..c9d52b5cdb624ad9acf5dc70b3c8ac595ac5e026 100644 (file)
@@ -99,7 +99,7 @@ CollisionMaskComponent :: struct {
                 }
             }
 
-            array.quicksort(stack, (n1, n2) => {
+            array.sort(stack, (n1, n2) => {
                 f1 := n1.g + n1.h;
                 f2 := n2.g + n2.h;
                 if f1 < f2 do return 1;
@@ -115,6 +115,7 @@ CollisionMaskComponent :: struct {
                     ~~(path_pos.x * grid_size),
                     ~~(path_pos.y * grid_size),
                 };
+                visited->delete(path_pos);
                 path_pos = visited[path_pos].prev;
             }
 
index a2f38c6bc2f4c8a9e9b7d0357668eb929549e3b1..83e177f98b0f4764fa122f0d51c01d0fbae155be 100644 (file)
@@ -1,4 +1,5 @@
-#local hash :: package core.hash
+
+use core {hash, math}
 
 #tag conv.Custom_Format.{format_vector2i}
 #tag conv.Custom_Parse.{parse_vector2i}
@@ -12,11 +13,11 @@ Vector2i :: struct {
 Vector2 :: struct {
     x, y: f32;
 
-    mag :: macro (v: Vector2) => math.sqrt(v.x * v.x + v.y * v.y);
+    mag :: (v: Vector2) => math.sqrt(v.x * v.x + v.y * v.y);
 
-    square_mag :: macro (v: Vector2) => v.x * v.x + v.y * v.y;
+    square_mag :: (v: Vector2) => v.x * v.x + v.y * v.y;
 
-    norm :: macro (v: Vector2) -> Vector2 {
+    norm :: (v: Vector2) -> Vector2 {
         l := math.sqrt(v.x * v.x + v.y * v.y);
         return .{ v.x / l, v.y / l };
     }
@@ -34,20 +35,20 @@ Vector3i :: struct {
 Vector3 :: struct {
     x, y, z: f32;
 
-    mag :: macro (v: Vector3) => math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
+    mag :: (v: Vector3) => math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
 
-    neg :: macro (v: Vector3) => Vector3.{ -v.x, -v.y, -v.z };
+    neg :: (v: Vector3) => Vector3.{ -v.x, -v.y, -v.z };
 
-    dot :: macro (v1, v2: Vector3) -> f32 {
+    dot :: (v1, v2: Vector3) -> f32 {
         return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
     }
 
-    norm :: macro (v: Vector3) -> Vector3 {
+    norm :: (v: Vector3) -> Vector3 {
         l := math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
         return .{ v.x / l, v.y / l, v.z / l };
     }
 
-    cross :: macro (v1, v2: Vector3) -> Vector3 {
+    cross :: (v1, v2: Vector3) -> Vector3 {
         return .{
             v1.y * v2.z - v1.z * v2.y,
             v1.z * v2.x - v1.x * v2.z,
@@ -55,7 +56,7 @@ Vector3 :: struct {
         };
     }
 
-    clamp :: macro (v: Vector3, min: Vector3, max: Vector3) -> Vector3 {
+    clamp :: (v: Vector3, min: Vector3, max: Vector3) -> Vector3 {
         return .{
             math.clamp(v.x, min.x, max.x),
             math.clamp(v.y, min.y, max.y),
@@ -64,30 +65,30 @@ Vector3 :: struct {
     }
 }
 
-#operator + macro (v1, v2: Vector2i)   => (typeof v1).{ v1.x + v2.x, v1.y + v2.y };
-#operator - macro (v1, v2: Vector2i)   => (typeof v1).{ v1.x - v2.x, v1.y - v2.y };
-#operator * macro (v: Vector2i, s: i32) => (typeof v ).{ v.x * s,     v.y * s     };
-#operator * macro (v1, v2: Vector2i)   => (typeof v1).{ v1.x * v2.x, v1.y * v2.y };
-#operator == macro (v1, v2: Vector2i)  => v1.x == v2.x && v1.y == v2.y;
-#match hash.to_u32 macro (v: Vector2i) => 13 * v.x + 17 * v.y;
-
-#operator + macro (v1, v2: Vector2)    => (typeof v1).{ v1.x + v2.x, v1.y + v2.y };
-#operator - macro (v1, v2: Vector2)    => (typeof v1).{ v1.x - v2.x, v1.y - v2.y };
-#operator * macro (v: Vector2, s: f32) => (typeof v ).{ v.x * s,     v.y * s     };
-#operator * macro (v1, v2: Vector2)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y };
-#operator == macro (v1, v2: Vector2)   => v1.x == v2.x && v1.y == v2.y;
-
-#operator + macro (v1, v2: Vector3)    => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
-#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: Vector3)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y, v1.z * v3.z };
-#operator == macro (v1, v2: Vector3)   => 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 (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 };
-#operator * macro (v1, v2: Vector3i)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y, v1.z * v3.z };
-#operator == macro (v1, v2: Vector3i)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
+#operator + (v1, v2: Vector2i)   => Vector2i.{ v1.x + v2.x, v1.y + v2.y };
+#operator - (v1, v2: Vector2i)   => Vector2i.{ v1.x - v2.x, v1.y - v2.y };
+#operator * (v: Vector2i, s: i32) => Vector2i.{ v.x * s,     v.y * s     };
+#operator * (v1, v2: Vector2i)   => Vector2i.{ v1.x * v2.x, v1.y * v2.y };
+#operator == (v1, v2: Vector2i)  => v1.x == v2.x && v1.y == v2.y;
+#match hash.to_u32 (v: Vector2i) => 13 * v.x + 17 * v.y;
+
+#operator + (v1, v2: Vector2)    => (typeof v1).{ v1.x + v2.x, v1.y + v2.y };
+#operator - (v1, v2: Vector2)    => (typeof v1).{ v1.x - v2.x, v1.y - v2.y };
+#operator * (v: Vector2, s: f32) => (typeof v ).{ v.x * s,     v.y * s     };
+#operator * (v1, v2: Vector2)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y };
+#operator == (v1, v2: Vector2)   => v1.x == v2.x && v1.y == v2.y;
+
+#operator + (v1, v2: Vector3)    => Vector3.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
+#operator - (v1, v2: Vector3)    => Vector3.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
+#operator * (v: Vector3, s: f32) => Vector3.{ v.x * s,     v.y * s,     v.z * s };
+#operator * (v1, v2: Vector3)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
+#operator == (v1, v2: Vector3)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
+
+#operator + (v1, v2: Vector3i)    => Vector3i.{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
+#operator - (v1, v2: Vector3i)    => Vector3i.{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
+#operator * (v: Vector3i, s: i32) => Vector3i.{ v.x * s,     v.y * s,     v.z * s };
+#operator * (v1, v2: Vector3i)    => (typeof v1).{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
+#operator == (v1, v2: Vector3i)   => v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
 
 #local {
     conv :: package core.conv
@@ -156,10 +157,10 @@ Rect :: struct {
             && r.y <= p.y && r.y + r.h >= p.y;
     }
 
-    center :: macro (use r: Rect) => Vector2.{ r.x+r.w/2, r.y+r.h/2 };
+    center :: (use r: Rect) => Vector2.{ r.x+r.w/2, r.y+r.h/2 };
 
-    top_left     :: macro (use r: Rect) => Vector2.{ r.x,   r.y   };
-    top_right    :: macro (use r: Rect) => Vector2.{ r.x+r.w, r.y   };
-    bottom_left  :: macro (use r: Rect) => Vector2.{ r.x,   r.y+r.h };
-    bottom_right :: macro (use r: Rect) => Vector2.{ r.x+r.w, r.y+r.h };
+    top_left     :: (use r: Rect) => Vector2.{ r.x,   r.y   };
+    top_right    :: (use r: Rect) => Vector2.{ r.x+r.w, r.y   };
+    bottom_left  :: (use r: Rect) => Vector2.{ r.x,   r.y+r.h };
+    bottom_right :: (use r: Rect) => Vector2.{ r.x+r.w, r.y+r.h };
 }