--- description: Standards for Three.js integration, VoxelGrid, and the Game Loop. globs: src/core/*.js, src/grid/*.js** --- # **Game Engine Standards** ## **The Game Loop** - **Responsibility:** The GameLoop is the "God Object" responsible for tying systems together. It owns the Scene, Renderer, Grid, and Managers. - **Phases:** The loop must respect the current phase: INIT, DEPLOYMENT, COMBAT, RESOLUTION. - **Input Routing:** The loop routes raw inputs from InputManager to the appropriate system (e.g., MovementSystem vs SkillTargeting) based on the current Phase. ## **Voxel System** 1. **Separation of Concerns:** - VoxelGrid.js: **Pure Data**. Stores IDs in Uint8Array. Handles physics queries (isSolid). No Three.js dependencies. - VoxelManager.js: **Rendering**. Reads VoxelGrid and updates THREE.InstancedMesh. Handles materials and textures. 2. **Performance:** - Never create individual THREE.Mesh objects for terrain. Use InstancedMesh. - Hide "Air" voxels by scaling them to 0 rather than removing them from the InstanceMatrix (unless refactoring for chunking). 3. **Coordinates:** - Use {x, y, z} objects for positions. - Y is **Up**. - Grid coordinates are integers. ## **Input** - Use InputManager for all hardware interaction. - Support Mouse, Keyboard, and Gamepad seamlessly. - Raycasting should return integer Grid Coordinates.