pub struct RenderBudget { /* private fields */ }Implementations§
Source§impl RenderBudget
impl RenderBudget
pub fn new(target_fps: f32) -> Result<RenderBudget, PerformanceError>
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Changing this setting restores full scale and starts a fresh warm-up. Repeating the current setting leaves history and the last reason intact.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Restore full presentation scale and begin a new measurement warm-up. Keeps the target FPS and enabled setting. Use after a scene/restart or timing-source change; it does not touch simulation or user preferences.
use ferravex_play::performance::{BudgetReason, BudgetSample, RenderBudget};
let mut budget = RenderBudget::new(60.)?;
budget.set_enabled(true);
let sample = BudgetSample {
frame_ms: 35., cpu_ms: 2., gpu_ms: Some(30.), paused: false,
};
for _ in 0..38 { // Eight warm-up samples, then 30 overload observations.
budget.observe(sample)?;
}
assert_eq!(budget.level(), 1);
assert_eq!(budget.state().reason, BudgetReason::LoweredQuality);
budget.reset();
assert_eq!(budget.scale(), 1.);
assert!(budget.state().enabled);
assert_eq!(budget.state().reason, BudgetReason::Reset);
assert_eq!(budget.state().warmup_remaining, 8);Sourcepub fn state(&self) -> BudgetState
pub fn state(&self) -> BudgetState
Inspect warm-up, hysteresis and the last reason without consuming data.
BudgetDecision and the existing observation API remain unchanged.
use ferravex_play::performance::{BudgetReason, BudgetSample, RenderBudget};
let mut budget = RenderBudget::default();
budget.set_enabled(true);
let decision = budget.observe(BudgetSample {
frame_ms: 16., cpu_ms: 2., gpu_ms: Some(8.), paused: false,
})?;
assert!(!decision.changed);
let state = budget.state();
assert_eq!(state.reason, BudgetReason::WarmingUp);
assert_eq!(state.warmup_remaining, 7);
assert_eq!(state.smoothed_gpu_ms, Some(8.));pub fn level(&self) -> u8
pub fn scale(&self) -> f32
Sourcepub fn observe(
&mut self,
s: BudgetSample,
) -> Result<BudgetDecision, PerformanceError>
pub fn observe( &mut self, s: BudgetSample, ) -> Result<BudgetDecision, PerformanceError>
Only confirmed, valid GPU measurements can lower fidelity. High CPU load, unavailable timers and background gaps never masquerade as GPU pressure.
The first eight consecutive eligible samples seed the exponential filter (weight 0.12). Subsequent samples add one overload point only when both current and smoothed GPU times exceed 110% of the target frame budget; otherwise two points decay. Thirty points lower quality one level. Recovery needs 180 consecutive samples with both times below 65%. Each change starts a 120-eligible-sample cooldown; evidence may accumulate during it. Scales remain bounded to 1.0 through 0.5 in steps of 0.125.
Paused, CPU-bound, missing-GPU and over-250-ms frames discard filter and
evidence history and require fresh warm-up, retaining scale and cooldown.
They do not advance the cooldown. Invalid data returns an error without
mutation. Self::state explains the decision; no clocks are consulted.
Trait Implementations§
Source§impl Clone for RenderBudget
impl Clone for RenderBudget
Source§fn clone(&self) -> RenderBudget
fn clone(&self) -> RenderBudget
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more