Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeodrippe committed Jan 25, 2025
1 parent 800603f commit f6e834d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
31 changes: 19 additions & 12 deletions src/vybe/c.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@

:else
(str (symbol component-or-var)))]
(-> var-str
(str/replace #"\." "_DOT_")
(str/replace #"/" "_SLASH_")
(str/replace #"-" "_DASH_")
(str/replace #"\*" "_STAR_")))
(cond-> (-> var-str
(str/replace #"\." "_DOT_")
(str/replace #"/" "_SLASH_")
(str/replace #"-" "_DASH_"))
(symbol? component-or-var)
(str/replace #"\*" "_STAR_")))
(catch Exception e
(throw (ex-info "Error in ->name" {:component-or-var component-or-var} e)))))

Expand Down Expand Up @@ -668,10 +669,13 @@ static inline int32 NEXTPOWEROFTWO(int32 x) { return (int32)1L << LOG2CEIL(x); }
(cond
;; <<< WE MODIFIED HERE >>>
(get-method c-macroexpand v)
(c-macroexpand {:var v
:form form
:args (rest form)
:env env})
(let [expanded (c-macroexpand {:var v
:form form
:args (rest form)
:env env})]
(vary-meta expanded
(fn [v]
(merge (meta form) v))))

macro?
(let [res (apply v form (:locals env) (rest form))] ; (m &form &env & args)
Expand Down Expand Up @@ -1398,7 +1402,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 48)))
(transpile (assoc opts ::version 49)))

obj-name (str "vybe_" sym-name "_"
(when (or (:no-cache sym-meta)
Expand Down Expand Up @@ -1567,10 +1571,13 @@ long long int: \"long long int\", unsigned long long int: \"unsigned long long i
:callout-opts {:type :error}})))
(str/join "\n\n")))]

(println (bling/callout {:label (format "C %s error"
(println (bling/callout {:label (format "C %s error%s"
(if analyzer-err
"ANALYZER"
"COMPILE"))
"COMPILE")
(if error-problem?
" (the error itself had an issue!)"
""))
:type :error}
err))

Expand Down
2 changes: 1 addition & 1 deletion src/vybe/flecs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@
(when-not (= (first (name k-each)) \_)
(with-meta [(symbol (str k-each "--arr"))
;; TODO support `:maybe`
;; OPTM The result of `ecs-field-id` can be
;; TODO OPTM The result of `ecs-field-id` can be
;; associated to its own variable.
(if (= idx-destructuring 1)
`(vf.c/vybe-pair-second ~w (vf.c/ecs-field-id ~it ~idx))
Expand Down
26 changes: 17 additions & 9 deletions src/vybe/game/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,15 @@
;; TODO We could also c-macroexpand/c-invoke from a protocol.
(defmethod vc/c-macroexpand #'conj
[{:keys [args]}]
`(vf.c/ecs-add-id ~vf/c-w ~(first args) ~(second args)))

(vf/defsystem-c ^:debug animation-node-player-2 w2
`(vf.c/ecs-add-id ~vf/c-w ~(first args)
~(let [c (second args)]
(if (keyword? c)
;; TODO OPTM We get by name for now,
;; this can be optimized.
`(vf.c/ecs-lookup ~vf/c-w ~(vf/vybe-name c))
c))))

(vf/defsystem-c ^:debug animation-node-player-2 w
[[_ node] [:vg.anim/target-node :*]
[_ c] [:vg.anim/target-component :*]
node-ref vf/Ref
Expand All @@ -278,19 +284,21 @@
(- (nth timeline* (inc idx))
(nth timeline* idx)))
0)]
(when (< idx* 0)
(conj parent-e :vg.anim/stop)

(conj parent-e (flecs/EcsDisabled) #_:vg.anim/stop)
#_(when (< idx* 0)
(conj parent-e :vg.anim/stop)

;; Just for triggering the `animation-loop` system.
#_(conj (vf/ent w node) :vg.anim.entity/stop))
;; Just for triggering the `animation-loop` system.
(conj node :vg.anim.entity/stop)
;; TODO
#_(conj (vf/ent w node) :vg.anim.entity/stop))




;; We modify the component from the ref and then we have to notify flecs
;; that it was modified.
#_(merge node-ref (nth values idx))
;; TODO lerp
#_(merge @node-ref (if t
(lerp-p (nth values idx)
(nth values (inc idx))
Expand Down
9 changes: 7 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,19 @@
- lerp later
- [ ] `parent-e` should be an VybeFlecsEntitySet
- https://stackoverflow.com/questions/66040677/implementing-basic-vtable-in-c
- [ ] :vf/entity should return this type
- [ ] get id from keyword
- we can't use a global definition like `ECS_DECLARE`
- but we can define it when adding the system (per world)
- [ ] simple get by name for now
- [ ] dispatch conj on type (no inheritance)
- [ ] accept qualified keywords (in some cases?)
- [ ] Fix `(first timeline*)`
- [ ] how to represent `nil` properly?
- [ ] lerp
- [ ] consider making systems no `always` by default
- [ ] `def` to a var from C?
- [ ] show line/column error correctly for an error before calling the compiler
- [ ] Remove variables starting with a `_` (just do the side-effect)
- [ ] optimization (-O3) check?
- [ ] provide models
- [ ] minimal
- [ ] more complex
Expand All @@ -316,6 +320,7 @@
- [-] bookdown (?)
- [x] local test render
- [x] publish test
- [ ] talk about the issues at https://github.com/pfeodrippe/vybe/issues/4
- [ ] framework
- [ ] start with minimal example
- [ ] by concept?
Expand Down

0 comments on commit f6e834d

Please sign in to comment.