Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeodrippe committed Jan 29, 2025
1 parent bfbc2fd commit bce9744
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- develop
# - develop
paths-ignore:
- '**/README.md'
- '**/CHANGELOG.md'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Create `vc/eval*` to debug standalone forms
- Accept meta `^:void` in `if`/`cond` expressions to signal to the C compiler that we don't care about the return
- Move animation-node-player to VybeC
- CPU went from 84% to 63%
- Add `vf/defsystem-c`

## v0.7.469
Expand Down
15 changes: 9 additions & 6 deletions src/vybe/flecs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2248,8 +2248,7 @@
:sym k
:flags flags})]

(and (vector? v)
#_(some #{:* :_} v))
(vector? v)
(if (vector? k)
(->> k
;; Index for the vector destructuring.
Expand All @@ -2269,8 +2268,10 @@
(remove nil?)
vec)
[(with-meta [(symbol (str k "--arr"))
;; TODO support `:maybe`
`(vf.c/ecs-field-id ~it ~idx)]
(if (contains? flags :maybe)
`(when (vf.c/ecs-field-is-set ~it ~idx)
(vf.c/ecs-field-id ~it ~idx))
`(vf.c/ecs-field-id ~it ~idx))]
{:idx idx
:type nil
:sym k
Expand All @@ -2279,8 +2280,10 @@
;; Tag branch.
(keyword? v)
[(with-meta [(symbol (str k "--arr"))
;; TODO support `:maybe`
`(vf.c/ecs-field-id ~it ~idx)]
(if (contains? flags :maybe)
`(when (vf.c/ecs-field-is-set ~it ~idx)
(vf.c/ecs-field-id ~it ~idx))
`(vf.c/ecs-field-id ~it ~idx))]
{:idx idx
:type nil
:sym k
Expand Down
68 changes: 68 additions & 0 deletions src/vybe/game/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,74 @@
(when-not raycast
[:vg/raycast :vg/enabled])]})))

(vf/defsystem-c ^:debug update-physics-2 w
[ ;; TODO Derive it from transform-global.
scale vt/Scale
{aabb-min :min aabb-max :max} vt/Aabb
vy-body [:maybe vj/VyBody]
transform-global [vt/Transform :global]
kinematic [:maybe :vg/kinematic]
dynamic [:maybe :vg/dynamic]
sensor [:maybe :vg/sensor]
;; Used to find if we are setting `[:vg/raycast :vg/disabled]`
;; in Blender.
raycast [:maybe {:flags #{:up :self}}
[:vg/raycast :*]]
#_ #_phys [:src (root) vj/PhysicsSystem]
#_ #_e :vf/entity
#_ #_it :vf/iter]
#_(println :e (vf/get-name e) :kin kinematic)
#_(let [half #(max (/ (- (% aabb-max)
(% aabb-min))
2.0)
0.1)
center #(+ (* (/ (+ (% aabb-max)
(% aabb-min))
2.0)))
scaled #(* (half %) 2 (scale %))
{:keys [x y z]} (vm/matrix->translation
(-> (vr.c/matrix-translate (center :x) (center :y) (center :z))
(vr.c/matrix-multiply transform-global)))
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))
{:keys [mesh material]} (when-not vy-body
(gen-cube {:x (scaled :x) :y (scaled :y) :z (scaled :z)}
(rand-int 10)))]
(merge w {(body-path body)
[:vg/debug mesh material phys body
(vt/Eid e)]

e [phys body
(when-not raycast
[:vg/raycast :vg/enabled])]})))

(vf/defobserver body-removed w
[:vf/events #{:remove}
body vj/VyBody
Expand Down

0 comments on commit bce9744

Please sign in to comment.