perf: cache static walls, fast-path sprite draws, cache canvas rect (0.9.1, v57)

This commit is contained in:
Quintine committed 2026-08-13 13:11:16 +10:00
1 parent 6cc8132046
commit d60baa6b29
8 files changed
+84 -47

No files matched your search

+5 -1
View File
@@ -9,6 +9,10 @@ const Input = {
anyKey: false,
};
let _rect = null;
Input.updateRect = function () { _rect = canvas ? canvas.getBoundingClientRect() : null; };
function initInput(canvas) {
window.addEventListener('keydown', (e) => {
const k = e.key.toLowerCase();
@@ -21,7 +25,7 @@ function initInput(canvas) {
window.addEventListener('blur', () => { Input.keys = {}; Input.mdown = false; });
function setMouse(e) {
const r = canvas.getBoundingClientRect();
const r = _rect || (_rect = canvas.getBoundingClientRect());
Input.mx = (e.clientX - r.left) * (W / r.width);
Input.my = (e.clientY - r.top) * (H / r.height);
}