From 48766ab009434c84ba03cf90d27d80c100e76e67 Mon Sep 17 00:00:00 2001 From: "A.Olokhtonov" Date: Sun, 21 Jul 2024 16:30:21 +0300 Subject: [PATCH] Cache generated geometry --- geometry.js | 9 ++++----- input.js | 18 ++++++++++++++++++ parse.js | 9 +++++++-- render.js | 6 +++++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/geometry.js b/geometry.js index 631eb7c..326c748 100644 --- a/geometry.js +++ b/geometry.js @@ -27,17 +27,16 @@ function generate(trace_id) { const sizes = []; const colors = []; - let instructions = []; + let instructions = {}; if (trace_id in traces) { - instructions = traces[trace_id]; + instructions = traces[trace_id].raw; } - console.log(instructions); - let y = 0; - for (const instruction of instructions) { + for (const id in instructions) { + const instruction = instructions[id]; for (let i = 0; i < instruction.lanes['0'].length; ++i) { const stage = instruction.lanes['0'][i]; let stage_cycles; diff --git a/input.js b/input.js index ad8dc36..e44e9fe 100644 --- a/input.js +++ b/input.js @@ -62,7 +62,24 @@ function wheel(e) { schedule_draw(); } +function jump_to_first_instruction() { + if (Object.keys(traces).length > 0) { + const trace = traces[Object.keys(traces)[0]].raw; + if (Object.keys(trace).length > 0) { + const first_instruction = trace[Object.keys(trace)[0]]; + offset.x = -first_instruction.cycle * config.w; + offset.y = 0 * config.h; + zoom_target = 1; + zoom = 1; + schedule_draw(); + } + } +} + function keydown(e) { + if (e.code === 'Digit0') { + jump_to_first_instruction(); + } } function keyup(e) { @@ -91,6 +108,7 @@ function drop(e) { const text = fr.result; console.log('Finished. String length:', text.length); if (parse(text)) { + jump_to_first_instruction(); schedule_draw(); } }; diff --git a/parse.js b/parse.js index 17e3289..450c832 100644 --- a/parse.js +++ b/parse.js @@ -7,7 +7,7 @@ function parse(text) { let line_index = 0; let c = -1; - const instructions = []; + const instructions = {}; //console.log(text); @@ -178,7 +178,12 @@ function parse(text) { console.log(`Parsed in ${Math.round(after - before)}ms`); - traces['0'] = instructions; + traces['0'] = { + 'raw': instructions, + }; + + + traces['0'].geo = generate('0'); return true; } diff --git a/render.js b/render.js index ed2885d..a58ca63 100644 --- a/render.js +++ b/render.js @@ -114,7 +114,11 @@ function draw(ts, animation) { gl.clearColor(0.11, 0.11, 0.11, 1); gl.clear(gl.COLOR_BUFFER_BIT); - const quads = generate('0'); + let quads = { 'count': 0 }; + + if ('0' in traces) { + quads = traces['0'].geo; + } if (quads.count > 0) { const program = programs['quad'];