LittleJS Proof of Concept for Nordic Skating
This directory contains a proof-of-concept implementation to validate that LittleJS can successfully integrate with the existing Nordic Skating codebase.
Quick Start
To test the POC:
# From the project root
cd /Users/pavel/code/nordic-skating
# Install LittleJS
npm install littlejsengine
# Navigate to POC directory
cd LITTLEJS_POC
# Install POC dependencies
npm install
# Run the POC
npm run dev
Then open http://localhost:3000 in your browser.
What This POC Demonstrates
- LittleJS + Three.js Integration: Shows that LittleJS can manage the game loop while Three.js handles rendering
- Input System: Demonstrates LittleJS input handling for keyboard, mouse, and gamepad
- Existing Code Reuse: Uses the existing lake generation and skater physics from the main project
- Camera System: Shows how the first-person camera can be implemented
- HUD Rendering: Demonstrates LittleJS's built-in text rendering for HUD elements
Expected Behavior
Controls
- WASD / Arrow Keys: Steer left and right
- W / S or Up / Down Arrows: Change pace (meander, cruise, brisk, racing, olympic)
- M: Toggle mute (logs to console in POC)
- R: Generate a random lake
Display
- First-person view following the skater
- HUD showing:
- Current speed in km/h
- Current pace
- Lake seed number
- Steering value
- Skater position
- Ice thickness at current position
- FPS counter
- Simple ice plane and sky
- Control instructions at bottom of screen
File Structure
LITTLEJS_POC/
├── index.html # HTML entry point
├── package.json # POC dependencies
├── vite.config.ts # Vite configuration
└── src/
└── littlejs-poc.ts # Main POC implementation
How It Works
- Initialization: The POC initializes both LittleJS and Three.js
- Input Handling: LittleJS captures all input and makes it available through its API
- Game Loop: LittleJS manages the game loop with proper delta time
- Physics: The existing skater physics from the main project are used unchanged
- Rendering: Three.js renders the scene, with camera position updated each frame
- HUD: LittleJS renders text-based HUD elements on top of the Three.js scene
Validation Checklist
Use this checklist to verify the POC works correctly:
- [ ] Application starts without errors
- [ ] Canvas fills the screen
- [ ] Keyboard steering works (A/D, Left/Right arrows)
- [ ] Mouse steering works (drag left/right)
- [ ] Pace changes with W/S or Up/Down arrows
- [ ] Random lake generation works with R key
- [ ] HUD displays correctly with all information
- [ ] Camera follows skater movement properly
- [ ] Speed and position values change as expected
- [ ] FPS counter shows reasonable frame rate
- [ ] No console errors
Troubleshooting
"Module not found" errors
The POC imports modules from the main project's src directory. If you get errors:
- Ensure you're running from the main project directory
- Check that the paths in
littlejs-poc.tsare correct for your setup - The alias in
vite.config.tsmaps..to the main project'ssrc
LittleJS not initializing
- Ensure LittleJS is installed:
npm install littlejsengine - Check that the import paths are correct
- Verify there are no version conflicts
Three.js rendering issues
- Check that the canvas element exists with id="scene"
- Verify the Three.js version is compatible
- Look for WebGL errors in the console
Input not working
- Check browser console for errors
- Verify that LittleJS input system is initialized
- Try different browsers (some may block certain input types)
Technical Notes
Key Integration Points
-
Three.js Renderer Setup:
typescript setThreeRenderer(THREE)This tells LittleJS to use Three.js for rendering. -
Input Handling:
typescript inputGetState('arrowLeft') // Check if key is pressed inputGetAxis('mouseX') // Get mouse/touch axis inputGetPressed('m') // Check if key was pressed this frame -
Game Loop:
typescript engineInit(init, update, updatePost, render, renderPost)LittleJS calls these functions automatically each frame. -
Delta Time:
typescript const dt = engine.timing.lastTimeStepUse this for physics updates to ensure frame-rate independence. -
HUD Rendering:
typescript drawTextScreen(text, position, size, color, align?)LittleJS provides simple text rendering on top of the main scene.
What's NOT in the POC (Yet)
The POC is intentionally minimal. These features are not implemented but would be in the full migration:
- Audio system (would use existing
iceSound.ts) - Complex ice rendering with thickness colors
- Shore/bank rendering
- Snow and weather effects
- Cracks and marks
- Sky rendering with time of day
- Settings UI
- About dialog
- History/state management for lake seeds
- Proper tilt steering calibration
Performance Considerations
The POC should run smoothly on most modern devices. Performance can be monitored via:
- FPS counter in the HUD
- Browser dev tools performance tab
- Console logs for timing information
Expected performance: - Desktop: 60+ FPS - Modern mobile: 30-60 FPS - Older devices: 20-30 FPS
Next Steps
If the POC works correctly:
- Test on multiple devices (desktop, mobile, tablet)
- Verify all input methods work as expected
- Compare feel with the current implementation
- Measure performance and compare with current version
- Proceed with full migration as outlined in
LITTLEJS_CONVERSION_PLAN.md
If the POC has issues:
- Debug the specific problems
- Adjust the integration approach
- Consider a minimal integration (just input + game loop) instead of full migration
Alternative: Testing Without POC Setup
If you want to test the integration without setting up the POC separately, you can temporarily modify the main project:
- Install LittleJS in the main project:
npm install littlejsengine - Rename
src/main.tstosrc/main.ts.backup - Copy
LITTLEJS_POC/src/littlejs-poc.tstosrc/main.ts - Update
index.htmlto use a canvas with id="scene" - Run
npm run dev
Then restore the original files when done testing.