Module notices

Source
Expand description

Bounded transient text/semantic notices, driven by accepted game events.

Storage is inline, with no allocation by the queue. Payloads and keys may borrow caller data or use fixed-size types; their own allocations and work are the caller’s responsibility. The queue neither validates game actions nor deduplicates event IDs: deliver each accepted event once, after rules run (and after any network/event deduplication). A key groups notices, not events. Keep must-read outcomes/result panels outside this transient queue.

All live entries age, including those hidden by higher priorities. The host chooses simulation or presentation seconds in NoticeQueue::advance; no clock, renderer, motion/flash preference or gameplay state is consulted. Render the same text under reduced motion, suppressing only host animation.

This Pinball-style recipe consumes an accepted-score stream, never a score difference or an attempted bumper hit. Its saturating sum is explicit caller policy; a rejected request produces no accepted-score event. A real Pinball adapter can feed PinballFeedback::points after each advance exactly once.

use ferravex_play::ui::notices::{
    Notice, NoticeChange, NoticeLifetime, NoticePriority, NoticeQueue,
};

#[derive(Debug, PartialEq)]
struct RecoveredPoints(u32);
enum RuleResult { AcceptedScore(u32), RejectedRequest }
let events = [RuleResult::AcceptedScore(100), RuleResult::RejectedRequest,
              RuleResult::AcceptedScore(200)];
let mut notices = NoticeQueue::<4, RecoveredPoints>::new();
for event in events {
    if let RuleResult::AcceptedScore(points) = event {
        let change = notices.coalesce_with(Notice {
            key: Some(1), priority: NoticePriority::Normal,
            message: RecoveredPoints(points), lifetime_seconds: 2.,
        }, NoticeLifetime::Refresh, |a, b| {
            RecoveredPoints(a.0.saturating_add(b.0))
        }).unwrap();
        // Every displaced/incoming payload is returned for caller disposal.
        assert!(matches!(change, NoticeChange::Inserted { evicted: None }
            | NoticeChange::Coalesced { .. }));
    }
}
assert_eq!(notices.front().unwrap().notice.message, RecoveredPoints(300));
assert_eq!(notices.advance(0.5), Ok(0));
assert_eq!(notices.front().unwrap().remaining_seconds, 1.5);
let dismissed = notices.dismiss(&1).unwrap();
assert_eq!(dismissed.message.0, 300);
notices.clear(); // Restart transient presentation; no game state is changed.
assert!(notices.is_empty());

Structs§

Notice
Caller-owned notice specification. None keys are always independent.
NoticeQueue
Fixed inline storage with stable descending-priority presentation order.
NoticeRejected
A rejected insertion retains ownership of its entire input.
NoticeTimeError
Invalid delta: nonfinite or negative. No time or entries were changed.
NoticeView
A presentation snapshot borrowing the queue; iteration never consumes text.

Enums§

NoticeChange
Successful submission, returning payloads the queue no longer needs. No caller payload/key destructor is invoked by successful submission itself.
NoticeDuplicate
Policy for an existing matching key. This is grouping, not event deduplication.
NoticeLifetime
Expiry policy when a matching key is coalesced successfully.
NoticePriority
Higher priorities appear first and can displace strictly lower priorities.
NoticeRejection
Rejection leaves queue contents and expiry unchanged.