Files

21 lines
1.9 KiB
JavaScript

// Render invalidation must not depend on whether a grain moved or the chunk stayed awake.
const {load,suite,flatWorld}=require('./harness');
const {run}=load(),{check,done}=suite();
flatWorld(run,128,128,100);
function marked(code,x,y){run('renderDirty.fill(0);'+code);return run(`!!renderDirty[(${y}>>5)*CW+(${x}>>5)]`);}
run('setCell(65*W+65,STONE,20,F_NAT);bot.x=63;bot.y=60;');
check('stationary drill damage invalidates the rock',marked('toolDig(65,65,0);',65,65) && run('digp[65*W+65]>0 && mat[65*W+65]===STONE'));
check('waking a cell invalidates its render chunk',marked('wakeXY(31,31);',31,31));
check('swapping cells invalidates both render chunks',marked('swapCells(10*W+10,70*W+70);',70,70)&&run('!!renderDirty[0]'));
check('exploration invalidates its render chunk',marked('fogMark(70,70,255);',70,70));
check('revealing the whole map invalidates every chunk',marked('fogRevealAll();',70,70)&&run('renderDirty.every(v=>v===1)'));
check('heat invalidates the chunk and conduction across its edges',marked('heatChunk(5,1);',64,40)&&run('!!renderDirty[1] && !!renderDirty[4] && !!renderDirty[9]'));
check('tree growth invalidates the background',marked('setTreeCell(70,70,WOOD);',70,70));
run('setCell(60*W+60,FIRE,900,0);life[60*W+60]=10;for(const j of [60*W+59,60*W+61,59*W+60,61*W+60])setCell(j,STONE,20,F_NAT);');
check('blocked fire aging invalidates without movement',marked('tick++;tickStamp++;simMove();',60,60) && run('life[60*W+60]===9'));
run('setCell(32*W+64,SAND,20,0);part[32*W+64]=P_GOPEN;setCell(31*W+64,EMPTY,20,0);');
check('closing a gate invalidates the displaced grain across a chunk edge',marked('toggleGateAt(64,32);',64,31) && run('mat[31*W+64]===SAND'));
run('awake.fill(0);setCell(63*W+63,SAND,20,0);renderDirty.fill(0);tick++;tickStamp++;simMove();');
check('movement invalidates its scanned chunk and diagonal destination',run('renderDirty[5] && renderDirty[9]'));
done();