I'll tackle this in two parts: performance tiers (shadows, AA, pixel ratio, instance counts, star density) and mobile touch controls (dual virtual joysticks + buttons). Let me start with the index.html viewport and CSS foundation, then the quality tier in the game engine.
Next, the CSS — touch-lock the document, kill overscroll bounce, add safe-area padding, and define the virtual joystick/button styles.
Now the game engine with a quality tier. Low tier disables shadows, lowers pixel ratio, cuts star/tree counts, and exposes a clean input-injection API for touch controls.
Now I'll update world.ts to accept a quality tier — fewer trees/hedges/lamps/stars and lower segment counts in low quality.
Now the key performance cuts — skip the heavy Point/Spot lights on low, reduce star/tree/hedge/lamp/bush counts, and lower segment counts on cylinders/spheres.
Now shrink the directional shadow frustum on low — big win on mobile GPUs.
Now the touch-controls React component — a left-side move joystick, a right-side look-drag surface, plus jump/sprint/pause buttons.
Let me rewrite the touch controls with a cleaner structure — fixed left/right surfaces, joystick base spawns at the initial finger position.
Now update App.tsx — wire in mobile detection, quality tier, touch controls, and a mobile-optimized HUD and menu.
Build to check for any remaining TypeScript errors.
Build passes cleanly at 803 KB (214 KB gzipped). Here's what changed:
Performance — way less laggy
Quality tier system (src/game/Game.ts now accepts { quality, mobile }):
- Low (mobile): pixel ratio capped at 1×, antialiasing disabled, shadows disabled entirely,
NoToneMapping (skips ACES compute), shorter draw distance (500 vs 900).
- High (desktop): original settings (2× DPR, PCFSoft shadows, ACES tonemapping, AA).
World.ts cuts on low tier:
- Directional shadow cast disabled; shadow map 512 vs 2048 (not used since
castShadow=false).
- PointLights/SpotLights removed (4 PointLights + 2 SpotLights gone on mobile — these are the single biggest GPU cost after shadows). Replaced with 2 cheap warm PointLights for ambience.
- Stars: 420 → 110.
- Trees: 46 → 22 (instanced).
- Hedges: every 5 units → every 12 units along the walls (~58% fewer).
- Path lamps: halved.
- Bushes: halved.
- Particle burst: 240 → 120 pool size, 32 particles per spawn vs 40.
Mobile support
Touch controls (src/TouchControls.tsx):
- Left half of screen: movement joystick that spawns wherever you first touch — knob tracks from the origin, clamped to a 58 px radius.
- Right half of screen: drag anywhere to look around (accumulated deltas fed into
game.addLook).
- Jump button (gold, bottom-right), Sprint button (hold, above jump), Pause (top-right), Mute (top-left).
- All buttons use
data-touch-button + stopPropagation so they never steal joystick input.
- Joystick base fades in/out at the finger position.
Viewport & CSS (index.html, index.css):
viewport-fit=cover, user-scalable=no, theme-color, apple-mobile-web-app-capable.
touch-action: none + overscroll-behavior: none on html/body/canvas — kills scroll bounce, pull-to-refresh, pinch zoom.
safe-area-inset-bottom padding on menus for notched devices.
- Custom
.touch-pad, .touch-knob, .touch-btn styles with gold gradients matching the estate identity.
App.tsx mobile HUD:
- All panels scale down (
md: variants keep desktop sizes).
- Keyboard hints panel hidden on mobile; replaced with a tiny "LEFT · WALK RIGHT · LOOK" pill.
- Location banner font/letter-spacing reduced; "find all 10" sub-line hidden.
- Compass shrinks to 56 px and repositions to
bottom-3 right-28 to clear the jump button.
- Mute/Pause moved from HUD panels to floating circular touch buttons.
- Menu shows a TOUCH CONTROLS card on mobile (2-column key/value) instead of the keyboard keycaps.
- Pause button calls
game.pauseFromUi() which properly stops the game without relying on pointer lock (which doesn't exist on mobile).
Game.ts mobile flow:
isMobile flag skips pointer-lock setup/listeners entirely.
- External input API (
setMove, addLook, setSprint, triggerJump) integrates cleanly alongside keyboard.
- Mobile detection via touch + viewport width + UA sniffing, so touch laptops still work.
Files built: index.html, src/index.css, src/game/Game.ts, src/game/world.ts, src/TouchControls.tsx, src/App.tsx