Skip to main content

Module onebit

Module onebit 

Source
Expand description

The one-bit renderer (game ADR-0074): draws a GlyphBuffer the size of the Playdate’s screen (50 × 15 cells of 8 × 16 pixels, ConsoleSpec::text) into a 400 × 240 one-bit Frame laid out as the Playdate’s own frame buffer, so its front end copies it to the screen as it is.

Colours become Shades, 8 × 8 patterns fixed to the screen’s pixels (so neighbouring tiles line up and patterns don’t swim when things move), as a Shades says. Two say it:

  • The game’s inks (InkShades, game ADR-0074): a colour that is an ink’s reserved code (the Playdate’s palette is made of them) is drawn in that ink, any other one white or black by its brightness. render draws with them.
  • Roles’ patterns (PatternMap, ADR-0008 §4): the skin’s palette names its colours by role, and its pattern map gives each role a foreground and a background Pattern. A colour of no role is dithered by its luminance; a glyph’s is solid, white or black, as text is never dithered. to_one_bit draws with them.

The order: the white ground; a backdrop’s scene in its window (game ADR-0048), drawn the same way; then the cell backgrounds, Under items, the white edges of Ink::BlackEdged glyphs, the glyphs (each half of a wide one in its own cell: the font’s one-bit atlas keeps the halves as two cells), Over items, and last the Ink::Invert rectangles, which flip what is under them. Pictures are one-bit Images (docs/design/playdate.md, One-bit pictures). A painted picture (ADR-0078) is looked up in the frame’s table: a one-bit one is drawn as a one-bit sprite, an RGBA or indexed one dithered as it is drawn (dither_row). Nothing here allocates.

Made for the device’s speed (ticket 1055, game ADR-0077): 32-bit coordinates, a pattern’s byte looked up, whole bytes written whole (a sprite’s too, ticket 3056), only the cells near the part being drawn visited, and render_changed redraws only where a frame differs from the last. reference is the plain renderer this one must equal.

Structs§

Font
The font as the one-bit renderer reads it: the glyph map and the one-bit atlas the game gives.
Image
A one-bit picture: height rows of stride bytes, a byte’s highest bit its left pixel, a set bit white; and optionally a mask of the same shape, a set bit where the picture is drawn (the Playdate’s own bitmap layout). Without a mask every pixel is drawn.
InkShades
The game’s inks (game ADR-0074): everything in rgb is drawn in ink_of(rgb).
OneBitFrame
A one-bit picture of the display, 400 × 240, in the Playdate’s layout: each row ROW_BYTES bytes (padded to a whole number of 32-bit words, as its display takes them), a byte’s highest bit its left pixel, a set bit white.
Pattern
A pattern of 8 × 8 pixels: one of the Base patterns, or one of them inverted. A pattern map spells it Dither50 or Inverted(Dither50).
PatternMap
What each colour of a skin’s palette is drawn in on a one-bit target: the patterns of its role, by the skin’s pattern map. A colour that is no role’s is dithered by its luminance (Bayer 8 × 8, as dither does); a glyph in it is white or black, whichever is nearer, as text is never dithered.
PatternMapDef
A pattern map: each palette role’s patterns on a one-bit target, the groups of roles that must stay distinct, and the roles text is drawn in.
RolePatterns
A role’s two patterns: fg for what is drawn in its colour (a glyph, a rectangle, a sprite painted in it), bg for a cell’s background in it (fg again, if the map doesn’t say).
RowMask
A set of the display’s rows, a bit each.
Shade
How a colour is drawn: an 8 × 8 pattern fixed to the screen, and what two of the game’s inks do besides.

Enums§

Base
One of the fixed patterns, before any inversion: black and white solids, three ordered dithers, and four kinds of line.
Phase
The steps of a render, in order, for timing them on the device (render_marked).

Constants§

FRAME_BYTES
Bytes in a Frame.
HEIGHT
The screen’s height in pixels.
ROW_BYTES
Bytes per row of a Frame: the Playdate’s stride (50 bytes of pixels, 2 unused).
WIDTH
The screen’s width in pixels.

Traits§

Images
Where the renderer finds a sprite’s one-bit picture.
Shades
What a frame’s colours are drawn in.

Functions§

changed_rows
The rows new differs from old in.
dither_row
The eight pixels of a frame byte on screen row y (a byte’s first pixel is always at a multiple of 8 across) whose brightnesses are light (0 black to 255 white, the first the leftmost), dithered as ADR-0078 says: pixel i is white where 4 × BAYER[y % 8][i] + 2 ≥ 255 − light[i] (shuyi_assets::onebit::BAYER), the Bayer dither of shuyi bake at the screen’s pixels. Its highest bit is the leftmost pixel, a set bit white. Integers only: the same on every platform.
ink_is_white
Whether ink makes screen pixel (x, y) white. Ink::BlackEdged and Ink::Invert are black here: the edge is drawn around glyphs, and only rectangles flip.
ink_of
The ink a colour is drawn in: the ink it is the code of, or else white if it is at least half bright (in the eye’s weighting of red, green and blue), black if not.
is_white
Whether pixel (x, y) of frame is white; off the screen, false.
luminance
A colour’s luminance, 0 (black) to 255 (white), in integer Rec. 601 weights: (77 r + 150 g + 29 b) >> 8.
render
Draws buf into out in the game’s inks (InkShades), from its top-left corner; whatever lies past 400 × 240 pixels is cut off. See the module for the order.
render_changed
Makes out, which holds old as render drew it, hold new as render would draw it, redrawing only the 8 × 16 pixel tiles of the screen where they may differ: around a changed cell (one pixel more for a glyph’s edge), under a changed item (the old and the new one), the window of a changed backdrop, and a painted item whose picture changed.
render_changed_with
render_changed, the colours drawn as shades says (as they were for old).
render_marked
render, calling mark as each Phase ends (the Playdate’s bench build times them).
render_marked_with
render_with, calling mark as each Phase ends.
render_with
render, its colours drawn as shades says.
to_one_bit
Draws frame as a one-bit target shows it: its colours in their roles’ patterns by map, glyphs from font, sprites’ one-bit pictures from images (render_with). The frame is drawn from the display’s top-left corner, and what lies past 400 × 240 pixels is cut off.

Type Aliases§

Frame
A one-bit picture of the screen in the Playdate’s layout: row after row of ROW_BYTES bytes, a byte’s highest bit its left pixel, a set bit white.
Rows
The eight rows of a pattern: a row’s highest bit is its left pixel, a set bit white, as in the Playdate’s frame buffer.