Throttle render loop to 30fps for improved performance in garden animation. Updated frame handling in createGarden function to reduce CPU/GPU load while maintaining smooth visuals.
Browse files30 unmodified lines313233343536629 unmodified lines66666766866967067167267367467567694 unmodified lines77177277377477577677777877978078178278330 unmodified linesconst DRY_RATE = 0.1; // growth-stages per second while dryconst WATER_BUMP = 0.18; // instant nudge each time you water// A cohesive, sunny GBC-ish palette.const P = {sky0: "#7ec8ff",629 unmodified lines// --- loop ------------------------------------------------------------------function frame(now) {if (!running) return;const dt = Math.min(0.05, (now - last) / 1000 || 0);last = now;update(dt);render();raf = requestAnimationFrame(frame);}// --- input wiring ----------------------------------------------------------94 unmodified linesstart() {if (running) return;running = true;last = 0;updateCaption();window.addEventListener("keydown", onKey, true);raf = requestAnimationFrame((now) => {last = now;frame(now);});},stop() {running = false;30 unmodified lines31323334353637383940629 unmodified lines67067167267367467567667767867968068194 unmodified lines77677777877978078178278378478530 unmodified linesconst DRY_RATE = 0.1; // growth-stages per second while dryconst WATER_BUMP = 0.18; // instant nudge each time you water// cap the render loop at 30fps — the garden animates gently, so there's no need// to redraw at the display's full 60/120Hz (keeps it light on the CPU/GPU).const FRAME_MS = 1000 / 30;// A cohesive, sunny GBC-ish palette.const P = {sky0: "#7ec8ff",629 unmodified lines// --- loop ------------------------------------------------------------------function frame(now) {if (!running) return;raf = requestAnimationFrame(frame);if (now - last < FRAME_MS - 1) return; // throttle to ~30fpsconst dt = Math.min(0.05, last ? (now - last) / 1000 : 0);last = now;update(dt);render();}// --- input wiring ----------------------------------------------------------94 unmodified linesstart() {if (running) return;running = true;last = 0; // 0 → the first frame renders immediately, then the gate kicks inupdateCaption();window.addEventListener("keydown", onKey, true);raf = requestAnimationFrame(frame);},stop() {running = false;
frontend/garden.js+9-7