From d2091939bb09dbad145e3017b802a54b69d0fcda Mon Sep 17 00:00:00 2001 From: Paulo Feodrippe Date: Tue, 28 Jan 2025 13:33:07 -0500 Subject: [PATCH] wip --- src/vybe/c.clj | 6 ++++- src/vybe/game/system.clj | 51 ++++++++++++++++++++++++++++++++-------- todo.md | 12 +++++++--- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/vybe/c.clj b/src/vybe/c.clj index 3ba6531..4a20f44 100644 --- a/src/vybe/c.clj +++ b/src/vybe/c.clj @@ -1002,7 +1002,11 @@ signal(SIGSEGV, sighandler); (str/join ";\n\n")))) :if - (let [{:keys [then else] t :test} v] + (let [{:keys [then else] t :test} v + ;; For supporting the `:else` from a `cond` macro. + t (if (= (:form t) :else) + (analyze true) + t)] (if (:form else) (format "( %s ? \n ({%s;}) : \n ({%s;}) )" (emit t) diff --git a/src/vybe/game/system.clj b/src/vybe/game/system.clj index c326367..77deed9 100644 --- a/src/vybe/game/system.clj +++ b/src/vybe/game/system.clj @@ -264,7 +264,7 @@ c))) nil)) -(vf/defsystem-c animation-node-player-2 _w +(vf/defsystem-c animation-node-player-2 w [[_ node] [:vg.anim/target-node :*] ;; TODO Maybe [:vg.anim/target-component [:vf/component'?c]] ? _ [:vg.anim/target-component '?c] @@ -281,18 +281,49 @@ (vp/arr values timeline_count vt/Translation) (vp/arr values timeline_count vt/Scale)) (vp/as [:* :void])) - ;; TODO Should this create a slice? (support for `count`, `first`, `last`, `nth`, iteration) timeline* (vp/arr timeline timeline_count :float) ;; TODO OPTM We could also leverage the previous index. idx* (vc/bs_lower_bound timeline* timeline_count (:current_time @player)) - idx (int (max (dec (or idx* timeline_count)) 0)) - ;; TODO idx* won't be `nil` - ;; TODO We should probably use the same truthy semantics as Clojure - t (when idx* - (/ (- (:current_time @player) - (nth timeline* idx)) - (- (nth timeline* (inc idx)) - (nth timeline* idx))))] + idx (cond + (= idx* 0) + 0 + + (>= idx* timeline_count) + -1 + + :else + (dec idx*)) + + #_ #_my-ref (-> (vf.c/ecs-ref-get-id (:w @node-ref) + (vp/& (:flecs_ref @node-ref)) + (:id (:flecs_ref @node-ref))) + #_(vp/p->map c))] + #_(tap> (long (vp/& (:flecs_ref @node-ref)))) + + ;; TODO We could use some `:void` metadata to indicate that + ;; a form does not return anything. + (if (>= idx 0) + (let [v (/ (- (:current_time @player) + (nth timeline* idx)) + (- (nth timeline* (inc idx)) + (nth timeline* idx)))] + + (cond + (= kind 0) + (nth (vp/arr values timeline_count vt/Translation) idx) + + #_(= kind 1) + #_(nth (vp/arr values timeline_count vt/Scale) idx) + + #_(= kind 2) + #_(nth (vp/arr values timeline_count vt/Rotation) idx)) + + #_(merge @node-ref (nth values idx) + #_(if t + (lerp-p (nth values idx) + (nth values (inc idx)) + t) + (nth values idx))))) #_(when (< idx* 0) (conj parent-e :vg.anim/stop) diff --git a/todo.md b/todo.md index 75d8e83..6eb0afe 100644 --- a/todo.md +++ b/todo.md @@ -306,16 +306,22 @@ - [x] mapping from entity id to component type - [x] don't use `comp-id` - [-] create cond automatically from it? - - [-] how to represent `nil` properly? - - [ ] fix `idx` - - [ ] fix `t` + - [x] fix `idx` + - [x] fix `t` - [ ] lerp + - [ ] just idx for translation + - [ ] scale + - [ ] rotation + - [ ] use lerp - [ ] :vf/entity should return a struct? - [ ] consider making systems `always` by default - [ ] `def` to a var from C? - [x] show line/column error correctly for an error before calling the compiler - [ ] Remove variables starting with a `_` in a `let` (just do the side-effect) - [ ] optimization (-O3)? + - [ ] how to represent `nil` properly? + - [ ] maybe with nullable + - [ ] should have slices? (support for `count`, `first`, `last`, `nth`, iteration) - [ ] built-in models - [x] minimal - [ ] more complex