From 500fd71d3e0b5796e3821f356f41cb28c9fa3610 Mon Sep 17 00:00:00 2001 From: "A.Olokhtonov" Date: Sun, 24 Nov 2024 00:05:00 +0300 Subject: [PATCH] Batching is working! (only in singethreaded mode though) --- client/client_recv.js | 10 +++++----- client/wasm/lod.c | 4 ++-- client/wasm/lod.wasm | Bin 3187 -> 3159 bytes client/webgl_geometry.js | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/client_recv.js b/client/client_recv.js index 154125d..4c8f3d4 100644 --- a/client/client_recv.js +++ b/client/client_recv.js @@ -364,7 +364,7 @@ function handle_event(state, context, event, options = {}) { } case EVENT.UNDO: { - geometry_add_dummy_stroke(context); + geometry_add_dummy_stroke(state, context); need_draw = undo(state, context, event, options); break; } @@ -372,7 +372,7 @@ function handle_event(state, context, event, options = {}) { case EVENT.IMAGE: { const p = {'x': event.x, 'y': event.y}; - geometry_add_dummy_stroke(context); + geometry_add_dummy_stroke(state, context); add_image(context, event.image_id, null, p, event.width, event.height); try { @@ -401,7 +401,7 @@ function handle_event(state, context, event, options = {}) { } case EVENT.IMAGE_MOVE: { - geometry_add_dummy_stroke(context); + geometry_add_dummy_stroke(state, context); const image_id = event.image_id; const image = get_image(context, image_id); @@ -415,7 +415,7 @@ function handle_event(state, context, event, options = {}) { } case EVENT.IMAGE_SCALE: { - geometry_add_dummy_stroke(context); + geometry_add_dummy_stroke(state, context); const image_id = event.image_id; const image = get_image(context, image_id); @@ -428,7 +428,7 @@ function handle_event(state, context, event, options = {}) { } case EVENT.ERASER: { - geometry_add_dummy_stroke(context); + geometry_add_dummy_stroke(state, context); need_draw = true; const stroke = state.events[event.stroke_id]; stroke.deleted = true; diff --git a/client/wasm/lod.c b/client/wasm/lod.c index d494367..a13020c 100644 --- a/client/wasm/lod.c +++ b/client/wasm/lod.c @@ -323,11 +323,11 @@ do_lod(int *clipped_indices, int clipped_count, float zoom, // Compute recommended LOD level, add to current batch or start new batch float sqrt_width = __builtin_sqrtf(width[stroke_index]); - int lod = __builtin_ceil(sqrt_zoom * sqrt_width * 0.3333f); // TODO: round + int lod = __builtin_roundeven(sqrt_zoom * sqrt_width); // NOTE: there is no regular round, but is shouldn't matt:er if (lod > 7) lod = 7; - if (batch_size > 0 && __builtin_abs(lod - last_lod) > 2) { + if (batch_size > 0 && lod != last_lod) { // Start new batch batches[batch_count * 2 + 0] = batch_size; batches[batch_count * 2 + 1] = last_lod; diff --git a/client/wasm/lod.wasm b/client/wasm/lod.wasm index 6fe6fbc53a4cfe636330794e293bac081714a40f..3a4dd811cd96697c46b17feba21f904cf567d14a 100755 GIT binary patch delta 1772 zcmZ8hOK%)S5T2e{+e><8-(Ii1etg}2#P+V^B!1>0lup1x5egC)4ut%G9uUd{2??U{ zfdeQU60f;&fD>>*D86#wUvT9R5OK@hx* z@C&Zljbpo!x6LjiHnD!dpbJcc5z*dd=)g2b4qSbS z(RGRiH~3CXmlo>@Z;v(c1f#KttboKQ1SkU;cgWv|_sj~G`JwpDv0X+|IV(}kDr=M; zj$w{lta`g9#(BR^W5}R{ZAQu*N1@xN(+omcYP4YjYkngLE(fFqGAayKQ146eb7eEN zt4eltr&1PJ6QF8{Wyk8oMa60?%rHO&MNUtj96z?sy7X1F$cz->YP3jY)5^qB**3j!^Nx&2fPia8qwuP-Y4Vaq1c!hdLC*jX4rzZz|y5KW646H+LU~%pZ)zQ}z?Q93TW=jZ+~z5*Tt+iZ?ZvF{vRo-nL2q^bl?- z5Bb?V*&AgNxp9lw#&oRZ1U5S^Y~+Z%djXLr3`?|Pl=>$c-K>o^~_W9LJP(g{QmMIdnj36dYs146+; zLIN~K$^jIR67O>3z=^K|LgWwd3%J6OL&%96$1uRFnRP(ys;9cEtGlXRz3QL4e{{e9 zQ>kA@x%%pryGdn`&3vHWTMFD4dn&ba%RzVBI+xMSHr-C zcf8fE>N!W^p(#_7Ag0R1qbK3;)x$iT(C)7z;oX{DbbB@0*q*!p(T{=mW&u-Tdj!)W z23Lb1xP0vIo4UrKA|TXYMg0uw6w!=kxbqCx_5>ZIxdTsl7nm1sFqwuaAu$R8N=E~?$KShen`JEVpxE_Tu7QMdRJ@v% zNe!pa;}R?0wq^5}A98a@r-W`*(ws)2J4d5c3`Hc|!wlMfJqRuY8F?X!0hST>CHbCI zvB&Ug-e}T5rA#n!#3?}}D`qDqDpFHnh7eU0G5zpheD%hc-(DJjYKQlP1TWnr^uwTnSi8f@UnyjaY){q&B9z!8GW$(J`}8MWfELR8yMR=CxR13Jo+TrPoq=YU&J7 z{KT@h>mxh-1VaqRWI|~&jdJTGw=m4c`w#5eL9?D>vu@M;sp2#hJ8Tm&KFXV%gg#$X z(oU2iWtFmGHp$XTO1fAvxnmP)iUdo-nI`E)s@Y=?dDl6{S1wm&c^=tGiVIlh_hKIX z{lA~t!dbIH3^k$~#AFUzxvt*dQ=DyZwzsETX0))4v?m*ix6L((AGtM!HoddQcfG5= zWux?IXw!V@OyV-=jM<)e&9?iKTe#$W$a4{yE?tJ^i-bC22(ci%KEmlSP9c%S$D3(2GqeRu>k#e)e#=RmqCOd_`F`-b)wI>!` zH|CeFvS)B!Ot^Ul z=gOHFKa!md>NfIc?V0>#vw=-)L1tU*ZMKd)B^2_MFvkd+c~oTt{~h^v%53u0kRI0h TX&*@YNjI~r<{$okC=LGs7{Ooj diff --git a/client/webgl_geometry.js b/client/webgl_geometry.js index 27085ea..982fa27 100644 --- a/client/webgl_geometry.js +++ b/client/webgl_geometry.js @@ -31,12 +31,15 @@ async function geometry_write_instances(state, context, callback) { return segment_count; } -function geometry_add_dummy_stroke(context) { +function geometry_add_dummy_stroke(state, context) { context.stroke_data = ser_ensure_by(context.stroke_data, config.bytes_per_stroke); ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0); ser_u16(context.stroke_data, 0); + + tv_add(state.wasm.buffers['width'].tv, 0); + state.wasm.buffers['width'].used += 4; } // Real stroke, add forever