pub struct FeedbackController<const N: usize> {
pub dropped: u64,
/* private fields */
}Expand description
Allocation-free feedback with 1..=128 recent IDs and at most N accepted
events between successful advance calls. Camera shake has
its own bounded eight-impulse pool; its overflow never suppresses sound.
Impact emphasis and flash use two scalar envelopes with no per-event storage.
Fields§
§dropped: u64Implementations§
Source§impl<const N: usize> FeedbackController<N>
impl<const N: usize> FeedbackController<N>
pub fn new( config: FeedbackConfig, seed: u64, ) -> Result<FeedbackController<N>, FeedbackError>
Sourcepub fn policy(&self) -> FeedbackPolicy
pub fn policy(&self) -> FeedbackPolicy
Current visual preferences, also usable by host animation adapters.
Sourcepub fn set_policy(&mut self, policy: FeedbackPolicy)
pub fn set_policy(&mut self, policy: FeedbackPolicy)
Applies validated preferences to pending as well as future frame output.
Disabled channels are cleared, so re-enabling them cannot replay an old
effect. Fractional intensity changes rescale pending frame output on the
next advance. Does not consume IDs or alter sound/rumble/configuration.
use ferravex_play::feedback::{FeedbackController, FeedbackPolicy};
let mut feedback = FeedbackController::<8>::new(Default::default(), 1).unwrap();
feedback.set_policy(FeedbackPolicy::new(true, false, 1.).unwrap());
assert!(feedback.policy().reduced_motion());Sourcepub fn configure(&mut self, config: FeedbackConfig) -> Result<(), FeedbackError>
pub fn configure(&mut self, config: FeedbackConfig) -> Result<(), FeedbackError>
Replaces valid configuration, clamping active emphasis to config.motion
and active flash to config.flash. Zero clears the respective envelope;
increasing a limit does not restore a cleared or clamped level. Invalid
configuration leaves all state unchanged.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all transient output, pending capacity and remembered IDs for a
restart. Preserves configuration, visual preferences, the shake seed
sequence and the cumulative dropped diagnostic. Previously used IDs
can be reused after this call.
Sourcepub fn emit_if_accepted(
&mut self,
id: u64,
accepted: bool,
event: FeedbackEvent,
) -> Result<Option<FeedbackResponse>, FeedbackError>
pub fn emit_if_accepted( &mut self, id: u64, accepted: bool, event: FeedbackEvent, ) -> Result<Option<FeedbackResponse>, FeedbackError>
Emits only when game rules accepted the action. Rejected actions return
Ok(None) without validating/reserving the ID, consuming burst capacity
or changing output. Accepted actions have the same validation, duplicate
suppression and return value as emit.
use ferravex_math::Vec3;
use ferravex_play::feedback::{FeedbackController, FeedbackEvent};
let mut feedback = FeedbackController::<1>::new(Default::default(), 1).unwrap();
let shot = FeedbackEvent::fire(Vec3::ZERO, 1.).unwrap();
assert!(feedback.emit_if_accepted(7, false, shot).unwrap().is_none());
assert!(feedback.emit_if_accepted(7, true, shot).unwrap().is_some());
assert!(feedback.emit_if_accepted(7, true, shot).unwrap().is_none());Sourcepub fn emit(
&mut self,
id: u64,
event: FeedbackEvent,
) -> Result<Option<FeedbackResponse>, FeedbackError>
pub fn emit( &mut self, id: u64, event: FeedbackEvent, ) -> Result<Option<FeedbackResponse>, FeedbackError>
IDs must be nonzero and unique in this controller’s current session. The bounded N-event dedup horizon supplements, rather than replaces, netcode ACKs.
Sourcepub fn impact(&self) -> ImpactSample
pub fn impact(&self) -> ImpactSample
Reads the current impact envelopes with live visual preferences applied. Does not advance time, release burst capacity, consume IDs or replay cues. Disabling a channel clears its stored level, so re-enabling cannot revive an old impact. Fractional policy changes rescale the current level.
use ferravex_math::Vec3;
use ferravex_play::feedback::{FeedbackController, FeedbackEvent, FeedbackPolicy};
let mut feedback = FeedbackController::<8>::new(Default::default(), 1).unwrap();
feedback.emit(1, FeedbackEvent::hurt(Vec3::ZERO, 1.).unwrap()).unwrap();
assert_eq!(feedback.impact().emphasis, 0.7);
feedback.set_policy(FeedbackPolicy::new(true, false, 1.).unwrap());
assert_eq!(feedback.impact().emphasis, 0.);
assert_eq!(feedback.impact().flash, 0.7);Sourcepub fn advance_with_impact(
&mut self,
dt: f32,
) -> Result<(FeedbackFrame, ImpactSample), FeedbackError>
pub fn advance_with_impact( &mut self, dt: f32, ) -> Result<(FeedbackFrame, ImpactSample), FeedbackError>
Advances presentation once and returns a frame with its matching impact
sample. Both scalar channels are sampled before decay, preserving the
existing flash timing and showing newly accepted impacts at their peak.
A subsequent impact reads the decayed state.
Use this in place of advance, not in addition to it.
It accepts finite presentation deltas in 0..=0.25; an invalid delta
leaves all state unchanged. Neither method advances or pauses gameplay,
networking or replay. Emphasis works in networked mode even though
presentation hit-stop is disabled there.
use ferravex_math::Vec3;
use ferravex_play::feedback::{FeedbackConfig, FeedbackController, FeedbackEvent};
let config = FeedbackConfig { networked: true, ..Default::default() };
let mut feedback = FeedbackController::<8>::new(config, 1).unwrap();
feedback.emit(1, FeedbackEvent::hurt(Vec3::ZERO, 1.).unwrap()).unwrap();
let (frame, impact) = feedback.advance_with_impact(1. / 60.).unwrap();
assert_eq!(impact.emphasis, 0.7);
assert_eq!(impact.flash, frame.flash);
assert_eq!(frame.hitstop_seconds, 0.);
assert!(feedback.impact().emphasis < impact.emphasis);Sourcepub fn advance(&mut self, dt: f32) -> Result<FeedbackFrame, FeedbackError>
pub fn advance(&mut self, dt: f32) -> Result<FeedbackFrame, FeedbackError>
Samples feedback and advances its presentation envelopes by finite dt
in 0..=0.25 seconds. Flash, rumble and hit-stop are sampled before decay;
camera shake is sampled after its advance. Invalid time leaves all state
unchanged. Also decays hit emphasis when using this existing entry point.