Browse Source

Fix strokes being added to storage even when skipped by SN logic

ssao
aolo2 10 months ago
parent
commit
dfecad2c99
  1. 4
      README.md
  2. 41
      client/client_recv.js
  3. 22
      client/math.js
  4. 12
      client/wasm/lod.c
  5. BIN
      client/wasm/lod.wasm
  6. 4
      client/webgl_geometry.js

4
README.md

@ -13,7 +13,7 @@ Release:
+ GC stalls!!! + GC stalls!!!
+ Stroke previews get connected when drawn without panning on touch devices + Stroke previews get connected when drawn without panning on touch devices
+ Redraw HTML (cursors) on local canvas moves + Redraw HTML (cursors) on local canvas moves
- New strokes dissapear on the HMH desk + New strokes dissapear on the HMH desk
- Debug - Debug
- Restore ability to limit event range - Restore ability to limit event range
* Listeners/events/multiplayer * Listeners/events/multiplayer
@ -51,7 +51,7 @@ Bonus:
* Handle pressure * Handle pressure
+ Add pressure data to quads + Add pressure data to quads
+ Account for pressure in quad/bbox calc + Account for pressure in quad/bbox calc
* Adjust curve simplification to include pressure info + Adjust curve simplification to include pressure info
- Migrate old non-pressure desks - Migrate old non-pressure desks
- Check out e.pressure on touch devices - Check out e.pressure on touch devices
- Send pressure in PREDRAW event - Send pressure in PREDRAW event

41
client/client_recv.js

