Expand description
An animated LOADING indicator for the stretches where a program is blocked on the disc.
A load that blocks for seconds (a chain-load, a pack read, a sound bank
streamed to the SPU) leaves the picture frozen, and a frozen picture reads
as a hang. This crate draws the one thing such a picture needs: a label
(Loading) with a tail that steps (trailing dots, or a ring of lights)
and an ink that breathes, so the screen visibly moves while the CPU is busy
elsewhere.
The adoption guide, game by game, is sdk/docs/LOADING-INDICATOR.md.
The look every PSoXide game uses is the corner widget: a small black
square in the bottom-right corner of the picture with a little animation in it
and no text (Style::in_corner with an empty label). The animation is the
game’s own: the built-in ring of lights in the game’s colours (Tail::Spinner)
or art it draws itself (Tail::Art). A label with dots is there for
programs that want words.
§Design
- Plain rectangles. Every glyph is drawn as GP0(60h) monochrome
rectangles from a [
psx_font::BitmapFont]’s 1-bit source, so the indicator needs no texture, no CLUT and no atlas, and disturbs no texture state. That is what lets one implementation serve a chain-load blob (nothing in VRAM but the picture), a game mid-boot and a menu with its own atlases. A game picks its look by giving the font, the scale, the inks, the backing colour and where the box sits (Style). - Polled, never waiting.
Indicator::polltakes the caller’s tick (one per VBlank) and draws only when the picture would change: at most once a VBlank, never waiting for one. A blocking loop calls it between its own steps (after each CD sector, each spin of a seek wait). Nothing here runs in an interrupt, so a draw never overlaps the caller’s own GPU traffic. - No hardware owned. The indicator builds GP0 packets and hands them to
a
Sink;Gp0(guest only) is the sink that writes them to the GPU with the one-wait-per-packet pacing the silicon needs. A host test sink records them, which is how the layout and the animation are tested. - No float, no 64-bit, no heap. Colours blend in integer steps and the breathing is a triangle wave over a sixteen-step ramp.
The caller owns the GPU state the rectangles are drawn under: the drawing
area and offset must cover the box, and the mask bit and draw mode must be
at their defaults (see prepare).
use psx_font::fonts::BASIC_8X16;
use psx_loading::{Indicator, Rgb, Sink, Style};
struct Count(usize);
impl Sink for Count {
fn packet(&mut self, _words: &[u32]) {
self.0 += 1;
}
}
const STYLE: Style = Style::new(&BASIC_8X16, "Loading", Rgb(200, 120, 20), Rgb(5, 5, 7));
let mut indicator = Indicator::new(STYLE);
let mut sink = Count(0);
// The first poll draws; the same tick again draws nothing.
assert!(indicator.poll(&mut sink, 0));
assert!(!indicator.poll(&mut sink, 0));Structs§
- Gp0
- The sink that writes packets to the GPU’s command port.
- Indicator
- A running indicator.
- Look
- What the indicator shows at one tick.
- Rgb
- An 8-bit-per-channel colour, as the GP0 rectangle commands take it.
- Style
- What the indicator looks like and where it sits.
Enums§
- Blend
- How the spinner’s lights combine with what is under them (the GPU’s semi-transparency modes, set through the draw-mode word GP0(E1h)).
- Tail
- What follows the label and moves.
Constants§
- LEVELS
- Steps of the breathing ramp: the ink is
ink_dimat level 0 andink_brightat this level.
Traits§
- Sink
- Where the indicator’s GP0 packets go.