Skip to content

Commit 158b42f

Browse files
author
Paulo Feodrippe
committed
Check if entity exists before deleting it
1 parent a716eb5 commit 158b42f

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/vybe/flecs.clj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@
250250
(-set-c this k v)
251251
this)
252252
(dissoc [this k]
253-
(vf.c/ecs-delete this (ent this k))
253+
(when (get this k)
254+
(vf.c/ecs-delete this (ent this k)))
254255
this)
255256
(keys [this] (-world-entities this))
256257
(keySet [this] (set (potemkin.collections/keys* this)))
@@ -1458,16 +1459,20 @@
14581459
[k v])
14591460
(concat (partition 2 bindings)
14601461
(list (list w :vf/world))))
1462+
bindings-map (into {} bindings)
1463+
_ (when-not (:vf/name bindings-map)
1464+
(throw (ex-info "`with-system` requires a :vf/name" {:bindings bindings
1465+
:body body})))
14611466
code `(-system ~w ~(mapv (fn [[k v]] [`(quote ~k) v]) bindings)
1462-
(fn [~(vec (remove keyword? (mapv first bindings)))]
1467+
(fn ~(symbol (str (namespace (:vf/name bindings-map))
1468+
"__"
1469+
(name (:vf/name bindings-map))))
1470+
[~(vec (remove keyword? (mapv first bindings)))]
14631471
(try
14641472
~@body
14651473
(catch Throwable e#
14661474
(println e#)))))
14671475
hashed (hash code)]
1468-
(when-not (contains? (set (mapv first bindings)) :vf/name)
1469-
(throw (ex-info "`with-system` requires a :vf/name" {:bindings bindings
1470-
:body body})))
14711476
`(let [hashed# (hash ~(mapv last bindings))]
14721477
(or (when-let [e# (get-in @*-each-cache [(vp/mem ~w) [~hashed hashed#]])]
14731478
(when (vf.c/ecs-is-alive ~w (ent ~w e#))
@@ -1566,8 +1571,15 @@
15661571
[k v])
15671572
(concat (partition 2 bindings)
15681573
(list (list w :vf/world))))
1574+
bindings-map (into {} bindings)
1575+
_ (when-not (:vf/name bindings-map)
1576+
(throw (ex-info "`with-system` requires a :vf/name" {:bindings bindings
1577+
:body body})))
15691578
code `(-observer ~w ~(mapv (fn [[k v]] [`(quote ~k) v]) bindings)
1570-
(fn [~(vec (remove keyword? (mapv first bindings)))]
1579+
(fn ~(symbol (str (namespace (:vf/name bindings-map))
1580+
"__"
1581+
(name (:vf/name bindings-map))))
1582+
[~(vec (remove keyword? (mapv first bindings)))]
15711583
(try
15721584
~@body
15731585
(catch Throwable e#

src/vybe/flecs/impl.clj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@
120120
:main-thread? (nil? ret)})))))))
121121
#_ (def methods-to-intern (-methods))
122122

123+
(defn -debug
124+
[v]
125+
(let [t (type v)]
126+
(if (contains? #{Long String Boolean} t)
127+
v
128+
t)))
129+
123130
(defmacro -intern-methods
124131
[init size]
125132
`(do ~(->> (-methods)
@@ -145,7 +152,7 @@
145152
~(mapv (comp symbol :name) args)
146153
;; Fn body.
147154
`(do #_(println '~'~(csk/->kebab-case-symbol n)
148-
(mapv type ~~(mapv (comp symbol :name) args)))
155+
(mapv -debug ~~(mapv (comp symbol :name) args)))
149156
(vp/try-p->map
150157
~~``(~(symbol "org.vybe.flecs.flecs" ~n)
151158
~@~(vec
@@ -175,7 +182,7 @@
175182
#_(macroexpand-1 '(-intern-methods 300 10))
176183
#_(meta #'draw-text!)
177184

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

src/vybe/jolt.clj

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@
266266

267267
;; -- Body
268268
(defn body-active?
269-
[body]
270-
(vj.c/jpc-body-is-active body))
269+
([body]
270+
(vj.c/jpc-body-is-active body))
271+
([phys body-id]
272+
(vj.c/jpc-body-interface-is-active (body-interface phys) body-id)))
271273

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

293+
(defn body-position
294+
[phys body-id]
295+
(let [pos (Vector3)]
296+
(vj.c/jpc-body-interface-get-position (body-interface phys) body-id pos)
297+
pos))
298+
299+
(defn body-rotation
300+
[phys body-id]
301+
(let [rot (Vector4)]
302+
(vj.c/jpc-body-interface-get-rotation (body-interface phys) body-id rot)
303+
rot))
304+
291305
;; -- Misc
292306
(defonce *temp-allocator
293307
(delay (vj.c/jpc-temp-allocator-create (* 16 1024 1024))))

0 commit comments

Comments
 (0)