Skip to content

Optimize performance, add textures, mobile controls, and production polish#1

Merged
alimohomad merged 1 commit into
mainfrom
devin/1777005605-optimize-and-polish
Apr 24, 2026
Merged

Optimize performance, add textures, mobile controls, and production polish#1
alimohomad merged 1 commit into
mainfrom
devin/1777005605-optimize-and-polish

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Massive overhaul of index.html to make Chungi Hunter 3D production-ready: big perf fixes, procedural textures, real mobile support, and gameplay polish. No external assets are required — all new textures are generated procedurally at runtime.

Performance (the big wins)

  • Analytical terrain height (O(1)) replaces the old per-frame getTerrainHeight() that iterated all 6,561 grid points for every entity. This alone removed ~70k ops per frame across player/8 bots/chungi/camera.
  • InstancedMesh for scenery: grass (500), stones (100), tree trunks (45), and tree foliage (~1,125 spheres) are now drawn in just a handful of draw calls instead of ~1,700.
  • Device-adaptive quality: on mobile / low-CPU devices the game auto-reduces pixel ratio, shadow map size, floor tessellation, cloud/grass/stone/tree counts, and canopy density.
  • Auto FPS fallback: if FPS drops below ~28 for a sustained period, the game drops to "low" quality and turns off shadows automatically.
  • Tab-hidden pause: the render/physics loop halts when the tab is hidden, saving battery on mobile.

Textures

  • Added a procedural canvas-texture system that generates defaults for:
    • Floor grass (radial gradient + noise)
    • Tree bark (vertical grain)
    • Leaves (layered greens, vertex-color tinted per tree)
    • Stone wall (brick pattern)
    • Rocks (noise)
    • Character armor (panel + rivets)
    • Chungi (subtle weave)
  • Textures uploaded via portal.html continue to override the procedural defaults exactly as before.

Mobile

  • Robust mobile detection (UA + maxTouchPoints + viewport width) sets a body.is-mobile class.
  • Larger, thumb-friendly action buttons, bigger pause button, scaled HUD at mobile widths.
  • Mobile-only hint banner shown briefly on match start.
  • Haptic feedback (navigator.vibrate) on jump, dash, throw, bot elimination, player hit, and victory.

Production polish

  • 3-hit health bar with invulnerability frames, red screen flash, and chungi knockback — replaces the old one-shot death.
  • Score system with per-elimination points (+100), survival bonus on victory, persistent best-score in localStorage.
  • Minimap (canvas, ~10 Hz) showing bots, chungi, player facing, and water.
  • FPS counter HUD (green/amber/red tiers) that also drives adaptive quality.
  • Persistent graphics settings (quality, shadows, camera distance) in localStorage, restored on load.
  • Loading overlay that fades out once the first frame renders.
  • Memory cleanup: eliminated bots dispose their geometries; obstacles no longer retain full THREE.Group references.

Review & Testing Checklist for Human

  • Open the game on desktop and confirm FPS 60 at default quality; the FPS counter should stay green.
  • Open on a phone (or DevTools mobile emulation) and confirm the action buttons are big enough, the minimap is visible, and there are no visual regressions.
  • Verify portal.html texture uploads still override the new procedural defaults (floor/wall/tree/player/bot/chungi).
  • Play a full round: take 3 hits and confirm GAME OVER fires only on the 3rd; eliminate all 8 bots and confirm the VICTORY screen shows the score including the survival bonus.
  • Refresh and confirm the best score, graphics quality, shadow quality, and camera distance are restored from the previous session.

Notes

  • No dependencies were added; everything runs on the same Three.js <script> already in index.html.
  • Line endings in index.html were normalized from CRLF to LF as part of the edit; portal.html was intentionally left as-is to keep the diff focused.
  • The old terrainHeights grid array is gone — terrain height is now purely analytical and matches the generated mesh exactly.

Link to Devin session: https://app.devin.ai/sessions/5b14cc25db654389a1752fce6fbdfb83
Requested by: @alimohomad

Performance:
- Replace O(n log n) per-frame getTerrainHeight() with analytical O(1) formula
  (was iterating 6561 grid points per entity per frame)
- Use InstancedMesh for grass (500), stones (100), tree trunks (45) and
  tree foliage (~1125 spheres), cutting ~1700 draw calls to ~5
- Device-aware quality: mobile/low-power auto-caps pixel ratio, shadow
  size, grass/stone/cloud/tree counts, and floor tessellation
- FPS counter with auto-drop to low quality when FPS < 28 for sustained period
- Pause render loop when tab hidden

Textures:
- Added procedural canvas textures as defaults: grass, bark, leaves, stone
  wall, rock, character armor, chungi weave
- Portal-uploaded textures continue to override these defaults

Mobile controls:
- Robust UA + touch + width detection
- Larger circular action buttons, bigger pause button on mobile
- Mobile hint banner shown briefly on start
- Haptic feedback on jump/dash/throw/hit/bot elimination/victory

Production polish:
- 3-hit health system with invulnerability frames, damage flash, knockback
- Persistent score with best-score localStorage
- Minimap (canvas) with bots, chungi, player facing
- Persistent graphics settings in localStorage, UI reflects saved state
- Loading overlay during init
- Bot meshes disposed properly on elimination (no leaks)
- Music gracefully retries if autoplay blocked

Co-Authored-By: Gamer33xz <razzacharya6@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant