Skip to content

Commit

Permalink
Fix FPS drop when too close to wall
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Jun 26, 2024
1 parent 6413c09 commit 02ddd98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,13 @@ function renderWallsToImageData(imageData: ImageData, player: Player, scene: Sce
u = t.x;
}

for (let dy = 0; dy < Math.ceil(stripHeight); ++dy) {
const y1 = Math.floor((SCREEN_HEIGHT - stripHeight)*0.5);
const y2 = Math.floor(y1 + stripHeight);
const by1 = Math.max(0, y1);
const by2 = Math.min(SCREEN_HEIGHT-1, y2);
for (let y = by1; y <= by2; ++y) {
const tx = Math.floor(u*cell.width);
const ty = Math.floor(dy/Math.ceil(stripHeight)*cell.height);

const y = Math.floor((SCREEN_HEIGHT - stripHeight)*0.5) + dy;
const ty = Math.floor((y - y1)/Math.ceil(stripHeight)*cell.height);
imageData.data[(y*SCREEN_WIDTH + x)*4 + 0] = cell.data[(ty*cell.width + tx)*4 + 0]/v.dot(d);
imageData.data[(y*SCREEN_WIDTH + x)*4 + 1] = cell.data[(ty*cell.width + tx)*4 + 1]/v.dot(d);
imageData.data[(y*SCREEN_WIDTH + x)*4 + 2] = cell.data[(ty*cell.width + tx)*4 + 2]/v.dot(d);
Expand Down

0 comments on commit 02ddd98

Please sign in to comment.