diff --git a/src/vybe/c.clj b/src/vybe/c.clj index 63e3715f..034b1515 100644 --- a/src/vybe/c.clj +++ b/src/vybe/c.clj @@ -843,8 +843,9 @@ int bs_lower_bound(float a[], int n, float x) { (+ a 40 520.0)) 15)) - ;; Anonymous function. - :fn + ;; Anonymous function (not supported right now as linux and windows + ;; have issues with it). + #_ #_:fn (let [meth (first (:methods v)) {:keys [params body]} meth return-tag (or (some-> (::schema (meta (first (:form meth)))) @@ -1027,7 +1028,9 @@ int bs_lower_bound(float a[], int n, float x) { (format (if (::-root (meta (first (:form v)))) "%s" "({%s;})") - (->> (concat statements [ret]) + (->> (concat (map #(vary-meta % assoc :void true) + statements) + [ret]) (mapv emit) (str/join ";\n\n")))) @@ -1508,7 +1511,7 @@ long long int: \"long long int\", unsigned long long int: \"unsigned long long i ([code-form {:keys [sym-meta sym sym-name] :as opts}] (let [{:keys [c-code ::c-data form-hash final-form init-struct-val]} (-> code-form - (transpile (assoc opts ::version 56))) + (transpile (assoc opts ::version 57))) obj-name (str "vybe_" sym-name "_" (when (or (:no-cache sym-meta) diff --git a/src/vybe/flecs/impl.clj b/src/vybe/flecs/impl.clj index 43602b94..90ea28ad 100644 --- a/src/vybe/flecs/impl.clj +++ b/src/vybe/flecs/impl.clj @@ -121,9 +121,11 @@ (vector main-name {:args args :ret ret + :java-fn-desc `(~(symbol desc-full-name)) - :ret-layout ret-layout :fn-address `(~(symbol (str "org.vybe.flecs.flecs/" address-name))) + + :ret-layout ret-layout :has-arena? (or (layout? ret) (some (comp address? :clj-type) args)) diff --git a/src/vybe/game/system.clj b/src/vybe/game/system.clj index fe0020e8..7dc91d70 100644 --- a/src/vybe/game/system.clj +++ b/src/vybe/game/system.clj @@ -7,6 +7,7 @@ [vybe.panama :as vp] [vybe.raylib.c :as vr.c] [vybe.jolt :as vj] + [vybe.jolt.c :as vj.c] [vybe.raylib :as vr] [vybe.math :as vm] #_[vybe.audio :as va] @@ -198,35 +199,42 @@ (vr.c/matrix-multiply @transform-global)) {:keys [x y z]} (vt/Translation [(:m12 matrix) (:m13 matrix) (:m14 matrix)]) - #_ #_body (if vy-body - (do (when kinematic - #_(println :KINEMATIC (matrix->rotation transform-global)) - (vj/move vy-body (vt/Vector3 [x y z]) (vm/matrix->rotation transform-global) (:delta_time it))) - vy-body) - (let [body (vj/body-add phys (vj/BodyCreationSettings - (cond-> {:position #_(vt/Vector4 [0 0 0 1]) - (vt/Vector4 [x y z 1]) - :rotation #_(vt/Rotation [0 0 0 1]) - (vm/matrix->rotation transform-global) - :shape (vj/box (vj/HalfExtent [(half :x) (half :y) (half :z)]) - scale - #_(vt/Vector4 [x y z 1]) - #_(vt/Translation [0 0 0]) - #_(matrix->rotation transform-global))} - kinematic - (assoc :motion_type (jolt/JPC_MOTION_TYPE_KINEMATIC)) - - sensor - (assoc :is_sensor true) - - dynamic - (assoc :motion_type (jolt/JPC_MOTION_TYPE_DYNAMIC) - :object_layer :vj.layer/moving))))] - (when (= (vf/get-name e) (vf/path [:my/model :vg.gltf/my-cube])) - #_(clojure.pprint/pprint (-> (vj/-body-get phys (:id body)) - :motion_properties - #_(vp/p->map vj/MotionProperties)))) - body)) + body (if vy-body + (do (when kinematic + (vj.c/jpc-body-interface-move-kinematic + (:body-interface @vy-body) + (:id @vy-body) + (vp/as (vp/& (vt/Vector3 [x y z])) :*) + (let [rot (vm/matrix->rotation-c (vp/as transform-global :*))] + (-> rot vp/& (vp/as :*))) + (:delta_time @it))) + vy-body) + #_(let [body (vj/body-add phys (vj/BodyCreationSettings + (cond-> {:position #_(vt/Vector4 [0 0 0 1]) + (vt/Vector4 [x y z 1]) + :rotation #_(vt/Rotation [0 0 0 1]) + (vm/matrix->rotation transform-global) + :shape (vj/box (vj/HalfExtent [(half :x) (half :y) (half :z)]) + scale + #_(vt/Vector4 [x y z 1]) + #_(vt/Translation [0 0 0]) + #_(matrix->rotation transform-global))} + kinematic + (assoc :motion_type (jolt/JPC_MOTION_TYPE_KINEMATIC)) + + sensor + (assoc :is_sensor true) + + dynamic + (assoc :motion_type (jolt/JPC_MOTION_TYPE_DYNAMIC) + :object_layer :vj.layer/moving))))] + (when (= (vf/get-name e) (vf/path [:my/model :vg.gltf/my-cube])) + #_(clojure.pprint/pprint (-> (vj/-body-get phys (:id body)) + :motion_properties + #_(vp/p->map vj/MotionProperties)))) + body)) + + #_ #_ {:keys [mesh material]} (when-not vy-body (gen-cube {:x (scaled :x) :y (scaled :y) :z (scaled :z)} (rand-int 10)))] diff --git a/src/vybe/jolt/impl.clj b/src/vybe/jolt/impl.clj index 6d9b5cdb..513ecfd6 100644 --- a/src/vybe/jolt/impl.clj +++ b/src/vybe/jolt/impl.clj @@ -87,6 +87,10 @@ desc-name ((comp :name bean) method) main-name (str/replace desc-name #"\$descriptor" "") + + desc-full-name (str (.getName (.getDeclaringClass method)) "/" desc-name) + address-name (str (str/replace desc-name #"\$descriptor" "") "$address") + ^Method main-method (->> declared-methods (filter (comp #(= main-name (.getName ^Method %)))) first)] @@ -109,6 +113,10 @@ (vector main-name {:args args :ret ret + + :java-fn-desc `(~(symbol desc-full-name)) + :fn-address `(~(symbol (str "org.vybe.jolt.jolt/" address-name))) + :ret-layout ret-layout :has-arena? (or (layout? ret) (some (comp address? :clj-type) @@ -121,7 +129,8 @@ `(do ~(->> (-methods) (drop init) (take size) - (mapv (fn [[n {:keys [args ret ret-layout has-arena?]}]] + (mapv (fn [[n {:keys [args ret ret-layout ^FunctionDescriptor java-fn-desc + fn-address has-arena?]}]] #_(when (= (System/getenv "VYBE_DEBUG") "true") (println :JOLT_VAR (csk/->kebab-case-symbol n))) (let [ray-args (mapv (fn [{:keys [name clj-type]}] @@ -138,7 +147,13 @@ ~(mapv (fn [{:keys [name clj-type]}] [(symbol name) clj-type]) args))) - :doc ~(format "Returns %s." (or ret "void"))} + :doc ~(format "Returns %s." (or ret "void")) + :vybe/fn-meta {:fn-desc [:fn {:foreign-fn-desc ~java-fn-desc + :fn-args (quote + ~(mapv (fn [{:keys [name]}] + (symbol name)) + args))}] + :fn-address ~fn-address}} ;; Fn args. ~(mapv (comp symbol :name) args) ;; Fn body. diff --git a/src/vybe/math.clj b/src/vybe/math.clj index e4e721af..85e17b1d 100644 --- a/src/vybe/math.clj +++ b/src/vybe/math.clj @@ -3,7 +3,10 @@ (:require [vybe.raylib.c :as vr.c] [vybe.type :as vt] - [vybe.jolt :as vj]) + [vybe.jolt :as vj] + [vybe.jolt.c :as vj.c] + [vybe.c :as vc] + [vybe.panama :as vp]) (:import (org.vybe.raylib raylib))) @@ -17,7 +20,7 @@ (vr.c/matrix-translate (:x translation) (:y translation) (:z translation)) (vr.c/matrix-translate 0 0 0))] (vr.c/matrix-multiply (vr.c/matrix-multiply mat-scale mat-rotation) mat-translation))) -#_(vg/matrix-transform +#_(matrix-transform (vt/Translation [0 0 0]) (vt/Rotation [0 0 0 1]) #_(vr.c/matrix-identity) @@ -36,6 +39,21 @@ (-> (vr.c/quaternion-from-matrix matrix) vj/normalize)) +(vc/defn* matrix->rotation-c :- vt/Rotation + [matrix :- [:* vt/Matrix]] + (let [out (vp/& (vt/Rotation)) + mat (vr.c/quaternion-from-matrix (vc/cast* @matrix vt/Transform))] + (vj.c/jpc-vec-4-normalize (vp/& mat) out) + @out)) +#_ (= (matrix->rotation (matrix-transform + (vt/Translation [0 1 0]) + (vt/Rotation [0 0.5 0 1]) + (vt/Scale [1 1 1]))) + (matrix->rotation-c (matrix-transform + (vt/Translation [0 1 0]) + (vt/Rotation [0 0.5 0 1]) + (vt/Scale [1 1 1])))) + (defn rad->degree [v] (* v (raylib/RAD2DEG))) diff --git a/todo.md b/todo.md index a0d63aa2..787d9514 100644 --- a/todo.md +++ b/todo.md @@ -317,8 +317,10 @@ - [-] support anon functions using clang blocks - __auto_type dddd = ^ void () { printf(\"test\"); } ; dddd(); - it doesn't work in windows/linux - - [ ] let :keys destructuring - - [ ] anon functions without blocks? + - [x] `let` :keys destructuring + - [x] anon functions without blocks? + - used macros + - [ ] - [ ] built-in models - [x] minimal - [ ] more complex