Skip to content

Commit

Permalink
refactor: cleanup canvas sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
NuclearRedeye committed Nov 19, 2024
1 parent 11411ab commit edb14d3
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/ts/config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
import { Point } from './interfaces/point';
import { Rectangle } from './interfaces/rectangle';

// Supported resolutions for the Back Buffer, lower resolutions yield better performance.
const resolutions: Point[] = [
{ x: 160, y: 120 },
{ x: 320, y: 240 },
{ x: 480, y: 360 },
{ x: 640, y: 480 },
{ x: 800, y: 600 }
const supportedResolutions: Rectangle[] = [
{ x: 0, y: 0, width: 160, height: 120 },
{ x: 0, y: 0, width: 320, height: 240 },
{ x: 0, y: 0, width: 480, height: 360 },
{ x: 0, y: 0, width: 640, height: 480 },
{ x: 0, y: 0, width: 800, height: 600 }
];

// Current resolution of the Back Buffer, defaults to 640x480.
let currentResolution = 3;

export const backBufferProps: Rectangle = {
x: 0,
y: 0,
width: 640,
height: 480
};
export let backBufferProps: Rectangle = supportedResolutions[currentResolution];

// Increases the resolution of the Back Buffer by 1, until the maximum supported resolution is reached.
export function increaseBackBufferSize(): boolean {
if (currentResolution + 1 >= resolutions.length) {
if (currentResolution + 1 >= supportedResolutions.length) {
return false;
}
currentResolution += 1;
backBufferProps.width = resolutions[currentResolution].x;
backBufferProps.height = resolutions[currentResolution].y;
backBufferProps = supportedResolutions[currentResolution];
return true;
}

Expand All @@ -37,7 +29,6 @@ export function decreaseBackBufferSize(): boolean {
return false;
}
currentResolution -= 1;
backBufferProps.width = resolutions[currentResolution].x;
backBufferProps.height = resolutions[currentResolution].y;
backBufferProps = supportedResolutions[currentResolution];
return true;
}

0 comments on commit edb14d3

Please sign in to comment.