Permalink
Browse files

update cljs wrapper, refactor compile script (autobuild src & test fi…

…le lists)
  • Loading branch information...
postspectacular committed Jul 18, 2016
1 parent 2d41be9 commit 8cdf18d0cd9a3d442ed7203715ec39bfdbde42e5
Showing with 36 additions and 36 deletions.
  1. +10 −3 compile
  2. +1 −1 geom-cljs/resources/public/index.html
  3. +25 −25 geom-cljs/src/thi/ng/geomc/core.cljs
  4. +0 −7 src/geom/mesh.c
View
13 compile
@@ -3,9 +3,12 @@
# compile with SIMD:
# ./compile.sh -asd
SRC="src/data/adjacency.c src/data/cons.c src/data/consrc.c src/data/hashset.c src/data/hashtable.c src/data/object.c src/data/octree.c src/data/quadtree.c src/data/spatialgrid.c src/geom/circle.c src/geom/clip.c src/geom/halfedge.c src/geom/isec.c src/geom/quadedge.c src/geom/triangle.c src/io/svg.c src/math/math.c src/math/hashfn.c src/math/matrix.c src/math/poisson.c src/math/vec.c src/mem/mpool.c src/sim/ca.c src/sim/verlet.c"
SRC=;
SRC_DIRS="src/data src/geom src/geom/clip src/math src/mem src/sim"
for d in $SRC_DIRS; do for f in `ls $d/*.c`; do SRC="$SRC $f"; done; done;
TESTS=
CFLAGS="-std=c11 -Os -Isrc"
CFLAGS="-std=c11 -O3 -Isrc"
EMFLAGS="-s ASM_JS=1 -s ASSERTIONS=0 -s INVOKE_RUN=0 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s MODULARIZE=1 -s NO_EXIT_RUNTIME=1 -s TOTAL_MEMORY='48*1024*1024' --js-library src/rt_cthing.js"
OUT=cthing.js
MIN=cthing.min.js
@@ -45,7 +48,8 @@ while getopts acdhkmstD: opt; do
m) CFLAGS="$CFLAGS -DCT_FEATURE_CHECK_MEM"
;;
t) CFLAGS="$CFLAGS -DNDEBUG -DCT_FEATURE_LOG"
TESTS="src/test/test.c test/main.c test/adjacency.c test/circle.c test/clip.c test/cons.c test/consrc.c test/hash.c test/hashset.c test/hashtable.c test/matrix.c test/mpool.c test/octree.c test/poisson.c test/quadtree.c test/qedge.c test/spatialgrid.c test/vec.c"
TESTS="src/test/test.c"
for f in `ls test/*.c`; do TESTS="$TESTS $f"; done;
;;
h) usage
;;
@@ -64,6 +68,8 @@ done
echo "cflags: $CFLAGS"
echo "emflags: $EMFLAGS"
echo "src: $SRC"
echo "test: $TESTS"
time emcc $CFLAGS \
--memory-init-file 0 \
@@ -80,6 +86,7 @@ echo "postprocessing..."
node postprocess.js
ls -la $MIN
cp $OUT geom-cljs/resources/public/js/
cp $MIN geom-cljs/resources/public/js/
# -s EXPORTED_FUNCTIONS=@exports.json
# -s ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS=1
@@ -8,7 +8,7 @@
<div id="app">
<canvas id="main" width="1280" height="720"></canvas>
</div>
<script src="js/geom.js" type="text/javascript"></script>
<script src="js/cthing.min.js" type="text/javascript"></script>
<script src="js/compiled/app.js" type="text/javascript"></script>
</body>
</html>
@@ -8,7 +8,7 @@
[thi.ng.geom.vector :as v]
[thi.ng.strf.core :as f]))
(defonce geom (js/geom))
(defonce cthing (js/cthing))
(enable-console-print!)
@@ -35,59 +35,59 @@
(deftype Vec2f [ptr]
IMag
(mag [_] (._ct_mag2f js/geom ptr))
(mag [_] (._ct_mag2f js/cthing ptr))
IMathOps
(+! [_ v] (._ct_add2fv_imm js/geom ptr (.-ptr ^Vec2f v)) _)
(-! [_ v] (._ct_sub2fv_imm js/geom ptr (.-ptr ^Vec2f v)) _)
(+! [_ v] (._ct_add2fv_imm js/cthing ptr (.-ptr ^Vec2f v)) _)
(-! [_ v] (._ct_sub2fv_imm js/cthing ptr (.-ptr ^Vec2f v)) _)
IPrintWithWriter
(-pr-writer [_ writer opts]
(pr-sequential-writer
writer pr-writer "#vec2f [" " " "]" opts
[(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right ptr 2))
(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right (+ ptr 4) 2))])))
[(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right ptr 2))
(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right (+ ptr 4) 2))])))
(deftype Vec3f [ptr]
IMag
(mag [_] (._ct_mag3f js/geom ptr))
(mag [_] (._ct_mag3f js/cthing ptr))
IMathOps
(+! [_ v] (._ct_add3fv_imm js/geom ptr (.-ptr ^Vec3f v)) _)
(+! [_ v] (._ct_add3fv_imm js/cthing ptr (.-ptr ^Vec3f v)) _)
ICross
(cross! [_ v] (._ct_cross3fv_imm js/geom ptr (.-ptr ^Vec3f v)) _)
(cross! [_ v] (._ct_cross3fv_imm js/cthing ptr (.-ptr ^Vec3f v)) _)
IMix
(mix! [_ b t] (._ct_mix3fv_imm js/geom ptr (.-ptr ^Vec3f b) t) _)
(mix! [_ b t] (._ct_mix3fv_imm js/cthing ptr (.-ptr ^Vec3f b) t) _)
IPrintWithWriter
(-pr-writer [_ writer opts]
(pr-sequential-writer
writer pr-writer "#vec3f [" " " "]" opts
[(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right ptr 2))
(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right (+ ptr 4) 2))
(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right (+ ptr 8) 2))])))
[(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right ptr 2))
(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right (+ ptr 4) 2))
(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right (+ ptr 8) 2))])))
(deftype Circle2f [ptr]
IArea
(area [_] (._ct_circle2f_area js/geom ptr))
(area [_] (._ct_circle2f_area js/cthing ptr))
ITessellate
(tessellate [_ {:keys [res target]}]
(let [target (or target (._malloc js/geom (* (inc res) 36)))]
(._ct_circle2f_tessellate js/geom ptr target res)))
(let [target (or target (._malloc js/cthing (* (inc res) 36)))]
(._ct_circle2f_tessellate js/cthing ptr target res)))
IPrintWithWriter
(-pr-writer [_ writer opts]
(pr-sequential-writer
writer pr-writer "#circle2f [" " " "]" opts
[(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right ptr 2))
(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right (+ ptr 4) 2))
(aget (.-HEAPF32 js/geom) (unsigned-bit-shift-right (+ ptr 8) 2))])))
[(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right ptr 2))
(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right (+ ptr 4) 2))
(aget (.-HEAPF32 js/cthing) (unsigned-bit-shift-right (+ ptr 8) 2))])))
(defn ^:export vec2f
[x y] (Vec2f. (._ct_vec2f js/geom x y nil)))
[x y] (Vec2f. (._ct_vec2f js/cthing x y nil)))
(defn ^:export vec3f
[x y z] (Vec3f. (._ct_vec3f js/geom x y z nil)))
[x y z] (Vec3f. (._ct_vec3f js/cthing x y z nil)))
(defn ^:export circle2f
[x y r]
(let [ptr (._malloc js/geom 12)]
(Circle2f. (._ct_circle2f_init js/geom ptr x y r))))
(let [ptr (._malloc js/cthing 12)]
(Circle2f. (._ct_circle2f_init js/cthing ptr x y r))))
(defn ^:export main
[]
@@ -144,13 +144,13 @@
(defn ^:export bench-tessel
[]
(let [c (circle2f 0 0 1)
tptr (._malloc js/geom (* 81 3 2 4))
tptr (._malloc js/cthing (* 81 3 2 4))
t0 (.getTime (js/Date.))]
(loop [i 1e5]
(when (pos? i)
(tessellate c {:res 80 :target tptr})
(recur (dec i))))
(._free js/geom tptr)
(._free js/cthing tptr)
(prn (- (.getTime (js/Date.)) t0))))
(defn ^:export bench-tessel2
View
@@ -87,10 +87,3 @@ int ct_mesh_add_face(CT_Mesh *m, CT_Vec3f **verts, size_t num) {
}
return 0;
}
int main() {
CT_Mesh m;
ct_mesh_init(&m, 12, 8);
ct_mesh_free(&m);
return 0;
}

0 comments on commit 8cdf18d

Please sign in to comment.