Struct FeedbackController

Source
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: u64

Implementations§

Source§

impl<const N: usize> FeedbackController<N>

Source

pub fn new( config: FeedbackConfig, seed: u64, ) -> Result<FeedbackController<N>, FeedbackError>

Source

pub fn policy(&self) -> FeedbackPolicy

Current visual preferences, also usable by host animation adapters.

Source

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());
Source

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.

Source

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.

Source

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());
Source

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.

Source

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);
Source

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);
Source

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.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for FeedbackController<N>

§

impl<const N: usize> RefUnwindSafe for FeedbackController<N>

§

impl<const N: usize> Send for FeedbackController<N>

§

impl<const N: usize> Sync for FeedbackController<N>

§

impl<const N: usize> Unpin for FeedbackController<N>

§

impl<const N: usize> UnwindSafe for FeedbackController<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.