@ -105,28 +105,13 @@ function des_event(d, state = null) {
const width = des_u16(d); const width = des_u16(d);
const color = des_u32(d); const color = des_u32(d);
const coords = des_f32array(d, point_count * 2); event.coords = des_f32array(d, point_count * 2);
const press = des_u8array(d, point_count); event.press = des_u8array(d, point_count);
des_align(d, 4); des_align(d, 4);
wasm_ensure_by(state, 1, coords.length);
const coordinates = state.wasm.buffers['coordinates'];
const pressures = state.wasm.buffers['pressures'];
tv_add(state.wasm.buffers['coords_from'].tv, coordinates.tv.size + point_count * 2);
state.wasm.buffers['coords_from'].used += 4; // 4 bytes, not 4 ints
// TODO: remove, this is duplicate data // TODO: remove, this is duplicate data
event.coords_from = coordinates.tv.size;
event.coords_to = coordinates.tv.size + point_count * 2;
tv_append(coordinates.tv, coords);
state.wasm.buffers['coordinates'].used += point_count * 2 * 4;
tv_append(pressures.tv, press);
state.wasm.buffers['pressures'].used += point_count;
event.stroke_id = stroke_id; event.stroke_id = stroke_id;
@ -255,6 +240,28 @@ function handle_event(state, context, event, options = {}) {
} }
case EVENT.STROKE: { case EVENT.STROKE: {
const point_count = event.coords.length / 2;
wasm_ensure_by(state, 1, event.coords.length);
const coordinates = state.wasm.buffers['coordinates'];
const pressures = state.wasm.buffers['pressures'];
event.coords_from = coordinates.tv.size;
event.coords_to = coordinates.tv.size + point_count * 2;
tv_add(state.wasm.buffers['coords_from'].tv, coordinates.tv.size + point_count * 2);
state.wasm.buffers['coords_from'].used += 4; // 4 bytes, not 4 ints
tv_append(coordinates.tv, event.coords);
state.wasm.buffers['coordinates'].used += point_count * 2 * 4;
tv_append(pressures.tv, event.press);
state.wasm.buffers['pressures'].used += point_count;
delete event.coords;
delete event.press;
// TODO: do not do this for my own strokes when we bake locally // TODO: do not do this for my own strokes when we bake locally
geometry_clear_player(state, context, event.user_id); geometry_clear_player(state, context, event.user_id);
need_draw = true; need_draw = true;

22
client/math.js

@ -91,8 +91,8 @@ function process_stroke(state, zoom, stroke) {
return npoints; return npoints;
} }
function rdp_find_max2(points, start, end) { function rdp_find_max2(zoom, points, start, end) {
const EPS = 0.25; const EPS = 1.0 / zoom;
let result = -1; let result = -1;
let max_dist = 0; let max_dist = 0;
@ -119,7 +119,7 @@ function rdp_find_max2(points, start, end) {
const x = rx + a.x; const x = rx + a.x;
const y = ry + a.y; const y = ry + a.y;
const dist = Math.abs(y - a.y); const dist = Math.abs(y - a.y) + Math.abs(a.pressure - p.pressure) / 255 + Math.abs(b.pressure - p.pressure) / 255;
if (dist > EPS && dist > max_dist) { if (dist > EPS && dist > max_dist) {
result = i; result = i;
@ -130,30 +130,30 @@ function rdp_find_max2(points, start, end) {
return result; return result;
} }
function process_rdp_r2(points, start, end) { function process_rdp_r2(zoom, points, start, end) {
let result = []; let result = [];
const max = rdp_find_max2(points, start, end); const max = rdp_find_max2(zoom, points, start, end);
if (max !== -1) { if (max !== -1) {
const before = process_rdp_r2(points, start, max); const before = process_rdp_r2(zoom, points, start, max);
const after = process_rdp_r2(points, max, end); const after = process_rdp_r2(zoom, points, max, end);
result = [...before, points[max], ...after]; result = [...before, points[max], ...after];
} }
return result; return result;
} }
function process_rdp2(points) { function process_rdp2(zoom, points) {
const result = process_rdp_r2(points, 0, points.length - 1); const result = process_rdp_r2(zoom, points, 0, points.length - 1);
result.unshift(points[0]); result.unshift(points[0]);
result.push(points[points.length - 1]); result.push(points[points.length - 1]);
return result; return result;
} }
// TODO: unify with regular process stroke // TODO: unify with regular process stroke
function process_stroke2(points) { function process_stroke2(zoom, points) {
const result = process_rdp2(points); const result = process_rdp2(zoom, points);
return result; return result;
} }

12
client/wasm/lod.c

@ -32,7 +32,7 @@ alloc_dynamic(int size)
} }
static int static int
rdp_find_max(float *coordinates, float zoom, int coords_from, rdp_find_max(float *coordinates, unsigned char *pressures, float zoom, int coords_from,
int segment_start, int segment_end) int segment_start, int segment_end)
{ {
float EPS = 1.0 / zoom; float EPS = 1.0 / zoom;
@ -44,7 +44,10 @@ rdp_find_max(float *coordinates, float zoom, int coords_from,
float ay = coordinates[coords_from + segment_start * 2 + 1]; float ay = coordinates[coords_from + segment_start * 2 + 1];
float bx = coordinates[coords_from + segment_end * 2 + 0]; float bx = coordinates[coords_from + segment_end * 2 + 0];
float by = coordinates[coords_from + segment_end * 2 + 1]; float by = coordinates[coords_from + segment_end * 2 + 1];
unsigned char ap = pressures[coords_from / 2 + segment_start];
unsigned char bp = pressures[coords_from / 2 + segment_end];
float dx = bx - ax; float dx = bx - ax;
float dy = by - ay; float dy = by - ay;
@ -56,10 +59,13 @@ rdp_find_max(float *coordinates, float zoom, int coords_from,
float px = coordinates[coords_from + i * 2 + 0]; float px = coordinates[coords_from + i * 2 + 0];
float py = coordinates[coords_from + i * 2 + 1]; float py = coordinates[coords_from + i * 2 + 1];
unsigned char pp = pressures[coords_from + i];
float apx = px - ax; float apx = px - ax;
float apy = py - ay; float apy = py - ay;
float dist = __builtin_fabsf(apx * dir_nx + apy * dir_ny); float dist = __builtin_fabsf(apx * dir_nx + apy * dir_ny);
//+ __builtin_abs(pp - ap) / 255.0f + __builtin_abs(pp - bp) / 255.0f;
if (dist > EPS && dist > max_dist) { if (dist > EPS && dist > max_dist) {
result = i; result = i;
@ -124,7 +130,7 @@ do_lod(int *clipped_indices, int clipped_count, float zoom,
if (type == 1) { if (type == 1) {
segments[segments_head++] = start; segments[segments_head++] = start;
} else { } else {
int max = rdp_find_max(coordinates, zoom, coords_from, start, end); int max = rdp_find_max(coordinates, pressures, zoom, coords_from, start, end);
if (max != -1) { if (max != -1) {
segment_count += 1; segment_count += 1;

BIN
client/wasm/lod.wasm

Binary file not shown.

4
client/webgl_geometry.js

@ -26,7 +26,7 @@ function geometry_prepare_stroke(state) {
return null; return null;
} }
const points = process_stroke2(state.players[state.me].points); const points = process_stroke2(state.canvas.zoom, state.players[state.me].points);
return { return {
'color': state.players[state.me].color, 'color': state.players[state.me].color,
@ -43,7 +43,7 @@ function geometry_write_instances(state, context) {
const segment_count = do_lod(state, context); const segment_count = do_lod(state, context);
if (config.debug_print) console.debug('instances:', state.segments.count, 'rdp max:', state.stats.rdp_max_count, 'rdp segments:', state.stats.rdp_segments); if (config.debug_print) console.debug('instances:', segment_count, 'rdp max:', state.stats.rdp_max_count, 'rdp segments:', state.stats.rdp_segments);
return segment_count; return segment_count;
} }

Loading…
Cancel
Save