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.
Nonekeys are always independent. - Notice
Queue - Fixed inline storage with stable descending-priority presentation order.
- Notice
Rejected - A rejected insertion retains ownership of its entire input.
- Notice
Time Error - Invalid delta: nonfinite or negative. No time or entries were changed.
- Notice
View - A presentation snapshot borrowing the queue; iteration never consumes text.
Enums§
- Notice
Change - Successful submission, returning payloads the queue no longer needs. No caller payload/key destructor is invoked by successful submission itself.
- Notice
Duplicate - Policy for an existing matching key. This is grouping, not event deduplication.
- Notice
Lifetime - Expiry policy when a matching key is coalesced successfully.
- Notice
Priority - Higher priorities appear first and can displace strictly lower priorities.
- Notice
Rejection - Rejection leaves queue contents and expiry unchanged.