fuzzyworld

nordic-skating / mistral-medium-35-littlejs / files / LITTLEJS_POC / README.md

Branch mistral-medium-35-littlejs · default branch · all branches

README.md

Blame: the commit that last changed each line · file · history

185c6976 2026-10-19 Pavel Safronov1# LittleJS Proof of Concept for Nordic Skating
2
3This directory contains a proof-of-concept implementation to validate that LittleJS can successfully integrate with the existing Nordic Skating codebase.
4
5## Quick Start
6
7To test the POC:
8
9```bash
10# From the project root
11cd /Users/pavel/code/nordic-skating
12
13# Install LittleJS
14npm install littlejsengine
15
16# Navigate to POC directory
17cd LITTLEJS_POC
18
19# Install POC dependencies
20npm install
21
22# Run the POC
23npm run dev
24```
25
26Then open `http://localhost:3000` in your browser.
27
28## What This POC Demonstrates
29
301. **LittleJS + Three.js Integration**: Shows that LittleJS can manage the game loop while Three.js handles rendering
312. **Input System**: Demonstrates LittleJS input handling for keyboard, mouse, and gamepad
323. **Existing Code Reuse**: Uses the existing lake generation and skater physics from the main project
334. **Camera System**: Shows how the first-person camera can be implemented
345. **HUD Rendering**: Demonstrates LittleJS's built-in text rendering for HUD elements
35
36## Expected Behavior
37
38### Controls
39- **WASD / Arrow Keys**: Steer left and right
40- **W / S or Up / Down Arrows**: Change pace (meander, cruise, brisk, racing, olympic)
41- **M**: Toggle mute (logs to console in POC)
42- **R**: Generate a random lake
43
44### Display
45- First-person view following the skater
46- HUD showing:
47 - Current speed in km/h
48 - Current pace
49 - Lake seed number
50 - Steering value
51 - Skater position
52 - Ice thickness at current position
53 - FPS counter
54- Simple ice plane and sky
55- Control instructions at bottom of screen
56
57## File Structure
58
59```
60LITTLEJS_POC/
61├── index.html # HTML entry point
62├── package.json # POC dependencies
63├── vite.config.ts # Vite configuration
64└── src/
65 └── littlejs-poc.ts # Main POC implementation
66```
67
68## How It Works
69
701. **Initialization**: The POC initializes both LittleJS and Three.js
712. **Input Handling**: LittleJS captures all input and makes it available through its API
723. **Game Loop**: LittleJS manages the game loop with proper delta time
734. **Physics**: The existing skater physics from the main project are used unchanged
745. **Rendering**: Three.js renders the scene, with camera position updated each frame
756. **HUD**: LittleJS renders text-based HUD elements on top of the Three.js scene
76
77## Validation Checklist
78
79Use this checklist to verify the POC works correctly:
80
81- [ ] Application starts without errors
82- [ ] Canvas fills the screen
83- [ ] Keyboard steering works (A/D, Left/Right arrows)
84- [ ] Mouse steering works (drag left/right)
85- [ ] Pace changes with W/S or Up/Down arrows
86- [ ] Random lake generation works with R key
87- [ ] HUD displays correctly with all information
88- [ ] Camera follows skater movement properly
89- [ ] Speed and position values change as expected
90- [ ] FPS counter shows reasonable frame rate
91- [ ] No console errors
92
93## Troubleshooting
94
95### "Module not found" errors
96
97The POC imports modules from the main project's `src` directory. If you get errors:
98
991. Ensure you're running from the main project directory
1002. Check that the paths in `littlejs-poc.ts` are correct for your setup
1013. The alias in `vite.config.ts` maps `..` to the main project's `src`
102
103### LittleJS not initializing
104
1051. Ensure LittleJS is installed: `npm install littlejsengine`
1062. Check that the import paths are correct
1073. Verify there are no version conflicts
108
109### Three.js rendering issues
110
1111. Check that the canvas element exists with id="scene"
1122. Verify the Three.js version is compatible
1133. Look for WebGL errors in the console
114
115### Input not working
116
1171. Check browser console for errors
1182. Verify that LittleJS input system is initialized
1193. Try different browsers (some may block certain input types)
120
121## Technical Notes
122
123### Key Integration Points
124
1251. **Three.js Renderer Setup**:
126 ```typescript
127 setThreeRenderer(THREE)
128 ```
129 This tells LittleJS to use Three.js for rendering.
130
1312. **Input Handling**:
132 ```typescript
133 inputGetState('arrowLeft') // Check if key is pressed
134 inputGetAxis('mouseX') // Get mouse/touch axis
135 inputGetPressed('m') // Check if key was pressed this frame
136 ```
137
1383. **Game Loop**:
139 ```typescript
140 engineInit(init, update, updatePost, render, renderPost)
141 ```
142 LittleJS calls these functions automatically each frame.
143
1444. **Delta Time**:
145 ```typescript
146 const dt = engine.timing.lastTimeStep
147 ```
148 Use this for physics updates to ensure frame-rate independence.
149
1505. **HUD Rendering**:
151 ```typescript
152 drawTextScreen(text, position, size, color, align?)
153 ```
154 LittleJS provides simple text rendering on top of the main scene.
155
156### What's NOT in the POC (Yet)
157
158The POC is intentionally minimal. These features are not implemented but would be in the full migration:
159
1601. Audio system (would use existing `iceSound.ts`)
1612. Complex ice rendering with thickness colors
1623. Shore/bank rendering
1634. Snow and weather effects
1645. Cracks and marks
1656. Sky rendering with time of day
1667. Settings UI
1678. About dialog
1689. History/state management for lake seeds
16910. Proper tilt steering calibration
170
171## Performance Considerations
172
173The POC should run smoothly on most modern devices. Performance can be monitored via:
174
1751. FPS counter in the HUD
1762. Browser dev tools performance tab
1773. Console logs for timing information
178
179Expected performance:
180- Desktop: 60+ FPS
181- Modern mobile: 30-60 FPS
182- Older devices: 20-30 FPS
183
184## Next Steps
185
186If the POC works correctly:
187
1881. **Test on multiple devices** (desktop, mobile, tablet)
1892. **Verify all input methods** work as expected
1903. **Compare feel** with the current implementation
1914. **Measure performance** and compare with current version
1925. **Proceed with full migration** as outlined in `LITTLEJS_CONVERSION_PLAN.md`
193
194If the POC has issues:
195
1961. **Debug** the specific problems
1972. **Adjust** the integration approach
1983. **Consider** a minimal integration (just input + game loop) instead of full migration
199
200## Alternative: Testing Without POC Setup
201
202If you want to test the integration without setting up the POC separately, you can temporarily modify the main project:
203
2041. Install LittleJS in the main project: `npm install littlejsengine`
2052. Rename `src/main.ts` to `src/main.ts.backup`
2063. Copy `LITTLEJS_POC/src/littlejs-poc.ts` to `src/main.ts`
2074. Update `index.html` to use a canvas with id="scene"
2085. Run `npm run dev`
209
210Then restore the original files when done testing.