Skip to content

Commit

Permalink
optimize app performance, modify pet config
Browse files Browse the repository at this point in the history
  • Loading branch information
SeakMengs committed Aug 10, 2023
1 parent 840c10a commit 087c4b6
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 118 deletions.
16 changes: 11 additions & 5 deletions src/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function Canvas() {
const DPR: number = window.devicePixelRatio;
const currentScreenHeight: number = Math.round(DPR * window.screen.height);
const canvasRef = useRef<HTMLCanvasElement>(null);
const FPS = 60;

// disable right click (context menu) for build version only. uncomment for development
// credit: https://github.com/tauri-apps/wry/issues/30
Expand Down Expand Up @@ -38,23 +39,28 @@ function Canvas() {
canvas!.height = currentScreenHeight;

function animate() {
context!.save();
context!.imageSmoothingEnabled = false;

window.requestAnimationFrame(animate)


// credit: https://stackoverflow.com/questions/4815166/how-do-i-make-a-transparent-canvas-in-html5
context!.clearRect(0, 0, canvas!.width, canvas!.height);

// Debug purposes
// context.fillStyle = 'black'
// context.fillRect(0, 0, canvas.width, canvas.height)

if (pets.length > 0) {
for (let i = 0; i < pets.length; i++) {
pets[i].animateBehavior();
pets[i].update(context);
}
}

context!.restore();

setTimeout(() => {
window.requestAnimationFrame(animate)
}, 1000 / FPS);
}

animate();
Expand Down
3 changes: 2 additions & 1 deletion src/components/setting_tabs/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ interface settingsProp {
}[];
}

// Top level await is now allow in production build.
// creating function and call it like this solve the problem :)
let isAutoStartUp: boolean

async function isAutoStartUpEnabled() {
isAutoStartUp = await isEnabled();
}
Expand Down
Loading

0 comments on commit 087c4b6

Please sign in to comment.