Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeodrippe committed Jan 28, 2025
1 parent eaed559 commit d209193
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/vybe/c.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 41 additions & 10 deletions src/vybe/game/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d209193

Please sign in to comment.