From 5d45eb325577b6a95ab5dd411e24139b33b5c8a9 Mon Sep 17 00:00:00 2001 From: "A.Olokhtonov" Date: Sat, 7 Sep 2024 17:35:44 +0300 Subject: [PATCH] Undo eraser --- README.txt | 6 +++--- client/bvh.js | 13 +++++++++++++ client/client_recv.js | 13 ++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.txt b/README.txt index bec53cf..96af0e1 100644 --- a/README.txt +++ b/README.txt @@ -8,14 +8,14 @@ Release: + Do not copy memory to wasm, instead use wasm memory to store data in the first place + SIMD for LOD? + Multithreading for LOD - + Textured quads (pictures, code already written in older version) + + Textured quads (pictures, code already written in older version + Resize and move pictures (draw handles) - Z-prepass fringe bug (also, when do we enable the prepass?) + Bugs + GC stalls!!! + Stroke previews get connected when drawn without panning on touch devices + Redraw HTML (cursors) on local canvas moves - + New strokes dissapear on the HMH desk + + New strokes dissapear on the HMH desk - Debug - Restore ability to limit event range * Listeners/events/multiplayer @@ -45,8 +45,8 @@ Release: - Live preview - Alignment (horizontal, vertical, diagonal, etc) + Undo + + Undo for eraser - Undo for images (add, move, scale) - - Undo for eraser - Redo + Snapping to grid - Snapping to other points? diff --git a/client/bvh.js b/client/bvh.js index 04bee14..fd57c2b 100644 --- a/client/bvh.js +++ b/client/bvh.js @@ -176,6 +176,19 @@ function bvh_delete_stroke(state, stroke) { } } +function bvh_undelete_stroke(state, stroke) { + let node = state.bvh.nodes[stroke.bvh_node]; + + while (node.parent_index !== null) { + if (node.is_fullnode) { + tv_add2(node.stroke_indices, stroke.index); + break; + } + + node = state.bvh.nodes[node.parent_index]; + } +} + function bvh_intersect_quad(state, bvh, quad, result_buffer) { if (bvh.root === null) { return; diff --git a/client/client_recv.js b/client/client_recv.js index 923ac27..16061a3 100644 --- a/client/client_recv.js +++ b/client/client_recv.js @@ -366,17 +366,24 @@ function handle_event(state, context, event, options = {}) { break; } else if (other_event.type === EVENT.UNDO) { // do not undo an undo, we are not Notepad + } else if (other_event.type === EVENT.IMAGE) { + console.log('TODO: undo image'); } else if (other_event.type === EVENT.IMAGE_MOVE) { // TODO - console.log('TODO: undo image scale'); + console.log('TODO: undo image move'); break; } else if (other_event.type === EVENT.IMAGE_SCALE) { // TODO console.log('TODO: undo image scale'); break; } else if (other_event.type === EVENT.ERASER) { - // TODO - console.log('TODO: undo eraser'); + const stroke = state.events[other_event.stroke_id]; + stroke.deleted = false; + if (!options.skip_bvh) { + bvh_undelete_stroke(state, stroke); + } + need_draw = true; + other_event.deleted = true; break; } else { console.error('cant undo event type', other_event.type);