Skip to content

Commit

Permalink
optimized floor render codes a little, floor is still diabled
Browse files Browse the repository at this point in the history
  • Loading branch information
AqeeAqee committed Aug 27, 2023
1 parent bd0e07c commit 1d3a16d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"branch": "v0.14.3",
"tag": "v0.14.3",
"commits": "https://github.com/microsoft/pxt-arcade/commits/aef27bb278de89a83ecb6ab02af5319c06d617e2",
"target": "1.12.30",
"target": "1.12.36",
"pxt": "5.21.6",
"targetId": "arcade"
},
Expand Down
41 changes: 20 additions & 21 deletions render_raycasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,33 +481,32 @@ namespace Render {

let ms:number
//floor
if(0){
ms= control.benchmark(()=>
{
const posZ = (SH * this.viewZPos / this.tilemapScaleSize)|0
for (let yFloor = SHHalf; yFloor < SH; yFloor++) {
const rowDistance = (posZ / (yFloor - SHHalf)) | 0
const floorStepX = -Math.idiv (rowDistance * this.planeX*2 , SW)
const floorStepY = -Math.idiv (rowDistance * this.planeY*2 , SW)

let floorX = (this.selfXFpx * fpx_scale + (rowDistance * (this.dirXFpx + this.planeX)))
let floorY = (this.selfYFpx * fpx_scale + (rowDistance * (this.dirYFpx + this.planeY)))
//if (0)
if (0) {
ms = control.benchmark(() => {
const posZ = (SH * this.viewZPos / this.tilemapScaleSize) | 0
for (let yFloor = SHHalf; yFloor < SH; yFloor++) {
const rowDistance = (posZ / (yFloor - SHHalf)) | 0
let floorX = this.selfXFpx * fpx_scale + (rowDistance * (this.dirXFpx + this.planeX))
let floorY = this.selfYFpx * fpx_scale + (rowDistance * (this.dirYFpx + this.planeY))
const floorStepX = -Math.idiv(rowDistance * this.planeX, SWHalf)
const floorStepY = -Math.idiv(rowDistance * this.planeY, SWHalf)
for (let xFloor = 0; xFloor < SW; xFloor++) { //21
const tileType = this.mapData[4 + (floorX >> fpx2) + (floorY >> fpx2) * this.map.width] //this.getTileIndex(floorX,floorY);//this.map.getTile(floorX, floorY)
const floorTex = this.textures[tileType]
if (floorTex) {
const tx = (floorX >> (fpx2_4)) & 0xF //17
const ty = (floorY >> (fpx2_4)) & 0xF
const c = floorTex.getPixel(tx, ty)
this.tempScreen.setPixel(xFloor, yFloor, c)
{
const floorTex = this.textures[tileType]
if (floorTex) {
const tx = (floorX >> (fpx2_4)) & 0xF //17
const ty = (floorY >> (fpx2_4)) & 0xF
const c = floorTex.getPixel(tx, ty)
this.tempScreen.setPixel(xFloor, yFloor, c)
}
}
floorX += floorStepX
floorY += floorStepY
}
}
})
this.tempScreen.print(ms.toString(),0,10)
}
})
this.tempScreen.print(ms.toString(), 0, 10)
}

// ms=control.benchmark(()=>{
Expand Down

0 comments on commit 1d3a16d

Please sign in to comment.