Fix many corner issues related to shape data structure change

This commit is contained in:
Alejandro Alonso 2024-10-29 09:15:24 +01:00 committed by Andrey Antukh
parent 4623f36042
commit 96bb282674
9 changed files with 125 additions and 107 deletions

View file

@ -9,26 +9,58 @@
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.types.shape.impl]
[app.config :as cf]
[promesa.core :as p]))
(def enabled?
(contains? cf/flags :render-wasm))
(defonce ^:dynamic internal-module #js {})
(defonce ^:dynamic internal-gpu-state #js {})
(set! app.common.types.shape.impl/enabled-wasm-ready-shape enabled?)
(defn set-objects [objects]
(let [shapes-buffer (unchecked-get internal-module "_shapes_buffer")
heap (unchecked-get internal-module "HEAPF32")
;; size *in bytes* for each shapes::Shape
rect-size 16
;; TODO: remove the `take` once we have the dynamic data structure in Rust
supported-shapes (take 2048 (filter #(not (cfh/root? %)) (vals objects)))
mem (js/Float32Array. (.-buffer heap) (shapes-buffer) (* rect-size (count supported-shapes)))]
(run! (fn [[shape index]]
(.set mem (.-buffer shape) (* index rect-size)))
(zipmap supported-shapes (range)))))
(defonce internal-module #js {})
(defonce internal-gpu-state #js {})
;; TODO: remove the `take` once we have the dynamic data structure in Rust
(def xform
(comp
(remove cfh/root?)
(take 2048)))
;; Size in number of f32 values that represents the shape selrect (
(def rect-size 4)
(defn set-objects
[objects]
;; FIXME: maybe change the name of `_shapes_buffer` (?)
(let [get-shapes-buffer-ptr
(unchecked-get internal-module "_shapes_buffer")
heap
(unchecked-get internal-module "HEAPF32")
shapes
(into [] xform (vals objects))
total-shapes
(count shapes)
heap-offset
(get-shapes-buffer-ptr)
heap-size
(* rect-size total-shapes)
mem
(js/Float32Array. (.-buffer heap)
heap-offset
heap-size)]
(loop [index 0]
(when (< index total-shapes)
(let [shape (nth shapes index)]
(.set ^js mem (.-buffer shape) (* index rect-size))
(recur (inc index)))))))
(defn draw-objects
[zoom vbox]