ffb-engine-development
Critical constraints and patterns for developing high-performance FFB logic
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
FFB Engine Development
Use this skill when modifying FFBEngine.h or any physics calculation logic.
Technical Constraints
1. The 400Hz Core Loop
-
FFBEngine::calculate_forceruns on a high-priority thread. -
NO HEAP ALLOCATION:
new,malloc,std::vector::push_back, etc., are strictly prohibited inside the core loop.
2. Phase Accumulation
- For any oscillating effects (sine waves, vibrations), use Phase Accumulation.
- ❌ Wrong:
sin(time * frequency)(Causes audio/tactile clicks when frequency changes). - ✅ Right:
m_phase += frequency * dt; output = sin(m_phase);
3. Coordinate Systems (LMU vs DirectInput)
- LMU/rFactor 2: Left-handed system (+X = Left).
- DirectInput: +Force = Right.
- Rule: Lateral forces (SoP, Rear Torque, Scrub Drag) must be INVERTED (negated) to produce the correct DirectInput force (Left).
-
Stability: Never use
abs()on lateral velocity for direction-dependent logic (like counter-steering); it destroys the sign.
4. Continuous Physics State (Anti-Glitch)
- Rule: Low Pass Filters (LPF) and physics state variables (Slip Angle, RPM smoothing) must be updated EVERY TICK.
- Reason: Stopping updates when telemetry is "unhealthy" makes filter states stale. Resuming later causes massive force spikes.
- Implementation: Ensure filters are updated outside of conditional blocks.
5. Reliability Standards
-
Validate Inputs: Check telemetry inputs for
NaNorInfusingstd::isfinite(). - Clamp Outputs: Ensure final FFB force output is always in the range [-1.0, 1.0] before sending to drivers.
-
Thread Safety: Access any shared state (like gains/settings) under
g_engine_mutex. -
Safe Gains: Use
std::clamp()to keep gain multipliers within safe predefined limits (e.g., [0.0, 10.0]).
Planning for FFB Effects
Before modifying FFB logic, analyze:
- Affected Effects: List all impacted physics behaviors (e.g., ABS, Understeer).
- User Impact: How will the FFB "feel" change? Do preset values need tuning?
- Data Flow: Trace how new telemetry fields or derived values reach the final force calculation.
Implementation Pattern for New Effects
- Add toggle and gain float to
FFBEngine. - Add phase accumulator variable if needed.
- Implement logic in
calculate_force. - Add visualization data to
FFBSnapshot. - Update
Config.h/cppfor persistence. - New features should default to
falseor0.0.
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!