Browse Source

Cache generated geometry

master
A.Olokhtonov 4 months ago
parent
commit
48766ab009
  1. 9
      geometry.js
  2. 18
      input.js
  3. 9
      parse.js
  4. 6
      render.js

9
geometry.js

@ -27,17 +27,16 @@ function generate(trace_id) {
const sizes = []; const sizes = [];
const colors = []; const colors = [];
let instructions = []; let instructions = {};
if (trace_id in traces) { if (trace_id in traces) {
instructions = traces[trace_id]; instructions = traces[trace_id].raw;
} }
console.log(instructions);
let y = 0; 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) { for (let i = 0; i < instruction.lanes['0'].length; ++i) {
const stage = instruction.lanes['0'][i]; const stage = instruction.lanes['0'][i];
let stage_cycles; let stage_cycles;

18
input.js

@ -62,7 +62,24 @@ function wheel(e) {
schedule_draw(); 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) { function keydown(e) {
if (e.code === 'Digit0') {
jump_to_first_instruction();
}
} }
function keyup(e) { function keyup(e) {
@ -91,6 +108,7 @@ function drop(e) {
const text = fr.result; const text = fr.result;
console.log('Finished. String length:', text.length); console.log('Finished. String length:', text.length);
if (parse(text)) { if (parse(text)) {
jump_to_first_instruction();
schedule_draw(); schedule_draw();
} }
}; };

9
parse.js

@ -7,7 +7,7 @@ function parse(text) {
let line_index = 0; let line_index = 0;
let c = -1; let c = -1;
const instructions = []; const instructions = {};
//console.log(text); //console.log(text);
@ -178,7 +178,12 @@ function parse(text) {
console.log(`Parsed in ${Math.round(after - before)}ms`); console.log(`Parsed in ${Math.round(after - before)}ms`);
traces['0'] = instructions; traces['0'] = {
'raw': instructions,
};
traces['0'].geo = generate('0');
return true; return true;
} }

6
render.js

@ -114,7 +114,11 @@ function draw(ts, animation) {
gl.clearColor(0.11, 0.11, 0.11, 1); gl.clearColor(0.11, 0.11, 0.11, 1);
gl.clear(gl.COLOR_BUFFER_BIT); 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) { if (quads.count > 0) {
const program = programs['quad']; const program = programs['quad'];

Loading…
Cancel
Save