From: Brendan Hansen Date: Fri, 23 Sep 2022 14:05:27 +0000 (-0500) Subject: macros were slowing things down X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6defeaa2395f4650644567e460e59f307d17c431;p=bar-game.git macros were slowing things down --- diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ca18c20 --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cd529eb..092c93b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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", diff --git a/run_tree/run.sh b/run_tree/run.sh index d7d7b85..e9050d4 100755 --- a/run_tree/run.sh +++ b/run_tree/run.sh @@ -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 $@ ;; diff --git a/src/entity/components/collision_mask.onyx b/src/entity/components/collision_mask.onyx index e42b1c2..c9d52b5 100644 --- a/src/entity/components/collision_mask.onyx +++ b/src/entity/components/collision_mask.onyx @@ -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; } diff --git a/src/utils/vecmath.onyx b/src/utils/vecmath.onyx index a2f38c6..83e177f 100644 --- a/src/utils/vecmath.onyx +++ b/src/utils/vecmath.onyx @@ -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 }; }