44 lines
2.3 KiB
Python
44 lines
2.3 KiB
Python
"""The former CPU light behavioural checks, now read from the actual GPU light grid."""
|
|
import pathlib,sys
|
|
sys.path.insert(0,str(pathlib.Path(__file__).resolve().parent.parent/'tools'))
|
|
from use_venv import ensure_playwright;ensure_playwright()
|
|
from browser import launch,consume_gpu_option
|
|
consume_gpu_option()
|
|
root=pathlib.Path(__file__).resolve().parent.parent
|
|
with launch(viewport={'width':636,'height':156}) as (_,pg,url):
|
|
errors=[]
|
|
pg.on('pageerror',lambda e:errors.append(str(e)))
|
|
pg.on('console',lambda m:errors.append(m.text) if m.type=='error' else None)
|
|
pg.add_init_script('requestAnimationFrame=()=>0;')
|
|
pg.goto(url);pg.evaluate('CAPS_CHECK')
|
|
pg.add_script_tag(path=str(root/'test/light-readback.js'))
|
|
source=(root/'test/light-cases.js').read_text()
|
|
result=pg.evaluate("""async source=>{
|
|
const results=[];
|
|
function check(name,ok,detail){results.push({name,ok:!!ok,detail});}
|
|
function done(){}
|
|
async function run(code){
|
|
code=code.replaceAll('computeLight();','await testLight();');
|
|
let value;
|
|
if(code.includes('await ')) {
|
|
if(code.trim().startsWith('(() =>')) code=code.replace('(() =>','(async () =>');
|
|
else code='(async()=>{'+code+'})()';
|
|
}
|
|
value=await (0,eval)(code);
|
|
if(!code.includes('testLight()')) await testLight();
|
|
return value;
|
|
}
|
|
async function flatWorld(run,w,h,g){
|
|
await run(`alloc(${w},${h});worldSeed=7;for(let x=0;x<W;x++){surfY[x]=${g};dirtY[x]=${g}+10;graniteY[x]=basaltY[x]=H;}
|
|
computeAmbient();fillNoise();for(let y=0;y<H;y++)for(let x=0;x<W;x++){const i=y*W+x;mat[i]=y>=${g}?STONE:EMPTY;flags[i]=y>=${g}?F_NAT:0;temp[i]=AMB[y];}
|
|
bot.x=(W>>1)-8;bot.y=${g}-30;bag=new Int32Array(NMAT);bagTotal=0;player.tankTier=3;updateRoof();resetWeather();weather.next=1e15;buildSky();`);
|
|
}
|
|
SET.zoom=2;SET.look='pixel';SET.fog=false;SET.glow='off';SET.daylight=1;SET.ambient=0.12;SET.lightEvery=1;
|
|
initRender(canvas);resizeRender();R.camX=0;R.camY=100;
|
|
return await eval('(async()=>{'+source+';return results;})()');
|
|
}""",source)
|
|
for r in result:
|
|
print(('PASS ' if r['ok'] else 'FAIL ')+r['name']+' '+str(r.get('detail','')))
|
|
assert all(r['ok'] for r in result)
|
|
assert not errors,errors
|