perf: use cached body dimensions in tick, remove redundant style sets

This commit is contained in:
2026-04-24 13:23:44 +02:00
parent 2ba0b90fce
commit 7cc57e966b

View File

@@ -192,36 +192,23 @@ export class GravityEngine {
this.bodies.forEach((body) => { this.bodies.forEach((body) => {
if (body.isDragging) { if (body.isDragging) {
// Only update visually while dragging, physics are paused
body.el.style.position = "fixed";
body.el.style.left = "0px";
body.el.style.top = "0px";
body.el.style.transform = `translate(${body.x}px, ${body.y}px)`; body.el.style.transform = `translate(${body.x}px, ${body.y}px)`;
return; return;
} }
// Apply Gravity
body.vy += gravity; body.vy += gravity;
body.x += body.vx; body.x += body.vx;
body.y += body.vy; body.y += body.vy;
// Apply Air Friction
body.vx *= 0.99; body.vx *= 0.99;
body.vy *= 0.99; body.vy *= 0.99;
const rect = body.el.getBoundingClientRect(); if (body.y + body.height > floorY) {
body.y = floorY - body.height;
// Floor Collision
if (body.y + rect.height > floorY) {
body.y = floorY - rect.height;
body.vy *= bounce; body.vy *= bounce;
body.vx *= 0.9; // Ground friction body.vx *= 0.9;
} }
// Render Step
body.el.style.position = "fixed";
body.el.style.left = "0px";
body.el.style.top = "0px";
body.el.style.transform = `translate(${body.x}px, ${body.y}px)`; body.el.style.transform = `translate(${body.x}px, ${body.y}px)`;
}); });