add string debugging for wasm. remove other debug code
This commit is contained in:
parent
aea377a0fa
commit
367eb5db06
5 changed files with 14 additions and 50 deletions
|
|
@ -17,7 +17,6 @@ if (!self.window) (function() {
|
||||||
|
|
||||||
const factor = self.base.config.clipper;
|
const factor = self.base.config.clipper;
|
||||||
const geo = self.geo;
|
const geo = self.geo;
|
||||||
const debug = false;
|
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
console.log(...arguments);
|
console.log(...arguments);
|
||||||
|
|
@ -141,20 +140,6 @@ if (!self.window) (function() {
|
||||||
return tops;
|
return tops;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runTests() {
|
|
||||||
let newPolygon = self.base.newPolygon;
|
|
||||||
let p1 = newPolygon().centerCircle({x:2,y:2,z:0}, 2, 50);
|
|
||||||
// let p1 = newPolygon().add(0,0).add(4,0).add(4,4).add(0,4);
|
|
||||||
let p2 = p1.clone().setZ(0).move({x:2, y:2});
|
|
||||||
let d1 = [];
|
|
||||||
let d2 = [];
|
|
||||||
geo.wasm.js.diff([p1], [p2], 0, d1, d2);
|
|
||||||
console.log('diff',{p1:p1.points, p2:p2.points, d1:d1[0].points, d2:d2[0].points});
|
|
||||||
let o1 = geo.wasm.js.offset([p1], 1, 0);
|
|
||||||
console.log('offs',{o1:o1[0].points});
|
|
||||||
wasm.test_string(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
function readString(pos, len) {
|
function readString(pos, len) {
|
||||||
let view = new DataReader(geo.wasm.heap, pos);
|
let view = new DataReader(geo.wasm.heap, pos);
|
||||||
let out = [];
|
let out = [];
|
||||||
|
|
@ -173,9 +158,7 @@ if (!self.window) (function() {
|
||||||
.then(response => response.arrayBuffer())
|
.then(response => response.arrayBuffer())
|
||||||
.then(bytes => WebAssembly.instantiate(bytes, {
|
.then(bytes => WebAssembly.instantiate(bytes, {
|
||||||
env: {
|
env: {
|
||||||
polygon: (a,b) => { console.log('polygon',a,b) },
|
debug_string: (len, ptr) => { console.log('wasm', readString(ptr, len)) }
|
||||||
point: (a,b) => { console.log('point',a,b) },
|
|
||||||
ostr: (len, ptr) => { console.log('ostr', readString(ptr, len)) }
|
|
||||||
},
|
},
|
||||||
wasi_snapshot_preview1: {
|
wasi_snapshot_preview1: {
|
||||||
args_get: (count,bufsize) => { return 0 },
|
args_get: (count,bufsize) => { return 0 },
|
||||||
|
|
@ -197,9 +180,7 @@ if (!self.window) (function() {
|
||||||
memory: exports.memory,
|
memory: exports.memory,
|
||||||
memmax: exports.memory.buffer.byteLength,
|
memmax: exports.memory.buffer.byteLength,
|
||||||
malloc: exports.mem_get,
|
malloc: exports.mem_get,
|
||||||
free: exports.mem_clr,
|
free: exports.mem_clr
|
||||||
set_debug: exports.set_debug,
|
|
||||||
test_string: exports.test_string
|
|
||||||
};
|
};
|
||||||
wasm.shared = wasm.malloc(1024 * 1024 * 30),
|
wasm.shared = wasm.malloc(1024 * 1024 * 30),
|
||||||
wasm.fn = {
|
wasm.fn = {
|
||||||
|
|
@ -212,10 +193,6 @@ if (!self.window) (function() {
|
||||||
union: polyUnion,
|
union: polyUnion,
|
||||||
offset: polyOffset
|
offset: polyOffset
|
||||||
};
|
};
|
||||||
if (debug) {
|
|
||||||
wasm.set_debug(1);
|
|
||||||
runTests();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2481,7 +2481,7 @@
|
||||||
platform.update_size();
|
platform.update_size();
|
||||||
|
|
||||||
// load wasm if indicated
|
// load wasm if indicated
|
||||||
KIRI.client.wasm(control.assembly);
|
KIRI.client.wasm(control.assembly === true);
|
||||||
};
|
};
|
||||||
|
|
||||||
UI.sync();
|
UI.sync();
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,9 @@ typedef int int32;
|
||||||
using namespace ClipperLib;
|
using namespace ClipperLib;
|
||||||
|
|
||||||
Uint8 *mem = 0;
|
Uint8 *mem = 0;
|
||||||
Uint8 debug = 0;
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern void polygon(Uint32 points, Uint32 inners);
|
extern void debug_string(Uint32 len, char *str);
|
||||||
extern void point(Uint32 x, Uint32 y);
|
|
||||||
extern void ostr(Uint32 len, std::string str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct length16 {
|
struct length16 {
|
||||||
|
|
@ -38,16 +35,23 @@ void mem_clr(Uint32 loc) {
|
||||||
free((void *)loc);
|
free((void *)loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void send_string(const char *format, ...) {
|
||||||
|
char buffer[100];
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
Uint32 len = vsprintf(buffer, format, args);
|
||||||
|
va_end(args);
|
||||||
|
debug_string(len, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
Uint32 readPoly(Path &path, Uint32 pos) {
|
Uint32 readPoly(Path &path, Uint32 pos) {
|
||||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||||
Uint16 points = ls->length;
|
Uint16 points = ls->length;
|
||||||
// if (debug) polygon(points, 0);
|
|
||||||
pos += 2;
|
pos += 2;
|
||||||
while (points > 0) {
|
while (points > 0) {
|
||||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
struct point32 *ip = (struct point32 *)(mem + pos);
|
||||||
pos += 8;
|
pos += 8;
|
||||||
path << IntPoint(ip->x, ip->y);
|
path << IntPoint(ip->x, ip->y);
|
||||||
// if (debug) point(ip->x, ip->y);
|
|
||||||
points--;
|
points--;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
|
|
@ -64,12 +68,10 @@ Uint32 readPolys(Paths &paths, Uint32 pos, Uint32 count) {
|
||||||
|
|
||||||
Uint32 writePolys(Paths &outs, Uint32 pos) {
|
Uint32 writePolys(Paths &outs, Uint32 pos) {
|
||||||
for (Path po : outs) {
|
for (Path po : outs) {
|
||||||
// if (debug) polygon(po.size(), 1);
|
|
||||||
struct length16 *ls = (struct length16 *)(mem + pos);
|
struct length16 *ls = (struct length16 *)(mem + pos);
|
||||||
ls->length = po.size();
|
ls->length = po.size();
|
||||||
pos += 2;
|
pos += 2;
|
||||||
for (IntPoint pt : po) {
|
for (IntPoint pt : po) {
|
||||||
// if (debug) point(pt.X, pt.Y);
|
|
||||||
struct point32 *ip = (struct point32 *)(mem + pos);
|
struct point32 *ip = (struct point32 *)(mem + pos);
|
||||||
ip->x = (int)pt.X;
|
ip->x = (int)pt.X;
|
||||||
ip->y = (int)pt.Y;
|
ip->y = (int)pt.Y;
|
||||||
|
|
@ -84,7 +86,6 @@ Uint32 writePolys(Paths &outs, Uint32 pos) {
|
||||||
|
|
||||||
__attribute__ ((export_name("poly_offset")))
|
__attribute__ ((export_name("poly_offset")))
|
||||||
Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset, float clean, Uint8 simple) {
|
Uint32 poly_offset(Uint32 memat, Uint32 polys, float offset, float clean, Uint8 simple) {
|
||||||
|
|
||||||
Paths ins(polys);
|
Paths ins(polys);
|
||||||
Paths outs;
|
Paths outs;
|
||||||
Uint32 pos = memat;
|
Uint32 pos = memat;
|
||||||
|
|
@ -186,17 +187,3 @@ Uint32 poly_diff(Uint32 memat, Uint32 polysA, Uint32 polysB, Uint8 AB, Uint8 BA,
|
||||||
|
|
||||||
return resat;
|
return resat;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__ ((export_name("set_debug")))
|
|
||||||
void set_debug(Uint8 value) {
|
|
||||||
debug = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__ ((export_name("test_string")))
|
|
||||||
void test_string(Uint8 value) {
|
|
||||||
// Creating a string from const char*
|
|
||||||
std::string str1 = "hello";
|
|
||||||
//std::string str1 = std::format("{} {}", "hello", value);
|
|
||||||
|
|
||||||
ostr(str1.length(), str1);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -4,7 +4,7 @@ kiri-sla.wasm: kiri-sla.c
|
||||||
emcc --no-entry -o kiri-sla.wasm kiri-sla.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
|
emcc --no-entry -o kiri-sla.wasm kiri-sla.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
|
||||||
|
|
||||||
kiri-geo.wasm: kiri-geo.cpp
|
kiri-geo.wasm: kiri-geo.cpp
|
||||||
emcc --no-entry -o kiri-geo.wasm clipper.cpp kiri-geo.cpp -Oz -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s TOTAL_MEMORY=40mb -std=c++20
|
emcc --no-entry -o kiri-geo.wasm clipper.cpp kiri-geo.cpp -Oz -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s TOTAL_MEMORY=40mb
|
||||||
|
|
||||||
kiri-ani.wasm: kiri-ani.c
|
kiri-ani.wasm: kiri-ani.c
|
||||||
emcc --no-entry -o kiri-ani.wasm kiri-ani.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
|
emcc --no-entry -o kiri-ani.wasm kiri-ani.c -O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue