phichain-compiler
Thephichain-compiler crate compiles Phichain charts into a primitive format suitable for gameplay. It performs optimizations like merging child lines, evaluating curve note tracks, and flattening the chart structure.
Installation
Add this to yourCargo.toml:
Dependencies
The crate depends on:phichain-chart(chart data structures)num0.4.3 (numerical computations)anyhow1.0 (error handling)nalgebra0.33.1 (linear algebra for transformations)
Core Function
Compile a Phichain chart into a primitive chart format.The compilation process:
- Merges child lines into their parents with proper transformations
- Evaluates curve note tracks to generate individual notes
- Converts to primitive chart format
Compilation Steps
1. Merge Child Lines
Child lines are merged into their parent lines by applying transformations:- Position offsets are combined
- Rotations are accumulated
- Events are transformed to parent coordinate space
- Notes are repositioned relative to parent
2. Evaluate Curve Note Tracks
Curve note tracks define smooth note patterns between two anchor notes. The compiler:- Samples points along the bezier curve
- Generates individual notes at each sample point
- Interpolates properties (speed, x position) along the curve
- Removes the curve track definition
3. Convert to Primitive Format
The final primitive chart:- Has a flat line structure (no nesting)
- Contains only basic note types
- Uses simple transition events
- Is optimized for fast rendering and gameplay
Primitive Chart Format
The compiled primitive chart format.
Complete Example
Understanding Compilation
Why Compile?
Phichain charts support advanced features like:- Nested lines - Child lines with relative transformations
- Curve note tracks - Smooth note patterns defined by bezier curves
- Complex events - Layered transformations and animations
Performance Benefits
Compilation Optimizations
Compilation Optimizations
- Flattened hierarchy - Eliminates nested line transformations during gameplay
- Pre-computed notes - Curve tracks are expanded into individual notes
- Simplified events - Complex event chains are resolved
- Reduced memory - Compact primitive format uses less memory
- Faster parsing - Simple structure for quick deserialization
When to Compile
Compilation Use Cases
Compilation Use Cases
- Before distribution - Ship compiled charts for better performance
- Chart validation - Verify charts compile without errors
- Performance testing - Test gameplay with optimized charts
- Cross-platform - Ensure charts work on all target platforms
- Editor preview - Quick preview of compiled output
Advanced Usage
Custom Compilation Pipeline
You can implement custom compilation steps:Error Handling
Compilation can fail for several reasons:See Also
- phichain-chart - Source chart format
- phichain-game - Use compiled charts in the game engine
- Chart Formats - Understanding chart structure