Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeodrippe committed Jan 31, 2025
1 parent 5279813 commit 987ce0f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 40 deletions.
11 changes: 7 additions & 4 deletions src/vybe/c.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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"))))

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/vybe/flecs/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
66 changes: 37 additions & 29 deletions src/vybe/game/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)))]
Expand Down
19 changes: 17 additions & 2 deletions src/vybe/jolt/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)
Expand All @@ -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]}]
Expand All @@ -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.
Expand Down
22 changes: 20 additions & 2 deletions src/vybe/math.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand All @@ -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)
Expand All @@ -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)))
6 changes: 4 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 987ce0f

Please sign in to comment.