Skip to content

Commit

Permalink
Check if entity exists before deleting it
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulo Feodrippe committed Jun 24, 2024
1 parent a716eb5 commit 158b42f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/vybe/flecs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@
(-set-c this k v)
this)
(dissoc [this k]
(vf.c/ecs-delete this (ent this k))
(when (get this k)
(vf.c/ecs-delete this (ent this k)))
this)
(keys [this] (-world-entities this))
(keySet [this] (set (potemkin.collections/keys* this)))
Expand Down Expand Up @@ -1458,16 +1459,20 @@
[k v])
(concat (partition 2 bindings)
(list (list w :vf/world))))
bindings-map (into {} bindings)
_ (when-not (:vf/name bindings-map)
(throw (ex-info "`with-system` requires a :vf/name" {:bindings bindings
:body body})))
code `(-system ~w ~(mapv (fn [[k v]] [`(quote ~k) v]) bindings)
(fn [~(vec (remove keyword? (mapv first bindings)))]
(fn ~(symbol (str (namespace (:vf/name bindings-map))
"__"
(name (:vf/name bindings-map))))
[~(vec (remove keyword? (mapv first bindings)))]
(try
~@body
(catch Throwable e#
(println e#)))))
hashed (hash code)]
(when-not (contains? (set (mapv first bindings)) :vf/name)
(throw (ex-info "`with-system` requires a :vf/name" {:bindings bindings
:body body})))
`(let [hashed# (hash ~(mapv last bindings))]
(or (when-let [e# (get-in @*-each-cache [(vp/mem ~w) [~hashed hashed#]])]
(when (vf.c/ecs-is-alive ~w (ent ~w e#))
Expand Down Expand Up @@ -1566,8 +1571,15 @@
[k v])
(concat (partition 2 bindings)
(list (list w :vf/world))))
bindings-map (into {} bindings)
_ (when-not (:vf/name bindings-map)
(throw (ex-info "`with-system` requires a :vf/name" {:bindings bindings
:body body})))
code `(-observer ~w ~(mapv (fn [[k v]] [`(quote ~k) v]) bindings)
(fn [~(vec (remove keyword? (mapv first bindings)))]
(fn ~(symbol (str (namespace (:vf/name bindings-map))
"__"
(name (:vf/name bindings-map))))
[~(vec (remove keyword? (mapv first bindings)))]
(try
~@body
(catch Throwable e#
Expand Down
11 changes: 9 additions & 2 deletions src/vybe/flecs/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
:main-thread? (nil? ret)})))))))
#_ (def methods-to-intern (-methods))

(defn -debug
[v]
(let [t (type v)]
(if (contains? #{Long String Boolean} t)
v
t)))

(defmacro -intern-methods
[init size]
`(do ~(->> (-methods)
Expand All @@ -145,7 +152,7 @@
~(mapv (comp symbol :name) args)
;; Fn body.
`(do #_(println '~'~(csk/->kebab-case-symbol n)
(mapv type ~~(mapv (comp symbol :name) args)))
(mapv -debug ~~(mapv (comp symbol :name) args)))
(vp/try-p->map
~~``(~(symbol "org.vybe.flecs.flecs" ~n)
~@~(vec
Expand Down Expand Up @@ -175,7 +182,7 @@
#_(macroexpand-1 '(-intern-methods 300 10))
#_(meta #'draw-text!)

#_(macroexpand-1 '(load-model "OOOB"))
#_(macroexpand-1 '(ecs-add-id w e id))
#_(macroexpand-1 '(update-camera! 1 2))
#_(macroexpand-1 '(get-monitor-name 0))

Expand Down
18 changes: 16 additions & 2 deletions src/vybe/jolt.clj
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@

;; -- Body
(defn body-active?
[body]
(vj.c/jpc-body-is-active body))
([body]
(vj.c/jpc-body-is-active body))
([phys body-id]
(vj.c/jpc-body-interface-is-active (body-interface phys) body-id)))

(defn body-move
"Move kinematic body.
Expand All @@ -288,6 +290,18 @@
[phys body-id]
(vj.c/jpc-body-interface-is-added (body-interface phys) body-id))

(defn body-position
[phys body-id]
(let [pos (Vector3)]
(vj.c/jpc-body-interface-get-position (body-interface phys) body-id pos)
pos))

(defn body-rotation
[phys body-id]
(let [rot (Vector4)]
(vj.c/jpc-body-interface-get-rotation (body-interface phys) body-id rot)
rot))

;; -- Misc
(defonce *temp-allocator
(delay (vj.c/jpc-temp-allocator-create (* 16 1024 1024))))
Expand Down

0 comments on commit 158b42f

Please sign in to comment.