# misc/loadingprogress (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/misc/loadingprogress/

Loading progress. (original misc/loadingprogress.js)
- The shown progress (get_shown_progress) smoothly follows the progress reported by the loading stages (set_progress, 0 ~ 1, never decreasing).
  Even when downloads bunch up and the progress jumps at once, the bar slides instead of jumping.
- Call update(time_delta) every frame. The follow fraction is 1 - exp(-rate * time), so the speed is the same regardless of frame interval.

## LoadingProgress (struct) (Clone, Debug, Default)

Loading progress.
- Download stages report with set_progress, and after update every frame, draw the bar with get_shown_progress.

Example: Smoothly follow the reported progress

```rust
use vanilla::LoadingProgress;

let mut loading_progress = LoadingProgress::new();
loading_progress.set_progress(0.5);
loading_progress.update(1.0 / 60.0);
let shown_progress = loading_progress.get_shown_progress();
assert!(shown_progress > 0.0 && shown_progress < 0.5);
loading_progress.set_progress(1.0);
for _ in 0..600 {
	loading_progress.update(1.0 / 60.0);
}
assert!(loading_progress.is_finished());
```

- `pub fn new() -> LoadingProgress` (constructor, since 0.4.0): Constructor. (follow rate is 6 times the remaining distance per second)
  - returns LoadingProgress: A new progress with reported and shown progress of 0.
- `pub fn set_progress(&mut self, progress: f64)` (method, since 0.4.0): Sets the reported progress. (clamped to 0 ~ 1, ignored if less than previously reported or NaN)
  - `progress` f64: Reported progress. (0 ~ 1)
- `pub fn get_progress(&self) -> f64` (method, since 0.4.0): Returns the reported progress.
  - returns f64: The largest progress reported so far. (0 ~ 1)
- `pub fn get_shown_progress(&self) -> f64` (method, since 0.4.0): Returns the shown progress. (Read when drawing)
  - returns f64: Progress currently following the reported progress. (0 ~ 1)
- `pub fn update(&mut self, time_delta: f64)` (method, since 0.4.0): Update. (the shown progress follows the reported progress. Unchanged if the time is 0 or less or not finite)
  - `time_delta` f64: Elapsed time. (seconds, closes 1 - exp(-rate * time_delta) of the remaining distance)
- `pub fn set_follow_rate(&mut self, follow_rate: f64)` (method, since 0.4.0): Sets the follow rate. (ratio of the remaining distance per second, must be greater than 0 and finite. Otherwise unchanged)
  - `follow_rate` f64: New rate. (default 6)
- `pub fn get_follow_rate(&self) -> f64` (method, since 0.4.0): Returns the follow speed.
  - returns f64: Current rate. (ratio of the remaining distance per second)
- `pub fn is_finished(&self) -> bool` (method, since 0.4.0): Whether the shown progress has reached the end (1).
  - returns bool: true if the shown progress is at least 1.
- `pub fn reset(&mut self)` (method, since 0.4.0): Resets. (Sets the reported progress and the shown progress to 0)
