physicsGames
View on GitHub βπ Architectural Vision & System Design
The core architectural vision of physicsGames is to deliver deterministic, 60 FPS physics simulations within a reactive web interface without the overhead of a virtual DOM. By leveraging Svelteβs compiler-first approach, the system minimizes runtime overhead, allowing the CPU to dedicate maximum cycles to mathematical vector calculations and collision detection.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Interface (Svelte) β
ββββββββββββββββββββββββββββββββββββββ²βββββββββββββββββββββββββββββββββββββ
β (Reactive Subscriptions)
ββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β State Management (Stores) β
ββββββββββββββββββββββββββββββββββββββ²βββββββββββββββββββββββββββββββββββββ
β (State Updates)
ββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β Physics Engine (Fixed Timestep Loop) β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββ βββββββββββββββββ β
β β Verlet Integration βββΊβ Collision Detection βββΊβ Solver/Bounds β β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββ βββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Core Data & System Flow
- Ingestion / Input: User interactions (mouse drags, gravity adjustments, vector forces) are captured via low-latency DOM event listeners and mapped directly to normalized coordinate spaces.
- Processing / Logic: The simulation runs on a decoupled, deterministic physics loop. It utilizes Verlet integration to calculate particle kinematics, resolving constraints and boundary collisions before committing the new state.
- Persistence & Caching: Simulation states and user-defined presets are serialized into lightweight JSON payloads, cached locally via browser storage, and synchronized reactively across components using Svelte stores.
π» Tech Stack & Engineering Decisions
Every technology in this stack was selected to maximize execution speed, minimize bundle size, and guarantee a smooth rendering pipeline.
- Frontend (Svelte): Chosen over React or Vue due to its compile-time design. Svelte compiles components down to surgical, direct DOM updates, eliminating virtual DOM diffing overheadβa critical requirement when updating hundreds of physics entities simultaneously.
- Build Tool (Vite): Selected for its instant Hot Module Replacement (HMR) and highly optimized Rollup-based production bundling. Viteβs configuration was tuned to handle asset loading and code-splitting efficiently.
- Data & Middleware (Svelte Stores): Used to manage global simulation parameters (e.g., gravity constants, friction coefficients). By externalizing state from the component lifecycle, simulation data remains persistent even during hot reloads, preventing state loss during development.
βοΈ Engineering Excellence & Best Practices
This codebase serves as a benchmark for high-performance frontend engineering, adhering to strict performance and reliability standards:
- Memory Management & GC Optimization: To prevent Garbage Collection (GC