@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
let traces = { } ;
let config = { } ;
let raster _tile = { 'x' : 0 , 'y' : 0 } ;
let numbers _rasterized = 0 ;
let max _stage _cycles = 0 ;
onmessage = ( e ) => {
const msg = e . data ;
@ -12,6 +12,7 @@ onmessage = (e) => {
@@ -12,6 +12,7 @@ onmessage = (e) => {
const text = msg . text ;
if ( parse ( text ) ) {
traces [ '0' ] . geo = generate ( '0' ) ;
delete traces [ '0' ] . raw ;
postMessage ( { 'type' : 'trace' , 'data' : traces [ '0' ] } ) ;
}
}
@ -64,7 +65,12 @@ function parse(text) {
@@ -64,7 +65,12 @@ function parse(text) {
if ( ! assert _arglen ( line _parts , 1 , 'C' ) ) return false ;
const cycles = Number ( line _parts [ 1 ] ) ;
if ( c === - 1 ) {
c = 0 ;
} else {
c += cycles ;
}
break ;
}
@ -262,7 +268,7 @@ function get_color(stage_name) {
@@ -262,7 +268,7 @@ function get_color(stage_name) {
return colors [ stage _name ] ;
}
function rasterize _and _pack ( text , cycles ) {
function rasterize _and _pack ( text ) {
// TODO: handle texture is full or stuff don't fit (unlikely)
const key = text ;
@ -285,28 +291,6 @@ function rasterize_and_pack(text, cycles) {
@@ -285,28 +291,6 @@ function rasterize_and_pack(text, cycles) {
rasterized [ key ] = [ u , v ] ;
if ( cycles > 1 ) {
for ( let i = numbers _rasterized + 1 ; i <= cycles ; ++ i ) {
const u = raster _tile . x * config . w / config . raster _texture _size ;
const v = raster _tile . y * config . h / config . raster _texture _size ;
postMessage ( { 'type' : 'rasterize' , 'data' : { 'text' : i , 'at' : { 'x' : raster _tile . x , 'y' : raster _tile . y } } } ) ;
raster _tile . x += 1 ;
if ( raster _tile . x === config . raster _texture _size / config . w ) {
raster _tile . x = 0 ;
raster _tile . y += 1 ;
}
rasterized [ i ] = [ u , v ] ;
}
if ( cycles > numbers _rasterized ) {
numbers _rasterized = cycles ;
}
}
return [ u , v ] ;
}
@ -324,6 +308,10 @@ function pack_instruction(instruction, positions, sizes, colors, uvs, starts, y)
@@ -324,6 +308,10 @@ function pack_instruction(instruction, positions, sizes, colors, uvs, starts, y)
stage _cycles = instruction . retcyc - stage . c ;
}
if ( stage _cycles > max _stage _cycles ) {
max _stage _cycles = stage _cycles ;
}
let [ r , g , b ] = get _color ( stage . name ) ;
let a = 255 ;
@ -331,7 +319,7 @@ function pack_instruction(instruction, positions, sizes, colors, uvs, starts, y)
@@ -331,7 +319,7 @@ function pack_instruction(instruction, positions, sizes, colors, uvs, starts, y)
a = 80 ;
}
const [ u , v ] = rasterize _and _pack ( stage . name , stage _cycles ) ;
const [ u , v ] = rasterize _and _pack ( stage . name ) ;
sizes . push ( stage _cycles * config . w + ( stage _cycles - 1 ) * config . padding , 1 * config . h ) ;
positions . push ( config . w * stage . c + config . padding * ( stage . c - 1 ) , config . h * y + config . padding * ( y - 1 ) ) ;
@ -380,8 +368,12 @@ function generate(trace_id) {
@@ -380,8 +368,12 @@ function generate(trace_id) {
++ y ;
}
postMessage ( { 'type' : 'rasterize_numbers' , 'up_to' : max _stage _cycles } ) ;
starts . push ( positions . length ) ;
console . log ( ` Total geometry: ${ Math . round ( result . count * config . bytes _per _quad / 1024 / 1024 ) } MB ` ) ;
if ( config . show _texture ) {
result . pos = new Float32Array ( [ 0 , 0 ] ) ;
result . size = new Float32Array ( [ config . raster _texture _size , config . raster _texture _size ] ) ;