|
|
@ -383,23 +383,27 @@ function mousemove(e, state, context) { |
|
|
|
if (state.erasing) { |
|
|
|
if (state.erasing) { |
|
|
|
const me = state.players[state.me]; |
|
|
|
const me = state.players[state.me]; |
|
|
|
const radius = Math.round(me.width / 2); |
|
|
|
const radius = Math.round(me.width / 2); |
|
|
|
|
|
|
|
const last_canvasp = screen_to_canvas(state, state.cursor); |
|
|
|
|
|
|
|
|
|
|
|
const cursor_bbox = { |
|
|
|
const cursor_bbox = { |
|
|
|
'x1': canvasp.x - radius, |
|
|
|
'x1': Math.min(canvasp.x, last_canvasp.x) - radius, |
|
|
|
'y1': canvasp.y - radius, |
|
|
|
'y1': Math.min(canvasp.y, last_canvasp.y) - radius, |
|
|
|
'x2': canvasp.x + radius, |
|
|
|
'x2': Math.max(canvasp.x, last_canvasp.x) + radius, |
|
|
|
'y2': canvasp.y + radius, |
|
|
|
'y2': Math.max(canvasp.y, last_canvasp.y) + radius, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
tv_ensure(state.erase_candidates, round_to_pow2(state.stroke_count, 4096)); |
|
|
|
tv_ensure(state.erase_candidates, round_to_pow2(state.stroke_count, 4096)); |
|
|
|
tv_clear(state.erase_candidates); |
|
|
|
tv_clear(state.erase_candidates); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Rough pass, not all of these might actually need to be erased
|
|
|
|
bvh_intersect_quad(state, state.bvh, cursor_bbox, state.erase_candidates); |
|
|
|
bvh_intersect_quad(state, state.bvh, cursor_bbox, state.erase_candidates); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fine pass, actually run expensive capsule vs capsule intersection tests
|
|
|
|
for (let i = 0; i < state.erase_candidates.size; ++i) { |
|
|
|
for (let i = 0; i < state.erase_candidates.size; ++i) { |
|
|
|
const stroke_id = state.erase_candidates.data[i]; |
|
|
|
const stroke_id = state.erase_candidates.data[i]; |
|
|
|
const stroke = state.events[stroke_id]; |
|
|
|
const stroke = state.events[stroke_id]; |
|
|
|
|
|
|
|
|
|
|
|
if (!stroke.deleted && stroke_intersects_cursor(state, stroke, canvasp, radius)) { |
|
|
|
if (!stroke.deleted && stroke_intersects_capsule(state, stroke, last_canvasp, canvasp, radius)) { |
|
|
|
stroke.deleted = true; |
|
|
|
stroke.deleted = true; |
|
|
|
bvh_delete_stroke(state, stroke); |
|
|
|
bvh_delete_stroke(state, stroke); |
|
|
|
queue_event(state, eraser_event(stroke_id)); |
|
|
|
queue_event(state, eraser_event(stroke_id)); |
|
|
|