Browse Source

Cache generated geometry

master
A.Olokhtonov 5 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) { @@ -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;

18
input.js

@ -62,7 +62,24 @@ function wheel(e) { @@ -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) { @@ -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();
}
};

9
parse.js

@ -7,7 +7,7 @@ function parse(text) { @@ -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) { @@ -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;
}

6
render.js

@ -114,7 +114,11 @@ function draw(ts, animation) { @@ -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'];

Loading…
Cancel
Save