|
|
@ -99,7 +99,7 @@ function wasm_ensure_by(state, nstrokes, ncoords) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function do_lod_wasm(state, context) { |
|
|
|
function do_lod(state, context) { |
|
|
|
state.wasm.exports.free_dynamic(); |
|
|
|
state.wasm.exports.free_dynamic(); |
|
|
|
|
|
|
|
|
|
|
|
const clipped_indices = state.wasm.exports.alloc_dynamic(context.clipped_indices.size * 4); |
|
|
|
const clipped_indices = state.wasm.exports.alloc_dynamic(context.clipped_indices.size * 4); |
|
|
@ -140,88 +140,3 @@ function do_lod_wasm(state, context) { |
|
|
|
|
|
|
|
|
|
|
|
return segment_count; |
|
|
|
return segment_count; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function do_lod(state, context) { |
|
|
|
|
|
|
|
if (state.debug.use_wasm) { |
|
|
|
|
|
|
|
return do_lod_wasm(state, context); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const zoom = state.canvas.zoom; |
|
|
|
|
|
|
|
const segments_data = state.segments.data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let segments_head = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < context.clipped_indices.size; ++i) { |
|
|
|
|
|
|
|
const stroke_index = context.clipped_indices.data[i]; |
|
|
|
|
|
|
|
const stroke = state.events[stroke_index]; |
|
|
|
|
|
|
|
const point_count = (stroke.coords_to - stroke.coords_from) / 2; |
|
|
|
|
|
|
|
const coords_from = stroke.coords_from; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (point_count > state.rdp_traverse_stack.length) { |
|
|
|
|
|
|
|
//console.size('allocate')
|
|
|
|
|
|
|
|
state.rdp_traverse_stack = new Uint32Array(round_to_pow2(point_count, 4096)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stack = state.rdp_traverse_stack; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Basic CSR crap
|
|
|
|
|
|
|
|
state.segments_from.data[i] = segments_head; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.canvas.zoom <= state.line_threshold.data[stroke_index]) { |
|
|
|
|
|
|
|
segments_data[segments_head++] = 0; |
|
|
|
|
|
|
|
segments_data[segments_head++] = point_count - 1; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
let segment_count = 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
segments_data[segments_head++] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let head = 0; |
|
|
|
|
|
|
|
// Using stack.push() allocates even if the stack is pre-allocated!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack[head++] = 0; |
|
|
|
|
|
|
|
stack[head++] = 0; |
|
|
|
|
|
|
|
stack[head++] = point_count - 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (head > 0) { |
|
|
|
|
|
|
|
const end = stack[--head]; |
|
|
|
|
|
|
|
const value = start = stack[--head]; |
|
|
|
|
|
|
|
const type = stack[--head]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (type === 1) { |
|
|
|
|
|
|
|
segments_data[segments_head++] = value; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
const max = rdp_find_max(state, zoom, coords_from, start, end); |
|
|
|
|
|
|
|
if (max !== -1) { |
|
|
|
|
|
|
|
segment_count += 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack[head++] = 0; |
|
|
|
|
|
|
|
stack[head++] = max; |
|
|
|
|
|
|
|
stack[head++] = end; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack[head++] = 1; |
|
|
|
|
|
|
|
stack[head++] = max; |
|
|
|
|
|
|
|
stack[head++] = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack[head++] = 0; |
|
|
|
|
|
|
|
stack[head++] = start; |
|
|
|
|
|
|
|
stack[head++] = max; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
segments_data[segments_head++] = point_count - 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (segment_count === 2 && state.canvas.zoom > state.line_threshold.data[stroke_index]) { |
|
|
|
|
|
|
|
state.line_threshold.data[stroke_index] = state.canvas.zoom; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state.segments_from.data[context.clipped_indices.size] = segments_head; |
|
|
|
|
|
|
|
state.segments_from.size = context.clipped_indices.size + 1; |
|
|
|
|
|
|
|
state.segments.size = segments_head; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
write_coordinates(state, context); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return segments_head; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|