Transform vRacer from a real-time rendered game with complex animation systems to a simplified, event-driven turn-based game that maintains visual quality while reducing complexity and resource usage.
- Animation System: 353 lines (
src/animations.ts) - Performance Monitoring: 337 lines (
src/performance.ts) - 60 FPS Animation Loop: Continuous rendering in
main.ts - Complex Layering: Multi-layer transparency system in
game.ts - Particle Systems: Real-time particle physics for visual effects
- CPU Usage: Continuous 60 FPS rendering loop
- Battery Drain: Unnecessary for turn-based gameplay
- Code Complexity: ~700+ lines of animation/performance code
- Maintenance Overhead: Multiple systems to debug and maintain
Goal: Test game without animations to validate functionality Impact: Immediate performance improvement, no code removal yet Risk Level: Low (easily reversible)
- Set
animations: falsein feature flags - Test all game functionality
- Measure performance improvement
- Document any visual regressions
- ✅ All gameplay mechanics work correctly
- ✅ No JavaScript errors in console
- ✅ Mouse interactions still responsive
- ✅ Game state changes render correctly
Goal: Replace continuous rendering with event-driven rendering Impact: Eliminate 60 FPS loop, major resource savings Risk Level: Medium (requires careful event handling)
- Remove
animationLoop()function frommain.ts - Replace with
render()calls on specific events:- Player moves (mouse click, keyboard input)
- UI state changes (toggles, hover)
- Game state updates (new game, reset)
- Update mouse hover handling to trigger renders
- Test responsiveness of all interactions
// REMOVE: Continuous animation loop
// if (isFeatureEnabled('animations')) {
// animationLoop()
// }
// REPLACE WITH: Event-driven rendering
function renderOnEvent() {
render()
}
// Call renderOnEvent() on:
// - canvas click events
// - mouse move (for hover effects)
// - keyboard inputs
// - toggle changes
// - game state updates- ✅ Game renders immediately on user interaction
- ✅ Hover effects still work smoothly
- ✅ No visual lag or missing updates
- ✅ CPU usage drops significantly when idle
Goal: Replace complex performance system with minimal debug info Impact: Remove 300+ lines of performance tracking code Risk Level: Low (debug feature, not core gameplay)
- Create minimal performance tracker (10-20 lines)
- Keep only basic render time logging for debug mode
- Remove frame time arrays, FPS calculations, memory tracking
- Update HUD to show simplified debug info
// Minimal performance tracking
class SimplePerformanceTracker {
private renderStart = 0
startRender() {
if (isFeatureEnabled('debugMode')) {
this.renderStart = performance.now()
}
}
endRender() {
if (isFeatureEnabled('debugMode') && this.renderStart > 0) {
const renderTime = performance.now() - this.renderStart
console.log(`Render time: ${renderTime.toFixed(2)}ms`)
}
}
}- ✅ Debug mode still shows basic render info
- ✅ No performance tracking overhead in production
- ✅ Bundle size reduced significantly
Goal: Delete animation system code and dependencies Impact: Remove 350+ lines, clean up imports Risk Level: Low (already disabled and tested)
- Delete
src/animations.ts - Remove animation imports from
main.tsandgame.ts - Remove animation manager references in draw function
- Update TypeScript types if needed
- Clean up any animation-related feature flags
- DELETE:
src/animations.ts - UPDATE:
src/main.ts(remove imports, animation references) - UPDATE:
src/game.ts(remove particle rendering) - UPDATE:
src/features.ts(remove animations flag)
- ✅ TypeScript compiles without errors
- ✅ No animation-related imports or references
- ✅ Game functions identically to Phase 1 testing
Goal: Reduce complexity in rendering layers and effects Impact: Cleaner, more maintainable rendering code Risk Level: Medium (core rendering logic)
- Simplify LayerManager opacity system
- Remove unnecessary layering complexity
- Streamline canvas drawing operations
- Keep essential visual elements:
- Track boundaries and surface
- Car positions with colors
- Move candidates
- Basic hover effects
- Grid and coordinates
// SIMPLIFY: Complex layering system
// Remove excessive transparency layers
// Keep only essential visual hierarchy:
// 1. Background (paper + grid)
// 2. Track (surface + borders)
// 3. Game elements (cars, trails, candidates)
// 4. UI feedback (hover, selection)- ✅ Visual quality maintained
- ✅ All game elements clearly visible
- ✅ Simplified code structure
- ✅ Faster rendering performance
Goal: Simple static replacements for dynamic effects Impact: Maintain visual feedback without complexity Risk Level: Low (purely cosmetic)
- Replace particle explosions with simple color changes
- Replace celebration effects with static success indicators
- Add simple visual feedback for crashes/wins
- Ensure accessibility of visual cues
// Instead of particle explosion:
function showCrashEffect(pos: Vec, ctx: CanvasRenderingContext2D, g: number) {
// Simple red flash or X mark
ctx.fillStyle = '#ff4444'
ctx.fillRect(pos.x * g - 5, pos.y * g - 5, 10, 10)
}
// Instead of celebration particles:
function showWinEffect(pos: Vec, ctx: CanvasRenderingContext2D, g: number) {
// Simple checkmark or star
ctx.fillStyle = '#44ff44'
// Draw checkmark shape
}- Backup current codebase
- Run full test suite to establish baseline
- Document current performance metrics
- Create feature branch for simplification work
- Update
animations: falseinsrc/features.ts - Test game functionality comprehensively
- Measure performance impact
- Document any issues or regressions
- Remove
animationLoop()fromsrc/main.ts - Add
render()calls to event handlers - Update mouse move handler for hover effects
- Test all interaction responsiveness
- Verify CPU usage improvement
- Create
SimplePerformanceTrackerclass - Replace complex performance system
- Update HUD debug display
- Test debug mode functionality
- Delete
src/animations.ts - Remove animation imports and references
- Clean up TypeScript compilation
- Update feature flags
- Verify no broken dependencies
- Streamline
draw()function insrc/game.ts - Simplify LayerManager complexity
- Remove unnecessary transparency layers
- Maintain visual quality standards
- Implement simple crash feedback
- Add basic win/success indicators
- Test visual accessibility
- Ensure all feedback is clear
- Full functionality test
- Performance comparison (before/after)
- Code review for cleanup opportunities
- Update documentation and README
- Bundle size analysis
- CPU Usage: 90%+ reduction when game is idle
- Battery Life: Significant improvement on mobile devices
- Memory Usage: Lower baseline memory consumption
- Startup Time: Faster initial load with smaller bundle
- Lines of Code: ~700 line reduction (20% smaller codebase)
- Complexity: Fewer interdependent systems
- Maintainability: Simpler debugging and feature development
- Bundle Size: Smaller JavaScript payload
- Build Time: Faster TypeScript compilation
- Debug Experience: Less noise in performance monitoring
- Feature Development: Cleaner architecture for new features
- Bug Fixing: Fewer systems to consider during debugging
- Core Gameplay: All turn-based mechanics
- Multi-car Support: Player switching, collisions
- UI Interactions: Mouse clicks, keyboard shortcuts
- Visual Quality: Track rendering, car display
- Feature Flags: All toggleable features work
- Mobile Responsiveness: Touch interactions, layout
- Resource Usage: CPU, memory monitoring
- Responsiveness: Input lag measurements
- Battery Impact: Mobile device power consumption
- Bundle Analysis: JavaScript size comparison
- Visual Feedback: Clear game state communication
- Interaction Smoothness: No perceived lag
- Accessibility: Visual cues remain clear
- Error Handling: Graceful degradation
- Git branch with all changes for easy revert
- Feature flag toggles for gradual rollout
- Performance baseline documentation for comparison
Each phase requires sign-off before proceeding:
- Functionality verification
- Performance validation
- Visual quality approval
- User experience confirmation
- Console error tracking during development
- User feedback collection after deployment
- Performance metric comparison
This plan provides a systematic approach to simplifying vRacer's rendering system while maintaining game quality and minimizing risk. Each phase builds on the previous one, allowing for validation and course correction along the way.
Next Step: Phase 1 implementation - disabling animations and testing functionality.